From 42719701dc17b5acef41223fe0237b9154cb3f0a Mon Sep 17 00:00:00 2001 From: simonb Date: Tue, 4 Apr 2006 14:07:07 +0000 Subject: rotated Xmb Fonts, by rotating as we draw --- ChangeLog | 5 +++ src/FbTk/Text.hh | 25 +++++++++++++++ src/FbTk/XmbFontImp.cc | 82 +++++++++++++++++++++++++++++++++++++++++++++----- src/FbTk/XmbFontImp.hh | 3 ++ 4 files changed, 107 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6f6a94..d195bc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ (Format: Year/Month/Day) Changes for 0.9.16: *06/04/04: + * Rotated Xmb Fonts (Simon) + - rotated when drawn. Probably not very efficient for + parentrelative backgrounds. If it proves an issue, we should + probably cache recently-drawn strings so we can just re-stipple. + XmbFontImp.hh/cc Text.hh * Rotated X Fonts again, plus minor external tab alignment fixes (Simon) - Still need to do XmbFonts. Most people probably load those instead of XFont these days. Will need yet another approach... diff --git a/src/FbTk/Text.hh b/src/FbTk/Text.hh index ceb0f19..5336546 100644 --- a/src/FbTk/Text.hh +++ b/src/FbTk/Text.hh @@ -75,6 +75,31 @@ inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w, } +// still require w and h in ROT0 coords +inline void untranslateCoords(Orientation orient, int &orig_x, int &orig_y, unsigned int w, unsigned int h) { + + int x = orig_x; + int y = orig_y; + + switch(orient) { + case ROT0: + break; + case ROT90: + orig_y = h - x; + orig_x = y; + break; + case ROT180: + orig_x = w - x; + orig_y = h - y; + break; + case ROT270: + orig_y = x; + orig_x = w - y; + break; + } + +} + // When positioning an X11 box inside another area, we need to // relocate the x,y coordinates inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w, unsigned int h, unsigned int bw) { diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc index e923040..f33942a 100644 --- a/src/FbTk/XmbFontImp.cc +++ b/src/FbTk/XmbFontImp.cc @@ -25,7 +25,8 @@ #include "App.hh" #include "StringUtil.hh" -#include "FbDrawable.hh" +#include "FbPixmap.hh" +#include "GContext.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -56,6 +57,8 @@ #include #endif +#include + using namespace std; namespace { @@ -183,24 +186,87 @@ bool XmbFontImp::load(const std::string &fontname) { return true; } -void XmbFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *text, +void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const char *text, size_t len, int x, int y, FbTk::Orientation orient) const { if (m_fontset == 0) return; + if (orient == ROT0) { +#ifdef X_HAVE_UTF8_STRING + if (m_utf8mode) { + Xutf8DrawString(d.display(), d.drawable(), m_fontset, + main_gc, x, y, + text, len); + } else +#endif //X_HAVE_UTF8_STRING + { + XmbDrawString(d.display(), d.drawable(), m_fontset, + main_gc, x, y, + text, len); + } + return; + } + + Display *dpy = App::instance()->display(); + Window rootwin = DefaultRootWindow(dpy); + + int xpos = x, ypos = y; + unsigned int w = d.width(); + unsigned int h = d.height(); + + translateSize(orient, w, h); + untranslateCoords(orient, xpos, ypos, w, h); + + // not straight forward, we actually draw it elsewhere, then rotate it + FbTk::FbPixmap canvas(rootwin, w, h, 1); + + // create graphic context for our canvas + FbTk::GContext font_gc(canvas); + font_gc.setBackground(None); + font_gc.setForeground(None); + + XFillRectangle(dpy, canvas.drawable(), font_gc.gc(), 0, 0, canvas.width(), canvas.height()); + font_gc.setForeground(1); + + #ifdef X_HAVE_UTF8_STRING if (m_utf8mode) { - Xutf8DrawString(w.display(), w.drawable(), m_fontset, - gc, x, y, - text, len); + Xutf8DrawString(dpy, canvas.drawable(), m_fontset, + font_gc.gc(), xpos, ypos, + text, len); } else #endif //X_HAVE_UTF8_STRING { - XmbDrawString(w.display(), w.drawable(), m_fontset, - gc, x, y, - text, len); + XmbDrawString(dpy, canvas.drawable(), m_fontset, + font_gc.gc(), xpos, ypos, + text, len); } + + canvas.rotate(orient); + + GC my_gc = XCreateGC(dpy, d.drawable(), 0, 0); + + XCopyGC(dpy, main_gc, GCForeground|GCBackground, my_gc); + + // vertical or upside down + + XSetFillStyle(dpy, my_gc, FillStippled); + + // vertical or upside down + + XSetFillStyle(dpy, my_gc, FillStippled); + + XSetStipple(dpy, my_gc, canvas.drawable()); + + XSetTSOrigin(dpy, my_gc, 0, 0); + + XFillRectangle(dpy, d.drawable(), my_gc, 0, 0, + canvas.width(), + canvas.height()); + + XFreeGC(dpy, my_gc); + } unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const { diff --git a/src/FbTk/XmbFontImp.hh b/src/FbTk/XmbFontImp.hh index 9ee5db5..4a8f20b 100644 --- a/src/FbTk/XmbFontImp.hh +++ b/src/FbTk/XmbFontImp.hh @@ -43,6 +43,9 @@ public: int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; } bool loaded() const { return m_fontset != 0; } bool utf8() const { return m_utf8mode; } + + bool validOrientation(FbTk::Orientation orient) { return true; }; // rotated on demand + private: XFontSet m_fontset; XFontSetExtents *m_setextents; -- cgit v0.11.2