OSDN Git Service

itemizing and shaping are done by one character. master
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 5 May 2009 09:51:05 +0000 (18:51 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Tue, 5 May 2009 09:51:05 +0000 (18:51 +0900)
src/thread_view_extend.c

index aa7b4a9..8a6d0ed 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  thread_view_extend.c
  *
- *  Copyright (C) 2007 by Aiwota Programmer
+ *  Copyright (C) 2007,2009 by Aiwota Programmer
  *  aiwotaprog@tetteke.tk
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -36,32 +36,38 @@ static PyTypeObject * _PyPangoContext_Type;
 void get_char_width(PangoContext *context, const char* text,
     int len, PangoAttrList *attrs, double* widths)
 {
-    GList *list, *list_s;
+    const char* p = text;
     int idx = 0;
 
-    list = pango_itemize(context, text, 0, len, attrs, NULL);
-    list_s = list;
-
-    while (list_s)
-    {
-        int i;
-        PangoItem *item = list_s->data;
-        PangoAnalysis *analysis = &item->analysis;
-        PangoGlyphString *glyphs = pango_glyph_string_new();
-
-        pango_shape(text + item->offset, item->length, analysis, glyphs);
-
-        for (i = 0; i < glyphs->num_glyphs; i++)
-        {
-            widths[idx++] =
-                pango_units_to_double(glyphs->glyphs[i].geometry.width);
-        }
-
-        pango_item_free(item);
-        pango_glyph_string_free(glyphs);
-        list_s = list_s->next;
-    }
-    g_list_free(list);
+       while (p - text < len) {
+               const char* const next = g_utf8_next_char(p);
+           GList *list = pango_itemize(context, p, 0, next-p, attrs, NULL);
+           GList *list_s = list;
+
+           while (list_s) {
+                       int i;
+                       PangoItem *item = list_s->data;
+                       PangoAnalysis *analysis = &item->analysis;
+                       PangoGlyphString *glyphs = pango_glyph_string_new();
+                       double width = 0;
+
+                       pango_shape(p + item->offset, item->length, analysis, glyphs);
+
+                       for (i = 0; i < glyphs->num_glyphs; i++)
+                       {
+                               width +=
+                                       pango_units_to_double(glyphs->glyphs[i].geometry.width);
+                       }
+                       widths[idx++] = width;
+
+                       pango_item_free(item);
+                       pango_glyph_string_free(glyphs);
+                       list_s = list_s->next;
+           }
+
+               g_list_free(list);
+               p = next;
+       }
 }
 
 static PyObject *
@@ -103,6 +109,7 @@ _wrap_get_char_width(PyObject *self, PyObject *args, PyObject *kwargs)
 
 
     slen = g_utf8_strlen(text, length);
+
     logical_widths = g_new(double, slen);
     get_char_width(context, text, length, attrs, logical_widths);