/*
* 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
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 *
slen = g_utf8_strlen(text, length);
+
logical_widths = g_new(double, slen);
get_char_width(context, text, length, attrs, logical_widths);