summaryrefslogtreecommitdiff
path: root/hw/xscreen/xs-font.c
blob: d17d29b4e471a9cf9d5adcd7a273d225f7fb2975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifdef HAVE_XS_CONFIG_H
#include <xs-config.h>
#endif
#include <X11/Xmd.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
#include <xcb/xproto.h>
#include <xcb/xcb_image.h>
#include "regionstr.h"
#include <X11/fonts/fontstruct.h>
#include "gcstruct.h"
#include "colormapst.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include "pixmapstr.h"
#include "region.h"
#include "servermd.h"


#include "xs-globals.h"
#include "xs-font.h"

Bool xsRealizeFont(ScreenPtr pScreen, FontPtr pFont)
{
    pointer priv;
    xcb_font_t font;
    xcb_atom_t name_atom, value_atom;

    int nprops;
    FontPropPtr props;
    int i;
    char *name;

    FontSetPrivate(pFont, xsFontPrivateIndex, NULL);

    name_atom = MakeAtom("FONT", 4, TRUE);
    value_atom = 0L;

    nprops = pFont->info.nprops;
    props = pFont->info.props;

    for (i = 0; i < nprops; i++) {
        if (props[i].name == name_atom) {
            value_atom = props[i].value;
            break;
        }
    }
    if (!value_atom)
        return FALSE;

    name = NameForAtom(value_atom);
    if (!name)
        return FALSE;

    priv = xalloc(sizeof(XscreenPrivFont));
    FontSetPrivate(pFont, xsFontPrivateIndex, priv);

    font = xcb_generate_id(xsConnection);
    XS_FONT_PRIV(pFont)->font = font;
    xcb_open_font(xsConnection, font, strlen(name), name);

    if (!XS_FONT_PRIV(pFont)->font)
        return FALSE;

    return TRUE;
}

Bool xsUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
{
    if (XS_FONT_PRIV(pFont)) {
        if (XS_FONT_PRIV(pFont)->font) 
            xcb_close_font(xsConnection, XS_FONT_PRIV(pFont)->font);
        xfree(XS_FONT_PRIV(pFont));
        FontSetPrivate(pFont, xsFontPrivateIndex, NULL);
    }
    return TRUE;
}