From 3b2288059d786fc6994debbaffeff898746a6921 Mon Sep 17 00:00:00 2001 From: Scott Gilbertson Date: Sat, 19 Apr 2003 17:52:15 +0000 Subject: [PATCH] natFont.cc (getStringWidth): Support 16-bit characters. 2003-04-19 Scott Gilbertson * libjava/gnu/gcj/xlib/natFont.cc (getStringWidth): Support 16-bit characters. * libjava/gnu/gcj/xlib/natGC.cc (drawString): Support 16-bit characters. From-SVN: r65820 --- libjava/ChangeLog | 7 +++++++ libjava/gnu/gcj/xlib/natFont.cc | 24 ++++++++++++++++-------- libjava/gnu/gcj/xlib/natGC.cc | 32 +++++++++++++++----------------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 350bef96f8b..d91604be9c0 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,10 @@ +2003-04-19 Scott Gilbertson + + * libjava/gnu/gcj/xlib/natFont.cc (getStringWidth): Support 16-bit + characters. + * libjava/gnu/gcj/xlib/natGC.cc (drawString): Support 16-bit + characters. + 2003-04-16 Richard Earnshaw * java/lang/ieeefp.h: Handle ARM platforms that have pure-endian diff --git a/libjava/gnu/gcj/xlib/natFont.cc b/libjava/gnu/gcj/xlib/natFont.cc index 7bfea7b17f8..0f8f43dc509 100644 --- a/libjava/gnu/gcj/xlib/natFont.cc +++ b/libjava/gnu/gcj/xlib/natFont.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation +/* Copyright (C) 2000, 2003 Free Software Foundation This file is part of libgcj. @@ -69,13 +69,21 @@ jint gnu::gcj::xlib::Font::getStringWidth(java::lang::String* text) { XFontStruct* fontStruct = (XFontStruct*) structure; - // FIXME: make proper unicode conversion - int len = JvGetStringUTFLength(text); - char ctxt[len+1]; - JvGetStringUTFRegion(text, 0, text->length(), ctxt); - ctxt[len] = '\0'; - int width = XTextWidth(fontStruct, ctxt, len); - return width; + // 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; ibyte1 = (jc >> 8) & 0xff; + xc->byte2 = jc & 0xff; + } + return XTextWidth16(fontStruct, xwchars, length); } void gnu::gcj::xlib::Font::finalize() diff --git a/libjava/gnu/gcj/xlib/natGC.cc b/libjava/gnu/gcj/xlib/natGC.cc index 1a1bd586d8e..11f4b28f22b 100644 --- a/libjava/gnu/gcj/xlib/natGC.cc +++ b/libjava/gnu/gcj/xlib/natGC.cc @@ -95,27 +95,25 @@ void gnu::gcj::xlib::GC::drawString(jstring text, jint x, jint y) ::Drawable drawableXID = target->getXID(); ::GC gc = (::GC) structure; - /* - FIXME: do something along the lines of the following instead: + jint length = text->length(); + jchar* txt = JvGetStringChars(text); - jint length = text->length(); - jchar* txt = JvGetStringChars(text); - - XChar2b xwchars[length]; + XChar2b xwchars[length]; - // FIXME: Add convertion and caching + // 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. - for (int i=0; ibyte1 = jc & 0xff; - xc->byte2 = jc >> 8; - } + for (int i=0; ibyte1 = (jc >> 8) & 0xff; + xc->byte2 = jc & 0xff; + } + XDrawString16(dpy, drawableXID, gc, x, y, xwchars, length); - XDrawString16(dpy, drawableXID, gc, x, y, xwchars, length); - */ - // FIXME, temporary code: int len = JvGetStringUTFLength(text); char ctxt[len+1];