node_hash->Put(&key, node);
gNodes->Put(&key, node);
GetFontNames(const char* aPattern, PRBool aAnyFoundry, nsFontNodeArrayXlib * aNodes){  Display       *dpy = xxlib_rgb_get_display(gXlibRgbHandle);  nsCAutoString  previousNodeName;  nsHashtable   *node_hash;    if (aAnyFoundry) {    NS_ASSERTION(aPattern[1] == '*', "invalid 'anyFoundry' pattern");    node_hash = gAFRENodes;  }  else {    node_hash = gFFRENodes;  }#ifdef USE_XPRINT#ifdef DEBUG  if(nsFontMetricsXlib::mPrinterMode)  {    if (!dpy)    {      NS_ERROR("Obtaining font information without having a |Display *|");      abort(); /* DIE!! */    }      if (XpGetContext(dpy) == None)    {      /* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */      NS_ERROR("Obtaining font information without valid print context (XListFonts()) _before_ XpSetContext()");      abort(); /* DIE!! */    }      }               #endif /* DEBUG */#endif /* USE_XPRINT */  int count;  char** list = ::XListFonts(dpy, 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* 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')) {      /* ugh */    }    // check if bitmap scaled font    else if ((pixelSize[0] == '0') && (pointSize[0] == '0')        && (resolutionX[0] != '0') && (resolutionY[0] != '0')) {      /* ugh */    }    // check if outline scaled font    else if ((pixelSize[0] == '0') && (pointSize[0] == '0')        && (resolutionX[0] == '0') && (resolutionY[0] == '0')) {      outline_scaled = PR_TRUE;    }    else {      static PRBool already_complained = PR_FALSE;      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);    nsFontCharSetMapXlib *charSetMap =      (nsFontCharSetMapXlib *) gCharSetMaps->Get(&charSetKey);    if (!charSetMap)      charSetMap = gNoneCharSetMap;    nsFontCharSetXlibInfo* 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(nsFontCharSetMapXlib*, gSpecialCharSets->Get(&familyCharSetKey));      if (!charSetMap)        charSetMap = gNoneCharSetMap;      charSetInfo = charSetMap->mInfo;    }    if (!charSetInfo) {      PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("cannot find charset %s\n", charSetName));      charSetInfo = &Unknown;    }    SetCharsetLangGroup(charSetInfo);    SetFontLangGroupInfo(charSetMap);    nsCAutoString nodeName("");    if (aAnyFoundry)      nodeName.Append('*');    else      nodeName.Append(foundry);    nodeName.Append('-');    nodeName.Append(familyName);    nodeName.Append('-');    nodeName.Append(charSetName);    nsCStringKey key(nodeName);    nsFontNodeXlib* node = (nsFontNodeXlib*) node_hash->Get(&key);    if (!node) {      node = new nsFontNodeXlib;      if (!node)        continue;      node_hash->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;    }    nsFontStyleXlib* style = NodeGetStyle(node, styleIndex);    if (!style)      continue;    nsCStringKey weightKey(weightName);    int weightNumber = NS_PTR_TO_INT32(gWeights->Get(&weightKey));    if (!weightNumber) {      PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("cannot find weight %s\n", weightName));      weightNumber = NS_FONT_WEIGHT_NORMAL;    }    int weightIndex = WEIGHT_INDEX(weightNumber);    nsFontWeightXlib *weight = NodeGetWeight(style, weightIndex);    if (!weight)      continue;    nsCStringKey setWidthKey(setWidth);    int stretchIndex = NS_PTR_TO_INT32(gStretches->Get(&setWidthKey));    if (!stretchIndex) {      PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("cannot find stretch %s\n", setWidth));      stretchIndex = 5;    }    stretchIndex--;    nsFontStretchXlib* stretch = NodeGetStretch(weight, stretchIndex);    if (!stretch)      continue;    if (scalable) {      if (!NodeAddScalable(stretch, outline_scaled, name, familyName,            weightName, slant, setWidth, addStyle, spacing, charSetName))        continue;    }      p = name;    while (p < charSetName) {      if (!*p) {        *p = '-';      }      p++;    }    int pixels = atoi(pixelSize);    NS_ASSERTION(!((pixels == 0) && (errno == EINVAL)), "unexpected pixel size");    if (!NodeAddSize(stretch, pixels, name, charSetInfo))       continue;  }  XFreeFontNames(list);#ifdef DEBUG_DUMP_TREE  DumpTree();#endif}