all repos — openbox @ 8b73f6f02517e717842d122d82e1eb08cda95e19

openbox fork - make it a bit more like ryudo

begin conversion to ustring. add some more members.
Dana Jansens danakj@orodu.net
commit

8b73f6f02517e717842d122d82e1eb08cda95e19

parent

ecfac5f20c72647b4865a14ccffc307c2b116319

5 files changed, 88 insertions(+), 39 deletions(-)

jump to
M configure.acconfigure.ac

@@ -32,7 +32,7 @@ AM_GNU_GETTEXT([external])

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
M otk/font.ccotk/font.cc

@@ -13,10 +13,6 @@

#include <iostream> #include <algorithm> -using std::string; -using std::cerr; -using std::endl; - #include "font.hh" #include "util.hh" #include "display.hh"

@@ -34,10 +30,10 @@ }

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),

@@ -86,7 +82,7 @@ }

void Font::drawString(XftDraw *d, int x, int y, const Color &color, - const string &string, bool utf8) const + const ustring &string) const { assert(d);

@@ -98,14 +94,9 @@ c.color.blue = 0;

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;

@@ -115,27 +106,19 @@ c.color.blue = color.blue() | color.blue() << 8;

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); }
M otk/font.hhotk/font.hh

@@ -2,6 +2,8 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-

#ifndef __font_hh #define __font_hh +#include "ustring.hh" + extern "C" { #include <X11/Xlib.h> #define _XFT_NO_COMPAT_ // no Xft 1 API

@@ -9,7 +11,6 @@ #include <X11/Xft/Xft.h>

} #include <assert.h> -#include <string> namespace otk {

@@ -57,8 +58,7 @@

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 /*!

@@ -66,7 +66,7 @@ Be Warned: If you use an XftDraw object and a color, or a font from

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; }; }
M otk/ustring.ccotk/ustring.cc

@@ -41,4 +41,54 @@ : _string(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(); +} + }
M otk/ustring.hhotk/ustring.hh

@@ -20,6 +20,14 @@ #include <string>

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,

@@ -31,12 +39,6 @@ 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,

2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 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 /*!

@@ -102,6 +104,8 @@ private:

T _pos; }; +#endif // DOXYGEN_IGNORE + //! This class provides a simple wrapper to a std::string that is encoded as //! UTF-8. /*!

@@ -140,6 +144,18 @@ ustring& operator=(const ustring& other);

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; };