Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsStylClipboardUtils.h File Reference
#include "prtypes.h"
#include "nscore.h"
#include <MacTypes.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

nsresult CreateStylFromScriptRuns (ScriptCodeRun *scriptCodeRuns, ItemCount scriptRunOutLen, char **stylData, PRInt32 *stylLen)

Function Documentation

nsresult CreateStylFromScriptRuns ( ScriptCodeRun *  scriptCodeRuns,
ItemCount  scriptRunOutLen,
char **  stylData,
PRInt32 stylLen 
)

Definition at line 44 of file nsStylClipboardUtils.cpp.

{
  PRInt32 scrpRecLen = sizeof(short) + sizeof(ScrpSTElement) * scriptRunOutLen;
  StScrpRec *scrpRec = NS_REINTERPRET_CAST(StScrpRec*, 
                                           nsMemory::Alloc(scrpRecLen));
  NS_ENSURE_TRUE(scrpRec, NS_ERROR_OUT_OF_MEMORY);
  
  OSErr err = noErr;    
  Str255 themeFontName;
  SInt16 textSize;
  Style textStyle;
  short fontFamilyID;
  FontInfo fontInfo;
  RGBColor textColor;
  textColor.red = textColor.green = textColor.blue = 0;
  
  // save font settings
  CGrafPtr curPort;
  short saveFontFamilyID;
  SInt16 saveTextSize;
  Style saveTextStyle;
  ::GetPort((GrafPtr*)&curPort);
  saveFontFamilyID = ::GetPortTextFont(curPort);
  saveTextSize = ::GetPortTextSize(curPort);
  saveTextStyle = ::GetPortTextFace(curPort);
  
  scrpRec->scrpNStyles = scriptRunOutLen;
  for (ItemCount i = 0; i < scriptRunOutLen; i++) {
    scrpRec->scrpStyleTab[i].scrpStartChar = scriptCodeRuns[i].offset;
    
    err = ::GetThemeFont(
                         kThemeApplicationFont, 
                         scriptCodeRuns[i].script, 
                         themeFontName, 
                         &textSize, 
                         &textStyle);
    if (err != noErr)
      break;
      
    ::GetFNum(themeFontName, &fontFamilyID);
      
    ::TextFont(fontFamilyID);
    ::TextSize(textSize);
    ::TextFace(textStyle);
    ::GetFontInfo(&fontInfo);
    
    scrpRec->scrpStyleTab[i].scrpFont = fontFamilyID;
    scrpRec->scrpStyleTab[i].scrpHeight = fontInfo.ascent +
                                          fontInfo.descent +
                                          fontInfo.leading;
    scrpRec->scrpStyleTab[i].scrpAscent = fontInfo.ascent;
    scrpRec->scrpStyleTab[i].scrpFace = textStyle;
    scrpRec->scrpStyleTab[i].scrpSize = textSize;
    scrpRec->scrpStyleTab[i].scrpColor = textColor;
  }
       
  // restore font settings
  ::TextFont(saveFontFamilyID);
  ::TextSize(saveTextSize);
  ::TextFace(saveTextStyle);
  
  if (err != noErr) {
    nsMemory::Free(scrpRec);
    return NS_ERROR_FAILURE;
  }

  *stylData = NS_REINTERPRET_CAST(char*, scrpRec);
  *stylLen = scrpRecLen;
         
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function: