Back to index

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

List of all members.

Public Member Functions

 nsFontXlibUserDefined (nsFontMetricsXlibContext *aFontMetricsContext)
virtual ~nsFontXlibUserDefined ()
virtual PRBool Init (nsFontXlib *aFont)
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, PRInt32 aSrcLen, char *aDest, PRInt32 aDestLen)
void LoadFont (void)
PRBool IsEmptyFont (XFontStruct *)
int SupportsChar (PRUnichar aChar)
virtual XFontStruct * GetXFontStruct (void)
virtual nsXFontGetXFont (void)
virtual PRBool GetXFontIs10646 (void)

Public Attributes

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 3528 of file nsFontMetricsXlib.cpp.


Constructor & Destructor Documentation

Definition at line 3549 of file nsFontMetricsXlib.cpp.

{
  mFontMetricsContext = aFontMetricsContext;
}

Definition at line 3554 of file nsFontMetricsXlib.cpp.

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

Member Function Documentation

PRUint32 nsFontXlibUserDefined::Convert ( const PRUnichar aSrc,
PRInt32  aSrcLen,
char *  aDest,
PRInt32  aDestLen 
) [virtual]

Definition at line 3577 of file nsFontMetricsXlib.cpp.

{
  if (aSrcLen > aDestLen) {
    aSrcLen = aDestLen;
  }
  mFontMetricsContext->mUserDefinedConverter->Convert(aSrc, &aSrcLen, aDest, &aDestLen);

  return aSrcLen;
}

Here is the caller graph for this function:

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

Implements nsFontXlib.

Definition at line 3608 of file nsFontMetricsXlib.cpp.

{
  char  buf[1024];
  char *p;
  PRInt32 bufLen;
  ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mFontMetricsContext->mUserDefinedConverter,
                         aString, aLength, buf, sizeof(buf), bufLen);
  PRUint32 len = Convert(aString, aLength, p, bufLen);
  xGC *gc = aContext->GetGC();

  int outWidth;
  if (mXFont->IsSingleByte()) {
    mXFont->DrawText8(aSurface->GetDrawable(), *gc, aX,
                                          aY + mBaselineAdjust, p, len);
    outWidth = mXFont->TextWidth8(p, len);
  }
  else {
    mXFont->DrawText16(aSurface->GetDrawable(), *gc, aX, aY + mBaselineAdjust,
                       (const XChar2b*)p, len);
    outWidth = mXFont->TextWidth16((const XChar2b*)p, len/2);
  }
  gc->Release();
  ENCODER_BUFFER_FREE_IF_NEEDED(p, buf);
  return outWidth;
}

Here is the call graph for this function:

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

Implements nsFontXlib.

Definition at line 3589 of file nsFontMetricsXlib.cpp.

{
  char buf[1024];
  char *p;
  PRInt32 bufLen;
  ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mFontMetricsContext->mUserDefinedConverter,
                         aString, aLength, buf, sizeof(buf), bufLen);
  PRUint32 len = Convert(aString, aLength, p, bufLen);

  int outWidth;
  if (mXFont->IsSingleByte())
    outWidth = mXFont->TextWidth8(p, len);
  else
    outWidth = mXFont->TextWidth16((const XChar2b*)p, len/2);
  ENCODER_BUFFER_FREE_IF_NEEDED(p, buf);
  return outWidth;
}

Here is the call graph for this function:

nsXFont * nsFontXlib::GetXFont ( void  ) [virtual, inherited]

Reimplemented in nsFontXlibSubstitute.

Definition at line 3145 of file nsFontMetricsXlib.cpp.

{
  return mXFont;
}

Here is the caller graph for this function:

PRBool nsFontXlib::GetXFontIs10646 ( void  ) [virtual, inherited]

Reimplemented in nsFontXlibSubstitute.

Definition at line 3151 of file nsFontMetricsXlib.cpp.

Here is the caller graph for this function:

XFontStruct * nsFontXlib::GetXFontStruct ( void  ) [virtual, inherited]

Reimplemented in nsFontXlibSubstitute.

Definition at line 3139 of file nsFontMetricsXlib.cpp.

{
  return mFont;
}

Here is the caller graph for this function:

Definition at line 3560 of file nsFontMetricsXlib.cpp.

{
  if (!aFont->GetXFont()) {
    aFont->LoadFont();
    if (!aFont->GetXFont()) {
      mCCMap = mFontMetricsContext->mEmptyCCMap;
      return PR_FALSE;
    }
  }
  mXFont = aFont->GetXFont();
  mCCMap = mFontMetricsContext->mUserDefinedCCMap;
  mName = aFont->mName;

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller 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 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: