typedef QHash<QString, QStringList> QFontSubst;
Q_GLOBAL_STATIC(QFontSubst, globalFontSubst)
+static const struct FontSubstitutesTblData {
+ const QLatin1String original;
+ const QLatin1String substitute;
+} FontSubstitutesTbl[] = {
+ { QLatin1String("arial"), QLatin1String("helvetica") },
+ { QLatin1String("times new roman"), QLatin1String("times") },
+ { QLatin1String("courier new"), QLatin1String("courier") },
+ { QLatin1String("sans serif"), QLatin1String("helvetica") },
+};
+static const qint16 FontSubstitutesTblSize = sizeof(FontSubstitutesTbl) / sizeof(FontSubstitutesTblData);
+
// create substitution dict
static void initFontSubst()
{
- // default substitutions
- static const char * const initTbl[] = {
-
-#if defined(Q_WS_X11)
- "arial", "helvetica",
- "times new roman", "times",
- "courier new", "courier",
- "sans serif", "helvetica",
-#endif
-
- 0, 0
- };
-
QFontSubst *fontSubst = globalFontSubst();
Q_ASSERT(fontSubst != 0);
if (!fontSubst->isEmpty())
return;
#endif
- for (int i=0; initTbl[i] != 0; i += 2) {
- QStringList &list = (*fontSubst)[QString::fromLatin1(initTbl[i])];
- list.append(QString::fromLatin1(initTbl[i+1]));
+ for (qint16 i = 0; i < FontSubstitutesTblSize; i++) {
+ QStringList &list = (*fontSubst)[FontSubstitutesTbl[i].original];
+ list.append(FontSubstitutesTbl[i].substitute);
}
}
};
enum { SpecialCharCount = sizeof(specialChars) / sizeof(uint) };
+static const struct DefaultFontTblData {
+ const QLatin1String name;
+ const bool fixedpitch;
+} DefaultFontTbl[] = {
+ { QLatin1String("Serif"), false },
+ { QLatin1String("Sans Serif"), false },
+ { QLatin1String("Monospace"), true },
+};
+static const qint16 DefaultFontTblSize = sizeof(DefaultFontTbl) / sizeof(DefaultFontTblData);
+
+static const char* PatternPropertiesTbl[] = {
+ FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT,
+ FC_SPACING, FC_FILE, FC_INDEX,
+ FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT,
+ FC_WIDTH,
+ FC_CAPABILITY,
+};
+static const qint16 PatternPropertiesTblSize = 15;
+
static void loadFontConfig()
{
Q_ASSERT_X(qt_x11Data, "QFontDatabase",
{
FcObjectSet *os = FcObjectSetCreate();
FcPattern *pattern = FcPatternCreate();
- const char *properties [] = {
- FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT,
- FC_SPACING, FC_FILE, FC_INDEX,
- FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT,
- FC_WIDTH,
- FC_CAPABILITY,
- (const char *)0
- };
- const char **p = properties;
- while (*p) {
- FcObjectSetAdd(os, *p);
- ++p;
+ for (qint16 i = 0; i < PatternPropertiesTblSize; i++) {
+ FcObjectSetAdd(os, PatternPropertiesTbl[i]);
}
fonts = FcFontList(0, pattern, os);
FcObjectSetDestroy(os);
FcFontSetDestroy (fonts);
- struct FcDefaultFont {
- const char *qtname;
- bool fixed;
- };
- const FcDefaultFont defaults[] = {
- { "Serif", false },
- { "Sans Serif", false },
- { "Monospace", true },
- { 0, false }
- };
- const FcDefaultFont *f = defaults;
- while (f->qtname) {
- QtFontFamily *family = db->family(QLatin1String(f->qtname), true);
- family->fixedPitch = f->fixed;
+ for (qint16 i = 0; i < DefaultFontTblSize; i++) {
+ QtFontFamily *family = db->family(DefaultFontTbl[i].name, true);
+ family->fixedPitch = DefaultFontTbl[i].fixedpitch;
family->synthetic = true;
QtFontFoundry *foundry = family->foundry(QString(), true);
QtFontStyle::Key styleKey;
- for (int i = 0; i < 4; ++i) {
- styleKey.style = (i%2) ? QFont::StyleNormal : QFont::StyleItalic;
- styleKey.weight = (i > 1) ? QFont::Bold : QFont::Normal;
+ for (int j = 0; j < 4; j++) {
+ styleKey.style = (j%2) ? QFont::StyleNormal : QFont::StyleItalic;
+ styleKey.weight = (j > 1) ? QFont::Bold : QFont::Normal;
QtFontStyle *style = foundry->style(styleKey, QString(), true);
style->smoothScalable = true;
QtFontSize *size = style->pixelSize(SMOOTH_SCALABLE, true);
QtFontEncoding *enc = size->encodingID(-1, 0, 0, 0, 0, true);
- enc->pitch = (f->fixed ? 'm' : 'p');
+ enc->pitch = (DefaultFontTbl[i].fixedpitch ? 'm' : 'p');
}
- ++f;
}
}
#endif // QT_NO_FONTCONFIG