• R/O
  • HTTP
  • SSH
  • HTTPS

fukui-no-namari-ext: Commit

Fukui no Namari用ライブラリ


Commit MetaInfo

Revisionb9e440d02c767da5b54b18b308ab80ae083190f1 (tree)
Time2009-05-05 18:51:05
AuthorAiwota Programmer <aiwotaprog@tett...>
CommiterAiwota Programmer

Log Message

itemizing and shaping are done by one character.

Change Summary

Incremental Difference

--- a/src/thread_view_extend.c
+++ b/src/thread_view_extend.c
@@ -1,7 +1,7 @@
11 /*
22 * thread_view_extend.c
33 *
4- * Copyright (C) 2007 by Aiwota Programmer
4+ * Copyright (C) 2007,2009 by Aiwota Programmer
55 * aiwotaprog@tetteke.tk
66 *
77 * This program is free software; you can redistribute it and/or modify
@@ -36,32 +36,38 @@ static PyTypeObject * _PyPangoContext_Type;
3636 void get_char_width(PangoContext *context, const char* text,
3737 int len, PangoAttrList *attrs, double* widths)
3838 {
39- GList *list, *list_s;
39+ const char* p = text;
4040 int idx = 0;
4141
42- list = pango_itemize(context, text, 0, len, attrs, NULL);
43- list_s = list;
44-
45- while (list_s)
46- {
47- int i;
48- PangoItem *item = list_s->data;
49- PangoAnalysis *analysis = &item->analysis;
50- PangoGlyphString *glyphs = pango_glyph_string_new();
51-
52- pango_shape(text + item->offset, item->length, analysis, glyphs);
53-
54- for (i = 0; i < glyphs->num_glyphs; i++)
55- {
56- widths[idx++] =
57- pango_units_to_double(glyphs->glyphs[i].geometry.width);
58- }
59-
60- pango_item_free(item);
61- pango_glyph_string_free(glyphs);
62- list_s = list_s->next;
63- }
64- g_list_free(list);
42+ while (p - text < len) {
43+ const char* const next = g_utf8_next_char(p);
44+ GList *list = pango_itemize(context, p, 0, next-p, attrs, NULL);
45+ GList *list_s = list;
46+
47+ while (list_s) {
48+ int i;
49+ PangoItem *item = list_s->data;
50+ PangoAnalysis *analysis = &item->analysis;
51+ PangoGlyphString *glyphs = pango_glyph_string_new();
52+ double width = 0;
53+
54+ pango_shape(p + item->offset, item->length, analysis, glyphs);
55+
56+ for (i = 0; i < glyphs->num_glyphs; i++)
57+ {
58+ width +=
59+ pango_units_to_double(glyphs->glyphs[i].geometry.width);
60+ }
61+ widths[idx++] = width;
62+
63+ pango_item_free(item);
64+ pango_glyph_string_free(glyphs);
65+ list_s = list_s->next;
66+ }
67+
68+ g_list_free(list);
69+ p = next;
70+ }
6571 }
6672
6773 static PyObject *
@@ -103,6 +109,7 @@ _wrap_get_char_width(PyObject *self, PyObject *args, PyObject *kwargs)
103109
104110
105111 slen = g_utf8_strlen(text, length);
112+
106113 logical_widths = g_new(double, slen);
107114 get_char_width(context, text, length, attrs, logical_widths);
108115
Show on old repository browser