int pixels = atoi(pixelSize); if (stretch->mSizesCount) { nsFontGTK** end = &stretch->mSizes[stretch->mSizesCount]; nsFontGTK** s; for (s = stretch->mSizes; s < end; s++) { if ((*s)->mSize == pixels) { break; } } if (s != end) { continue; } } if (stretch->mSizesCount == stretch->mSizesAlloc) { int newSize = 2 * (stretch->mSizesAlloc ? stretch->mSizesAlloc : 1); nsFontGTK** newPointer = new nsFontGTK*[newSize]; if (newPointer) { for (int j = stretch->mSizesAlloc - 1; j >= 0; j--) { newPointer[j] = stretch->mSizes[j]; } stretch->mSizesAlloc = newSize; delete [] stretch->mSizes; stretch->mSizes = newPointer; } else { continue; } }
GetFontNames(const char* aPattern, nsFontNodeArray* aNodes){#ifdef NS_FONT_DEBUG_CALL_TRACE  if (gDebug & NS_FONT_DEBUG_CALL_TRACE) {    printf("GetFontNames %s\n", aPattern);  }#endif  nsCAutoString previousNodeName;  /*   * We do not use XListFontsWithInfo here, because it is very expensive.   * Instead, we get that info at load time (gdk_font_load).   */  int count;  char** list = ::XListFonts(GDK_DISPLAY(), aPattern, INT_MAX, &count);  if ((!list) || (count < 1)) {    return;  }  for (int i = 0; i < count; i++) {    char* name = list[i];    if ((!name) || (name[0] != '-')) {      continue;    }    char buf[512];    PL_strncpyz(buf, name, sizeof(buf));    char *fName = buf;    char* p = name + 1;    int scalable = 0;    PRBool outline_scaled = PR_FALSE;#ifdef FIND_FIELD#undef FIND_FIELD#endif#define FIND_FIELD(var)           \  char* var = p;                  \  while ((*p) && ((*p) != '-')) { \    p++;                          \  }                               \  if (*p) {                       \    *p++ = 0;                     \  }                               \  else {                          \    continue;                     \  }#ifdef SKIP_FIELD#undef SKIP_FIELD#endif#define SKIP_FIELD(var)           \  while ((*p) && ((*p) != '-')) { \    p++;                          \  }                               \  if (*p) {                       \    p++;                          \  }                               \  else {                          \    continue;                     \  }    FIND_FIELD(foundry);    // XXX What to do about the many Applix fonts that start with "ax"?    FIND_FIELD(familyName);    FIND_FIELD(weightName);    FIND_FIELD(slant);    FIND_FIELD(setWidth);    FIND_FIELD(addStyle);    FIND_FIELD(pixelSize);    if (pixelSize[0] == '0') {      scalable = 1;    }    FIND_FIELD(pointSize);    if (pointSize[0] == '0') {      scalable = 1;    }    FIND_FIELD(resolutionX);    if (resolutionX[0] == '0') {      scalable = 1;    }    FIND_FIELD(resolutionY);    if (resolutionY[0] == '0') {      scalable = 1;    }    // check if bitmap non-scaled font    if ((pixelSize[0] != '0') || (pointSize[0] != '0')) {      SCALED_FONT_PRINTF(("bitmap (non-scaled) font: %s", fName));    }    // check if bitmap scaled font    else if ((pixelSize[0] == '0') && (pointSize[0] == '0')          && (resolutionX[0] != '0') && (resolutionY[0] != '0')) {      SCALED_FONT_PRINTF(("bitmap scaled font: %s", fName));    }    // check if outline scaled font    else if ((pixelSize[0] == '0') && (pointSize[0] == '0')          && (resolutionX[0] == '0') && (resolutionY[0] == '0')) {      outline_scaled = PR_TRUE;      SCALED_FONT_PRINTF(("outline scaled font: %s", fName));    }    else {      SCALED_FONT_PRINTF(("unexpected font values: %s", fName));      SCALED_FONT_PRINTF(("      pixelSize[0] = %c", pixelSize[0]));      SCALED_FONT_PRINTF(("      pointSize[0] = %c", pointSize[0]));      SCALED_FONT_PRINTF(("    resolutionX[0] = %c", resolutionX[0]));      SCALED_FONT_PRINTF(("    resolutionY[0] = %c", resolutionY[0]));      static PRBool already_complained = PR_FALSE;      // only complaing once       if (!already_complained) {        already_complained = PR_TRUE;        NS_ASSERTION(pixelSize[0] == '0', "font scaler type test failed");        NS_ASSERTION(pointSize[0] == '0', "font scaler type test failed");        NS_ASSERTION(resolutionX[0] == '0', "font scaler type test failed");        NS_ASSERTION(resolutionY[0] == '0', "font scaler type test failed");      }    }    FIND_FIELD(spacing);    FIND_FIELD(averageWidth);    if (averageWidth[0] == '0') {      scalable = 1;    }    char* charSetName = p; // CHARSET_REGISTRY & CHARSET_ENCODING    if (!*charSetName) {      continue;    }    nsCStringKey charSetKey(charSetName);    nsFontCharSetMap* charSetMap =      (nsFontCharSetMap*) gCharSetMaps->Get(&charSetKey);    if (!charSetMap)      charSetMap = gNoneCharSetMap;    nsFontCharSetInfo* charSetInfo = charSetMap->mInfo;    // indirection for font specific charset encoding     if (charSetInfo == &Special) {      nsCAutoString familyCharSetName(familyName);      familyCharSetName.Append('-');      familyCharSetName.Append(charSetName);      nsCStringKey familyCharSetKey(familyCharSetName);      charSetMap = NS_STATIC_CAST(nsFontCharSetMap*, gSpecialCharSets->Get(&familyCharSetKey));      if (!charSetMap)        charSetMap = gNoneCharSetMap;      charSetInfo = charSetMap->mInfo;    }    if (!charSetInfo) {#ifdef NOISY_FONTS      printf("cannot find charset %s\n", charSetName);#endif      charSetInfo = &Unknown;    }    SetCharsetLangGroup(charSetInfo);    SetFontLangGroupInfo(charSetMap);    nsCAutoString nodeName(foundry);    nodeName.Append('-');    nodeName.Append(familyName);    nodeName.Append('-');    nodeName.Append(charSetName);    nsCStringKey key(nodeName);    nsFontNode* node = (nsFontNode*) gNodes->Get(&key);    if (!node) {      node = new nsFontNode;      if (!node) {        continue;      }      gNodes->Put(&key, node);      node->mName = nodeName;      node->mCharSetInfo = charSetInfo;    }    int found = 0;    if (nodeName == previousNodeName) {      found = 1;    }    else {      found = (aNodes->IndexOf(node) >= 0);    }    previousNodeName = nodeName;    if (!found) {      aNodes->AppendElement(node);    }    int styleIndex;    // XXX This does not cover the full XLFD spec for SLANT.    switch (slant[0]) {    case 'i':      styleIndex = NS_FONT_STYLE_ITALIC;      break;    case 'o':      styleIndex = NS_FONT_STYLE_OBLIQUE;      break;    case 'r':    default:      styleIndex = NS_FONT_STYLE_NORMAL;      break;    }    nsFontStyle* style = node->mStyles[styleIndex];    if (!style) {      style = new nsFontStyle;      if (!style) {        continue;      }      node->mStyles[styleIndex] = style;    }    nsCStringKey weightKey(weightName);    int weightNumber = NS_PTR_TO_INT32(gWeights->Get(&weightKey));    if (!weightNumber) {#ifdef NOISY_FONTS      printf("cannot find weight %s\n", weightName);#endif      weightNumber = NS_FONT_WEIGHT_NORMAL;    }    int weightIndex = WEIGHT_INDEX(weightNumber);    nsFontWeight* weight = style->mWeights[weightIndex];    if (!weight) {      weight = new nsFontWeight;      if (!weight) {        continue;      }      style->mWeights[weightIndex] = weight;    }      nsCStringKey setWidthKey(setWidth);    int stretchIndex = NS_PTR_TO_INT32(gStretches->Get(&setWidthKey));    if (!stretchIndex) {#ifdef NOISY_FONTS      printf("cannot find stretch %s\n", setWidth);#endif      stretchIndex = 5;    }    stretchIndex--;    nsFontStretch* stretch = weight->mStretches[stretchIndex];    if (!stretch) {      stretch = new nsFontStretch;      if (!stretch) {        continue;      }      weight->mStretches[stretchIndex] = stretch;    }    if (scalable) {      // if we have both an outline scaled font and a bitmap       // scaled font pick the outline scaled font      if ((stretch->mScalable) && (!stretch->mOutlineScaled)           && (outline_scaled)) {        PR_smprintf_free(stretch->mScalable);        stretch->mScalable = nsnull;      }      if (!stretch->mScalable) {        stretch->mOutlineScaled = outline_scaled;        if (outline_scaled) {          stretch->mScalable =               PR_smprintf("%s-%s-%s-%s-%s-%s-%%d-*-0-0-%s-*-%s",               name, familyName, weightName, slant, setWidth, addStyle,               spacing, charSetName);        }        else {          stretch->mScalable =               PR_smprintf("%s-%s-%s-%s-%s-%s-%%d-*-*-*-%s-*-%s",               name, familyName, weightName, slant, setWidth, addStyle,               spacing, charSetName);        }      }      continue;    }      int pixels = atoi(pixelSize);    if (stretch->mSizesCount) {      nsFontGTK** end = &stretch->mSizes[stretch->mSizesCount];      nsFontGTK** s;      for (s = stretch->mSizes; s < end; s++) {        if ((*s)->mSize == pixels) {          break;        }      }      if (s != end) {        continue;      }    }    if (stretch->mSizesCount == stretch->mSizesAlloc) {      int newSize = 2 * (stretch->mSizesAlloc ? stretch->mSizesAlloc : 1);      nsFontGTK** newPointer = new nsFontGTK*[newSize];      if (newPointer) {        for (int j = stretch->mSizesAlloc - 1; j >= 0; j--) {          newPointer[j] = stretch->mSizes[j];        }        stretch->mSizesAlloc = newSize;        delete [] stretch->mSizes;        stretch->mSizes = newPointer;      }      else {        continue;      }    }    p = name;    while (p < charSetName) {      if (!*p) {        *p = '-';      }      p++;    }    char* copy = PR_smprintf("%s", name);    if (!copy) {      continue;    }    nsFontGTK* size = new nsFontGTKNormal();    if (!size) {      continue;    }    stretch->mSizes[stretch->mSizesCount++] = size;    size->mName = copy;    // size->mFont is initialized in the constructor    size->mSize = pixels;    size->mBaselineAdjust = 0;    size->mCCMap = nsnull;    size->mCharSetInfo = charSetInfo;  }  XFreeFontNames(list);#ifdef DEBUG_DUMP_TREE  DumpTree();#endif}