changeset 1715:493343d3d7ae

Use utf8encode/utf8decode (instead of mbrtowc/wcrtomb) for smallcaps. With these functions there's no need to alter the locale.
author Jorge Arellano Cid <jcid@dillo.org>
date Sat, 09 Oct 2010 14:38:41 -0400
parents 80f90763d2c3
children c805b4e0b7ce
files dw/fltkplatform.cc dw/fltkviewbase.cc src/dillo.cc
diffstat 3 files changed, 8 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Fri Oct 08 13:06:12 2010 -0400
+++ b/dw/fltkplatform.cc	Sat Oct 09 14:38:41 2010 -0400
@@ -355,18 +355,15 @@
 {
    char chbuf[MB_CUR_MAX];
    wchar_t wc, wcu;
-   mbstate_t st1, st2;
    int width = 0;
    FltkFont *ff = (FltkFont*) font;
    int curr = 0, next = 0, nb;
    
    if (font->fontVariant == 1) {
       int sc_fontsize = lout::misc::roundInt(ff->size * 0.78);
-      memset (&st1, '\0', sizeof (mbstate_t));
-      memset (&st2, '\0', sizeof (mbstate_t));
       for (curr = 0; next < len; curr = next) {
          next = nextGlyph(text, curr);
-         nb = (int)mbrtowc(&wc, text + curr, next - curr, &st1);
+         wc = utf8decode(text + curr, text + next, &nb);
          if ((wcu = towupper(wc)) == wc) {
             /* already uppercase, just draw the character */
             setfont(ff->font, ff->size);
@@ -374,7 +371,7 @@
             width += (int)getwidth(text + curr, next - curr);
          } else {
             /* make utf8 string for converted char */
-            nb = wcrtomb(chbuf, wcu, &st2);
+            nb = utf8encode(wcu, chbuf);
             setfont(ff->font, sc_fontsize);
             width += font->letterSpacing;
             width += (int)getwidth(chbuf, nb);
--- a/dw/fltkviewbase.cc	Fri Oct 08 13:06:12 2010 -0400
+++ b/dw/fltkviewbase.cc	Sat Oct 09 14:38:41 2010 -0400
@@ -27,6 +27,7 @@
 #include <fltk/events.h>
 #include <fltk/Cursor.h>
 #include <fltk/run.h>
+#include <fltk/utf.h>
 
 #include <stdio.h>
 #include <wchar.h>
@@ -492,18 +493,15 @@
       /* Nonzero letter spacing adjustment, draw each glyph individually */
       int viewX = translateCanvasXToViewX (x),
           viewY = translateCanvasYToViewY (y);
-      int curr = 0, next = 0, cb;
+      int curr = 0, next = 0, nb;
       char chbuf[MB_CUR_MAX];
       wchar_t wc, wcu;
-      mbstate_t st1, st2;
 
       if (font->fontVariant == 1) {
          int sc_fontsize = lout::misc::roundInt(ff->size * 0.78);
-         memset (&st1, '\0', sizeof (mbstate_t));
-         memset (&st2, '\0', sizeof (mbstate_t));
          for (curr = 0; next < len; curr = next) {
             next = theLayout->nextGlyph(text, curr);
-            cb = (int)mbrtowc(&wc, text + curr, next - curr, &st1);
+            wc = utf8decode(text + curr, text + next, &nb);
             if ((wcu = towupper(wc)) == wc) {
                /* already uppercase, just draw the character */
                setfont(ff->font, ff->size);
@@ -512,11 +510,11 @@
                viewX += (int)getwidth(text + curr, next - curr);
             } else {
                /* make utf8 string for converted char */
-               int n = wcrtomb(chbuf, wcu, &st2);
+               nb = utf8encode(wcu, chbuf);
                setfont(ff->font, sc_fontsize);
-               drawtext(chbuf, n, viewX, viewY);
+               drawtext(chbuf, nb, viewX, viewY);
                viewX += font->letterSpacing;
-               viewX += (int)getwidth(chbuf, n);
+               viewX += (int)getwidth(chbuf, nb);
             }
          }
       } else {
--- a/src/dillo.cc	Fri Oct 08 13:06:12 2010 -0400
+++ b/src/dillo.cc	Sat Oct 09 14:38:41 2010 -0400
@@ -369,9 +369,6 @@
       }
    }
 
-   /* We use utf-8 internally, force character conversions follow suit */
-   setlocale (LC_CTYPE, "en_US.utf8");
-
    fltk::run();
 
    /*