From 26c1cd0ceeb289abdf9ddfecdc699a27db8b0339 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Wed, 8 Sep 2010 20:48:01 +0200 Subject: code simplification --- src/FbTk/XFontImp.cc | 23 ++++++++--------------- src/FbTk/XFontImp.hh | 2 +- src/FbTk/XmbFontImp.cc | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/FbTk/XFontImp.cc b/src/FbTk/XFontImp.cc index fa88593..73ae384 100644 --- a/src/FbTk/XFontImp.cc +++ b/src/FbTk/XFontImp.cc @@ -102,14 +102,14 @@ void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char* text if (!text || !*text || m_fontstruct == 0) return; + std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, len)); + // use roated font functions? if (orient != ROT0 && validOrientation(orient)) { - drawRotText(w.drawable(), screen, gc, text, len, x, y, orient); + drawRotText(w.drawable(), screen, gc, localestr.c_str(), localestr.size(), x, y, orient); return; } - std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, 0, len)); - XSetFont(w.display(), gc, m_fontstruct->fid); XDrawString(w.display(), w.drawable(), gc, x, y, localestr.data(), localestr.size()); } @@ -330,7 +330,10 @@ void XFontImp::freeRotFont(XRotFontStruct *rotfont) { rotfont = 0; } -void XFontImp::drawRotText(Drawable w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { +void XFontImp::drawRotText(Drawable w, int screen, GC gc, const char* text, size_t len, int x, int y, FbTk::Orientation orient) const { + + if (!text || !*text || len<1) + return; Display *dpy = App::instance()->display(); static GC my_gc = 0; @@ -338,27 +341,17 @@ void XFontImp::drawRotText(Drawable w, int screen, GC gc, const FbString &text, XRotFontStruct *rotfont = m_rotfonts[orient]; - if (text.empty() || len<1) - return; - if (my_gc == 0) my_gc = XCreateGC(dpy, w, 0, 0); XCopyGC(dpy, gc, GCForeground|GCBackground, my_gc); // vertical or upside down - XSetFillStyle(dpy, my_gc, FillStippled); - string localestr = text; - localestr.erase(len, string::npos); - localestr = FbStringUtil::FbStrToLocale(localestr); - const char *ctext = localestr.data(); - len = localestr.size(); - // loop through each character in texting for (size_t i = 0; i= 0 && ichar<95) { diff --git a/src/FbTk/XFontImp.hh b/src/FbTk/XFontImp.hh index ccebbb7..600bb68 100644 --- a/src/FbTk/XFontImp.hh +++ b/src/FbTk/XFontImp.hh @@ -72,7 +72,7 @@ private: void rotate(FbTk::Orientation orient); void freeRotFont(XRotFontStruct * rotfont); - void drawRotText(Drawable w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const; + void drawRotText(Drawable w, int screen, GC gc, const char* text, size_t len, int x, int y, FbTk::Orientation orient) const; XRotFontStruct *m_rotfonts[4]; ///< rotated font structure (only 3 used) bool m_rotfonts_loaded[4]; // whether we've tried yet diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc index 7613a40..8f2bdf9 100644 --- a/src/FbTk/XmbFontImp.cc +++ b/src/FbTk/XmbFontImp.cc @@ -204,7 +204,7 @@ void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const cha } else #endif //X_HAVE_UTF8_STRING { - std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, 0, len)); + std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, len)); XmbDrawString(d.display(), d.drawable(), m_fontset, main_gc, x, y, localestr.data(), localestr.size()); @@ -241,7 +241,7 @@ void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const cha } else #endif //X_HAVE_UTF8_STRING { - std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, 0, len)); + std::string localestr = FbStringUtil::FbStrToLocale(FbString(text, len)); XmbDrawString(dpy, canvas.drawable(), m_fontset, font_gc.gc(), xpos, ypos, localestr.data(), localestr.size()); -- cgit v0.11.2