Changeset 4143 for libcaca/trunk


Ignore:
Timestamp:
Dec 18, 2009, 10:17:54 PM (10 years ago)
Author:
Sam Hocevar
Message:

Deduce X11 font size from a relevant sample to avoid oversized font
cells. Fixes bug #21 (X11 Unicode support).

Location:
libcaca/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/driver/x11.c

    r4142 r4143  
    210210    if (dp->drv.p->font_set)
    211211    {
    212         XFontSetExtents *ex = XExtentsOfFontSet(dp->drv.p->font_set);
     212        /* Do not trust the fontset, because some fonts may have
     213         * irrelevantly large glyphs. Pango and rxvt use the same method. */
     214        static wchar_t const test[] =
     215        {
     216            '0', '1', '8', 'a', 'd', 'x', 'm', 'y', 'g', 'W', 'X', '\'', '_',
     217            0x00cd, 0x00e7, 0x00d5, 0x0114, 0x0177, /* Í ç Õ Ĕ ŷ */
     218            /* 0x0643, */ /* ﻙ */
     219            0x304c, 0x672c, /* が本 */
     220            0,
     221        };
     222
     223        XRectangle ink, logical;
     224
    213225        dp->drv.p->font_width =
    214              XmbTextEscapement(dp->drv.p->font_set, "CAca", 4) / 4;
    215         dp->drv.p->font_height = ex->max_logical_extent.height;
    216         dp->drv.p->font_offset = ex->max_logical_extent.height
    217                                   + ex->max_logical_extent.y;
     226             (XmbTextEscapement(dp->drv.p->font_set, "CAca", 4) + 2) / 4;
     227        XwcTextExtents(dp->drv.p->font_set, test, sizeof(test) / sizeof(*test),
     228                       &ink, &logical);
     229        dp->drv.p->font_height = ink.height;
     230        dp->drv.p->font_offset = ink.height + ink.y;
    218231    }
    219232    else
     
    902915    {
    903916        wchar_t wch = ch;
    904         XwcDrawString(dpy, px, dp->drv.p->font_set, gc,
    905                       x + (fw - w) / 2, yoff, &wch, 1);
     917        XwcDrawString(dpy, px, dp->drv.p->font_set, gc, x, yoff, &wch, 1);
    906918    }
    907919    else
     
    923935        }
    924936
    925         XDrawString16(dpy, px, gc,
    926                       x + (ch16.byte1 ? 0 : (fw - w) / 2), yoff, &ch16, 1);
     937        XDrawString16(dpy, px, gc, x, yoff, &ch16, 1);
    927938    }
    928939}
  • libcaca/trunk/examples/unicode.c

    r2821 r4143  
    4545    caca_put_str(cv, 1, 3, "This is Unicode:  | äßç δεφ ☺♥♀ ╞╬╗ |");
    4646    caca_put_str(cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
     47    caca_put_str(cv, 41, 4, "Size test: 018adxmygWX'_ÍçÕĔŷ ﻙ が本");
    4748
    4849    caca_put_str(cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
Note: See TracChangeset for help on using the changeset viewer.