2003-04-19 19:52:15 +02:00
|
|
|
/* Copyright (C) 2000, 2003 Free Software Foundation
|
2000-10-22 19:46:09 +02:00
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#include <gcj/cni.h>
|
|
|
|
#include <gnu/gcj/RawData.h>
|
|
|
|
#include <java/lang/String.h>
|
|
|
|
|
|
|
|
#include <gnu/gcj/xlib/Display.h>
|
|
|
|
#include <gnu/gcj/xlib/Font.h>
|
|
|
|
#include <gnu/gcj/xlib/XException.h>
|
|
|
|
|
|
|
|
gnu::gcj::RawData* gnu::gcj::xlib::Font::loadFont(Display* display,
|
|
|
|
jstring lfdNamePattern)
|
|
|
|
{
|
|
|
|
::Display* dpy = (::Display*) display->display;
|
|
|
|
int len = JvGetStringUTFLength(lfdNamePattern);
|
|
|
|
char cName[len+1];
|
|
|
|
JvGetStringUTFRegion(lfdNamePattern, 0, lfdNamePattern->length(),
|
|
|
|
cName);
|
|
|
|
cName[len] = '\0';
|
|
|
|
|
|
|
|
XFontStruct* fontStruct = XLoadQueryFont(dpy, cName);
|
|
|
|
if (fontStruct == 0)
|
|
|
|
{
|
exception.cc (java_eh_info): Make value type jthrowable.
* exception.cc (java_eh_info): Make value type jthrowable.
(_Jv_type_matcher): Remove now unneeded cast.
(_Jv_Throw): Make argument type jthrowable. Munge name
for SJLJ_EXCEPTIONS here ...
* gcj/cni.h: ... not here.
(JvThrow): Remove.
* gcj/javaprims.h (_Jv_Throw, _Jv_Sjlj_Throw): Update declarations.
* defineclass.cc, interpret.cc, jni.cc, posix-threads.cc,
prims.cc, resolve.cc, gnu/gcj/runtime/natFirstThread.cc,
gnu/gcj/xlib/natDrawable.cc, gnu/gcj/xlib/natFont.cc,
gnu/gcj/xlib/natWMSizeHints.cc, gnu/gcj/xlib/natWindowAttributes.cc,
gnu/gcj/xlib/natXImage.cc, java/io/natFile.cc,
java/io/natFileDescriptorEcos.cc, java/io/natFileDescriptorPosix.cc,
java/io/natFileDescriptorWin32.cc, java/io/natFileWin32.cc,
java/lang/natClass.cc, java/lang/natClassLoader.cc,
java/lang/natDouble.cc, java/lang/natObject.cc,
java/lang/natPosixProcess.cc, java/lang/natRuntime.cc,
java/lang/natString.cc, java/lang/natSystem.cc,
java/lang/natThread.cc, java/lang/reflect/natArray.cc,
java/lang/reflect/natConstructor.cc, java/lang/reflect/natField.cc,
java/lang/reflect/natMethod.cc, java/util/zip/natDeflater.cc,
java/util/zip/natInflater.cc:
Use throw, not JvThrow or _Jv_Throw.
From-SVN: r40838
2001-03-26 09:05:32 +02:00
|
|
|
throw new XException(JvNewStringLatin1("font not found"));
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return reinterpret_cast<gnu::gcj::RawData*>(fontStruct);
|
|
|
|
}
|
|
|
|
|
|
|
|
jint gnu::gcj::xlib::Font::getXIDFromStruct(gnu::gcj::RawData* structure)
|
|
|
|
{
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
|
|
|
return fontStruct->fid;
|
|
|
|
}
|
|
|
|
|
|
|
|
jint gnu::gcj::xlib::Font::getMaxAscent()
|
|
|
|
{
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
2003-06-10 03:50:12 +02:00
|
|
|
return fontStruct->max_bounds.ascent+1; // +1 to include the baseline
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
jint gnu::gcj::xlib::Font::getMaxDescent()
|
|
|
|
{
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
2003-06-10 03:50:12 +02:00
|
|
|
return fontStruct->max_bounds.descent-1; // -1 to exclude the baseline
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
jint gnu::gcj::xlib::Font::getAscent()
|
|
|
|
{
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
2003-06-10 03:50:12 +02:00
|
|
|
jint returnValue = fontStruct->ascent;
|
|
|
|
if (fontStruct->min_byte1==0 && fontStruct->min_char_or_byte2<=(unsigned)'O')
|
|
|
|
returnValue = fontStruct
|
|
|
|
->per_char[(unsigned)'O'-fontStruct->min_char_or_byte2]
|
2003-06-10 04:45:07 +02:00
|
|
|
.ascent;
|
2003-06-10 03:50:12 +02:00
|
|
|
return returnValue+1; // +1 to include the baseline
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
jint gnu::gcj::xlib::Font::getDescent()
|
|
|
|
{
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
2003-06-10 03:50:12 +02:00
|
|
|
jint returnValue = fontStruct->descent;
|
|
|
|
if (fontStruct->min_byte1==0 && fontStruct->min_char_or_byte2<=(unsigned)'y')
|
|
|
|
returnValue = fontStruct
|
|
|
|
->per_char[(unsigned)'y'-fontStruct->min_char_or_byte2]
|
2003-06-10 04:45:07 +02:00
|
|
|
.descent;
|
2003-06-10 03:50:12 +02:00
|
|
|
return returnValue-1; // -1 to exclude the baseline
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
jint gnu::gcj::xlib::Font::getStringWidth(java::lang::String* text)
|
|
|
|
{
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
|
|
|
|
2003-04-19 19:52:15 +02:00
|
|
|
// FIXME: Convert to the character set used in the font, which may
|
|
|
|
// or may not be unicode. For now, treat everything as 16-bit and
|
|
|
|
// use character codes directly, which should be OK for unicode or
|
|
|
|
// 8-bit ascii fonts.
|
|
|
|
jint length = text->length();
|
|
|
|
jchar* txt = JvGetStringChars(text);
|
|
|
|
XChar2b xwchars[length];
|
|
|
|
for (int i=0; i<length; i++)
|
|
|
|
{
|
|
|
|
XChar2b* xc = &(xwchars[i]);
|
|
|
|
jchar jc = txt[i];
|
|
|
|
xc->byte1 = (jc >> 8) & 0xff;
|
|
|
|
xc->byte2 = jc & 0xff;
|
|
|
|
}
|
|
|
|
return XTextWidth16(fontStruct, xwchars, length);
|
2000-10-22 19:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void gnu::gcj::xlib::Font::finalize()
|
|
|
|
{
|
|
|
|
if (structure != 0)
|
|
|
|
{
|
|
|
|
::Display* dpy = (::Display*) display->display;
|
|
|
|
XFontStruct* fontStruct = (XFontStruct*) structure;
|
|
|
|
int result = XFreeFont(dpy, fontStruct);
|
|
|
|
|
|
|
|
if (result == BadFont)
|
|
|
|
throw new XException(display, result);
|
|
|
|
|
|
|
|
structure = 0; xid = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|