Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Attributes
nsFontXlibSubstitute Class Reference
Inheritance diagram for nsFontXlibSubstitute:
Inheritance graph
[legend]
Collaboration diagram for nsFontXlibSubstitute:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsFontXlibSubstitute (nsFontXlib *aFont)
virtual ~nsFontXlibSubstitute ()
virtual XFontStruct * GetXFontStruct (void)
virtual nsXFontGetXFont (void)
virtual PRBool GetXFontIs10646 (void)
virtual int GetWidth (const PRUnichar *aString, PRUint32 aLength)
virtual int DrawString (nsRenderingContextXlib *aContext, nsIDrawingSurfaceXlib *aSurface, nscoord aX, nscoord aY, const PRUnichar *aString, PRUint32 aLength)
virtual PRUint32 Convert (const PRUnichar *aSrc, PRUint32 aSrcLen, PRUnichar *aDest, PRUint32 aDestLen)
void LoadFont (void)
PRBool IsEmptyFont (XFontStruct *)
int SupportsChar (PRUnichar aChar)

Public Attributes

nsFontXlibmSubstituteFont
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
nsFontMetricsXlibContext
mFontMetricsContext
PRUint16mCCMap
nsFontCharSetInfoXlibmCharSetInfo
char * mName
nsFontXlibUserDefinedmUserDefinedFont
PRUint16 mSize
PRInt16 mBaselineAdjust
PRInt16 mMaxAscent
PRInt16 mMaxDescent

Protected Attributes

XFontStruct * mFont
XFontStruct * mFontHolder
nsXFontmXFont
PRPackedBool mAlreadyCalledLoadFont

Detailed Description

Definition at line 3348 of file nsFontMetricsXlib.cpp.


Constructor & Destructor Documentation

Definition at line 3373 of file nsFontMetricsXlib.cpp.

Definition at line 3379 of file nsFontMetricsXlib.cpp.

{
  // Do not free mSubstituteFont here. It is owned by somebody else.
}

Member Function Documentation

PRUint32 nsFontXlibSubstitute::Convert ( const PRUnichar aSrc,
PRUint32  aSrcLen,
PRUnichar aDest,
PRUint32  aDestLen 
) [virtual]

Definition at line 3385 of file nsFontMetricsXlib.cpp.

{
  nsresult res;
  if (!mFontMetricsContext->mFontSubConverter) {
    mFontMetricsContext->mFontSubConverter = do_CreateInstance(NS_SAVEASCHARSET_CONTRACTID);
    if (mFontMetricsContext->mFontSubConverter) {
      res = mFontMetricsContext->mFontSubConverter->Init("ISO-8859-1",
                             nsISaveAsCharset::attr_FallbackQuestionMark +
                               nsISaveAsCharset::attr_EntityAfterCharsetConv +
                               nsISaveAsCharset::attr_IgnoreIgnorables,
                             nsIEntityConverter::transliterate);
      if (NS_FAILED(res))
        mFontMetricsContext->mFontSubConverter = nsnull; // destroy converter
    }
  }

  if (mFontMetricsContext->mFontSubConverter) {
    nsAutoString tmp(aSrc, aSrcLen);
    char* conv = nsnull;

    /* timecop revisit with nsXPIDLCString */
    res = mFontMetricsContext->mFontSubConverter->Convert(tmp.get(), &conv);
    if (NS_SUCCEEDED(res) && conv) {
      char *p = conv;
      PRUint32 i;
      for (i = 0; i < aDestLen; i++) {
        if (*p) {
          aDest[i] = *p;
        }
        else {
          break;
        }
        p++;
      }
      nsMemory::Free(conv);
      conv = nsnull;
      return i;
    }
  }

  if (aSrcLen > aDestLen) {
    aSrcLen = aDestLen;
  }
  for (PRUint32 i = 0; i < aSrcLen; i++)
    aDest[i] = '?';

  return aSrcLen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsFontXlibSubstitute::DrawString ( nsRenderingContextXlib aContext,
nsIDrawingSurfaceXlib aSurface,
nscoord  aX,
nscoord  aY,
const PRUnichar aString,
PRUint32  aLength 
) [virtual]

Implements nsFontXlib.

Definition at line 3458 of file nsFontMetricsXlib.cpp.

{
  PRUnichar buf[512];
  PRUnichar *p = buf;
  PRUint32 bufLen = sizeof(buf)/sizeof(PRUnichar);
  if ((aLength*2) > bufLen) {
    PRUnichar *tmp;
    tmp = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * (aLength*2));
    if (tmp) {
      p = tmp;
      bufLen = (aLength*2);
    }
  }
  PRUint32 len = Convert(aString, aLength, p, bufLen);
  int outWidth = mSubstituteFont->DrawString(aContext, aSurface, 
                                             aX, aY, p, len);
  if (p != buf)
    nsMemory::Free(p);
  return outWidth;
}

Here is the call graph for this function:

int nsFontXlibSubstitute::GetWidth ( const PRUnichar aString,
PRUint32  aLength 
) [virtual]

Implements nsFontXlib.

Definition at line 3436 of file nsFontMetricsXlib.cpp.

{
  PRUnichar buf[512];
  PRUnichar *p = buf;
  PRUint32 bufLen = sizeof(buf)/sizeof(PRUnichar);
  if ((aLength*2) > bufLen) {
    PRUnichar *tmp;
    tmp = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * (aLength*2));
    if (tmp) {
      p = tmp;
      bufLen = (aLength*2);
    }
  }
  PRUint32 len = Convert(aString, aLength, p, bufLen);
  int outWidth = mSubstituteFont->GetWidth(p, len);
  if (p != buf)
    nsMemory::Free(p);
  return outWidth;

}

Here is the call graph for this function:

Reimplemented from nsFontXlib.

Definition at line 3517 of file nsFontMetricsXlib.cpp.

{
  return mSubstituteFont->GetXFont();
}

Here is the call graph for this function:

Reimplemented from nsFontXlib.

Definition at line 3523 of file nsFontMetricsXlib.cpp.

Here is the call graph for this function:

XFontStruct * nsFontXlibSubstitute::GetXFontStruct ( void  ) [virtual]

Reimplemented from nsFontXlib.

Definition at line 3511 of file nsFontMetricsXlib.cpp.

Here is the call graph for this function:

PRBool nsFontXlib::IsEmptyFont ( XFontStruct *  xFont) [inherited]

Definition at line 2977 of file nsFontMetricsXlib.cpp.

{
  if (!xFont)
    return PR_TRUE;

  //
  // scan and see if we can find at least one glyph
  //
  if (xFont->per_char) {
    PRInt32 minByte1 = xFont->min_byte1;
    PRInt32 maxByte1 = xFont->max_byte1;
    PRInt32 minByte2 = xFont->min_char_or_byte2;
    PRInt32 maxByte2 = xFont->max_char_or_byte2;
    PRInt32 charsPerRow = maxByte2 - minByte2 + 1;
    for (PRInt32 row = minByte1; row <= maxByte1; row++) {
      PRInt32 offset = (((row - minByte1) * charsPerRow) - minByte2);
      for (PRInt32 cell = minByte2; cell <= maxByte2; cell++) {
        XCharStruct* bounds = &xFont->per_char[offset + cell];
        if (bounds->ascent || bounds->descent) {
          return PR_FALSE;
        }
      }
    }
  }

  return PR_TRUE;
}

Here is the caller graph for this function:

void nsFontXlib::LoadFont ( void  ) [inherited]

Definition at line 3006 of file nsFontMetricsXlib.cpp.

{
  if (mAlreadyCalledLoadFont)
    return;

  Display *aDisplay = xxlib_rgb_get_display(mFontMetricsContext->mXlibRgbHandle);

#ifdef USE_XPRINT
  if (mFontMetricsContext->mPrinterMode)
  {
    if (XpGetContext(aDisplay) == None)
    {
      /* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */
      NS_ERROR("Obtaining font information without a valid print context (XLoadQueryFont()) _before_ XpSetContext()\n");
#ifdef DEBUG
      abort();
#else
      return;
#endif /* DEBUG */      
    }
  }
#endif /* USE_XPRINT */

  mAlreadyCalledLoadFont = PR_TRUE;

  XFontStruct *xlibFont = nsnull;

  NS_ASSERTION(!mFont, "mFont should not be loaded");
#ifdef USE_AASB
  if (mAABaseSize==0)
#endif /* USE_AASB */
  {
    NS_ASSERTION(!mFontHolder, "mFontHolder should not be loaded");
    xlibFont = ::XLoadQueryFont(aDisplay, mName);
    if(!xlibFont)
    {
#ifdef DEBUG
      printf("nsFontXlib::LoadFont(): loading of font '%s' failed\n", mName);
#endif /* DEBUG */
      return;
    }

    mXFont = new nsXFontNormal(aDisplay, xlibFont);
  }
#ifdef USE_AASB
  else {
    NS_ASSERTION(mFontHolder, "mFontHolder should be loaded");
    xlibFont = mFontHolder;
    mXFont = new nsXFontAAScaledBitmap(xxlib_rgb_get_display(mFontMetricsContext->mXlibRgbHandle),
                                       xxlib_rgb_get_screen(mFontMetricsContext->mXlibRgbHandle),
                                       xlibFont, mSize, mAABaseSize);
  }
#endif /* USE_AASB */

  NS_ASSERTION(mXFont,"failed to load mXFont");
  if (!mXFont)
    return;
  if (!mXFont->LoadFont()) {
    delete mXFont;
    mXFont = nsnull;
    return;
  }

  if (xlibFont) {
    XFontStruct* xFont = mXFont->GetXFontStruct();
    XFontStruct* xFont_with_per_char;
#ifdef USE_AASB
    if (mAABaseSize==0)
#endif /* USE_AASB */
      xFont_with_per_char = xFont;
#ifdef USE_AASB
    else
      xFont_with_per_char = mFontHolder;
#endif /* #ifdef USE_AASB */

    mMaxAscent = xFont->ascent;
    mMaxDescent = xFont->descent;

    if (mCharSetInfo == mFontMetricsContext->mISO106461) {
      mCCMap = GetMapFor10646Font(xFont_with_per_char);
      if (!mCCMap) {
        mXFont->UnloadFont();
        mXFont = nsnull;
        ::XFreeFont(aDisplay, xlibFont);
        mFontHolder = nsnull;
        return;
      }
    }

    // Redhat 6.2 Japanese has invalid jisx201 fonts
    // Solaris 2.6 has invalid cns11643 fonts for planes 4-7
    if ((mCharSetInfo == &JISX0201)
        || (mCharSetInfo == &CNS116434)
        || (mCharSetInfo == &CNS116435)
        || (mCharSetInfo == &CNS116436)
        || (mCharSetInfo == &CNS116437)
       ) {
      if (IsEmptyFont(xFont_with_per_char)) {
#ifdef NS_FONT_DEBUG_LOAD_FONT
        if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) {
          printf("\n");
          printf("***************************************\n");
          printf("invalid font \"%s\", %s %d\n", mName, __FILE__, __LINE__);
          printf("***************************************\n");
          printf("\n");
        }
#endif
        mXFont->UnloadFont();
        mXFont = nsnull;
        ::XFreeFont(aDisplay, xlibFont);
        mFontHolder = nsnull;
        return;
      }
    }
    mFont = xlibFont;

#ifdef NS_FONT_DEBUG_LOAD_FONT
    if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) {
      printf("loaded %s\n", mName);
    }
#endif

  }

#ifdef NS_FONT_DEBUG_LOAD_FONT
  else if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) {
    printf("cannot load %s\n", mName);
  }
#endif

}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsFontXlib::SupportsChar ( PRUnichar  aChar) [inline, inherited]

Definition at line 285 of file nsFontMetricsXlib.h.

    { return mCCMap && CCMAP_HAS_CHAR(mCCMap, aChar); };

Here is the caller graph for this function:


Member Data Documentation

Definition at line 328 of file nsFontMetricsXlib.h.

Definition at line 317 of file nsFontMetricsXlib.h.

Definition at line 309 of file nsFontMetricsXlib.h.

Definition at line 310 of file nsFontMetricsXlib.h.

XFontStruct* nsFontXlib::mFont [protected, inherited]

Definition at line 325 of file nsFontMetricsXlib.h.

XFontStruct* nsFontXlib::mFontHolder [protected, inherited]

Definition at line 326 of file nsFontMetricsXlib.h.

Definition at line 280 of file nsFontMetricsXlib.h.

Definition at line 321 of file nsFontMetricsXlib.h.

Definition at line 322 of file nsFontMetricsXlib.h.

char* nsFontXlib::mName [inherited]

Definition at line 311 of file nsFontMetricsXlib.h.

Definition at line 313 of file nsFontMetricsXlib.h.

Definition at line 3370 of file nsFontMetricsXlib.cpp.

Definition at line 312 of file nsFontMetricsXlib.h.

nsXFont* nsFontXlib::mXFont [protected, inherited]

Definition at line 327 of file nsFontMetricsXlib.h.


The documentation for this class was generated from the following file: