#include "LColor.h"
#include "xftFontLoader.h"
#include "frontends/font_metrics.h"
-#include "codeConvert.h"
#include "support/lstrings.h"
}
-void GPainter::text(int x, int y, std::string const & s, LyXFont const & f)
-{
- size_t size = s.length() + 1;
- boost::scoped_array<wchar_t> wcs(new wchar_t[size]);
- size = mbstowcs(wcs.get(), s.c_str(), size);
- return text(x, y, wcs.get(), size, f);
-}
-
-
-void GPainter::text(int x, int y, char c, LyXFont const & f)
-{
- char s[2] = { c, '\0' };
- text(x, y, s, 1, f);
-}
-
-
inline XftFont * getXftFont(LyXFont const & f)
{
return fontLoader.load(f.family(), f.series(),
- f.realShape(), f.size());
+ f.realShape(), f.size());
}
-void GPainter::text(int x, int y, wchar_t const * s, int ls, LyXFont const & f)
+// ENCODING: we assume we've got 8-bit string in whatever format Xft
+// wants. We should be finding out what the backend's giving us and
+// then converting it before feeding it to Xft using XftDrawStringUtf8
+void GPainter::text(int x, int y, char const * s, size_t ls, LyXFont const & f)
{
XftFont * font = getXftFont(f);
XftColor * xftClr = owner_.getColorHandler().
getXftColor(f.realColor());
XftDraw * draw = owner_.getXftDraw();
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
- XftDrawString32(draw, xftClr, font, x, y,
- wcsToXftChar32StrFast(s), ls);
+ XftDrawString8(draw, xftClr, font, x, y,
+ reinterpret_cast<XftChar8 *>(const_cast<char *>(s)), ls);
} else {
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
XftFont * fontS = getXftFont(smallfont);
- wchar_t c;
+ char c;
int tmpx = x;
for (int i = 0; i < ls; ++i) {
c = lyx::support::uppercase(s[i]);
if (c != s[i]) {
- XftDrawString32(draw, xftClr, fontS, tmpx, y,
- wcsToXftChar32StrFast(&c), 1);
+ XftDrawString8(draw, xftClr, fontS, tmpx, y,
+ reinterpret_cast<XftChar8 *>(const_cast<char *>(&c)), 1);
tmpx += font_metrics::width(c, smallfont);
} else {
- XftDrawString32(draw, xftClr, font, tmpx, y,
- wcsToXftChar32StrFast(&c), 1);
+ XftDrawString8(draw, xftClr, font, tmpx, y,
+ reinterpret_cast<XftChar8 *>(const_cast<char *>(&c)), 1);
tmpx += font_metrics::width(c, f);
}
}
}
-void GPainter::text(int x, int y, char const * s, size_t ls, LyXFont const & f)
+void GPainter::text(int x, int y, std::string const & s, LyXFont const & f)
{
- boost::scoped_array<wchar_t> wcs(new wchar_t[ls + 1]);
- size_t len;
- if (fontLoader.isSpecial(f)) {
- unsigned char const * us =
- reinterpret_cast<unsigned char const *>(s);
- len = ls;
- std::copy(us, us + ls, wcs.get());
- } else
- len = mbstowcs(wcs.get(), s, ls + 1);
- text(x, y, wcs.get(), len, f);
+ text (x, y, s.c_str(), s.size(), f);
}
+
+void GPainter::text(int x, int y, char c, LyXFont const & f)
+{
+ text (x, y, &c, 1, f);
+}
+
+
} // namespace frontend
} // namespace lyx
#include "lyxrc.h"
#include "encoding.h"
#include "language.h"
-#include "codeConvert.h"
#include "support/lstrings.h"
#include "debug.h"
return info.xOff;
}
-
-wchar_t C2WC(char ch)
-{
- wchar_t wcs[2] = {0, 0};
- char mbs[2] = {0, 0};
- mbs[0] = ch;
- mbstowcs(wcs, mbs, 2);
- return wcs[0];
-}
-
-
} // namespace anon
}
-int ascent(wchar_t c,LyXFont const & f)
+int ascent(char c,LyXFont const & f)
{
XftFont * font = getXftFont(f);
XGlyphInfo glyph;
- XftTextExtents32(getDisplay(), font,
- wcsToXftChar32StrFast(&c),
+ XftTextExtents8(getDisplay(), font,
+ reinterpret_cast<XftChar8 *>(&c),
1,
&glyph);
return XGlyphAscent(glyph);
}
-int ascent(char c, LyXFont const & f)
-{
- return ascent(C2WC(c), f);
-}
-
-
-int descent(wchar_t c,LyXFont const & f)
+int descent(char c,LyXFont const & f)
{
XftFont * font = getXftFont(f);
XGlyphInfo glyph;
- XftTextExtents32(getDisplay(), font,
- wcsToXftChar32StrFast(&c),
+ XftTextExtents8(getDisplay(), font,
+ reinterpret_cast<XftChar8 *>(&c),
1,
&glyph);
return XGlyphDescent(glyph);
}
-int descent(char c, LyXFont const & f)
-{
- return descent(C2WC(c), f);
-}
-
-
-int lbearing(wchar_t c,LyXFont const & f)
+int lbearing(char c,LyXFont const & f)
{
XftFont * font = getXftFont(f);
XGlyphInfo glyph;
- XftTextExtents32(getDisplay(), font,
- wcsToXftChar32StrFast(&c),
+ XftTextExtents8(getDisplay(), font,
+ reinterpret_cast<XftChar8 *>(&c),
1,
&glyph);
return XGlyphLbearing(glyph);
}
-int rbearing(wchar_t c,LyXFont const & f)
+int rbearing(char c,LyXFont const & f)
{
XftFont * font = getXftFont(f);
XGlyphInfo glyph;
- XftTextExtents32(getDisplay(), font,
- wcsToXftChar32StrFast(&c),
+ XftTextExtents8(getDisplay(), font,
+ reinterpret_cast<XftChar8 *>(&c),
1,
&glyph);
return XGlyphRbearing(glyph);
}
-int lbearing(char c, LyXFont const & f)
-{
- return lbearing(C2WC(c), f);
-}
-
-
-int rbearing(char c, LyXFont const & f)
-{
- return rbearing(C2WC(c), f);
-}
-
-
-int width(wchar_t const * s, size_t n, LyXFont const & f)
+int width(char const * s, size_t n, LyXFont const & f)
{
XftFont * font = getXftFont(f);
XGlyphInfo glyph;
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){
- XftTextExtents32(getDisplay(), font,
- const_cast<XftChar32 *>(
- wcsToXftChar32StrFast(s)),
- n,
- &glyph);
+ XftTextExtents8(getDisplay(), font,
+ reinterpret_cast<XftChar8 *>(const_cast<char *>(s)), n, &glyph);
return XGlyphLogWidth(glyph);
} else {
int result = 0;
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
XftFont * fontS = getXftFont(smallfont);
for (size_t i = 0; i < n; ++i) {
- wchar_t wc = lyx::support::uppercase(s[i]);
- if (wc != s[i]) {
- XftTextExtents32(getDisplay(), fontS,
- wcsToXftChar32StrFast(&wc),
+ char c = lyx::support::uppercase(s[i]);
+ if (c != s[i]) {
+ XftTextExtents8(getDisplay(), fontS,
+ reinterpret_cast<XftChar8 *>(&c),
1,
&glyph);
result += XGlyphLogWidth(glyph);
} else {
- XftTextExtents32(getDisplay(), font,
- wcsToXftChar32StrFast(&wc),
+ XftTextExtents8(getDisplay(), font,
+ reinterpret_cast<XftChar8 *>(&c),
1,
&glyph);
result += XGlyphLogWidth(glyph);
}
-int width(wchar_t c,LyXFont const & f)
-{
- return width(&c, 1, f);
-}
-
-
-int width(char const * s, size_t n, LyXFont const & f)
-{
- boost::scoped_array<wchar_t> wcs(new wchar_t[n]);
- int len; // Signed to handle error retvals
- if (fontLoader.isSpecial(f)) {
- unsigned char const * us =
- reinterpret_cast<unsigned char const *>(s);
- len = n;
- std::copy(us, us + n, wcs.get());
- } else {
- len = mbstowcs(wcs.get(), s, n);
- if (len < 0) {
- lyxerr[Debug::FONT] << "Invalid multibyte encoding! '" << s << "'\n";
- return n * width("0", 1, f);
- }
- }
- return width(wcs.get(), static_cast<size_t>(len), f);
-}
-
-
int signedWidth(string const & s, LyXFont const & f)
{
if (s.empty())
return 0;
- boost::scoped_array<wchar_t> wcs(new wchar_t[s.length() + 1]);
- int len = mbstowcs(wcs.get(), s.c_str(), s.length());
- if (wcs[0] == '-')
- return width(wcs.get() + 1, len - 1, f);
+ if (s[0] == '-')
+ return width(s.c_str() + 1, s.size() - 1, f);
else
- return width(wcs.get(), len, f);
+ return width(s.c_str(), s.size(), f);
}