Back to index

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

List of all members.

Public Member Functions

 nsGlyphTable (const nsString &aPrimaryFontName)
 ~nsGlyphTable ()
void GetPrimaryFontName (nsString &aPrimaryFontName)
PRBool Has (nsPresContext *aPresContext, nsMathMLChar *aChar)
PRBool Has (nsPresContext *aPresContext, PRUnichar aChar)
PRBool HasVariantsOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
PRBool HasVariantsOf (nsPresContext *aPresContext, PRUnichar aChar)
PRBool HasPartsOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
PRBool HasPartsOf (nsPresContext *aPresContext, PRUnichar aChar)
PRBool IsComposite (nsPresContext *aPresContext, nsMathMLChar *aChar)
PRInt32 ChildCountOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsGlyphCode TopOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsGlyphCode MiddleOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsGlyphCode BottomOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsGlyphCode GlueOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsGlyphCode BigOf (nsPresContext *aPresContext, nsMathMLChar *aChar, PRInt32 aSize)
nsGlyphCode LeftOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsGlyphCode RightOf (nsPresContext *aPresContext, nsMathMLChar *aChar)
nsresult GetBoundingMetrics (nsIRenderingContext &aRenderingContext, nsFont &aFont, nsGlyphCode &aGlyphCode, nsBoundingMetrics &aBoundingMetrics)
void DrawGlyph (nsIRenderingContext &aRenderingContext, nsFont &aFont, nsGlyphCode &aGlyphCode, nscoord aX, nscoord aY, nsRect *aClipRect=nsnull)

Private Member Functions

char GetAnnotation (nsMathMLChar *aChar, PRInt32 aPosition)
nsGlyphCode ElementAt (nsPresContext *aPresContext, nsMathMLChar *aChar, PRUint32 aPosition)

Private Attributes

PRInt32 mType
nsStringArray mFontName
PRInt32 mState
nsCOMPtr< nsIPersistentPropertiesmGlyphProperties
nsString mGlyphCache
PRUnichar mCharCache

Detailed Description

Definition at line 220 of file nsMathMLChar.cpp.


Constructor & Destructor Documentation

nsGlyphTable::nsGlyphTable ( const nsString aPrimaryFontName) [inline]

Definition at line 222 of file nsMathMLChar.cpp.

Definition at line 231 of file nsMathMLChar.cpp.


Member Function Documentation

nsGlyphCode nsGlyphTable::BigOf ( nsPresContext aPresContext,
nsMathMLChar aChar,
PRInt32  aSize 
) [inline]

Definition at line 272 of file nsMathMLChar.cpp.

                                                                                     {
    return ElementAt(aPresContext, aChar, 4 + aSize);
  }

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::BottomOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
) [inline]

Definition at line 266 of file nsMathMLChar.cpp.

                                                                         {
    return ElementAt(aPresContext, aChar, 2);
  }

Here is the caller graph for this function:

PRInt32 nsGlyphTable::ChildCountOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
)

Definition at line 503 of file nsMathMLChar.cpp.

{
  // this will sync the cache as well ...
  if (!IsComposite(aPresContext, aChar)) return 0;
  // the lists of glyphs of a composite char are space-separated
  return 1 + mGlyphCache.CountChar(kSpaceCh);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGlyphTable::DrawGlyph ( nsIRenderingContext aRenderingContext,
nsFont aFont,
nsGlyphCode aGlyphCode,
nscoord  aX,
nscoord  aY,
nsRect aClipRect = nsnull 
)

Definition at line 596 of file nsMathMLChar.cpp.

{
  if (aClipRect) {
    aRenderingContext.PushState();
    aRenderingContext.SetClipRect(*aClipRect, nsClipCombine_kIntersect);
  }
  if (aGlyphCode.font) {
    // glyph not associated to our primary font, it comes from an external font
    mFontName.StringAt(aGlyphCode.font, aFont.name);
    aRenderingContext.SetFont(aFont, nsnull);
  }

  //if (mType == NS_TABLE_TYPE_UNICODE)
    aRenderingContext.DrawString((PRUnichar*)&aGlyphCode.code, PRUint32(1), aX, aY);
  //else
  //NS_ASSERTION(0, "Error *** Not yet implemented");
  //aRenderingContext.DrawStringI((PRUint16*)&aGlyphCode.code, PRUint32(1), aX, aY);

  if (aGlyphCode.font) {
    // restore our primary font in the rendering context
    mFontName.StringAt(0, aFont.name);
    aRenderingContext.SetFont(aFont, nsnull);
  }
  if (aClipRect)
    aRenderingContext.PopState();
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::ElementAt ( nsPresContext aPresContext,
nsMathMLChar aChar,
PRUint32  aPosition 
) [private]

Definition at line 352 of file nsMathMLChar.cpp.

{
  if (mState == NS_TABLE_STATE_ERROR) return kNullGlyph;
  // Load glyph properties if this is the first time we have been here
  if (mState == NS_TABLE_STATE_EMPTY) {
    if (!CheckFontExistence(aPresContext, *mFontName[0])) {
      mState = NS_TABLE_STATE_ERROR;
      return kNullGlyph;
    }
    nsresult rv = LoadProperties(*mFontName[0], mGlyphProperties);
#ifdef NS_DEBUG
    nsCAutoString uriStr;
    uriStr.AssignLiteral("resource://gre/res/fonts/mathfont");
    LossyAppendUTF16toASCII(*mFontName[0], uriStr);
    uriStr.StripWhitespace(); // that may come from mFontName
    uriStr.AppendLiteral(".properties");
    printf("Loading %s ... %s\n",
            uriStr.get(),
            (NS_FAILED(rv)) ? "Failed" : "Done");
#endif
    if (NS_FAILED(rv)) {
      mState = NS_TABLE_STATE_ERROR; // never waste time with this table again
      return kNullGlyph;
    }
    mState = NS_TABLE_STATE_READY;

    // see if there are external fonts needed for certain chars in this table
    nsCAutoString key;
    nsAutoString value;
    for (PRInt32 i = 1; ; i++) {
      key.AssignLiteral("external.");
      key.AppendInt(i, 10);
      rv = mGlyphProperties->GetStringProperty(key, value);
      if (NS_FAILED(rv)) break;
      Clean(value);
      mFontName.AppendString(value); // i.e., mFontName[i] holds this font name
    }
  }

  // If aChar is a child char to be used by a parent composite char, make
  // sure that it is really attached to this table
  if (aChar->mParent && (aChar->mGlyphTable != this)) return kNullGlyph;

  // Update our cache if it is not associated to this character
  PRUnichar uchar = aChar->mData[0];
  if (mCharCache != uchar) {
    // The key in the property file is interpreted as ASCII and kept
    // as such ...
    char key[10]; PR_snprintf(key, sizeof(key), "\\u%04X", uchar);
    nsAutoString value;
    nsresult rv = mGlyphProperties->GetStringProperty(nsDependentCString(key), value);
    if (NS_FAILED(rv)) return kNullGlyph;
    Clean(value);
    // See if this char uses external fonts; e.g., if the 2nd glyph is taken from the
    // external font '1', the property line looks like \uNNNN = \uNNNN\uNNNN@1\uNNNN.
    // This is where mGlyphCache is pre-processed to explicitly store all glyph codes
    // as combined pairs of 'code@font', excluding the '@' separator. This means that
    // mGlyphCache[2*k] will later be rendered with mFontName[mGlyphCache[2*k+1]-'0']
    // Note: font identifier is internally an ASCII digit to avoid the null char issue
    nsAutoString buffer, puaValue;
    char puaKey[10];
    PRInt32 length = value.Length();
    for (PRInt32 i = 0, j = 0; i < length; i++, j++) {
      PRUnichar code = value[i];
      PRUnichar font = PRUnichar('0');
      // see if we are at the beginning of a child char
      if (code == kSpaceCh) {
        // reset the annotation indicator to be 0 for the next code point
        j = -1;
      }
      // see if this code point is an *indirect reference* to
      // the PUA, and lookup "key.[TLMBRG1-9]" in the PUA
      else if (code == PRUnichar(0xF8FF)) {
        PR_snprintf(puaKey, sizeof(puaKey), "%s.%c", key, GetAnnotation(aChar, j));
        rv = gPUAProperties->GetStringProperty(nsDependentCString(puaKey), puaValue);
        if (NS_FAILED(rv) || puaValue.IsEmpty()) return kNullGlyph;
        code = puaValue[0];
      }
      // see if this code point is a *direct reference* to
      // the PUA, and lookup "code.[TLMBRG1-9]" in the PUA
      else if ((i+2 < length) && (value[i+1] == PRUnichar('.'))) {
        i += 2;
        // safe cast of value[i], it's ascii
        PR_snprintf(puaKey, sizeof(puaKey), "\\u%04X.%c", code, char(value[i]));
        rv = gPUAProperties->GetStringProperty(nsDependentCString(puaKey), puaValue);
        if (NS_FAILED(rv) || puaValue.IsEmpty()) return kNullGlyph;
        code = puaValue[0];
      }
      // see if an external font is needed for the code point
      if ((i+2 < length) && (value[i+1] == PRUnichar('@')) &&
          (value[i+2] >= PRUnichar('0')) && (value[i+2] <= PRUnichar('9'))) {
        i += 2;
        font = value[i];
        // The char cannot be handled if this font is not installed
        nsAutoString fontName;
        mFontName.StringAt(font-'0', fontName);
        if (!fontName.Length() || !CheckFontExistence(aPresContext, fontName)) {
          return kNullGlyph;
        }
      }
      buffer.Append(code);
      buffer.Append(font);
    }
    // update our cache with the new settings
    mGlyphCache.Assign(buffer);
    mCharCache = uchar;
  }

  // If aChar is a composite char, only its children are allowed
  // to use its glyphs in this table, i.e., the parent char itself
  // is disabled and cannot be stretched directly with these glyphs.
  // This guarantees a coherent behavior in Stretch().
  if (!aChar->mParent && (kNotFound != mGlyphCache.FindChar(kSpaceCh))) {
    return kNullGlyph;
  }

  // If aChar is a child char, the index of the glyph is relative to
  // the offset of the list of glyphs corresponding to the child char
  PRUint32 offset = 0;
  PRUint32 length = mGlyphCache.Length();
  if (aChar->mParent) {
    nsMathMLChar* child = aChar->mParent->mSibling;
    while (child && (child != aChar)) {
      offset += 5; // skip the 4 partial glyphs + the whitespace separator
      child = child->mSibling;
    }
    length = 2*(offset + 4); // stay confined in the 4 partial glyphs of this child
  }
  PRUint32 index = 2*(offset + aPosition); // 2* is to account for the code@font pairs
  if (index+1 >= length) return kNullGlyph;
  nsGlyphCode ch;
  ch.code = mGlyphCache.CharAt(index);
  ch.font = mGlyphCache.CharAt(index + 1) - '0'; // the ASCII trick is kept internal...
  return (ch == PRUnichar(0xFFFD)) ? kNullGlyph : ch;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char nsGlyphTable::GetAnnotation ( nsMathMLChar aChar,
PRInt32  aPosition 
) [private]

Definition at line 335 of file nsMathMLChar.cpp.

{
  NS_ASSERTION(aChar->mDirection == NS_STRETCH_DIRECTION_VERTICAL ||
               aChar->mDirection == NS_STRETCH_DIRECTION_HORIZONTAL,
               "invalid call");
  static const char kVertical[]   = "TMBG";
  static const char kHorizontal[] = "LMRG";
  if (aPosition >= 4) {
    // return an ASCII digit for the size=0,1,2,...
    return '0' + aPosition - 4;
  }
  return (aChar->mDirection == NS_STRETCH_DIRECTION_VERTICAL) ?
      kVertical[aPosition] :
      kHorizontal[aPosition];
}

Here is the caller graph for this function:

nsresult nsGlyphTable::GetBoundingMetrics ( nsIRenderingContext aRenderingContext,
nsFont aFont,
nsGlyphCode aGlyphCode,
nsBoundingMetrics &  aBoundingMetrics 
)

Definition at line 567 of file nsMathMLChar.cpp.

{
  nsresult rv;
  if (aGlyphCode.font) {
    // glyph not associated to our primary font, it comes from an external font
    mFontName.StringAt(aGlyphCode.font, aFont.name);
    aRenderingContext.SetFont(aFont, nsnull);
  }

  //if (mType == NS_TABLE_TYPE_UNICODE)
    rv = aRenderingContext.GetBoundingMetrics((PRUnichar*)&aGlyphCode.code, PRUint32(1), aBoundingMetrics);
  //else mType == NS_TABLE_TYPE_GLYPH_INDEX
  //return NS_ERROR_NOT_IMPLEMENTED;
  //rv = aRenderingContext.GetBoundingMetricsI((PRUint16*)&aGlyphCode.code, PRUint32(1), aBoundingMetrics);

  if (aGlyphCode.font) {
    // restore our primary font in the rendering context
    mFontName.StringAt(0, aFont.name);
    aRenderingContext.SetFont(aFont, nsnull);
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGlyphTable::GetPrimaryFontName ( nsString aPrimaryFontName) [inline]

Definition at line 236 of file nsMathMLChar.cpp.

                                                      {
    mFontName.StringAt(0, aPrimaryFontName);
  }

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::GlueOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
) [inline]

Definition at line 269 of file nsMathMLChar.cpp.

                                                                       {
    return ElementAt(aPresContext, aChar, 3);
  }

Here is the caller graph for this function:

PRBool nsGlyphTable::Has ( nsPresContext aPresContext,
nsMathMLChar aChar 
)

Definition at line 512 of file nsMathMLChar.cpp.

{
  return HasVariantsOf(aPresContext, aChar) || HasPartsOf(aPresContext, aChar);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGlyphTable::Has ( nsPresContext aPresContext,
PRUnichar  aChar 
)

Definition at line 518 of file nsMathMLChar.cpp.

{
  nsMathMLChar tmp;
  tmp.mData = aChar;
  tmp.mDirection = GetStretchyDirection(aChar);
  return (tmp.mDirection == NS_STRETCH_DIRECTION_UNSUPPORTED)
    ? PR_FALSE
    : Has(aPresContext, &tmp);
}

Here is the call graph for this function:

PRBool nsGlyphTable::HasPartsOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
)

Definition at line 546 of file nsMathMLChar.cpp.

{
  return  GlueOf(aPresContext, aChar) || TopOf(aPresContext, aChar) ||
          BottomOf(aPresContext, aChar) || MiddleOf(aPresContext, aChar) ||
          IsComposite(aPresContext, aChar);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGlyphTable::HasPartsOf ( nsPresContext aPresContext,
PRUnichar  aChar 
)

Definition at line 554 of file nsMathMLChar.cpp.

{
  nsMathMLChar tmp;
  tmp.mData = aChar;
  tmp.mDirection = GetStretchyDirection(aChar);
  return (tmp.mDirection == NS_STRETCH_DIRECTION_UNSUPPORTED)
    ? PR_FALSE
    : HasPartsOf(aPresContext, &tmp);
}

Here is the call graph for this function:

PRBool nsGlyphTable::HasVariantsOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
)

Definition at line 529 of file nsMathMLChar.cpp.

{
  return BigOf(aPresContext, aChar, 1) != 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGlyphTable::HasVariantsOf ( nsPresContext aPresContext,
PRUnichar  aChar 
)

Definition at line 535 of file nsMathMLChar.cpp.

{
  nsMathMLChar tmp;
  tmp.mData = aChar;
  tmp.mDirection = GetStretchyDirection(aChar);
  return (tmp.mDirection == NS_STRETCH_DIRECTION_UNSUPPORTED)
    ? PR_FALSE
    : HasVariantsOf(aPresContext, &tmp);
}

Here is the call graph for this function:

PRBool nsGlyphTable::IsComposite ( nsPresContext aPresContext,
nsMathMLChar aChar 
)

Definition at line 489 of file nsMathMLChar.cpp.

{
  // there is only one level of recursion in our model. a child
  // cannot be composite because it cannot have its own children
  if (aChar->mParent) return PR_FALSE;
  // shortcut to sync the cache with this char...
  mCharCache = 0; mGlyphCache.Truncate(); ElementAt(aPresContext, aChar, 0);
  // the cache remained empty if the char wasn't found in this table
  if (8 >= mGlyphCache.Length()) return PR_FALSE;
  // the lists of glyphs of a composite char are space-separated
  return (kSpaceCh == mGlyphCache.CharAt(8));
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::LeftOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
) [inline]

Definition at line 275 of file nsMathMLChar.cpp.

                                                                       {
    return ElementAt(aPresContext, aChar, 0);
  }

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::MiddleOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
) [inline]

Definition at line 263 of file nsMathMLChar.cpp.

                                                                         {
    return ElementAt(aPresContext, aChar, 1);
  }

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::RightOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
) [inline]

Definition at line 278 of file nsMathMLChar.cpp.

                                                                        {
    return ElementAt(aPresContext, aChar, 2);
  }

Here is the caller graph for this function:

nsGlyphCode nsGlyphTable::TopOf ( nsPresContext aPresContext,
nsMathMLChar aChar 
) [inline]

Definition at line 260 of file nsMathMLChar.cpp.

                                                                      {
    return ElementAt(aPresContext, aChar, 0);
  }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 331 of file nsMathMLChar.cpp.

nsStringArray nsGlyphTable::mFontName [private]

Definition at line 306 of file nsMathMLChar.cpp.

Definition at line 330 of file nsMathMLChar.cpp.

Definition at line 312 of file nsMathMLChar.cpp.

Definition at line 309 of file nsMathMLChar.cpp.

Definition at line 301 of file nsMathMLChar.cpp.


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