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_TYPE_SIGNAL
#include <iostream>
#include <algorithm>
-using std::string;
-using std::cerr;
-using std::endl;
-
#include "font.hh"
#include "util.hh"
#include "display.hh"
namespace otk {
-string Font::_fallback_font = "fixed";
+std::string Font::_fallback_font = "fixed";
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)
: _screen_num(screen_num),
_fontstring(fontstring),
void Font::drawString(XftDraw *d, int x, int y, const Color &color,
- const string &string, bool utf8) const
+ const ustring &string) const
{
assert(d);
c.color.alpha = _tint | _tint << 8; // transparent shadow
c.pixel = BlackPixel(Display::display, _screen_num);
- if (utf8)
- XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
- _xftfont->ascent + y + _offset,
- (FcChar8*)string.c_str(), string.size());
- else
- XftDrawString8(d, &c, _xftfont, x + _offset,
- _xftfont->ascent + y + _offset,
- (FcChar8*)string.c_str(), string.size());
+ XftDrawStringUtf8(d, &c, _xftfont, x + _offset,
+ _xftfont->ascent + y + _offset,
+ (FcChar8*)string.c_str(), string.size());
}
XftColor c;
c.pixel = color.pixel();
c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
- if (utf8)
- XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
- (FcChar8*)string.c_str(), string.size());
- else
- XftDrawString8(d, &c, _xftfont, x, _xftfont->ascent + y,
- (FcChar8*)string.c_str(), string.size());
+ XftDrawStringUtf8(d, &c, _xftfont, x, _xftfont->ascent + y,
+ (FcChar8*)string.c_str(), string.size());
return;
}
-unsigned int Font::measureString(const string &string, bool utf8) const
+unsigned int Font::measureString(const ustring &string) const
{
XGlyphInfo info;
- if (utf8)
- XftTextExtentsUtf8(Display::display, _xftfont,
- (FcChar8*)string.c_str(), string.size(), &info);
- else
- XftTextExtents8(Display::display, _xftfont,
- (FcChar8*)string.c_str(), string.size(), &info);
+ XftTextExtentsUtf8(Display::display, _xftfont,
+ (FcChar8*)string.c_str(), string.size(), &info);
return info.xOff + (_shadow ? _offset : 0);
}
#ifndef __font_hh
#define __font_hh
+#include "ustring.hh"
+
extern "C" {
#include <X11/Xlib.h>
#define _XFT_NO_COMPAT_ // no Xft 1 API
}
#include <assert.h>
-#include <string>
namespace otk {
unsigned int height() const;
unsigned int maxCharWidth() const;
- unsigned int measureString(const std::string &string,
- bool utf8 = false) const;
+ unsigned int measureString(const ustring &string) const;
//! Draws a string into an XftDraw object
/*!
different screens, you WILL have unpredictable results! :)
*/
void drawString(XftDraw *d, int x, int y, const Color &color,
- const std::string &string, bool utf8 = false) const;
+ const ustring &string) const;
};
}
{
}
+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();
+}
+
}
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
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,
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
/*!
Note this is not a random access iterator but a bidirectional one, since all
T _pos;
};
+#endif // DOXYGEN_IGNORE
+
//! This class provides a simple wrapper to a std::string that is encoded as
//! UTF-8.
/*!
ustring(const std::string& 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;
};