Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsUnicodeRenderingToolkit Class Reference

#include <nsUnicodeRenderingToolkit.h>

Collaboration diagram for nsUnicodeRenderingToolkit:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsUnicodeRenderingToolkit ()
virtual ~nsUnicodeRenderingToolkit ()
nsresult PrepareToDraw (float aP2T, nsIDeviceContext *aContext, nsGraphicState *aGS, CGrafPtr aPort, PRBool aRightToLeftText)
nsresult GetTextDimensions (const PRUnichar *aString, PRUint32 aLength, nsTextDimensions &aDimension, PRInt32 *aFontID)
nsresult GetWidth (const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID)
nsresult DrawString (const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord *aSpacing)

Private Member Functions

PRBool TECFallbackGetDimensions (const PRUnichar *pChar, nsTextDimensions &oWidth, short fontNum, nsUnicodeFontMappingMac &fontMapping)
PRBool TECFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth, short fontNum, nsUnicodeFontMappingMac &fontMapping)
PRBool ATSUIFallbackGetDimensions (const PRUnichar *pChar, nsTextDimensions &oWidth, short fontNum, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor)
PRBool ATSUIFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth, short fontNum, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor)
PRBool SurrogateGetDimensions (const PRUnichar *aSurrogatePt, nsTextDimensions &oWidth, short fontNum, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor)
PRBool SurrogateDrawChar (const PRUnichar *aSurrogatePt, PRInt32 x, PRInt32 y, short &oWidth, short fontNum, short aSize, PRBool aBold, PRBool aItalic, nscolor aColor)
PRBool UPlusFallbackGetWidth (const PRUnichar *pChar, short &oWidth)
PRBool UPlusFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth)
PRBool QuestionMarkFallbackGetWidth (const PRUnichar *pChar, short &oWidth)
PRBool QuestionMarkFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth)
PRBool LatinFallbackGetWidth (const PRUnichar *pChar, short &oWidth)
PRBool LatinFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth)
PRBool PrecomposeHangulFallbackGetWidth (const PRUnichar *pChar, short &oWidth, short koreanFont, short origFont)
PRBool PrecomposeHangulFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth, short koreanFont, short origFont)
PRBool TransliterateFallbackGetWidth (const PRUnichar *pChar, short &oWidth)
PRBool TransliterateFallbackDrawChar (const PRUnichar *pChar, PRInt32 x, PRInt32 y, short &oWidth)
PRBool LoadTransliterator ()
void GetScriptTextWidth (const char *aText, ByteCount aLen, short &aWidth)
void DrawScriptText (const char *aText, ByteCount aLen, PRInt32 x, PRInt32 y, short &aWidth)
nsresult GetTextSegmentWidth (const PRUnichar *aString, PRUint32 aLength, short fontNum, nsUnicodeFontMappingMac &fontMapping, PRUint32 &oWidth)
nsresult GetTextSegmentDimensions (const PRUnichar *aString, PRUint32 aLength, short fontNum, nsUnicodeFontMappingMac &fontMapping, nsTextDimensions &aDimension)
nsresult DrawTextSegment (const PRUnichar *aString, PRUint32 aLength, short fontNum, nsUnicodeFontMappingMac &fontMapping, PRInt32 x, PRInt32 y, PRUint32 &oWidth)
nsUnicodeFallbackCacheGetTECFallbackCache ()

Private Attributes

float mP2T
nsIDeviceContextmContext
nsGraphicStatemGS
CGrafPtr mPort
nsATSUIToolkit mATSUIToolkit
nsCOMPtr< nsISaveAsCharsetmTrans
PRBool mRightToLeftText

Detailed Description

Definition at line 54 of file nsUnicodeRenderingToolkit.h.


Constructor & Destructor Documentation

Definition at line 57 of file nsUnicodeRenderingToolkit.h.

{};

Definition at line 58 of file nsUnicodeRenderingToolkit.h.

{};

Member Function Documentation

PRBool nsUnicodeRenderingToolkit::ATSUIFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth,
short  fontNum,
short  aSize,
PRBool  aBold,
PRBool  aItalic,
nscolor  aColor 
) [private]

Definition at line 542 of file nsUnicodeRenderingToolkit.cpp.

{
  nsMacUnicodeFontInfo info;
  if (nsATSUIUtils::IsAvailable()  
      && (IN_STANDARD_MAC_ROMAN_FONT(*aCharPt) 
         ||IN_SYMBOL_FONT(*aCharPt)
         ||SPECIAL_IN_SYMBOL_FONT(*aCharPt)
         ||info.HasGlyphFor(*aCharPt)))
  {
    mATSUIToolkit.PrepareToDraw(mPort, mContext );
    nsresult res;
    if(SPECIAL_IN_SYMBOL_FONT(*aCharPt)) 
    {
      short rep = 0;
      if ((*aCharPt) > 0x230b)
        rep = (*aCharPt) - 0x2325;
      else 
        rep = (*aCharPt) - 0x2308;
      res = mATSUIToolkit.DrawString(gSymbolReplacement+rep, 1, x, y, oWidth, aSize, 
                                     origFontNum, 
                                     aBold, aItalic, aColor);
    } else {
      res = mATSUIToolkit.DrawString(aCharPt, 1, x, y, oWidth, aSize, 
                                     origFontNum, 
                                     aBold, aItalic, aColor);
    }
    if (NS_SUCCEEDED(res))
      return PR_TRUE;
  }

  if (IN_ARABIC_PRESENTATION_A_OR_B(*aCharPt))
  {      
    PRUnichar isolated;
    if (NS_SUCCEEDED(FormAorBIsolated(*aCharPt, info, &isolated))) {
      if (ATSUIFallbackDrawChar(&isolated, x, y, oWidth, origFontNum, 
                                aSize, aBold, aItalic, aColor))
         return PR_TRUE;
    }                                                 
  }

  // we know some ATSUI font do not have bold, turn it off and try again
  if (aBold)
  {
    if (ATSUIFallbackDrawChar(aCharPt, x, y, oWidth, origFontNum, 
                              aSize, PR_FALSE, aItalic, aColor))
       return PR_TRUE;
  }

  // we know some ATSUI font do not have italic, turn it off and try again
  if (aItalic)
  {
    if (ATSUIFallbackDrawChar(aCharPt, x, y, oWidth, origFontNum, 
                              aSize, PR_FALSE, PR_FALSE, aColor))
       return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::ATSUIFallbackGetDimensions ( const PRUnichar pChar,
nsTextDimensions oWidth,
short  fontNum,
short  aSize,
PRBool  aBold,
PRBool  aItalic,
nscolor  aColor 
) [private]

Definition at line 401 of file nsUnicodeRenderingToolkit.cpp.

{
  
  nsMacUnicodeFontInfo info;
  if (nsATSUIUtils::IsAvailable()  
      && (IN_STANDARD_MAC_ROMAN_FONT(*aCharPt) 
         ||IN_SYMBOL_FONT(*aCharPt)
         ||SPECIAL_IN_SYMBOL_FONT(*aCharPt)
         ||info.HasGlyphFor(*aCharPt)))
  {
    mATSUIToolkit.PrepareToDraw(mPort, mContext );
    nsresult res;
    if (SPECIAL_IN_SYMBOL_FONT(*aCharPt))
    {
      short rep = 0;
      if ((*aCharPt) > 0x230b)
         rep = (*aCharPt) - 0x2325;
      else 
         rep = (*aCharPt) - 0x2308;
      res = mATSUIToolkit.GetTextDimensions(gSymbolReplacement+rep, 1, oDim, aSize, 
                                            origFontNum, 
                                            aBold, aItalic, aColor);
    } 
    else 
    {
      res = mATSUIToolkit.GetTextDimensions(aCharPt, 1, oDim, aSize, 
                                            origFontNum, 
                                            aBold, aItalic, aColor);
    }
    if (NS_SUCCEEDED(res)) 
      return PR_TRUE;
  }

  if (IN_ARABIC_PRESENTATION_A_OR_B(*aCharPt))
  {      
    PRUnichar isolated;
    if (NS_SUCCEEDED( FormAorBIsolated(*aCharPt, info, &isolated))) 
    {
      if (ATSUIFallbackGetDimensions(&isolated, oDim, origFontNum, 
                                     aSize, aBold, aItalic, aColor))
         return PR_TRUE;
    }                                                 
  }

  // we know some ATSUI font do not have bold, turn it off and try again
  if (aBold) 
  {
         if (ATSUIFallbackGetDimensions(aCharPt, oDim, origFontNum, 
                                        aSize, PR_FALSE, aItalic, aColor))
            return PR_TRUE;
  }

  // we know some ATSUI font do not have italic, turn it off and try again
  if (aItalic) 
  {
         if (ATSUIFallbackGetDimensions(aCharPt, oDim, origFontNum, 
                                        aSize, PR_FALSE, PR_FALSE, aColor))
            return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsUnicodeRenderingToolkit::DrawScriptText ( const char *  aText,
ByteCount  aLen,
PRInt32  x,
PRInt32  y,
short &  aWidth 
) [private]

Definition at line 1200 of file nsUnicodeRenderingToolkit.cpp.

{
       ::MoveTo(x, y);
       ::DrawText(buf,0,aLen);
       
       Point   penLoc;
       ::GetPen(&penLoc);
       oWidth = penLoc.h - x;
}

Here is the caller graph for this function:

nsresult nsUnicodeRenderingToolkit::DrawString ( const PRUnichar aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
PRInt32  aFontID,
const nscoord aSpacing 
)

Definition at line 1827 of file nsUnicodeRenderingToolkit.cpp.

{
  nsresult res = NS_OK;
  nsFontMetricsMac *metrics = (nsFontMetricsMac*) mGS->mFontMetrics;
  nsUnicodeFontMappingMac* fontmap = metrics->GetUnicodeFontMapping();

  PRInt32 x = aX;
  PRInt32 transformedY = aY;
  mGS->mTMatrix.TransformCoord(&x, &transformedY);

  PRUint32 i;
  PRInt32 currentX = aX;
  PRUint32 thisWidth = 0;
       
  if (aSpacing)
  {
    // fix me ftang -  handle (mRightToLeftText) here
    for (i = 0; i < aLength; )
    {
      PRUint32 drawLen;
      short curFontNum = fontmap->GetFontID(aString[i]);

      for (drawLen = 1; (i + drawLen) < aLength; drawLen++)
      {
        PRUnichar uc = aString[i+drawLen];
       if(! (IS_CONTEXTUAL_CHARS(uc) || 
                  IS_FORMAT_CONTROL_CHARS(uc) ||
             IS_COMBINING_CHARS(uc)) ) {
         break;
       }
      }

      PRInt32 transformedX = currentX, ignoreY = 0;
      mGS->mTMatrix.TransformCoord(&transformedX, &ignoreY);
      res = DrawTextSegment(aString+i, drawLen, curFontNum, *fontmap, transformedX, transformedY, thisWidth);
           if (NS_FAILED(res))
                       return res;
      
      for (PRUint32 j = 0; j < drawLen; j++)
                currentX += aSpacing[i + j];
                
              i += drawLen;
    }
  }
  else    // no spacing array
  {
    short thisFont, nextFont;
    
    PRUint32 start;

      // normal left to right
        thisFont = fontmap->GetFontID(aString[0]);
           for (i = 1, start = 0; i < aLength; i++)
           {
              PRUnichar uch = aString[i];
              if(! IS_FORMAT_CONTROL_CHARS(uch))
              {
                     nextFont = fontmap->GetFontID(uch);
                     if (thisFont != nextFont) 
               {
                 // start new font run...
                 PRInt32 transformedX = currentX, ignoreY = 0;
                 mGS->mTMatrix.TransformCoord(&transformedX, &ignoreY);
                 
            res = DrawTextSegment(aString + start, i - start, thisFont, *fontmap, transformedX, transformedY, thisWidth);
                     if (NS_FAILED(res))
                              return res;
                            
                       currentX += NSToCoordRound(float(thisWidth) * mP2T);
                       start = i;
                       thisFont = nextFont;
                     }
              }
           }

           PRInt32 transformedX = currentX, ignoreY = 0;
           mGS->mTMatrix.TransformCoord(&transformedX, &ignoreY);
      res = DrawTextSegment(aString+start, aLength-start, thisFont, *fontmap, transformedX, transformedY, thisWidth);
    if (NS_FAILED(res))
      return res;
  }
  
       return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsUnicodeRenderingToolkit::DrawTextSegment ( const PRUnichar aString,
PRUint32  aLength,
short  fontNum,
nsUnicodeFontMappingMac fontMapping,
PRInt32  x,
PRInt32  y,
PRUint32 oWidth 
) [private]

Definition at line 1563 of file nsUnicodeRenderingToolkit.cpp.

{
       if(aLength == 0 || fontNum == IGNORABLE_FONT_NUM) {
              oWidth = 0;
              return NS_OK;
       }      
       NS_PRECONDITION(BAD_FONT_NUM != fontNum, "illegal font num");
    short textWidth = 0;
    PRUint32 processLen = 0;
    char *heapBuf = nsnull;
    PRUint32 heapBufSize = 0;
    short thisWidth = 0;
    char stackBuf[STACK_TRESHOLD];
    char *buf ;
    ByteCount processBytes;
    ByteCount outLen;
       const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts();

    ::TextFont(fontNum);
       
       // find buf from stack or heap. We only need to do this once in this function.
       // put this out of the loop for performance...
       ByteCount bufLen = aLength * 2 + 10;
       if( bufLen > STACK_TRESHOLD)
       {
              if(bufLen > heapBufSize )
              {
                     if(heapBuf)
                            delete[] heapBuf;
                     heapBuf = new char [bufLen];
                     heapBufSize = bufLen;
                     if(nsnull == heapBuf) {
                            return NS_ERROR_OUT_OF_MEMORY;
                     }                           
              } 
              buf = heapBuf;
        } else {
              bufLen = STACK_TRESHOLD;
              buf = stackBuf;
       }

    do {
      outLen = 0;
      processBytes = 0;
        
      if(fontMapping.ConvertUnicodeToGlyphs(fontNum, aString, aLength - processLen,
                buf, bufLen, outLen, processBytes, 0))
      {
        DrawScriptText(buf, outLen, x, y, thisWidth);
        
        textWidth += thisWidth;
        x += thisWidth;                   
        
        NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result");
        
        PRInt32 processUnicode = processBytes / 2;
        processLen += processUnicode;
        aString += processUnicode;
      }
               
         // Cannot precess by TEC, process one char a time by fallback mechanism
         if( processLen < aLength)
         {
                PRBool fallbackDone = PR_FALSE;

      if (IS_HIGH_SURROGATE(*aString) && 
          ((processLen+1) < aLength) &&
          IS_LOW_SURROGATE(*(aString+1)) )
      {
         const nsFont *font = &mGS->mFontMetrics->Font();
         fallbackDone = SurrogateDrawChar(aString, x, y, thisWidth, fontNum, 
                                          font->size, 
                                          (font->weight > NS_FONT_WEIGHT_NORMAL), 
                                          ((NS_FONT_STYLE_ITALIC ==  font->style) || (NS_FONT_STYLE_OBLIQUE ==  font->style)),
                                          mGS->mColor ); 
         if (fallbackDone)
         {      
           textWidth += thisWidth;
           x += thisWidth;         
           aString += 2;
           processLen += 2;
           continue;
         }
      }
#ifndef DISABLE_TEC_FALLBACK
                // Fallback by try different Script code
                if (! IS_SKIP_TEC_FALLBACK(*aString))
                fallbackDone = TECFallbackDrawChar(aString, x, y, thisWidth, fontNum, fontMapping);
#endif
                //
                // We really don't care too much of performance after this
                // This will only be called when we cannot display this character in ANY mac script avaliable
                // 

#ifndef DISABLE_ATSUI_FALLBACK  
                // Fallback by using ATSUI
                if(! fallbackDone)  {
                     const nsFont *font = &mGS->mFontMetrics->Font();
                     fallbackDone = ATSUIFallbackDrawChar(aString, x, y, thisWidth, fontNum, 
                                                                             font->size, 
                                                                             (font->weight > NS_FONT_WEIGHT_NORMAL), 
                                                                             ((NS_FONT_STYLE_ITALIC ==  font->style) || (NS_FONT_STYLE_OBLIQUE ==  font->style)),
                                                                             mGS->mColor );
                }
#endif
                if(! fallbackDone) {
                   if(IS_ZERO_WIDTH_CHAR(*aString))
                   {
                      thisWidth = 0;
                      fallbackDone = PR_TRUE;
                   }
                }
      
#ifndef DISABLE_LATIN_FALLBACK
                if(! fallbackDone)
                     fallbackDone = LatinFallbackDrawChar(aString, x, y, thisWidth);
#endif
#ifndef DISABLE_PRECOMPOSEHANGUL_FALLBACK
                if(! fallbackDone)
                     fallbackDone = PrecomposeHangulFallbackDrawChar(aString, x, y, thisWidth,scriptFallbackFonts[smKorean], fontNum);
#endif
#ifndef DISABLE_TRANSLITERATE_FALLBACK  
                // Fallback to Transliteration
                if(! fallbackDone) {
                     fallbackDone = TransliterateFallbackDrawChar(aString, x, y, thisWidth);
                }
#endif
#ifndef DISABLE_UPLUS_FALLBACK  
                // Fallback to U+xxxx
                if(! fallbackDone)
                     fallbackDone = UPlusFallbackDrawChar(aString, x, y, thisWidth);
#endif
                     
                // Fallback to question mark
                if(! fallbackDone)
                     QuestionMarkFallbackDrawChar(aString, x, y, thisWidth);
                     
                textWidth += thisWidth;
                x += thisWidth;
                
                // for fallback measure/drawing, we always do one char a time.
                aString++;
                processLen++;
         }
    } while (processLen < aLength);
    
    // release buffer if it is from heap
    if(heapBuf)
       delete[] heapBuf;
       
    oWidth = textWidth;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsUnicodeRenderingToolkit::GetScriptTextWidth ( const char *  aText,
ByteCount  aLen,
short &  aWidth 
) [private]

Definition at line 1103 of file nsUnicodeRenderingToolkit.cpp.

{
       oWidth = ::TextWidth(buf, 0, aLen);
}

Here is the caller graph for this function:

Definition at line 160 of file nsUnicodeRenderingToolkit.cpp.

{
       static nsUnicodeFallbackCache* gTECFallbackCache = nsnull;
       
       if( ! gTECFallbackCache)
              gTECFallbackCache = new nsUnicodeFallbackCache();
       return gTECFallbackCache;
}

Here is the caller graph for this function:

nsresult nsUnicodeRenderingToolkit::GetTextDimensions ( const PRUnichar aString,
PRUint32  aLength,
nsTextDimensions aDimension,
PRInt32 aFontID 
)

Definition at line 1733 of file nsUnicodeRenderingToolkit.cpp.

{
  nsresult res = NS_OK;
  nsFontMetricsMac *metrics = (nsFontMetricsMac*) mGS->mFontMetrics;
  nsUnicodeFontMappingMac* fontmap = metrics->GetUnicodeFontMapping();

  PRUint32 i;
  short fontNum[2];
  fontNum[0] = fontNum[1] = BAD_FONT_NUM;
  PRUint32 start;
    
  nsTextDimensions textDim;
  nsTextDimensions thisDim;
  
  for(i =0, start = 0; i < aLength; i++)
  {
    fontNum[ i % 2] = fontmap->GetFontID(aString[i]);
    if ((fontNum[0] != fontNum[1]) && (0 != i))
    {  // start new font run...
      thisDim.Clear();
      res =  GetTextSegmentDimensions(aString+start, i - start, fontNum[(i + 1) % 2], *fontmap, thisDim);
      if (NS_FAILED (res)) 
        return res;    
      textDim.Combine(thisDim);
      start = i;
    }
  }
  res = GetTextSegmentDimensions(aString+start, aLength - start, fontNum[(i + 1) % 2], *fontmap, thisDim);
  if (NS_FAILED (res)) 
    return res;    
  textDim.Combine(thisDim);

  aDim.width = NSToCoordRound(float(textDim.width) * mP2T);
  aDim.ascent = NSToCoordRound(float(textDim.ascent) * mP2T);
  aDim.descent = NSToCoordRound(float(textDim.descent) * mP2T);
  return res;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsUnicodeRenderingToolkit::GetTextSegmentDimensions ( const PRUnichar aString,
PRUint32  aLength,
short  fontNum,
nsUnicodeFontMappingMac fontMapping,
nsTextDimensions aDimension 
) [private]

Definition at line 1231 of file nsUnicodeRenderingToolkit.cpp.

{
  oDim.Clear();
  if(aLength == 0 || fontNum == IGNORABLE_FONT_NUM) 
    return NS_OK;
  NS_PRECONDITION(BAD_FONT_NUM != fontNum, "illegal font num");
  PRUint32 processLen = 0;
  char *heapBuf = nsnull;
  PRUint32 heapBufSize = 0;
  short thisWidth = 0;
  char stackBuf[STACK_TRESHOLD];
  char *buf ;
  ByteCount processBytes;
  ByteCount outLen;
  const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts();
  
  ::TextFont(fontNum);
  
  FontInfo fInfo;
  ::GetFontInfo(&fInfo);
  nsTextDimensions segDim;
  segDim.ascent = fInfo.ascent;
  segDim.descent = fInfo.descent;
  oDim.Combine(segDim);
  
  // find buf from stack or heap. We only need to do this once in this function.
  // put this out of the loop for performance...
  ByteCount bufLen = aLength * 2 + 10;
  if (bufLen > STACK_TRESHOLD)
  {
    if (bufLen > heapBufSize)
    {
      if (heapBuf)
        nsMemory::Free(heapBuf);
      heapBuf = (char*) nsMemory::Alloc(bufLen);
      heapBufSize = bufLen;
      if (nsnull == heapBuf) 
        return NS_ERROR_OUT_OF_MEMORY;
    } 
    buf = heapBuf;
  } 
  else 
  {
    bufLen = STACK_TRESHOLD;
    buf = stackBuf;
  }
  do {
    outLen = 0;
    processBytes = 0;

    if(fontMapping.ConvertUnicodeToGlyphs(fontNum, aString, aLength - processLen,
            buf, bufLen, outLen, processBytes, 0))
    {
        GetScriptTextWidth(buf, outLen, thisWidth);
      
        segDim.Clear();
        segDim.width = thisWidth;
        oDim.Combine(segDim);
    
        NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result");
    
        PRInt32 processUnicode = processBytes / 2;
        processLen += processUnicode;
        aString += processUnicode;
    }
         
    // Cannot precess by TEC, process one char a time by fallback mechanism
    if (processLen < aLength)
    {
      PRBool fallbackDone = PR_FALSE;
      segDim.Clear();
      
      if (IS_HIGH_SURROGATE(*aString) && 
          ((processLen+1) < aLength) &&
          IS_LOW_SURROGATE(*(aString+1)))
      {
         const nsFont *font = &mGS->mFontMetrics->Font();
         fallbackDone = SurrogateGetDimensions(aString, segDim, fontNum, 
                                               font->size, 
                                               (font->weight > NS_FONT_WEIGHT_NORMAL), 
                                               ((NS_FONT_STYLE_ITALIC ==  font->style) || 
                                               (NS_FONT_STYLE_OBLIQUE ==  font->style)),
                                               mGS->mColor );     
         if (fallbackDone)
         {   
           oDim.Combine(segDim);    
           // for fallback measure/drawing, we always do one char a time.
           aString += 2;
           processLen += 2;
           continue;
         }
      }
#ifndef DISABLE_TEC_FALLBACK
      // Fallback by try different Script code
      if (! IS_SKIP_TEC_FALLBACK(*aString))
        fallbackDone = TECFallbackGetDimensions(aString, segDim, fontNum, fontMapping);
#endif

      //
      // We really don't care too much of performance after this
      // This will only be called when we cannot display this character in ANY mac script avaliable
      // 
#ifndef DISABLE_ATSUI_FALLBACK  
      // Fallback by using ATSUI
      if (!fallbackDone)  
      {
        const nsFont *font = &mGS->mFontMetrics->Font();
        fallbackDone = ATSUIFallbackGetDimensions(aString, segDim, fontNum, 
                                                  font->size, 
                                                  (font->weight > NS_FONT_WEIGHT_NORMAL), 
                                                  ((NS_FONT_STYLE_ITALIC ==  font->style) || 
                                                   (NS_FONT_STYLE_OBLIQUE ==  font->style)),
                                                  mGS->mColor );
      }

#endif
                if(! fallbackDone) {
                   if(IS_ZERO_WIDTH_CHAR(*aString))
                   {
                      fallbackDone = PR_TRUE;
                   }
                }
#ifndef DISABLE_LATIN_FALLBACK
      if (!fallbackDone) 
      {
        fallbackDone = LatinFallbackGetWidth(aString, thisWidth);
        if (fallbackDone)
          segDim.width = thisWidth;
      }
#endif
#ifndef DISABLE_PRECOMPOSEHANGUL_FALLBACK
      if (!fallbackDone)
      {
        fallbackDone = PrecomposeHangulFallbackGetWidth(aString, thisWidth,
                                                        scriptFallbackFonts[smKorean], fontNum);
        if (fallbackDone)
          segDim.width = thisWidth;
      }
#endif
#ifndef DISABLE_TRANSLITERATE_FALLBACK  
      // Fallback to Transliteration
      if (!fallbackDone) 
      {
        fallbackDone = TransliterateFallbackGetWidth(aString, thisWidth);
        if (fallbackDone)
          segDim.width = thisWidth;
      }
#endif
#ifndef DISABLE_UPLUS_FALLBACK  
      // Fallback to UPlus
      if (!fallbackDone)
      {
        fallbackDone = UPlusFallbackGetWidth(aString, thisWidth);
        if (fallbackDone)
          segDim.width = thisWidth;
      }
#endif
        
      // Fallback to question mark
      if (!fallbackDone) 
      {
        QuestionMarkFallbackGetWidth(aString, thisWidth);
        if (fallbackDone)
          segDim.width = thisWidth;
      }
      
      oDim.Combine(segDim);    
      // for fallback measure/drawing, we always do one char a time.
      aString++;
      processLen++;
    }
  } while (processLen < aLength);
    
    // release buffer if it is from heap
  if (heapBuf)
    nsMemory::Free(heapBuf);
      
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsUnicodeRenderingToolkit::GetTextSegmentWidth ( const PRUnichar aString,
PRUint32  aLength,
short  fontNum,
nsUnicodeFontMappingMac fontMapping,
PRUint32 oWidth 
) [private]

Definition at line 1217 of file nsUnicodeRenderingToolkit.cpp.

{
  nsTextDimensions dim;
  nsresult res = GetTextSegmentDimensions(aString, aLength, fontNum, fontMapping, dim);
  oWidth = dim.width;
  return res;
}

Here is the call graph for this function:

nsresult nsUnicodeRenderingToolkit::GetWidth ( const PRUnichar aString,
PRUint32  aLength,
nscoord aWidth,
PRInt32 aFontID 
)

Definition at line 1722 of file nsUnicodeRenderingToolkit.cpp.

{
  nsTextDimensions dim;

  nsresult res = GetTextDimensions(aString, aLength, dim, aFontID);
  aWidth = dim.width;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::LatinFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth 
) [private]

Definition at line 1047 of file nsUnicodeRenderingToolkit.cpp.

{
  if(0x1E00 == (0xFF00 & *aCharPt)) 
  {
       PRInt32 idx = 3 * ( *aCharPt & 0x00FF);
       if(' ' != g1E00Dec[idx])
       {
      CGrafPtr thePort;
      ::GetPort((GrafPtr*)&thePort);
           short aSize = ::GetPortTextSize(thePort);    
           short dummy;
           short realwidth;
              char comb[2];
              short xadj;
              short yadj;
              short yadjB=0;
              
              PRBool baseTooBig =  ('A'<= g1E00Dec[idx]  ) && (g1E00Dec[idx] <= 'Z'  ) 
                                   || ('f' == g1E00Dec[idx])|| ('l' == g1E00Dec[idx])|| ('k' == g1E00Dec[idx]);
              PRBool firstIsAbove    = ('A'<= g1E00Dec[idx+1]) && (g1E00Dec[idx+1] <= 'Z') ;
              PRBool secondIsAbove   = ('A'<= g1E00Dec[idx+2]) && (g1E00Dec[idx+2] <= 'Z') ;
              
              GetScriptTextWidth(g1E00Dec+idx, 1, oWidth);
              if(baseTooBig && (firstIsAbove ||secondIsAbove ))
              ::TextSize(aSize *3/4);            

              DrawScriptText(g1E00Dec+idx, 1, x, y, realwidth);

              if(baseTooBig && (firstIsAbove ||secondIsAbove ))
                     ::TextSize(aSize);                 
              if(' ' != g1E00Dec[idx+1]) {
                     CCodeToMacRoman(g1E00Dec[idx+1],comb[0], realwidth, aSize, xadj, yadj);
                     
                     GetScriptTextWidth(comb, 1, dummy);
                     
                     DrawScriptText( comb, 1, x + xadj + ( realwidth - dummy ) / 2, y + yadj + yadjB, dummy);
              }
              if(' ' != g1E00Dec[idx+2]) {
                     if( firstIsAbove && secondIsAbove)
                            yadjB = yadjB - aSize / 6;         
              
                     CCodeToMacRoman(g1E00Dec[idx+2],comb[0], realwidth, aSize, xadj, yadj);
                     GetScriptTextWidth(comb, 1, dummy);
                     DrawScriptText( comb, 1, x + xadj+ ( realwidth - dummy ) / 2, y+ yadj + yadjB, dummy);
              }
              return PR_TRUE;
       }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::LatinFallbackGetWidth ( const PRUnichar pChar,
short &  oWidth 
) [private]

Definition at line 1030 of file nsUnicodeRenderingToolkit.cpp.

{
  if(0x1E00 == (0xFF00 & *aCharPt)) 
  {
       PRInt32 idx = 3 * ( *aCharPt & 0x00FF);
       if(' ' != g1E00Dec[idx])
       {
              GetScriptTextWidth(g1E00Dec+idx, 1, oWidth);
              return PR_TRUE;
       }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 678 of file nsUnicodeRenderingToolkit.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::PrecomposeHangulFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth,
short  koreanFont,
short  origFont 
) [private]

Definition at line 884 of file nsUnicodeRenderingToolkit.cpp.

{
  if(CAN_DO_PRECOMPOSE_HANGUL(*aCharPt, koreanFont)) {
         char euckr[8];
         if(koreanFont != origFont)
              ::TextFont(koreanFont);              
         UnicodePrecomposedHangulTo4EUCKR(*aCharPt, euckr);
         DrawScriptText(euckr, 8, x, y, oWidth); 
         if(koreanFont != origFont)
              ::TextFont(origFont);                
         return PR_TRUE;
  } else {
         return PR_FALSE;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::PrecomposeHangulFallbackGetWidth ( const PRUnichar pChar,
short &  oWidth,
short  koreanFont,
short  origFont 
) [private]

Definition at line 863 of file nsUnicodeRenderingToolkit.cpp.

{
  if(CAN_DO_PRECOMPOSE_HANGUL(*aCharPt, koreanFont)) {
         char euckr[8];
         if(koreanFont != origFont)
              ::TextFont(koreanFont);              
         UnicodePrecomposedHangulTo4EUCKR(*aCharPt, euckr);
         GetScriptTextWidth(euckr, 8, oWidth); 
         if(koreanFont != origFont)
              ::TextFont(origFont);                
         return PR_TRUE;
  } else {
         return PR_FALSE;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsUnicodeRenderingToolkit::PrepareToDraw ( float  aP2T,
nsIDeviceContext aContext,
nsGraphicState aGS,
CGrafPtr  aPort,
PRBool  aRightToLeftText 
)

Definition at line 1917 of file nsUnicodeRenderingToolkit.cpp.

{
       mP2T = aP2T;
       mContext = aContext;
       mGS = aGS;
       mPort = aPort;
       mRightToLeftText = aRightToLeftText;
       return NS_OK;
}

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::QuestionMarkFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth 
) [private]

Definition at line 663 of file nsUnicodeRenderingToolkit.cpp.

{
  CGrafPtr thePort;
  ::GetPort((GrafPtr*)&thePort);
  short saveSize = ::GetPortTextSize(thePort);          
  ::TextSize(QUESTION_FALLBACKSIZE);
  DrawScriptText(question, 3, x, y, oWidth);
  ::TextSize(saveSize);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 649 of file nsUnicodeRenderingToolkit.cpp.

{
  CGrafPtr thePort;
  ::GetPort((GrafPtr*)&thePort);
  short saveSize = ::GetPortTextSize(thePort);          
  ::TextSize(QUESTION_FALLBACKSIZE);
  GetScriptTextWidth(question, 3,oWidth);
  ::TextSize(saveSize);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::SurrogateDrawChar ( const PRUnichar aSurrogatePt,
PRInt32  x,
PRInt32  y,
short &  oWidth,
short  fontNum,
short  aSize,
PRBool  aBold,
PRBool  aItalic,
nscolor  aColor 
) [private]

Definition at line 618 of file nsUnicodeRenderingToolkit.cpp.

{
  nsresult res;
  mATSUIToolkit.PrepareToDraw(mPort, mContext );
  res = mATSUIToolkit.DrawString(aSurrogatePt, 2, x, y, oWidth, aSize, 
                                 origFontNum, 
                                 aBold, aItalic, aColor);
  return NS_SUCCEEDED(res);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::SurrogateGetDimensions ( const PRUnichar aSurrogatePt,
nsTextDimensions oWidth,
short  fontNum,
short  aSize,
PRBool  aBold,
PRBool  aItalic,
nscolor  aColor 
) [private]

Definition at line 606 of file nsUnicodeRenderingToolkit.cpp.

{
  nsresult res;
  mATSUIToolkit.PrepareToDraw(mPort, mContext );
  res = mATSUIToolkit.GetTextDimensions(aSurrogatePt, 2, oDim, aSize, 
                                        origFontNum, 
                                        aBold, aItalic, aColor);
  return NS_SUCCEEDED(res);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::TECFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth,
short  fontNum,
nsUnicodeFontMappingMac fontMapping 
) [private]

Definition at line 314 of file nsUnicodeRenderingToolkit.cpp.

{
  char buf[20];
  ByteCount processBytes = 0;
  ByteCount outLen = 0;
  ScriptCode fallbackScript;
  nsUnicodeFallbackCache* cache = GetTECFallbackCache();
  const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts();
  
  // since we always call TECFallbackGetWidth before TECFallbackDrawChar
  // we could assume that we can always get the script code from cache.
  if ((0xf780 <= *aCharPt) && (*aCharPt <= 0xf7ff))
  {
    // If we are encountering our PUA characters for User-Defined characters, we better
    // just drop the high-byte and draw the text for the low-byte.
    *buf = (*aCharPt & 0x00FF);
    DrawScriptText (buf,1,x,y,oWidth);

    return PR_TRUE;
  }
  else if (cache->Get(*aCharPt, fallbackScript))
  {
    if (BAD_SCRIPT == fallbackScript)
      return PR_FALSE;
    
    if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1,
        buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask))
    {
        ::TextFont(scriptFallbackFonts[fallbackScript]);
        DrawScriptText(buf, outLen, x, y, oWidth);
        ::TextFont(origFontNum);
        return PR_TRUE;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::TECFallbackGetDimensions ( const PRUnichar pChar,
nsTextDimensions oWidth,
short  fontNum,
nsUnicodeFontMappingMac fontMapping 
) [private]

Definition at line 171 of file nsUnicodeRenderingToolkit.cpp.

{
  char buf[20];
  ByteCount processBytes = 0;
  ByteCount outLen = 0;
  ScriptCode fallbackScript;
  nsUnicodeFallbackCache* cache = GetTECFallbackCache();
  short aWidth;
  FontInfo finfo;
  const short *scriptFallbackFonts = fontMapping.GetScriptFallbackFonts();
  
  if ((0xf780 <= *aCharPt) && (*aCharPt <= 0xf7ff))
  {
    // If we are encountering our PUA characters for User-Defined characters, we better
    // just drop the high-byte and return the width for the low-byte.
    *buf = (*aCharPt & 0x00FF);
    ::GetFontInfo(&finfo);
    oDim.ascent = finfo.ascent;
    oDim.descent = finfo.descent;
    
    GetScriptTextWidth (buf,1,aWidth);
    oDim.width = aWidth;

    return PR_TRUE;
  }
  else if (cache->Get(*aCharPt, fallbackScript))
  {
    if (BAD_SCRIPT == fallbackScript)
      return PR_FALSE;
    
    if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1,
        buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask))
    {  
        ::TextFont(scriptFallbackFonts[fallbackScript]);
        GetScriptTextWidth(buf, outLen, aWidth);
        ::GetFontInfo(&finfo);
        oDim.ascent = finfo.ascent;
        oDim.descent = finfo.descent;
        oDim.width = aWidth;
        ::TextFont(origFontNum);
    }
    return PR_TRUE;
  }
  
  for(fallbackScript = 0 ; fallbackScript < 32; fallbackScript++)
  {
    if (BAD_FONT_NUM != scriptFallbackFonts[fallbackScript])
    {
        if(fontMapping.ConvertUnicodeToGlyphs(scriptFallbackFonts[fallbackScript], aCharPt, 1,
            buf, STACK_TRESHOLD, outLen, processBytes, kUnicodeLooseMappingsMask))
        {
            NS_PRECONDITION(0 == (processBytes % 2), "strange conversion result");
            ::TextFont(scriptFallbackFonts[fallbackScript]);
            GetScriptTextWidth(buf, outLen, aWidth);
            ::GetFontInfo(&finfo);
            oDim.ascent = finfo.ascent;
            oDim.descent = finfo.descent;
            oDim.width = aWidth;
            ::TextFont(origFontNum);        
            break;
        }          
    }
  }
  
  if (0 == outLen)
    fallbackScript = BAD_SCRIPT;
    
  // put into cache
  cache->Set(*aCharPt, fallbackScript);
  
  return (BAD_SCRIPT != fallbackScript);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::TransliterateFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth 
) [private]

Definition at line 760 of file nsUnicodeRenderingToolkit.cpp.

{
  if(LoadTransliterator()) {
    nsAutoString tmp(aCharPt, 1);
    char* conv = nsnull;
    if(NS_SUCCEEDED(mTrans->Convert(tmp.get(), &conv)) && conv) {
           CGrafPtr thePort;
           ::GetPort((GrafPtr*)&thePort);
           short aSize = ::GetPortTextSize(thePort);           
       PRInt32 l=strlen(conv);
       if((l>3) && ('^' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sup
       {
              short small = aSize * 2 / 3;
              ::TextSize(small);
              DrawScriptText(conv+2, l-3, x, y-small/2, oWidth);
              ::TextSize(aSize);
       } 
       else if((l>3) && ('v' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sub
       {
              short small = aSize * 2 / 3;
              ::TextSize(small);
              DrawScriptText(conv+2, l-3, x, y+small/2, oWidth);
              ::TextSize(aSize);
              } 
              else if((l>1) && ('0' <= conv[0]) && ( conv[0] <= '9') && ('/' == conv[1])) // fract
       {
              short small = aSize * 2 / 3;
              short tmpw=0;
              
              ::TextSize(small);
              DrawScriptText(conv, 1, x, y-small/2, tmpw);
              oWidth = tmpw;
              
              ::TextSize(aSize);
              DrawScriptText(conv+1, 1, x+oWidth, y, tmpw);
              oWidth += tmpw;
              
              if(l>2) {
                     ::TextSize(small);
                     DrawScriptText(conv+2, l-2, x+oWidth, y+small/2, tmpw);
                     oWidth += tmpw;
                     ::TextSize(aSize);
              }
       } else {
                     DrawScriptText(conv, l, x, y, oWidth);
              }
       nsMemory::Free(conv);
       return PR_TRUE;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 702 of file nsUnicodeRenderingToolkit.cpp.

{
  if(LoadTransliterator()) {
    nsAutoString tmp(aCharPt, 1);
    char* conv = nsnull;
    if(NS_SUCCEEDED(mTrans->Convert(tmp.get(), &conv)) && conv) {
      CGrafPtr thePort;
      ::GetPort((GrafPtr*)&thePort);
           short aSize = ::GetPortTextSize(thePort);                         
              PRInt32 l=strlen(conv);
       if((l>3) && ('^' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sup
       {
              short small = aSize * 2 / 3;
              ::TextSize(small);
                     GetScriptTextWidth(conv+2, l-3,oWidth);   
              ::TextSize(aSize);
       } 
       else if((l>3) && ('v' == conv[0]) && ('(' == conv[1]) && (')' == conv[l-1])) // sub
       {
              short small = aSize * 2 / 3;
              ::TextSize(small);
                     GetScriptTextWidth(conv+2, l-3,oWidth);   
              ::TextSize(aSize);
              } 
              else if((l>1) && ('0' <= conv[0]) && ( conv[0] <= '9') && ('/' == conv[1])) // fract
       {
              short small = aSize * 2 / 3;
              short tmpw=0;
              
              ::TextSize(small);
                     GetScriptTextWidth(conv, 1 ,tmpw);   
                     oWidth = tmpw;
              
              ::TextSize(aSize);
                     GetScriptTextWidth(conv+1, 1,tmpw);   
              oWidth += tmpw;
              
              if(l>2) {
                     ::TextSize(small);
                            GetScriptTextWidth(conv+2, l-2,tmpw);   
                     oWidth += tmpw;
                     ::TextSize(aSize);
              }
       } else {
                     GetScriptTextWidth(conv, l,oWidth);   
              }
              
               
       nsMemory::Free(conv);
       return PR_TRUE;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::UPlusFallbackDrawChar ( const PRUnichar pChar,
PRInt32  x,
PRInt32  y,
short &  oWidth 
) [private]

Definition at line 924 of file nsUnicodeRenderingToolkit.cpp.

{
  CGrafPtr thePort;
  ::GetPort((GrafPtr*)&thePort);
  short saveSize = ::GetPortTextSize(thePort);          
  char buf[16];
  PRUint32 len = PR_snprintf(buf, 16 , "<U+%04X>", *aCharPt);
  ::TextSize(UPLUS_FALLBACKSIZE);
  if(len != -1) 
    DrawScriptText(buf, len, x, y, oWidth);
  ::TextSize(saveSize);
  return (-1 != len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsUnicodeRenderingToolkit::UPlusFallbackGetWidth ( const PRUnichar pChar,
short &  oWidth 
) [private]

Definition at line 907 of file nsUnicodeRenderingToolkit.cpp.

{
  CGrafPtr thePort;
  ::GetPort((GrafPtr*)&thePort);
  short saveSize = ::GetPortTextSize(thePort);          
  char buf[16];
  PRUint32 len = PR_snprintf(buf, 16 , "<U+%04X>", *aCharPt);
  ::TextSize(UPLUS_FALLBACKSIZE);
  if(len != -1) 
    GetScriptTextWidth(buf, len, oWidth);
  ::TextSize(saveSize);
  return (-1 != len);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 135 of file nsUnicodeRenderingToolkit.h.

Definition at line 131 of file nsUnicodeRenderingToolkit.h.

Definition at line 132 of file nsUnicodeRenderingToolkit.h.

Definition at line 130 of file nsUnicodeRenderingToolkit.h.

Definition at line 134 of file nsUnicodeRenderingToolkit.h.

Definition at line 137 of file nsUnicodeRenderingToolkit.h.

Definition at line 136 of file nsUnicodeRenderingToolkit.h.


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