From 460d3850919831c107b28c09881f857647444745 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Wed, 16 Oct 2002 23:13:54 +0000
Subject: utf8

---
 src/XftFontImp.cc | 48 +++++++++++++++++++++++++++++++++++-------------
 src/XftFontImp.hh |  9 +++++----
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/src/XftFontImp.cc b/src/XftFontImp.cc
index d31a74e..619b791 100644
--- a/src/XftFontImp.cc
+++ b/src/XftFontImp.cc
@@ -19,12 +19,13 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-//$Id: XftFontImp.cc,v 1.1 2002/10/14 18:14:20 fluxgen Exp $
+//$Id: XftFontImp.cc,v 1.2 2002/10/16 23:13:15 fluxgen Exp $
 
 #include "XftFontImp.hh"
 #include "BaseDisplay.hh"
 
-XftFontImp::XftFontImp(const char *name):m_xftfont(0) {
+XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0),
+m_utf8mode(utf8) {
 	if (name != 0)
 		load(name);
 }
@@ -83,30 +84,51 @@ void XftFontImp::drawText(Drawable w, int screen, GC gc, const char *text, size_
 		&rendcol, &xftcolor);
 
 	// draw string
-	XftDrawString8 (draw,
-		&xftcolor,
-		m_xftfont,
-		x, y,
-		(XftChar8 *)(text), len);
+#ifdef X_HAVE_UTF8_STRING
+	if (m_utf8mode) {
+		XftDrawStringUtf8(draw,
+			&xftcolor,
+			m_xftfont,
+			x, y,
+			(XftChar8 *)(text), len);
+	} else 
+#endif // X_HAVE_UTF8_STRING
+	{
+		XftDrawString8(draw,
+			&xftcolor,
+			m_xftfont,
+			x, y,
+			(XftChar8 *)(text), len);
+	}
 
 	XftColorFree(disp, DefaultVisual(disp, screen), 
 		DefaultColormap(disp, screen), &xftcolor);
 	XftDrawDestroy(draw);
 }
 
-unsigned int XftFontImp::textWidth(const char *text, unsigned int len) const {
+unsigned int XftFontImp::textWidth(const char * const text, unsigned int len) const {
 	if (m_xftfont == 0)
 		return 0;
 	XGlyphInfo ginfo;
-	XftTextExtents8(BaseDisplay::getXDisplay(),
-		m_xftfont,
-		(XftChar8 *)text, len,
-		&ginfo);
+#ifdef X_HAVE_UTF8_STRING
+	if (m_utf8mode) {
+		XftTextExtentsUtf8(BaseDisplay::getXDisplay(),
+			m_xftfont,
+			(XftChar8 *)text, len,
+			&ginfo);
+	} else 
+#endif  //X_HAVE_UTF8_STRING
+	{
+		XftTextExtents8(BaseDisplay::getXDisplay(),
+			m_xftfont,
+			(XftChar8 *)text, len,
+			&ginfo);
+	}
 	return ginfo.xOff;
 }
 
 unsigned int XftFontImp::height() const {
 	if (m_xftfont == 0)
 		return 0;
-	return m_xftfont->ascent + m_xftfont->descent;
+	return m_xftfont->height;
 }
diff --git a/src/XftFontImp.hh b/src/XftFontImp.hh
index 5cfc6ee..d03e65a 100644
--- a/src/XftFontImp.hh
+++ b/src/XftFontImp.hh
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-//$Id: XftFontImp.hh,v 1.2 2002/10/15 16:44:26 fluxgen Exp $
+//$Id: XftFontImp.hh,v 1.3 2002/10/16 23:13:54 fluxgen Exp $
 
 #ifndef XFTFONTIMP_HH
 #define XFTFONTIMP_HH
@@ -29,15 +29,16 @@
 
 class XftFontImp:public FbTk::FontImp {
 public:
-	explicit XftFontImp(const char *fontname=0);
+	XftFontImp(const char *fontname, bool utf8);
 	~XftFontImp();
 	bool load(const std::string &name);
 	void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const;
-	unsigned int textWidth(const char *text, unsigned int len) const;
+	unsigned int textWidth(const char * const text, unsigned int len) const;
 	unsigned int height() const;
 	bool loaded() const { return m_xftfont != 0; }
 private:
-	XftFont *m_xftfont;	
+	XftFont *m_xftfont;
+	bool m_utf8mode;
 };
 
 #endif // XFTFONTIMP_HH
-- 
cgit v0.11.2