6 #include "FontLoader.h"
13 XFontStruct * getXFontstruct(LyXFont const & f)
15 return fontloader.load(f.family(), f.series(),
16 f.realShape(), f.size());
21 XID getFontID(LyXFont const & f)
23 return getXFontstruct(f)->fid;
25 // } // end of anon namespace
27 int lyxfont::maxAscent(LyXFont const & f)
29 return getXFontstruct(f)->ascent;
33 int lyxfont::maxDescent(LyXFont const & f)
35 return getXFontstruct(f)->descent;
39 int lyxfont::ascent(char c, LyXFont const & f)
41 XFontStruct * finfo = getXFontstruct(f);
42 unsigned int uc = static_cast<unsigned char>(c);
44 && uc >= finfo->min_char_or_byte2
45 && uc <= finfo->max_char_or_byte2)
46 return finfo->per_char[uc - finfo->min_char_or_byte2].ascent;
52 int lyxfont::descent(char c, LyXFont const & f)
54 XFontStruct * finfo = getXFontstruct(f);
55 unsigned int uc = static_cast<unsigned char>(c);
57 && uc >= finfo->min_char_or_byte2
58 && uc <= finfo->max_char_or_byte2)
59 return finfo->per_char[uc - finfo->min_char_or_byte2].descent;
61 return finfo->descent;
65 int lyxfont::lbearing(char c, LyXFont const & f)
67 XFontStruct * finfo = getXFontstruct(f);
68 unsigned int uc = static_cast<unsigned char>(c);
70 && uc >= finfo->min_char_or_byte2
71 && uc <= finfo->max_char_or_byte2)
72 return finfo->per_char[uc - finfo->min_char_or_byte2].lbearing;
78 int lyxfont::rbearing(char c, LyXFont const & f)
80 XFontStruct * finfo = getXFontstruct(f);
81 unsigned int uc = static_cast<unsigned char>(c);
83 && uc >= finfo->min_char_or_byte2
84 && uc <= finfo->max_char_or_byte2)
85 return finfo->per_char[uc - finfo->min_char_or_byte2].rbearing;
91 int lyxfont::width(char c, LyXFont const & f)
93 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
94 return lyxrc.use_gui ? ::XTextWidth(getXFontstruct(f), &c, 1)
98 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
99 if (islower(static_cast<unsigned char>(c))) {
101 return ::XTextWidth(getXFontstruct(smallfont), &c, 1);
103 return ::XTextWidth(getXFontstruct(f), &c, 1);
109 int lyxfont::width(char const * s, int n, LyXFont const & f)
114 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
115 return ::XTextWidth(getXFontstruct(f), s, n);
117 // emulate smallcaps since X doesn't support this
118 unsigned int result = 0;
120 LyXFont smallfont(f);
121 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
122 for (int i = 0; i < n; ++i) {
124 // when islower is a macro, the cast is needed (JMarc)
125 if (islower(static_cast<unsigned char>(c))) {
127 result += ::XTextWidth(getXFontstruct(smallfont), &c, 1);
129 result += ::XTextWidth(getXFontstruct(f), &c, 1);
137 int lyxfont::signedWidth(string const & s, LyXFont const & f)
139 if (s.empty()) return 0;
140 if (s.c_str()[0] == '-')
141 return -width(s.c_str() + 1, s.length() - 1, f);
143 return width(s.c_str(), s.length(), f);
147 int lyxfont::XTextWidth(LyXFont const & f, char * str, int count)
149 return ::XTextWidth(getXFontstruct(f), str, count);
153 void lyxfont::XSetFont(Display * display, GC gc, LyXFont const & f)
155 ::XSetFont(display, gc, getFontID(f));
158 //} // end of namespace font
159 //} // end of namespace lyx