Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
nsXFontAAScaledBitmap Class Reference

#include <nsXFontAAScaledBitmap.h>

Inheritance diagram for nsXFontAAScaledBitmap:
Inheritance graph
[legend]
Collaboration diagram for nsXFontAAScaledBitmap:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsXFontAAScaledBitmap (Display *aDisplay, int aScreen, GdkFont *, PRUint16, PRUint16)
 ~nsXFontAAScaledBitmap ()
void DrawText8 (GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32, const char *, PRUint32)
void DrawText16 (GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32, const XChar2b *, PRUint32)
PRBool GetXFontProperty (Atom, unsigned long *)
XFontStruct * GetXFontStruct ()
PRBool LoadFont ()
void TextExtents8 (const char *, PRUint32, PRInt32 *, PRInt32 *, PRInt32 *, PRInt32 *, PRInt32 *)
void TextExtents16 (const XChar2b *, PRUint32, PRInt32 *, PRInt32 *, PRInt32 *, PRInt32 *, PRInt32 *)
PRInt32 TextWidth8 (const char *, PRUint32)
PRInt32 TextWidth16 (const XChar2b *, PRUint32)
void UnloadFont ()
PRBool IsSingleByte ()

Static Public Member Functions

static PRBool InitGlobals (Display *aDisplay, int aScreen)
static void FreeGlobals ()

Protected Member Functions

void DrawText8or16 (GdkDrawable *Drawable, GdkGC *GC, PRInt32, PRInt32, void *, PRUint32)
void TextExtents8or16 (void *, PRUint32, PRInt32 *, PRInt32 *, PRInt32 *, PRInt32 *, PRInt32 *)
PRBool GetScaledGreyImage (const char *, nsAntiAliasedGlyph **)

Static Protected Member Functions

static PRBool DisplayIsLocal (Display *)

Protected Attributes

PRBool mAlreadyLoaded
DisplaymDisplay
GC mForegroundGC
GdkFont * mGdkFont
nsHashtable * mGlyphHash
double mRatio
XFontStruct mScaledFontInfo
GlyphMetrics mScaledMax
int mScreen
Pixmap mUnscaledBitmap
XFontStruct * mUnscaledFontInfo
GlyphMetrics mUnscaledMax
PRUint16 mUnscaledSize
PRBool mIsSingleByte

Static Protected Attributes

static DisplaysDisplay = nsnull
static GC sBackgroundGC = nsnull
static PRUint8 sWeightedScaleDarkText [256]
static PRUint8 sWeightedScaleLightText [256]

Detailed Description

Definition at line 60 of file nsXFontAAScaledBitmap.h.


Constructor & Destructor Documentation

nsXFontAAScaledBitmap::nsXFontAAScaledBitmap ( Display aDisplay,
int  aScreen,
GdkFont *  aGdkFont,
PRUint16  aSize,
PRUint16  aUnscaledSize 
)

Definition at line 639 of file nsXFontAAScaledBitmap.cpp.

{
  mAlreadyLoaded       = PR_FALSE;
  mDisplay             = aDisplay;
  mScreen              = aScreen;
  mGdkFont             = ::gdk_font_ref(aGdkFont);
  mUnscaledSize        = aUnscaledSize;
  mRatio               = ((double)aSize)/((double)aUnscaledSize);
  mIsSingleByte        = 0;
  mForegroundGC        = nsnull;
  mGlyphHash           = nsnull;
  mUnscaledBitmap      = nsnull;
  memset(&mScaledFontInfo, 0, sizeof(mScaledFontInfo));
  memset(&mUnscaledMax,    0, sizeof(mUnscaledMax));
  memset(&mScaledMax,      0, sizeof(mScaledMax));
}

Here is the call graph for this function:

Definition at line 785 of file nsXFontAAScaledBitmap.cpp.

{
  if (mGlyphHash) {
    mGlyphHash->Reset(FreeGlyphHash, nsnull);
    delete mGlyphHash;
  }
  if (mForegroundGC) {
    XFreeGC(mDisplay, mForegroundGC);
  }
  if (mGdkFont) {
    ::gdk_font_unref(mGdkFont);
  }
  if (mUnscaledBitmap) {
    XFreePixmap(mDisplay, mUnscaledBitmap);
  }
}

Here is the call graph for this function:


Member Function Documentation

PRBool nsXFontAAScaledBitmap::DisplayIsLocal ( Display aDisplay) [static, protected]

Definition at line 122 of file nsXFontAAScaledBitmap.cpp.

{
  // if shared memory works then the display is local
  if (gdk_get_use_xshm())
    return PR_TRUE;

  return PR_FALSE;

}

Here is the caller graph for this function:

void nsXFontAAScaledBitmap::DrawText16 ( GdkDrawable *  Drawable,
GdkGC *  GC,
PRInt32  aX,
PRInt32  aY,
const XChar2b *  aString,
PRUint32  aLength 
) [virtual]

Implements nsXFont.

Definition at line 141 of file nsXFontAAScaledBitmap.cpp.

{
  DrawText8or16(aDrawable, aGC, aX, aY, (void*)aString, aLength);
}

Here is the call graph for this function:

void nsXFontAAScaledBitmap::DrawText8 ( GdkDrawable *  Drawable,
GdkGC *  GC,
PRInt32  aX,
PRInt32  aY,
const char *  aString,
PRUint32  aLength 
) [virtual]

Implements nsXFont.

Definition at line 133 of file nsXFontAAScaledBitmap.cpp.

{
  DrawText8or16(aDrawable, aGC, aX, aY, (void*)aString, aLength);
}

Here is the call graph for this function:

void nsXFontAAScaledBitmap::DrawText8or16 ( GdkDrawable *  Drawable,
GdkGC *  GC,
PRInt32  aX,
PRInt32  aY,
void a8or16String,
PRUint32  aLength 
) [protected]

Definition at line 155 of file nsXFontAAScaledBitmap.cpp.

{
  // make the indeterminate input variables determinate
  const char    *string8  = (const char    *)a8or16String;
  const XChar2b *string16 = (const XChar2b *)a8or16String;

#if DEBUG_SHOW_GLYPH_BOX
  // grey shows image size
  // red shows character cells
  // green box shows text ink
#endif

  if (aLength < 1) {
    return;
  }

  //
  // Get a area guaranteed to be big enough.
  //
  // This can be bigger than necessary but for debuggability
  // this code can draw the char cells.  Calculating the
  // exact size needed both the character cells and
  // pixels to the left and right of the character cells
  // is quite messy.
  //
  PRUint32 image_width  = (mScaledMax.width * aLength) + mScaledMax.lbearing;
  PRUint32 image_height = mScaledMax.ascent+mScaledMax.descent;
  PRInt32 x_pos = mScaledMax.lbearing;

  Drawable win = GDK_WINDOW_XWINDOW(aDrawable);
  GC gc = GDK_GC_XGC(aGC);
  XGCValues values;
  if (!XGetGCValues(mDisplay, gc, GCForeground, &values)) {
    NS_ASSERTION(0, "failed to get foreground pixel");
    return;
  }
  nscolor color = nsX11AlphaBlend::PixelToNSColor(values.foreground);

  // weight dark text differently from light text
  PRUint32 color_val = NS_GET_R(color) + NS_GET_G(color) + NS_GET_B(color);
  PRUint8 *weight_table;
  if ((NS_GET_R(color)>200) || (NS_GET_R(color)>200) || (NS_GET_R(color)>200)
      || (color_val>3*128))
    weight_table = sWeightedScaleLightText;
  else
    weight_table = sWeightedScaleDarkText;

  //
  // Get the background
  //
  XImage *sub_image = nsX11AlphaBlend::GetBackground(mDisplay, mScreen, win,
                                 aX-mScaledMax.lbearing, aY-mScaledMax.ascent,
                                 image_width, image_height);
  if (sub_image==nsnull) {
#ifdef DEBUG
    // complain if the requested area is not completely off screen
    int win_width = DisplayWidth(mDisplay, mScreen);
    int win_height = DisplayHeight(mDisplay, mScreen);
    if (((int)(aX-mScaledMax.lbearing+image_width) > 0)  // not hidden to left
        && ((int)(aX-mScaledMax.lbearing) < win_width)   // not hidden to right
        && ((int)(aY-mScaledMax.ascent+image_height) > 0)// not hidden to top
        && ((int)(aY-mScaledMax.ascent) < win_height))   // not hidden to bottom
    {
      NS_ASSERTION(sub_image, "failed to get the image");
    }
#endif
    return;
  }

#if DEBUG_SHOW_GLYPH_BOX
  DEBUG_AADRAWBOX(sub_image,0,0,image_width,image_height,0,0,0,255/4);
  int lbearing, rbearing, width, ascent, descent;
  if (mIsSingleByte)
    TextExtents8(aString8, aLength, &lbearing, &rbearing, &width,
                 &ascent, &descent);
  else
    TextExtents16(aString16, aLength, &lbearing, &rbearing, &width,
                  &ascent, &descent);

  DEBUG_AADRAWBOX(sub_image, x_pos+lbearing, mScaledMax.ascent-ascent,
                  rbearing-lbearing, ascent+descent, 0,255,0, 255/2);
#endif

  //
  // Get aa-scaled glyphs and blend with background
  //
  blendGlyph blendGlyph = nsX11AlphaBlend::GetBlendGlyph();
  for (PRUint32 i=0; i<aLength; i++) {
#if DEBUG_SHOW_GLYPH_BOX
    PRUint32 box_width;
    if (mIsSingleByte)
      box_width = TextWidth8(&aString8[i], 1);
    else
      box_width = TextWidth16(&aString16[i], 1);
    nscolor red = NS_RGB(255,0,0);
    AADrawBox(sub_image, x_pos, 0, box_width, mScaledMax.ascent, red, 255/4);
    AADrawBox(sub_image, x_pos, mScaledMax.ascent, box_width,
              mScaledMax.descent, red,255/4);
#endif
    nsAntiAliasedGlyph *scaled_glyph;
    PRBool got_image;
    if (mIsSingleByte)
      got_image = GetScaledGreyImage(&string8[i], &scaled_glyph);
    else
      got_image = GetScaledGreyImage((const char*)&string16[i], &scaled_glyph);
    if (!got_image) {
      PRUint32 char_width;
      if (mIsSingleByte)
        char_width = XTextWidth(mUnscaledFontInfo, &string8[i], 1);
      else
        char_width = XTextWidth16(mUnscaledFontInfo, &string16[i], 1);
      x_pos += SCALED_SIZE(char_width);
      continue;
    }
    NS_ASSERTION(scaled_glyph->GetBorder()==0,
                 "do not support non-zero border");
    DEBUG_DUMP((dump_byte_table(scaled_glyph->GetBuffer(),
                    scaled_glyph->GetBufferWidth(),
                    scaled_glyph->GetBufferHeight())));
    //
    // blend the aa-glyph onto the background
    //
    (*blendGlyph)(sub_image, scaled_glyph, weight_table, color,
                  x_pos + scaled_glyph->GetLBearing(), 0);

    DEBUG_DUMP((dump_XImage_blue_data(sub_image)));
    x_pos += scaled_glyph->GetAdvance();
  }
  DEBUG_DUMP((dump_XImage_blue_data(sub_image)));

  //
  // Send it to the display
  //
  XPutImage(mDisplay, win, gc, sub_image,
            0, 0, aX-mScaledMax.lbearing, aY-mScaledMax.ascent,
            image_width, image_height);
  XDestroyImage(sub_image);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 297 of file nsXFontAAScaledBitmap.cpp.

Here is the caller graph for this function:

PRBool nsXFontAAScaledBitmap::GetScaledGreyImage ( const char *  aChar,
nsAntiAliasedGlyph **  aGreyImage 
) [protected]

Definition at line 315 of file nsXFontAAScaledBitmap.cpp.

{
  XChar2b *aChar2b = nsnull;
  PRUint32 antiJagPadding;
  XImage *ximage;
  nsAntiAliasedGlyph *scaled_image;
  PRUnichar charKey[2];

  // get the char key
  if (mIsSingleByte)
    charKey[0] = (PRUnichar)*aChar;
  else {
    aChar2b = (XChar2b *)aChar;
    charKey[0] = aChar2b->byte1<<8 | aChar2b->byte2;
  }
  charKey[1] = 0;
  nsStringKey key(charKey, 1);

  // look in the cache for the glyph image
  scaled_image = (nsAntiAliasedGlyph*)mGlyphHash->Get(&key);
  if (!scaled_image) {
    // get the char metrics
    int direction, font_ascent, font_descent;
    XCharStruct charMetrics;
    if (mIsSingleByte)
      XTextExtents(mUnscaledFontInfo, aChar, 1, &direction,
                   &font_ascent, &font_descent, &charMetrics);
    else
      XTextExtents16(mUnscaledFontInfo, aChar2b,1, &direction,
                     &font_ascent, &font_descent, &charMetrics);

    // figure the amount to scale
    PRInt32 left_edge  = GLYPH_LEFT_EDGE(&charMetrics);
    PRInt32 right_edge = GLYPH_RIGHT_EDGE(&charMetrics);
    PRUint32 unscaled_width = right_edge - left_edge;
    NS_ASSERTION(unscaled_width<=mUnscaledMax.width, "unexpected glyph width");

    // clear the bitmap
    XFillRectangle(mDisplay, mUnscaledBitmap, sBackgroundGC, 0, 0,
                                unscaled_width, mUnscaledMax.height);
    // draw the char
    if (mIsSingleByte)
      XDrawString(mDisplay, mUnscaledBitmap, mForegroundGC,
               -left_edge, mUnscaledMax.ascent, aChar, 1);
    else
      XDrawString16(mDisplay, mUnscaledBitmap, mForegroundGC,
               -left_edge, mUnscaledMax.ascent, aChar2b, 1);
    // get the pixels
    ximage = XGetImage(mDisplay, mUnscaledBitmap,
                     0, 0, unscaled_width, mUnscaledMax.height,
                     AllPlanes, ZPixmap);
    NS_ASSERTION(ximage, "failed to XGetSubImage()");
    if (!ximage) {
      return PR_FALSE;
    }
    DEBUG_DUMP((dump_XImage_blue_data(ximage)));

    // must pad when anti-jagging
    if (mRatio < 1.25)
      antiJagPadding = 0;
    else
      antiJagPadding = 2; // this may change if the anti-jagging code changes

    // create the empty nsAntiAliasedGlyph
    nsAntiAliasedGlyph unscaled_image(unscaled_width, mUnscaledMax.height,
                                      antiJagPadding);
    PRUint8 buf[IMAGE_BUFFER_SIZE]; // try to use the stack for data
    if (!unscaled_image.Init(buf, IMAGE_BUFFER_SIZE)) {
      NS_ASSERTION(0, "failed to Init() unscaled_image");
      XDestroyImage(ximage);
      return PR_FALSE;
    }

    //
    // get ready to scale
    //
    unscaled_image.SetImage(&charMetrics, ximage);
    DEBUG_DUMP((dump_byte_table(unscaled_image.GetBuffer(),
                    unscaled_image.GetBufferWidth(),
                    unscaled_image.GetBufferHeight())));
    XDestroyImage(ximage);

    //
    // Create the scaled glyph
    //
    GlyphMetrics glyphMetrics;
    glyphMetrics.width    = SCALED_SIZE(unscaled_width);
    glyphMetrics.height   = SCALED_SIZE(mUnscaledMax.height);
    glyphMetrics.lbearing = SCALED_SIZE(left_edge);
    glyphMetrics.rbearing = SCALED_SIZE(right_edge);
    glyphMetrics.advance  = SCALED_SIZE(charMetrics.width);
    glyphMetrics.ascent   = SCALED_SIZE(charMetrics.ascent);
    glyphMetrics.descent  = SCALED_SIZE(charMetrics.descent);

    scaled_image = new nsAntiAliasedGlyph(SCALED_SIZE(unscaled_width),
                                          SCALED_SIZE(mUnscaledMax.height), 0);
    NS_ASSERTION(scaled_image, "failed to create scaled_image");
    if (!scaled_image) {
      return PR_FALSE;
    }
    if (!scaled_image->Init()) {
      NS_ASSERTION(0, "failed to initialize scaled_image");
      delete scaled_image;
      return PR_FALSE;
    }
    scaled_image->SetSize(&glyphMetrics);

    //
    // scale
    //
    if (antiJagPadding==0)
      scale_image(&unscaled_image, scaled_image);
    else
      scale_imageAntiJag(&unscaled_image, scaled_image);

    DEBUG_DUMP((dump_byte_table(scaled_image->GetBuffer(),
                    scaled_image->GetBufferWidth(),
                    scaled_image->GetBufferHeight())));

    // store in hash
    mGlyphHash->Put(&key, scaled_image);
  }
  *aGreyImage = scaled_image;
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsXFontAAScaledBitmap::GetXFontProperty ( Atom  aAtom,
unsigned long aValue 
) [virtual]

Implements nsXFont.

Definition at line 443 of file nsXFontAAScaledBitmap.cpp.

{
  unsigned long val;
  PRBool rslt = ::XGetFontProperty(mUnscaledFontInfo, aAtom, &val);
  if (!rslt)
    return PR_FALSE;

  switch (aAtom) {
    case XA_X_HEIGHT:
      if (val >= 0x00ffffff) {// Bug 43214: arbitrary to exclude garbage values
        return PR_FALSE;
      }
    case XA_SUBSCRIPT_Y:
    case XA_SUPERSCRIPT_Y:
    case XA_UNDERLINE_POSITION:
    case XA_UNDERLINE_THICKNESS:
      *aValue = (unsigned long)SCALED_SIZE(val);
      break;
    default:
      *aValue = val;
  }
  return rslt;
}
XFontStruct * nsXFontAAScaledBitmap::GetXFontStruct ( ) [virtual]

Implements nsXFont.

Definition at line 468 of file nsXFontAAScaledBitmap.cpp.

{
  NS_ASSERTION(mGdkFont, "GetXFontStruct called before font loaded");
  if (mGdkFont==nsnull)
    return nsnull;

  return &mScaledFontInfo;
}
PRBool nsXFontAAScaledBitmap::InitGlobals ( Display aDisplay,
int  aScreen 
) [static]

Definition at line 478 of file nsXFontAAScaledBitmap.cpp.

{
  Window root_win;

  sDisplay = aDisplay; // used to free shared sBackgroundGC

  // if not a local display then might be slow so don't run
  if (!DisplayIsLocal(aDisplay)) {
    goto cleanup_and_return;
  }

  root_win = RootWindow(sDisplay, aScreen);
  sBackgroundGC = XCreateGC(sDisplay, root_win, 0, NULL);
  NS_ASSERTION(sBackgroundGC, "failed to create sBackgroundGC");
  if (!sBackgroundGC) {
    goto cleanup_and_return;
  }
  XSetForeground(sDisplay, sBackgroundGC, 0);

  WeightTableInitLinearCorrection(sWeightedScaleDarkText,
                                  gAASBDarkTextMinValue, gAASBDarkTextGain);
  WeightTableInitLinearCorrection(sWeightedScaleLightText,
                                  gAASBLightTextMinValue, gAASBLightTextGain);
  return PR_TRUE;

cleanup_and_return:
  if (sBackgroundGC) {
    XFreeGC(sDisplay, sBackgroundGC);
    sBackgroundGC = nsnull;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsXFont::IsSingleByte ( ) [inline, inherited]

Definition at line 52 of file nsXFont.h.

{ return mIsSingleByte; };

Here is the caller graph for this function:

Implements nsXFont.

Definition at line 513 of file nsXFontAAScaledBitmap.cpp.

{
  NS_ASSERTION(!mAlreadyLoaded, "LoadFont called more than once");
  mAlreadyLoaded = PR_TRUE;

  if (!mGdkFont)
    return PR_FALSE;
  mUnscaledFontInfo = (XFontStruct *)GDK_FONT_XFONT(mGdkFont);

  XFontStruct *usfi = mUnscaledFontInfo;
  XFontStruct *sfi  = &mScaledFontInfo;

  mIsSingleByte = (usfi->min_byte1 == 0) && (usfi->max_byte1 == 0);

  mUnscaledMax.width    = MAX(usfi->max_bounds.rbearing,usfi->max_bounds.width);
  mUnscaledMax.width   -= MIN(usfi->min_bounds.lbearing, 0);
  mUnscaledMax.height   = usfi->max_bounds.ascent   + usfi->max_bounds.descent;
  mUnscaledMax.lbearing = usfi->max_bounds.lbearing;
  mUnscaledMax.rbearing = usfi->max_bounds.rbearing;
  mUnscaledMax.advance  = usfi->max_bounds.width;
  mUnscaledMax.ascent   = usfi->max_bounds.ascent;
  mUnscaledMax.descent  = usfi->max_bounds.descent;

  mScaledMax.width    = SCALED_SIZE(mUnscaledMax.width);
  mScaledMax.lbearing = SCALED_SIZE(mUnscaledMax.lbearing);
  mScaledMax.rbearing = SCALED_SIZE(mUnscaledMax.rbearing);
  mScaledMax.advance  = SCALED_SIZE(mUnscaledMax.width);
  mScaledMax.ascent   = SCALED_SIZE(mUnscaledMax.ascent);
  mScaledMax.descent  = SCALED_SIZE(mUnscaledMax.ascent + mUnscaledMax.descent)
                        - SCALED_SIZE(mUnscaledMax.ascent);
  mScaledMax.height   = mScaledMax.ascent + mScaledMax.descent;

  //
  // Scale the XFontStruct
  //
  sfi->fid               = 0;
  sfi->direction         = usfi->direction;
  sfi->min_char_or_byte2 = usfi->min_char_or_byte2;
  sfi->max_char_or_byte2 = usfi->max_char_or_byte2;
  sfi->min_byte1         = usfi->min_byte1;
  sfi->max_byte1         = usfi->max_byte1;
  sfi->all_chars_exist   = usfi->all_chars_exist;
  sfi->default_char      = usfi->default_char;
  sfi->n_properties      = 0;
  sfi->properties        = nsnull;
  sfi->ext_data          = nsnull;

  sfi->min_bounds.lbearing = SCALED_SIZE(usfi->min_bounds.lbearing);
  sfi->min_bounds.rbearing = SCALED_SIZE(usfi->min_bounds.rbearing);
  sfi->min_bounds.width    = SCALED_SIZE(usfi->min_bounds.width);
  sfi->min_bounds.ascent   = SCALED_SIZE(usfi->min_bounds.ascent);
  sfi->min_bounds.descent  =
            SCALED_SIZE(usfi->min_bounds.ascent + usfi->min_bounds.descent)
            - SCALED_SIZE(usfi->min_bounds.ascent);
  sfi->min_bounds.attributes = usfi->min_bounds.attributes;

  sfi->max_bounds.lbearing = SCALED_SIZE(usfi->max_bounds.lbearing);
  sfi->max_bounds.rbearing = SCALED_SIZE(usfi->max_bounds.rbearing);
  sfi->max_bounds.width    = SCALED_SIZE(usfi->max_bounds.width);
  sfi->max_bounds.ascent   = SCALED_SIZE(usfi->max_bounds.ascent);
  sfi->max_bounds.descent  =
            SCALED_SIZE(usfi->max_bounds.ascent + usfi->max_bounds.descent)
            - SCALED_SIZE(usfi->max_bounds.ascent);
  sfi->max_bounds.attributes = usfi->max_bounds.attributes;

  sfi->per_char = nsnull;
  sfi->ascent   = SCALED_SIZE(usfi->ascent);
  sfi->descent  = SCALED_SIZE(usfi->descent);

  //
  // need a unique foreground GC for each font size/face
  // to use to draw the unscaled bitmap font
  //
  mForegroundGC = XCreateGC(mDisplay, RootWindow(mDisplay, mScreen), 0, NULL);
  NS_ASSERTION(mForegroundGC, "failed to create mForegroundGC");
  if (!mForegroundGC) {
    goto cleanup_and_return;
  }

  XSetFont(mDisplay, mForegroundGC, usfi->fid);
  XSetForeground(mDisplay, mForegroundGC, 0xFFFFFF);

  mUnscaledBitmap = XCreatePixmap(mDisplay,
                          RootWindow(mDisplay,DefaultScreen(mDisplay)),
                          mUnscaledMax.width, mUnscaledMax.height,
                          DefaultDepth(mDisplay, mScreen));
  if (!mUnscaledBitmap)
    goto cleanup_and_return;

  mGlyphHash = new nsHashtable();
  if (!mGlyphHash)
    goto cleanup_and_return;

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

cleanup_and_return:
  if (mUnscaledFontInfo) {
    mUnscaledFontInfo = nsnull;
  }
  if (mForegroundGC) {
    XFreeGC(mDisplay, mForegroundGC);
    mForegroundGC = nsnull;
  }
  if (mUnscaledBitmap) {
    XFreePixmap(mDisplay, mUnscaledBitmap);
    mUnscaledBitmap = nsnull;
  }
  if (mGlyphHash) {
    delete mGlyphHash;
    mGlyphHash = nsnull;
  }
  memset(&mScaledFontInfo, 0, sizeof(mScaledFontInfo));
  memset(&mUnscaledMax,    0, sizeof(mUnscaledMax));
  memset(&mScaledMax,      0, sizeof(mScaledMax));
  return PR_FALSE;
}

Here is the call graph for this function:

void nsXFontAAScaledBitmap::TextExtents16 ( const XChar2b *  aString,
PRUint32  aLength,
PRInt32 aLBearing,
PRInt32 aRBearing,
PRInt32 aWidth,
PRInt32 aAscent,
PRInt32 aDescent 
) [virtual]

Implements nsXFont.

Definition at line 671 of file nsXFontAAScaledBitmap.cpp.

{
  TextExtents8or16((void *)aString, aLength, aLBearing, aRBearing, aWidth,
                   aAscent, aDescent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsXFontAAScaledBitmap::TextExtents8 ( const char *  aString,
PRUint32  aLength,
PRInt32 aLBearing,
PRInt32 aRBearing,
PRInt32 aWidth,
PRInt32 aAscent,
PRInt32 aDescent 
) [virtual]

Implements nsXFont.

Definition at line 661 of file nsXFontAAScaledBitmap.cpp.

{
  TextExtents8or16((void *)aString, aLength, aLBearing, aRBearing, aWidth,
                   aAscent, aDescent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsXFontAAScaledBitmap::TextExtents8or16 ( void a8or16String,
PRUint32  aLength,
PRInt32 aLBearing,
PRInt32 aRBearing,
PRInt32 aWidth,
PRInt32 aAscent,
PRInt32 aDescent 
) [protected]

Definition at line 687 of file nsXFontAAScaledBitmap.cpp.

{
  // make the indeterminate input variables determinate
  const char    *string8  = (const char    *)a8or16String;
  const XChar2b *string16 = (const XChar2b *)a8or16String;

  int dir, unscaled_ascent, unscaled_descent;
  XCharStruct char_metrics;
  int leftBearing  = 0;
  int rightBearing = 0;
  int width        = 0;
  int ascent       = 0;
  int descent      = 0;

  // initialize the values
  if (aLength >= 1) {
    if (mIsSingleByte)
      XTextExtents(mUnscaledFontInfo, string8++, 1,
                     &dir, &unscaled_ascent, &unscaled_descent, &char_metrics);
    else
      XTextExtents16(mUnscaledFontInfo, string16++, 1,
                     &dir, &unscaled_ascent, &unscaled_descent, &char_metrics);
    leftBearing  = SCALED_SIZE(char_metrics.lbearing);
    rightBearing = SCALED_SIZE(char_metrics.rbearing);
    ascent       = SCALED_SIZE(char_metrics.ascent);
    descent      = SCALED_SIZE(mUnscaledMax.ascent+char_metrics.descent)
                   - SCALED_SIZE(mUnscaledMax.ascent);
    width        = SCALED_SIZE(char_metrics.width);
  }

  //
  // Must go char by char to handle float->int rounding
  // of the x position. If this is not done then when selecting
  // (highlighting) text the selection x pos can differ
  // which can make the text move around as more/less is selected
  //
  for (PRUint32 i=1; i<aLength; i++) {
    if (mIsSingleByte)
      XTextExtents(mUnscaledFontInfo, string8++, 1,
                   &dir, &unscaled_ascent, &unscaled_descent, &char_metrics);
    else
      XTextExtents16(mUnscaledFontInfo, string16++, 1,
                   &dir, &unscaled_ascent, &unscaled_descent, &char_metrics);
    //
    // In theory the second (or later) char may have a
    // lbearing more to the left than the first char.
    // Similarly for the rbearing.
    //
    leftBearing  = MIN(leftBearing,  width+SCALED_SIZE(char_metrics.lbearing));
    rightBearing = MAX(rightBearing, width+SCALED_SIZE(char_metrics.rbearing));
    ascent       = MAX(ascent,  SCALED_SIZE(char_metrics.ascent));
    descent      = MAX(descent,
                       SCALED_SIZE(mUnscaledMax.ascent+char_metrics.descent)
                       - SCALED_SIZE(mUnscaledMax.ascent));
    width        += SCALED_SIZE(char_metrics.width);
  }
  *aLBearing     = leftBearing;
  *aRBearing     = rightBearing;
  *aWidth        = width;
  *aAscent       = ascent;
  *aDescent      = descent;
}

Here is the caller graph for this function:

PRInt32 nsXFontAAScaledBitmap::TextWidth16 ( const XChar2b *  aString,
PRUint32  aLength 
) [virtual]

Implements nsXFont.

Definition at line 767 of file nsXFontAAScaledBitmap.cpp.

{
  int width = 0;
  // figure the width calculating all the per-char rounding
  for (PRUint32 i=0; i<aLength; i++) {
    int unscaled_width = XTextWidth16(mUnscaledFontInfo, aString+i, 1);
    width += SCALED_SIZE(unscaled_width);
  }
  return width;
}

Here is the caller graph for this function:

PRInt32 nsXFontAAScaledBitmap::TextWidth8 ( const char *  aString,
PRUint32  aLength 
) [virtual]

Implements nsXFont.

Definition at line 754 of file nsXFontAAScaledBitmap.cpp.

{
  int width = 0;
  // figure the width calculating all the per-char rounding
  for (PRUint32 i=0; i<aLength; i++) {
    int unscaled_width = XTextWidth(mUnscaledFontInfo, aString+i, 1);
    width += SCALED_SIZE(unscaled_width);
  }

  return width;
}

Here is the caller graph for this function:

Implements nsXFont.

Definition at line 779 of file nsXFontAAScaledBitmap.cpp.

{
  NS_ASSERTION(mGdkFont, "UnloadFont called when font not loaded");
  delete this;
}

Member Data Documentation

Definition at line 103 of file nsXFontAAScaledBitmap.h.

Definition at line 104 of file nsXFontAAScaledBitmap.h.

Definition at line 105 of file nsXFontAAScaledBitmap.h.

GdkFont* nsXFontAAScaledBitmap::mGdkFont [protected]

Definition at line 106 of file nsXFontAAScaledBitmap.h.

nsHashtable* nsXFontAAScaledBitmap::mGlyphHash [protected]

Definition at line 107 of file nsXFontAAScaledBitmap.h.

PRBool nsXFont::mIsSingleByte [protected, inherited]

Definition at line 63 of file nsXFont.h.

double nsXFontAAScaledBitmap::mRatio [protected]

Definition at line 108 of file nsXFontAAScaledBitmap.h.

XFontStruct nsXFontAAScaledBitmap::mScaledFontInfo [protected]

Definition at line 109 of file nsXFontAAScaledBitmap.h.

Definition at line 110 of file nsXFontAAScaledBitmap.h.

Definition at line 111 of file nsXFontAAScaledBitmap.h.

Definition at line 112 of file nsXFontAAScaledBitmap.h.

XFontStruct* nsXFontAAScaledBitmap::mUnscaledFontInfo [protected]

Definition at line 113 of file nsXFontAAScaledBitmap.h.

Definition at line 114 of file nsXFontAAScaledBitmap.h.

Definition at line 115 of file nsXFontAAScaledBitmap.h.

Definition at line 120 of file nsXFontAAScaledBitmap.h.

Definition at line 119 of file nsXFontAAScaledBitmap.h.

Definition at line 122 of file nsXFontAAScaledBitmap.h.

Definition at line 123 of file nsXFontAAScaledBitmap.h.


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