~ubuntu-branches/ubuntu/trusty/xterm/trusty-proposed

« back to all changes in this revision

Viewing changes to fontutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-06-17 10:40:36 UTC
  • mfrom: (1.4.12 upstream) (11.1.26 sid)
  • Revision ID: james.westby@ubuntu.com-20110617104036-id4ml81yetasewp9
Tags: 270-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/patches/950_ubuntu_charclass_highlight.diff: Enabled URL
    highlighting
  - debian/patches/Add 951_uxterm_utf8_title.diff: Set utf8Titles to true by
    default when using uxterm, so that it displays utf8 directories in titles
    properly.  May cause issues with apps that use control sequences for
    updating the xterm titlebar - users should use xterm or set utf8Title
    to false in this case.
  - debian/gbp.conf: Use "Ubuntu" in "debian-branch" directly

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XTermId: fontutils.c,v 1.353 2010/10/23 00:27:22 tom Exp $ */
 
1
/* $XTermId: fontutils.c,v 1.358 2011/04/24 22:58:56 tom Exp $ */
2
2
 
3
3
/************************************************************
4
4
 
919
919
    DbgResource("w/bold", f_wb, fWBold);
920
920
#endif
921
921
 
922
 
    if (!xtermOpenFont(xw, myfonts.f_n, &fnts[fNorm], warn[fNorm], True))
 
922
    /*
 
923
     * If we are opening the default font, and it happens to be missing, force
 
924
     * that to the compiled-in default font, e.g., "fixed".  If we cannot open
 
925
     * the font, disable it from the menu.
 
926
     */
 
927
    if (!xtermOpenFont(xw,
 
928
                       myfonts.f_n,
 
929
                       &fnts[fNorm],
 
930
                       warn[fNorm],
 
931
                       (fontnum == fontMenu_default))) {
 
932
        SetItemSensitivity(fontMenuEntries[fontnum].widget, False);
923
933
        goto bad;
 
934
    }
924
935
 
925
936
    strcpy(normal, myfonts.f_n);
926
937
    if (!check_fontname(myfonts.f_b)) {
1232
1243
/*
1233
1244
 * Collect font-names that we can modify with the load-vt-fonts() action.
1234
1245
 */
1235
 
typedef struct {
1236
 
    VTFontNames default_font;
1237
 
    String menu_font_names[fontMenu_lastBuiltin + 1][fMAX];
1238
 
} SubResourceRec;
1239
 
 
1240
1246
#define MERGE_SUBFONT(src,dst,name) \
1241
1247
        if (IsEmpty(dst.name)) { \
1242
1248
            TRACE(("MERGE_SUBFONT " #dst "." #name " merge %s\n", NonNull(src.name))); \
1251
1257
            for (m = 0; m < fMAX; ++m) { \
1252
1258
                dst.menu_font_names[n][m] = x_strdup(src.menu_font_names[n][m]); \
1253
1259
            } \
1254
 
        }
 
1260
            TRACE((".. " #dst ".menu_fonts_names[%d] = %s\n", n, dst.menu_font_names[n][fNorm])); \
 
1261
        }
 
1262
 
 
1263
void
 
1264
xtermSaveVTFonts(XtermWidget xw)
 
1265
{
 
1266
    TScreen *screen = TScreenOf(xw);
 
1267
    Cardinal n, m;
 
1268
 
 
1269
    if (!screen->savedVTFonts) {
 
1270
 
 
1271
        screen->savedVTFonts = True;
 
1272
        TRACE(("xtermSaveVTFonts saving original\n"));
 
1273
        screen->cacheVTFonts.default_font = xw->misc.default_font;
 
1274
        COPY_MENU_FONTS(xw->screen, screen->cacheVTFonts);
 
1275
    }
 
1276
}
 
1277
 
 
1278
#define SAME_STRING(x,y) ((x) == (y) || ((x) && (y) && !strcmp(x, y)))
 
1279
#define SAME_MEMBER(n)   SAME_STRING(a->n, b->n)
 
1280
 
 
1281
static Boolean
 
1282
sameSubResources(SubResourceRec * a, SubResourceRec * b)
 
1283
{
 
1284
    Boolean result = True;
 
1285
    int n;
 
1286
 
 
1287
    if (!SAME_MEMBER(default_font.f_n)
 
1288
        || !SAME_MEMBER(default_font.f_b)
 
1289
        || !SAME_MEMBER(default_font.f_w)
 
1290
        || !SAME_MEMBER(default_font.f_wb)) {
 
1291
        TRACE(("sameSubResources: default_font differs\n"));
 
1292
        result = False;
 
1293
    } else {
 
1294
        for (n = 0; n < NMENUFONTS; ++n) {
 
1295
            if (!SAME_MEMBER(menu_font_names[n][fNorm])) {
 
1296
                TRACE(("sameSubResources: menu_font_names[%d] differs\n", n));
 
1297
                result = False;
 
1298
                break;
 
1299
            }
 
1300
        }
 
1301
    }
 
1302
 
 
1303
    return result;
 
1304
}
1255
1305
 
1256
1306
/*
1257
1307
 * Load the "VT" font names from the given subresource name/class.  These
1260
1310
static Bool
1261
1311
xtermLoadVTFonts(XtermWidget xw, String myName, String myClass)
1262
1312
{
1263
 
    static Bool initialized = False;
1264
 
    static SubResourceRec original, referenceRec, subresourceRec;
 
1313
    SubResourceRec subresourceRec;
 
1314
    SubResourceRec referenceRec;
1265
1315
 
1266
1316
    /*
1267
1317
     * These are duplicates of the VT100 font resources, but with a special
1286
1336
    Bool status = True;
1287
1337
    TScreen *screen = TScreenOf(xw);
1288
1338
 
1289
 
    if (!initialized) {
 
1339
    TRACE(("called xtermLoadVTFonts(name=%s, class=%s)\n",
 
1340
           NonNull(myName), NonNull(myClass)));
1290
1341
 
1291
 
        initialized = True;
1292
 
        TRACE(("xtermLoadVTFonts saving original\n"));
1293
 
        original.default_font = xw->misc.default_font;
1294
 
        COPY_MENU_FONTS(xw->screen, original);
1295
 
    }
 
1342
    xtermSaveVTFonts(xw);
1296
1343
 
1297
1344
    if (IsEmpty(myName)) {
1298
1345
        TRACE(("xtermLoadVTFonts restoring original\n"));
1299
 
        xw->misc.default_font = original.default_font;
1300
 
        COPY_MENU_FONTS(original, xw->screen);
1301
 
        for (n = 0; n < XtNumber(original.menu_font_names); ++n)
1302
 
            screen->MenuFontName(n) = original.MenuFontName(n);
 
1346
        xw->misc.default_font = screen->cacheVTFonts.default_font;
 
1347
        COPY_MENU_FONTS(screen->cacheVTFonts, xw->screen);
 
1348
        for (n = 0; n < XtNumber(screen->cacheVTFonts.menu_font_names); ++n) {
 
1349
            screen->MenuFontName(n) = screen->cacheVTFonts.MenuFontName(n);
 
1350
        }
1303
1351
    } else {
1304
1352
        TRACE(("xtermLoadVTFonts(%s, %s)\n", myName, myClass));
1305
1353
 
 
1354
        memset(&referenceRec, 0, sizeof(referenceRec));
1306
1355
        memset(&subresourceRec, 0, sizeof(subresourceRec));
1307
1356
        XtGetSubresources((Widget) xw, (XtPointer) &subresourceRec,
1308
1357
                          myName, myClass,
1310
1359
                          (Cardinal) XtNumber(font_resources),
1311
1360
                          NULL, (Cardinal) 0);
1312
1361
 
1313
 
        if (memcmp(&referenceRec, &subresourceRec, sizeof(referenceRec))) {
 
1362
        /*
 
1363
         * XtGetSubresources returns no status, so we compare the returned
 
1364
         * data against a zero'd struct to see if any data is returned.
 
1365
         */
 
1366
        if (memcmp(&referenceRec, &subresourceRec, sizeof(referenceRec))
 
1367
            && !sameSubResources(&(screen->cacheVTFonts), &subresourceRec)) {
 
1368
 
 
1369
            screen->mergedVTFonts = True;
1314
1370
 
1315
1371
            /*
1316
1372
             * If a particular resource value was not found, use the original.
1388
1444
    }
1389
1445
    if (!result) {
1390
1446
        TRACE(("current fonts are not all wide%s\n", nullOk ? " nullOk" : ""));
1391
 
        result = xtermLoadVTFonts(xw, "utf8Fonts", "Utf8Fonts");
 
1447
        result = xtermLoadVTFonts(xw, XtNutf8Fonts, XtCUtf8Fonts);
1392
1448
    }
1393
1449
    TRACE(("xtermLoadWideFonts:%d\n", result));
1394
1450
    return result;