begin conversion to ustring. add some more members.
This commit is contained in:
parent
ecfac5f20c
commit
8b73f6f025
5 changed files with 88 additions and 39 deletions
|
@ -32,7 +32,7 @@ AM_GNU_GETTEXT([external])
|
||||||
|
|
||||||
PYTHON_DEVEL
|
PYTHON_DEVEL
|
||||||
|
|
||||||
AC_CHECK_HEADERS(ctype.h dirent.h fcntl.h libgen.h locale.h nl_types.h process.h signal.h stdarg.h stdio.h stdlib.h string.h time.h unistd.h sys/param.h sys/select.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/wait.h)
|
AC_CHECK_HEADERS(ctype.h dirent.h fcntl.h libgen.h locale.h nl_types.h process.h signal.h stdarg.h stdint.h stdio.h stdlib.h string.h time.h unistd.h sys/param.h sys/select.h sys/signal.h sys/stat.h sys/time.h sys/types.h sys/wait.h)
|
||||||
AC_HEADER_TIME
|
AC_HEADER_TIME
|
||||||
# AC_TYPE_SIGNAL
|
# AC_TYPE_SIGNAL
|
||||||
|
|
||||||
|
|
25
otk/font.cc
25
otk/font.cc
|
@ -13,10 +13,6 @@ extern "C" {
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::cerr;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
#include "font.hh"
|
#include "font.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "display.hh"
|
#include "display.hh"
|
||||||
|
@ -34,10 +30,10 @@ extern "C" {
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
string Font::_fallback_font = "fixed";
|
std::string Font::_fallback_font = "fixed";
|
||||||
bool Font::_xft_init = false;
|
bool Font::_xft_init = false;
|
||||||
|
|
||||||
Font::Font(int screen_num, const string &fontstring,
|
Font::Font(int screen_num, const std::string &fontstring,
|
||||||
bool shadow, unsigned char offset, unsigned char tint)
|
bool shadow, unsigned char offset, unsigned char tint)
|
||||||
: _screen_num(screen_num),
|
: _screen_num(screen_num),
|
||||||
_fontstring(fontstring),
|
_fontstring(fontstring),
|
||||||
|
@ -86,7 +82,7 @@ Font::~Font(void)
|
||||||
|
|
||||||
|
|
||||||
void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
const string &string, bool utf8) const
|
const ustring &string) const
|
||||||
{
|
{
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
|
@ -98,14 +94,9 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
c.color.alpha = _tint | _tint << 8; // transparent shadow
|
c.color.alpha = _tint | _tint << 8; // transparent shadow
|
||||||
c.pixel = BlackPixel(Display::display, _screen_num);
|
c.pixel = BlackPixel(Display::display, _screen_num);
|
||||||
|
|
||||||
if (utf8)
|
|
||||||
XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
|
XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
|
||||||
_xftfont->ascent + y + _offset,
|
_xftfont->ascent + y + _offset,
|
||||||
(FcChar8*)string.c_str(), string.size());
|
(FcChar8*)string.c_str(), string.size());
|
||||||
else
|
|
||||||
XftDrawString8(d, &c, _xftfont, x + _offset,
|
|
||||||
_xftfont->ascent + y + _offset,
|
|
||||||
(FcChar8*)string.c_str(), string.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XftColor c;
|
XftColor c;
|
||||||
|
@ -115,27 +106,19 @@ void Font::drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
c.pixel = color.pixel();
|
c.pixel = color.pixel();
|
||||||
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
|
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
|
||||||
|
|
||||||
if (utf8)
|
|
||||||
XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
||||||
(FcChar8*)string.c_str(), string.size());
|
(FcChar8*)string.c_str(), string.size());
|
||||||
else
|
|
||||||
XftDrawString8(d, &c, _xftfont, x, _xftfont->ascent + y,
|
|
||||||
(FcChar8*)string.c_str(), string.size());
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int Font::measureString(const string &string, bool utf8) const
|
unsigned int Font::measureString(const ustring &string) const
|
||||||
{
|
{
|
||||||
XGlyphInfo info;
|
XGlyphInfo info;
|
||||||
|
|
||||||
if (utf8)
|
|
||||||
XftTextExtentsUtf8(Display::display, _xftfont,
|
XftTextExtentsUtf8(Display::display, _xftfont,
|
||||||
(FcChar8*)string.c_str(), string.size(), &info);
|
(FcChar8*)string.c_str(), string.size(), &info);
|
||||||
else
|
|
||||||
XftTextExtents8(Display::display, _xftfont,
|
|
||||||
(FcChar8*)string.c_str(), string.size(), &info);
|
|
||||||
|
|
||||||
return info.xOff + (_shadow ? _offset : 0);
|
return info.xOff + (_shadow ? _offset : 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#ifndef __font_hh
|
#ifndef __font_hh
|
||||||
#define __font_hh
|
#define __font_hh
|
||||||
|
|
||||||
|
#include "ustring.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#define _XFT_NO_COMPAT_ // no Xft 1 API
|
#define _XFT_NO_COMPAT_ // no Xft 1 API
|
||||||
|
@ -9,7 +11,6 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
@ -57,8 +58,7 @@ public:
|
||||||
unsigned int height() const;
|
unsigned int height() const;
|
||||||
unsigned int maxCharWidth() const;
|
unsigned int maxCharWidth() const;
|
||||||
|
|
||||||
unsigned int measureString(const std::string &string,
|
unsigned int measureString(const ustring &string) const;
|
||||||
bool utf8 = false) const;
|
|
||||||
|
|
||||||
//! Draws a string into an XftDraw object
|
//! Draws a string into an XftDraw object
|
||||||
/*!
|
/*!
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
different screens, you WILL have unpredictable results! :)
|
different screens, you WILL have unpredictable results! :)
|
||||||
*/
|
*/
|
||||||
void drawString(XftDraw *d, int x, int y, const Color &color,
|
void drawString(XftDraw *d, int x, int y, const Color &color,
|
||||||
const std::string &string, bool utf8 = false) const;
|
const ustring &string) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,4 +41,54 @@ ustring::ustring(const char* src)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ustring::size_type find_offset(const char *str, const char *pos)
|
||||||
|
{
|
||||||
|
ustring::size_type offset = 0;
|
||||||
|
|
||||||
|
while (str < pos) {
|
||||||
|
str += g_utf8_skip[*str];
|
||||||
|
offset += g_utf8_skip[*str];
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
ustring::size_type ustring::size() const
|
||||||
|
{
|
||||||
|
const char *const pdata = _string.data();
|
||||||
|
return find_offset(pdata, pdata + _string.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
ustring::size_type ustring::length() const
|
||||||
|
{
|
||||||
|
const char *const pdata = _string.data();
|
||||||
|
return find_offset(pdata, pdata + _string.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
ustring::size_type ustring::bytes() const
|
||||||
|
{
|
||||||
|
return _string.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
ustring::size_type ustring::capacity() const
|
||||||
|
{
|
||||||
|
return _string.capacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
ustring::size_type ustring::max_size() const
|
||||||
|
{
|
||||||
|
return _string.max_size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char* ustring::data() const
|
||||||
|
{
|
||||||
|
return _string.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* ustring::c_str() const
|
||||||
|
{
|
||||||
|
return _string.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,14 @@ extern "C" {
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
|
#ifdef HAVE_STDINT_H
|
||||||
|
typedef uint32_t unichar;
|
||||||
|
#else
|
||||||
|
typedef u_int32_t unichar;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DOXYGEN_IGNORE
|
||||||
|
|
||||||
//! The number of bytes to skip to find the next character in the string
|
//! The number of bytes to skip to find the next character in the string
|
||||||
const char g_utf8_skip[256] = {
|
const char g_utf8_skip[256] = {
|
||||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||||
|
@ -32,12 +40,6 @@ const char g_utf8_skip[256] = {
|
||||||
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
|
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_STDINT_H
|
|
||||||
typedef uint32_t unichar;
|
|
||||||
#else
|
|
||||||
typedef u_int32_t unichar;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//! The iterator type for ustring
|
//! The iterator type for ustring
|
||||||
/*!
|
/*!
|
||||||
Note this is not a random access iterator but a bidirectional one, since all
|
Note this is not a random access iterator but a bidirectional one, since all
|
||||||
|
@ -102,6 +104,8 @@ private:
|
||||||
T _pos;
|
T _pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // DOXYGEN_IGNORE
|
||||||
|
|
||||||
//! This class provides a simple wrapper to a std::string that is encoded as
|
//! This class provides a simple wrapper to a std::string that is encoded as
|
||||||
//! UTF-8.
|
//! UTF-8.
|
||||||
/*!
|
/*!
|
||||||
|
@ -140,6 +144,18 @@ public:
|
||||||
ustring(const std::string& src);
|
ustring(const std::string& src);
|
||||||
ustring::ustring(const char* src);
|
ustring::ustring(const char* src);
|
||||||
|
|
||||||
|
// sizes
|
||||||
|
|
||||||
|
ustring::size_type size() const;
|
||||||
|
ustring::size_type length() const;
|
||||||
|
ustring::size_type bytes() const;
|
||||||
|
ustring::size_type capacity() const;
|
||||||
|
ustring::size_type max_size() const;
|
||||||
|
|
||||||
|
// internal data
|
||||||
|
|
||||||
|
const char* data() const;
|
||||||
|
const char* c_str() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue