Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsSVGLibartGlyphMetricsFT.cpp File Reference
#include "nsCOMPtr.h"
#include "nsISVGGlyphMetricsSource.h"
#include "nsISVGRendererGlyphMetrics.h"
#include "nsPromiseFlatString.h"
#include "nsFont.h"
#include "nsIFontMetrics.h"
#include "nsPresContext.h"
#include "float.h"
#include "nsIDOMSVGMatrix.h"
#include "nsIDOMSVGRect.h"
#include "nsSVGTypeCIDs.h"
#include "nsIComponentManager.h"
#include "nsISVGLibartGlyphMetricsFT.h"
#include "nsIDeviceContext.h"
#include "nsSVGLibartFreetype.h"
#include "libart-incs.h"
#include "nsArray.h"
#include "nsDataHashtable.h"

Go to the source code of this file.

Classes

class  nsSVGLibartGlyphMetricsFT
 Libart freetype-based glyph metrics implementation. More...
struct  nsSVGLibartGlyphMetricsFT::GlyphDescriptor
struct  FindFontStruct

Functions

nsresult NS_NewSVGLibartGlyphMetricsFT (nsISVGRendererGlyphMetrics **result, nsISVGGlyphMetricsSource *src)
void NS_InitSVGLibartGlyphMetricsFTGlobals ()
void NS_FreeSVGLibartGlyphMetricsFTGlobals ()
static PRBool FindFont (const nsString &aFamily, PRBool aGeneric, void *aData)

Class Documentation

struct FindFontStruct

Definition at line 326 of file nsSVGLibartGlyphMetricsFT.cpp.

Collaboration diagram for FindFontStruct:
Class Members
nsFont font
nsCOMPtr
< nsITrueTypeFontCatalogEntry >
font_entry

Function Documentation

static PRBool FindFont ( const nsString aFamily,
PRBool  aGeneric,
void aData 
) [static]

Definition at line 332 of file nsSVGLibartGlyphMetricsFT.cpp.

{
  PRBool retval = PR_TRUE;
  
  FindFontStruct* font_data = (FindFontStruct*) aData;
  
#ifdef DEBUG
  printf("trying to instantiate font %s, generic=%d\n", NS_ConvertUCS2toUTF8(aFamily).get(),
         aGeneric);
#endif

  nsCAutoString family_name;
  
  if (aGeneric) {
    PRUint8 id;
    nsFont::GetGenericID(aFamily, &id);
    switch (id) {
      case kGenericFont_serif:
        family_name.AssignLiteral("times new roman");
        break;
      case kGenericFont_monospace:
        family_name.AssignLiteral("courier new");
        break;
      case kGenericFont_sans_serif:
      default:
        family_name.AssignLiteral("arial");
        break;
    }
  }
  else {
    family_name = NS_ConvertUCS2toUTF8(aFamily);
    ToLowerCase(family_name);
  }
  
  nsCAutoString language;
  PRUint16 slant = nsIFontCatalogService::kFCSlantRoman;
  if (font_data->font.style && NS_FONT_STYLE_ITALIC)
    slant = nsIFontCatalogService::kFCSlantItalic;
    
  nsCOMPtr<nsIArray> arr;
  nsSVGLibartFreetype::fontCatalog->GetFontCatalogEntries(family_name,
                                                          language,
                                                          font_data->font.weight,
                                                          nsIFontCatalogService::kFCWeightAny,
                                                          slant,
                                                          nsIFontCatalogService::kFCSpacingAny,
                                                          getter_AddRefs(arr));
  PRUint32 count;
  arr->GetLength(&count);
#ifdef DEBUG
  printf("FindFont(%s): number of fonts found: %d\n", family_name.get(), count);
#endif
  if (count>0) {
    retval =  PR_FALSE; // break
    // just take the first one for now:
    arr->QueryElementAt(0, NS_GET_IID(nsITrueTypeFontCatalogEntry),
                        getter_AddRefs(font_data->font_entry));
  }
  else {
    // try alias if there is one:
    const nsString *alias = nsnull;
    nsSVGLibartGlyphMetricsFT::sFontAliases.Get(NS_ConvertUTF8toUCS2(family_name),
                                                &alias);
    if (alias) {
      // XXX this might cause a stack-overflow if there are cyclic
      // aliases in sFontAliases
      retval = FindFont(*alias, PR_FALSE, aData);      
    }
  }
  
  return retval;      
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 169 of file nsSVGLibartGlyphMetricsFT.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 149 of file nsSVGLibartGlyphMetricsFT.cpp.

{
  
  NS_ASSERTION(!nsSVGLibartGlyphMetricsFT::sFontAliases.IsInitialized(),
               "font aliases already initialized");
  nsSVGLibartGlyphMetricsFT::sFontAliases.Init(3);

  static NS_NAMED_LITERAL_STRING(arial, "arial");
  nsSVGLibartGlyphMetricsFT::sFontAliases.Put(NS_LITERAL_STRING("helvetica"),
                                              &arial);

  static NS_NAMED_LITERAL_STRING(courier, "courier new");
  nsSVGLibartGlyphMetricsFT::sFontAliases.Put(NS_LITERAL_STRING("courier"),
                                              &courier);

  static NS_NAMED_LITERAL_STRING(times, "times new roman");
  nsSVGLibartGlyphMetricsFT::sFontAliases.Put(NS_LITERAL_STRING("times"),
                                              &times);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 139 of file nsSVGLibartGlyphMetricsFT.cpp.

{
  *result = new nsSVGLibartGlyphMetricsFT(src);
  if (!*result) return NS_ERROR_OUT_OF_MEMORY;
  
  NS_ADDREF(*result);
  return NS_OK;
}

Here is the call graph for this function: