static VALUE rg_font(VALUE self) { PangoFontDescription* desc; PangoLanguage* lang; GSList* extra_attrs; VALUE ary, ret; desc = pango_font_description_new(); pango_attr_iterator_get_font(_SELF(self), desc, &lang, &extra_attrs); ary = rb_ary_new(); while(extra_attrs) { rb_ary_push(ary, ATTR2RVAL(extra_attrs->data)); extra_attrs = extra_attrs->next; } ret = rb_ary_new3(3, PANGOFONTDESCRIPTION2RVAL(desc), PANGOLANGUAGE2RVAL(lang), ary); pango_font_description_free(desc); return ret; }
static void go_pango_translate_here (PangoAttrIterator *state_iter, PangoAttrIterator *attr_iter, PangoAttrList *attrs) { double font_scale = 1.; double scale = 1.; int rise = 0; PangoAttribute *pa; PangoFontDescription *desc = pango_font_description_new (); GSList *the_attrs, *l; gint range_start, range_end; pango_attr_iterator_range (attr_iter, &range_start, &range_end); if (range_start == range_end) return; desc = pango_font_description_new (); pango_attr_iterator_get_font (state_iter, desc, NULL, NULL); font_scale = pango_font_description_get_size (desc)/ (double)PANGO_SCALE/10.; pango_font_description_free (desc); pa = pango_attr_iterator_get (state_iter, PANGO_ATTR_SCALE); if (pa) scale = ((PangoAttrFloat *)pa)->value; pa = pango_attr_iterator_get (state_iter, PANGO_ATTR_RISE); if (pa) rise = ((PangoAttrInt *)pa)->value; /* We should probably figured out the default font size used */ /* rather than assuming it is 10 pts * scale */ if (font_scale == 0) font_scale = scale; the_attrs = pango_attr_iterator_get_attrs (attr_iter); for (l = the_attrs; l != NULL; l = l->next) { PangoAttribute *attribute = l->data; PangoAttrType type = attribute->klass->type; if (type == go_pango_attr_superscript_get_attr_type ()) { GOPangoAttrSuperscript *attr = (GOPangoAttrSuperscript *)attribute; if (attr->val) { scale *= GO_SUPERSCRIPT_SCALE; rise += GO_SUPERSCRIPT_RISE * font_scale; font_scale *= GO_SUPERSCRIPT_SCALE; } } else { /* go_pango_attr_subscript_type */ GOPangoAttrSubscript *attr = (GOPangoAttrSubscript *)attribute; if (attr->val) { scale *= GO_SUBSCRIPT_SCALE; rise += GO_SUBSCRIPT_RISE * font_scale; font_scale *= GO_SUBSCRIPT_SCALE; } } } if (the_attrs != NULL) { PangoAttribute *attr = pango_attr_scale_new (scale); attr->start_index = range_start; attr->end_index = range_end; pango_attr_list_insert (attrs, attr); attr = pango_attr_rise_new (rise); attr->start_index = range_start; attr->end_index = range_end; pango_attr_list_insert (attrs, attr); } g_slist_free_full (the_attrs, (GDestroyNotify)pango_attribute_destroy); }