source: trunk/gcc/libjava/gnu/gcj/xlib/natFont.cc

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.3 KB
Line 
1/* Copyright (C) 2000 Free Software Foundation
2
3 This file is part of libgcj.
4
5This software is copyrighted work licensed under the terms of the
6Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7details. */
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
19gnu::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
38jint gnu::gcj::xlib::Font::getXIDFromStruct(gnu::gcj::RawData* structure)
39{
40 XFontStruct* fontStruct = (XFontStruct*) structure;
41 return fontStruct->fid;
42}
43
44jint gnu::gcj::xlib::Font::getMaxAscent()
45{
46 XFontStruct* fontStruct = (XFontStruct*) structure;
47 return fontStruct->max_bounds.ascent;
48}
49
50jint gnu::gcj::xlib::Font::getMaxDescent()
51{
52 XFontStruct* fontStruct = (XFontStruct*) structure;
53 return fontStruct->max_bounds.descent;
54}
55
56jint gnu::gcj::xlib::Font::getAscent()
57{
58 XFontStruct* fontStruct = (XFontStruct*) structure;
59 return fontStruct->ascent;
60}
61
62jint gnu::gcj::xlib::Font::getDescent()
63{
64 XFontStruct* fontStruct = (XFontStruct*) structure;
65 return fontStruct->ascent;
66}
67
68jint 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
81void 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
Note: See TracBrowser for help on using the repository browser.