fix loading of rotated fonts on style change

This commit is contained in:
simonb 2007-01-05 13:43:54 +00:00
parent 3a79de034f
commit ad7fd2d867
8 changed files with 39 additions and 14 deletions

View file

@ -1,6 +1,8 @@
(Format: Year/Month/Day)
Changes for 1.0rc3:
*07/01/05:
* Fix loading of rotated fonts on style change (Simon)
FbTk/... FontImp.hh XftFontImp.hh/cc XmbFontImp.hh/cc XFontImp.hh/cc
* Change default Xft font to "monospace" (was "fixed") (Simon)
- The "fixed" font loads a bitmap Xfont
- Note that bitmap fonts do not rotate properly, and especially the

View file

@ -44,7 +44,7 @@ class FontImp {
public:
virtual ~FontImp() { }
virtual bool load(const std::string &name) = 0;
virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const = 0;
virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) = 0;
virtual unsigned int textWidth(const FbString &text, unsigned int size) const = 0;
virtual bool validOrientation(FbTk::Orientation orient) { return orient == ROT0; }
virtual int ascent() const = 0;

View file

@ -45,8 +45,10 @@ using std::nothrow;
namespace FbTk {
XFontImp::XFontImp(const char *fontname):m_fontstruct(0) {
for (int i = ROT0; i <= ROT270; ++i)
for (int i = ROT0; i <= ROT270; ++i) {
m_rotfonts[i] = 0;
m_rotfonts_loaded[i] = false;
}
if (fontname != 0)
load(fontname);
@ -78,19 +80,23 @@ bool XFontImp::load(const string &fontname) {
m_fontstruct = font; //set new font
for (int i = ROT0; i <= ROT270; ++i)
if (m_rotfonts[i] != 0)
for (int i = ROT0; i <= ROT270; ++i) {
m_rotfonts_loaded[i] = false;
if (m_rotfonts[i] != 0) {
freeRotFont(m_rotfonts[i]);
m_rotfonts[i] = 0;
}
}
return true;
}
void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const {
void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) {
if (m_fontstruct == 0)
return;
// use roated font functions?
if (orient != ROT0 && m_rotfonts[orient] != 0) {
if (orient != ROT0 && validOrientation(orient)) {
drawRotText(w.drawable(), screen, gc, text, len, x, y, orient);
return;
}
@ -389,7 +395,12 @@ bool XFontImp::validOrientation(FbTk::Orientation orient) {
if (orient == ROT0 || m_rotfonts[orient])
return true;
if (m_rotfonts_loaded[orient])
return false; // load must have failed
m_rotfonts_loaded[orient] = true;
rotate(orient);
return m_rotfonts[orient] != 0;
}

View file

@ -40,7 +40,7 @@ public:
unsigned int height() const;
int ascent() const;
int descent() const { return m_fontstruct ? m_fontstruct->descent : 0; }
void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const;
void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient);
bool validOrientation(FbTk::Orientation orient);
@ -79,6 +79,7 @@ private:
void drawRotText(Drawable w, int screen, GC gc, const FbString &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
XFontStruct *m_fontstruct; ///< X font structure
};

View file

@ -36,8 +36,10 @@ namespace FbTk {
XftFontImp::XftFontImp(const char *name, bool utf8):
m_utf8mode(utf8), m_name("") {
for (int r = ROT0; r <= ROT270; r++)
for (int r = ROT0; r <= ROT270; r++) {
m_xftfonts[r] = 0;
m_xftfonts_loaded[r] = false;
}
if (name != 0)
load(name);
@ -62,21 +64,24 @@ bool XftFontImp::load(const std::string &name) {
}
// destroy all old fonts and set new
for (int r = ROT0; r <= ROT270; r++)
for (int r = ROT0; r <= ROT270; r++) {
m_xftfonts_loaded[r] = false;
if (m_xftfonts[r] != 0) {
XftFontClose(App::instance()->display(), m_xftfonts[r]);
m_xftfonts[r] = 0;
}
}
m_xftfonts[ROT0] = newxftfont;
m_xftfonts_loaded[ROT0] = true;
m_name = name;
return true;
}
void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const {
void XftFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) {
if (m_xftfonts[orient] == 0)
if (!validOrientation(orient))
return;
// we adjust y slightly so that the baseline is in the right spot
@ -212,9 +217,14 @@ bool XftFontImp::validOrientation(FbTk::Orientation orient) {
if (orient == ROT0 || m_xftfonts[orient])
return true;
if (m_xftfonts_loaded[orient])
return false; // m_xftfonts is zero here
if (m_xftfonts[ROT0] == 0)
return false;
m_xftfonts_loaded[orient] = true;
// otherwise, try to load that orientation
// radians is actually anti-clockwise, so we reverse it
double radians = -(orient) * 90 * M_PI / 180;

View file

@ -36,7 +36,7 @@ public:
XftFontImp(const char *fontname, bool utf8);
~XftFontImp();
bool load(const std::string &name);
void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y , FbTk::Orientation orient) const;
void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y , FbTk::Orientation orient);
unsigned int textWidth(const FbString &text, unsigned int len) const;
unsigned int height() const;
int ascent() const { return m_xftfonts[0] ? m_xftfonts[0]->ascent : 0; }
@ -47,6 +47,7 @@ public:
private:
XftFont *m_xftfonts[4]; // 4 possible orientations
bool m_xftfonts_loaded[4]; // whether we've tried loading the orientation
// rotated xft fonts don't give proper extents info, so we keep the "real"
// one around for it
bool m_utf8mode;

View file

@ -190,7 +190,7 @@ bool XmbFontImp::load(const string &fontname) {
}
void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const FbString &text,
size_t len, int x, int y, FbTk::Orientation orient) const {
size_t len, int x, int y, FbTk::Orientation orient) {
if (m_fontset == 0)
return;

View file

@ -36,7 +36,7 @@ public:
XmbFontImp(const char *fontname, bool utf8);
~XmbFontImp();
bool load(const std::string &name);
virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const;
virtual void drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient);
unsigned int textWidth(const FbString &text, unsigned int len) const;
unsigned int height() const;
int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; }