[poppler] Fontconfig patch

Jeff Muizelaar jeff at infidigm.net
Sun Jul 17 02:58:13 EST 2005


Here are some comments:

On Fri, Jul 15, 2005 at 10:33:27PM +0200, Albert Astals Cid wrote:

> -//------------------------------------------------------------------------
>  // accessors
>  //------------------------------------------------------------------------
>  
> @@ -1126,24 +907,186 @@
>    return NULL;
>  }
>  
> -DisplayFontParam *GlobalParams::getDisplayFont(GooString *fontName) {
> -  DisplayFontParam *dfp;
> +char *giveLowerChar(char *c1, char *c2)

might as well add const to these

> +{
> +  if (c1 && c2)
> +  {
> +    if (c1 < c2) return c1;

All of the if statements of the if (stmt) do_stuff;  type should be:

if (c1 < c2)
	return c1;

to match the style of the rest of the code.

> +    else return c2;
> +  }
> +  else if (c1) return c1;
> +  else return c2;
> +}
> +
> +FcPattern *buildFcPattern(GfxFont *font)
> +{
> +  int weight = FC_WEIGHT_NORMAL,
> +      slant = FC_SLANT_ROMAN,
> +      width = FC_WIDTH_NORMAL,
> +      spacing = FC_PROPORTIONAL;
> +  bool deleteFamily = false;
> +  char *family, *name, *lang, *h = 0, *aux = 0;

use NULL instead of 0

> +  FcPattern *p;
>  
> -  lockGlobalParams;
> -  dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
> -  unlockGlobalParams;
> -  return dfp;
> +  // this is all heuristics will be overwritten if font had proper info
> +  name = font->getName()->getCString();
> +  
> +  // remove the - from the names, for some reason, Fontconfig does not understand "MS-Mincho"
> +  // but does with "MS Mincho"
> +  int len = strlen(name);
> +  for (int i = 0; i < len; i++) name[i] = (name[i] == '-' ? ' ' : name[i]);

Same style thing as the ifs

> +  
> +  // This is the "descriptors" font names use usually, we could add more
> +  h = strstr(name, "Oblique");
> +  if (h) slant = FC_SLANT_OBLIQUE;
> +  
> +  aux = strstr(name, "Italic");
> +  if (aux) slant = FC_SLANT_ITALIC;
> +  h = giveLowerChar(h, aux);
> +  
> +  aux = strstr(name, "Bold");
> +  if (aux) weight = FC_WEIGHT_BOLD;
> +  h = giveLowerChar(h, aux);
> +  
> +  aux = strstr(name, "Light");
> +  if (aux) weight = FC_WEIGHT_LIGHT;
> +  h = giveLowerChar(h, aux);
> +  
> +  aux = strstr(name, "Condensed");
> +  if (aux) width=FC_WIDTH_CONDENSED;
                   ^
missing space

> +  h = giveLowerChar(h, aux);
> +  
> +  if (h)
> +  {
> +    // There have been "modifiers" in the name, crop them to obtain the family name
> +    family = new char[len+1];
> +    strcpy(family, name);
> +    int pos = 0;
> +    while (&(name[pos]) != h) pos++;

could be
pos = (h - name);

> +    family[pos] = '\0';
> +    pos--;
> +    while (family[pos] == ',' || family[pos] == ' ')
> +    {
> +      family[pos] = '\0';
> +      pos--;
> +    }
> +    deleteFamily = true;
> +  }
> +  else family = name;
> +  
> +  // use font flags
> +  if (font->isFixedWidth()) spacing = FC_MONO;
> +  if (font->isBold()) weight = FC_WEIGHT_BOLD;
> +  if (font->isItalic()) slant = FC_SLANT_ITALIC;
> +  
> +  // if the FontDescriptor specified a family name use it
> +  if (font -> getFamily()) family = font -> getFamily() -> getCString();

get rid of the spaces around '->'

> +  
> +  // if the FontDescriptor specified a weight use it
> +  switch (font -> getWeight())
> +  {
> +    case GfxFont::W100: weight = FC_WEIGHT_EXTRALIGHT; break; 
> +    case GfxFont::W200: weight = FC_WEIGHT_LIGHT; break; 
> +    case GfxFont::W300: weight = FC_WEIGHT_BOOK; break; 
> +    case GfxFont::W400: weight = FC_WEIGHT_NORMAL; break; 
> +    case GfxFont::W500: weight = FC_WEIGHT_MEDIUM; break; 
> +    case GfxFont::W600: weight = FC_WEIGHT_DEMIBOLD;break; 

  	  missing space ------------------------------^

> +    case GfxFont::W700: weight = FC_WEIGHT_BOLD; break; 
> +    case GfxFont::W800: weight = FC_WEIGHT_EXTRABOLD; break; 
> +    case GfxFont::W900: weight = FC_WEIGHT_BLACK; break; 
> +    default: break; 
> +  }
> +  
> +  // if the FontDescriptor specified a width use it
> +  switch (font -> getStretch())
> +  {
> +    case GfxFont::UltraCondensed: width = FC_WIDTH_ULTRACONDENSED; break; 
> +    case GfxFont::ExtraCondensed: width = FC_WIDTH_EXTRACONDENSED; break; 
> +    case GfxFont::Condensed: width = FC_WIDTH_CONDENSED; break; 
> +    case GfxFont::SemiCondensed: width = FC_WIDTH_SEMICONDENSED; break; 
> +    case GfxFont::Normal: width = FC_WIDTH_NORMAL; break; 
> +    case GfxFont::SemiExpanded: width = FC_WIDTH_SEMIEXPANDED; break; 
> +    case GfxFont::Expanded: width = FC_WIDTH_EXPANDED; break; 
> +    case GfxFont::ExtraExpanded: width = FC_WIDTH_EXTRAEXPANDED; break; 
> +    case GfxFont::UltraExpanded: width = FC_WIDTH_ULTRAEXPANDED; break; 
> +    default: break; 
> +  }
> +  
> +  // find the language we want the font to support
> +  if (font->isCIDFont())
> +  {
> +    GooString *collection = ((GfxCIDFont *)font)->getCollection();
> +    if (collection)
> +    {
> +      if (strcmp(collection->getCString(), "Adobe-GB1") == 0) lang = "zh-cn"; // Simplified Chinese
> +      else if (strcmp(collection->getCString(), "Adobe-CNS1") == 0) lang = "zh-tw"; // Traditional Chinese
> +      else if (strcmp(collection->getCString(), "Adobe-Japan1") == 0) lang = "ja"; // Japanese
> +      else if (strcmp(collection->getCString(), "Adobe-Japan2") == 0) lang = "ja"; // Japanese
> +      else if (strcmp(collection->getCString(), "Adobe-Korea1") == 0) lang = "ko"; // Korean
> +      else
> +      {
> +        error(-1, "Unknown CID font collection, please report to poppler bugzilla.");
> +        lang = "xx";
> +      }
> +    }
> +    else lang = "xx";
> +  }
> +  else lang = "xx";
> +  
> +  p = FcPatternBuild(0, FC_FAMILY, FcTypeString, family,
> +                    FC_SLANT, FcTypeInteger, slant, FC_WEIGHT, FcTypeInteger, weight,
> +                    FC_WIDTH, FcTypeInteger, width, FC_SPACING, FcTypeInteger, spacing,
> +                    FC_LANG, FcTypeString, lang, (char*)0);
> +  if (deleteFamily) delete family;
> +  return p;
>  }


More information about the poppler mailing list