1 | /* Copyright (C) 2000 Free Software Foundation
|
---|
2 |
|
---|
3 | This file is part of libgcj.
|
---|
4 |
|
---|
5 | This software is copyrighted work licensed under the terms of the
|
---|
6 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
7 | details. */
|
---|
8 |
|
---|
9 | #include <X11/Xlib.h>
|
---|
10 |
|
---|
11 | #include <gcj/cni.h>
|
---|
12 | #include <gnu/gcj/RawData.h>
|
---|
13 | #include <java/lang/String.h>
|
---|
14 |
|
---|
15 | #include <gnu/gcj/xlib/Display.h>
|
---|
16 | #include <gnu/gcj/xlib/Font.h>
|
---|
17 | #include <gnu/gcj/xlib/XException.h>
|
---|
18 |
|
---|
19 | gnu::gcj::RawData* gnu::gcj::xlib::Font::loadFont(Display* display,
|
---|
20 | jstring lfdNamePattern)
|
---|
21 | {
|
---|
22 | ::Display* dpy = (::Display*) display->display;
|
---|
23 | int len = JvGetStringUTFLength(lfdNamePattern);
|
---|
24 | char cName[len+1];
|
---|
25 | JvGetStringUTFRegion(lfdNamePattern, 0, lfdNamePattern->length(),
|
---|
26 | cName);
|
---|
27 | cName[len] = '\0';
|
---|
28 |
|
---|
29 | XFontStruct* fontStruct = XLoadQueryFont(dpy, cName);
|
---|
30 | if (fontStruct == 0)
|
---|
31 | {
|
---|
32 | throw new XException(JvNewStringLatin1("font not found"));
|
---|
33 | }
|
---|
34 |
|
---|
35 | return reinterpret_cast<gnu::gcj::RawData*>(fontStruct);
|
---|
36 | }
|
---|
37 |
|
---|
38 | jint gnu::gcj::xlib::Font::getXIDFromStruct(gnu::gcj::RawData* structure)
|
---|
39 | {
|
---|
40 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
41 | return fontStruct->fid;
|
---|
42 | }
|
---|
43 |
|
---|
44 | jint gnu::gcj::xlib::Font::getMaxAscent()
|
---|
45 | {
|
---|
46 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
47 | return fontStruct->max_bounds.ascent;
|
---|
48 | }
|
---|
49 |
|
---|
50 | jint gnu::gcj::xlib::Font::getMaxDescent()
|
---|
51 | {
|
---|
52 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
53 | return fontStruct->max_bounds.descent;
|
---|
54 | }
|
---|
55 |
|
---|
56 | jint gnu::gcj::xlib::Font::getAscent()
|
---|
57 | {
|
---|
58 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
59 | return fontStruct->ascent;
|
---|
60 | }
|
---|
61 |
|
---|
62 | jint gnu::gcj::xlib::Font::getDescent()
|
---|
63 | {
|
---|
64 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
65 | return fontStruct->ascent;
|
---|
66 | }
|
---|
67 |
|
---|
68 | jint gnu::gcj::xlib::Font::getStringWidth(java::lang::String* text)
|
---|
69 | {
|
---|
70 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
71 |
|
---|
72 | // FIXME: make proper unicode conversion
|
---|
73 | int len = JvGetStringUTFLength(text);
|
---|
74 | char ctxt[len+1];
|
---|
75 | JvGetStringUTFRegion(text, 0, text->length(), ctxt);
|
---|
76 | ctxt[len] = '\0';
|
---|
77 | int width = XTextWidth(fontStruct, ctxt, len);
|
---|
78 | return width;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void gnu::gcj::xlib::Font::finalize()
|
---|
82 | {
|
---|
83 | if (structure != 0)
|
---|
84 | {
|
---|
85 | ::Display* dpy = (::Display*) display->display;
|
---|
86 | XFontStruct* fontStruct = (XFontStruct*) structure;
|
---|
87 | int result = XFreeFont(dpy, fontStruct);
|
---|
88 |
|
---|
89 | if (result == BadFont)
|
---|
90 | throw new XException(display, result);
|
---|
91 |
|
---|
92 | structure = 0; xid = 0;
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|