summaryrefslogtreecommitdiff
path: root/hw/xscreen/xs-font.c
blob: 1e8301375536217a3130d5bf3197c573b57cce4d (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 <X11/XCB/xcb.h>
#include <X11/XCB/xcb_aux.h>
#include <X11/XCB/xproto.h>
#include <X11/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;
    XCBFONT font;
    XCBATOM name_atom, value_atom;

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

    FontSetPrivate(pFont, xsFontPrivateIndex, NULL);

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

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

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

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

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

    font = XCBFONTNew(xsConnection);
    XS_FONT_PRIV(pFont)->font = font;
    XCBOpenFont(xsConnection, font, strlen(name), name);

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

    return TRUE;
}

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