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

« back to all changes in this revision

Viewing changes to fontutils.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2010-03-31 12:32:27 UTC
  • mfrom: (1.1.17 upstream) (11.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100331123227-8a6qwmyciob6j88y
Tags: 256-1ubuntu1
* Merge from Debian unstable.
* Revert the libutempter change for lucid. (LP: #539473)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XTermId: fontutils.c,v 1.327 2009/12/10 09:35:41 tom Exp $ */
 
1
/* $XTermId: fontutils.c,v 1.336 2010/01/01 15:02:26 tom Exp $ */
2
2
 
3
3
/************************************************************
4
4
 
5
 
Copyright 1998-2008,2009 by Thomas E. Dickey
 
5
Copyright 1998-2009,2010 by Thomas E. Dickey
6
6
 
7
7
                        All Rights Reserved
8
8
 
1725
1725
}
1726
1726
 
1727
1727
#if OPT_RENDERFONT
 
1728
void
 
1729
xtermCloseXft(TScreen * screen, XTermXftFonts * pub)
 
1730
{
 
1731
    if (pub->font != 0) {
 
1732
        XftFontClose(screen->display, pub->font);
 
1733
        pub->font = 0;
 
1734
    }
 
1735
}
 
1736
 
1728
1737
/*
1729
1738
 * Get the faceName/faceDoublesize resource setting.  Strip off "xft:", which
1730
1739
 * is not recognized by XftParseName().
1731
1740
 */
1732
 
static char *
1733
 
getFaceName(XtermWidget xw, char *wideName GCC_UNUSED)
 
1741
char *
 
1742
getFaceName(XtermWidget xw, Bool wideName GCC_UNUSED)
1734
1743
{
1735
1744
#if OPT_RENDERWIDE
1736
 
    char *result = ((wideName != NULL)
 
1745
    char *result = (wideName
1737
1746
                    ? xw->misc.face_wide_name
1738
1747
                    : xw->misc.face_name);
1739
1748
#else
1740
1749
    char *result = xw->misc.face_name;
1741
1750
#endif
1742
 
    if (!strncmp(result, "xft:", 4))
 
1751
    if (!IsEmpty(result) && !strncmp(result, "xft:", 4))
1743
1752
        result += 4;
1744
1753
    return x_nonempty(result);
1745
1754
}
 
1755
 
 
1756
/*
 
1757
 * If we change the faceName, we'll have to re-acquire all of the fonts that
 
1758
 * are derived from it.
 
1759
 */
 
1760
void
 
1761
setFaceName(XtermWidget xw, const char *value)
 
1762
{
 
1763
    TScreen *screen = TScreenOf(xw);
 
1764
    int n;
 
1765
 
 
1766
    xw->misc.face_name = x_strdup(value);
 
1767
    for (n = 0; n < NMENUFONTS; ++n) {
 
1768
        xw->misc.face_size[n] = -1.0;
 
1769
        xtermCloseXft(screen, &(screen->renderFontNorm[n]));
 
1770
        xtermCloseXft(screen, &(screen->renderFontBold[n]));
 
1771
        xtermCloseXft(screen, &(screen->renderFontBold[n]));
 
1772
#if OPT_RENDERWIDE
 
1773
        xtermCloseXft(screen, &(screen->renderWideNorm[n]));
 
1774
        xtermCloseXft(screen, &(screen->renderWideBold[n]));
 
1775
        xtermCloseXft(screen, &(screen->renderWideItal[n]));
 
1776
#endif
 
1777
    }
 
1778
}
1746
1779
#endif
1747
1780
 
1748
1781
/*
1767
1800
     * overrides it.
1768
1801
     */
1769
1802
    if (xw->misc.render_font && !IsIconWin(screen, win)) {
1770
 
        char *face_name = getFaceName(xw, NULL);
 
1803
        char *face_name = getFaceName(xw, False);
1771
1804
        int fontnum = screen->menu_font_number;
1772
1805
        XftFont *norm = screen->renderFontNorm[fontnum].font;
1773
1806
        XftFont *bold = screen->renderFontBold[fontnum].font;
1915
1948
                                 : 2.0);
1916
1949
#endif
1917
1950
 
1918
 
                face_name = getFaceName(xw, xw->misc.face_wide_name);
 
1951
                face_name = getFaceName(xw, True);
1919
1952
                TRACE(("xtermComputeFontInfo wide(face %s, char_width %d)\n",
1920
1953
                       NonNull(face_name),
1921
1954
                       char_width));
2616
2649
        memset(&fnt, 0, sizeof(fnt));
2617
2650
        screen->menu_font_sizes[fontnum] = -1;
2618
2651
        if (xtermOpenFont(xw, screen->MenuFontName(fontnum), &fnt, fwAlways, True)) {
2619
 
            screen->menu_font_sizes[fontnum] = FontSize(fnt.fs);
2620
 
            TRACE(("menu_font_sizes[%d] = %ld\n", fontnum,
2621
 
                   screen->menu_font_sizes[fontnum]));
 
2652
            if (fontnum <= fontMenu_lastBuiltin
 
2653
                || strcmp(fnt.fn, DEFFONT))
 
2654
                screen->menu_font_sizes[fontnum] = FontSize(fnt.fs);
2622
2655
            xtermCloseFont(xw, &fnt);
2623
2656
        }
2624
2657
    }
2971
3004
 
2972
3005
        if (which == fontMenu_fontsel) {        /* go get the selection */
2973
3006
            FindFontSelection(xw, myfonts.f_n, False);
2974
 
            return;
2975
3007
        } else {
2976
3008
            int oldFont = screen->menu_font_number;
2977
3009
 
2983
3015
            } else { \
2984
3016
                TRACE(("set myfonts." #field " reused\n")); \
2985
3017
            }
 
3018
#define SAVE_FNAME(field, name) \
 
3019
            if (myfonts.field != 0) { \
 
3020
                if (screen->menu_font_names[which][name] == 0 \
 
3021
                 || strcmp(screen->menu_font_names[which][name], myfonts.field)) { \
 
3022
                    TRACE(("updating menu_font_names[%d][" #name "] to %s\n", \
 
3023
                           which, myfonts.field)); \
 
3024
                    screen->menu_font_names[which][name] = x_strdup(myfonts.field); \
 
3025
                } \
 
3026
            }
 
3027
 
2986
3028
            USE_CACHED(f_n, fNorm);
2987
3029
            USE_CACHED(f_b, fBold);
2988
3030
#if OPT_WIDE_CHARS
2992
3034
            if (xtermLoadFont(xw,
2993
3035
                              &myfonts,
2994
3036
                              doresize, which)) {
2995
 
                return;
 
3037
                /*
 
3038
                 * If successful, save the data so that a subsequent query via
 
3039
                 * OSC-50 will return the expected values.
 
3040
                 */
 
3041
                SAVE_FNAME(f_n, fNorm);
 
3042
                SAVE_FNAME(f_b, fBold);
 
3043
#if OPT_WIDE_CHARS
 
3044
                SAVE_FNAME(f_w, fWide);
 
3045
                SAVE_FNAME(f_wb, fWBold);
 
3046
#endif
2996
3047
            } else {
2997
3048
                xtermLoadFont(xw,
2998
3049
                              xtermFontName(screen->MenuFontName(oldFont)),
2999
3050
                              doresize, oldFont);
 
3051
                Bell(XkbBI_MinorError, 0);
3000
3052
            }
3001
3053
        }
 
3054
    } else {
 
3055
        Bell(XkbBI_MinorError, 0);
3002
3056
    }
3003
 
 
3004
 
    Bell(XkbBI_MinorError, 0);
3005
3057
    return;
3006
3058
}