/* exported interface documented in gtk/layout_pango.h */ PangoFontDescription * nsfont_style_to_description(const plot_font_style_t *fstyle) { unsigned int size; PangoFontDescription *desc; PangoStyle style = PANGO_STYLE_NORMAL; switch (fstyle->family) { case PLOT_FONT_FAMILY_SERIF: desc = pango_font_description_from_string(nsoption_charp(font_serif)); break; case PLOT_FONT_FAMILY_MONOSPACE: desc = pango_font_description_from_string(nsoption_charp(font_mono)); break; case PLOT_FONT_FAMILY_CURSIVE: desc = pango_font_description_from_string(nsoption_charp(font_cursive)); break; case PLOT_FONT_FAMILY_FANTASY: desc = pango_font_description_from_string(nsoption_charp(font_fantasy)); break; case PLOT_FONT_FAMILY_SANS_SERIF: default: desc = pango_font_description_from_string(nsoption_charp(font_sans)); break; } size = (fstyle->size * PANGO_SCALE) / FONT_SIZE_SCALE; if (fstyle->flags & FONTF_ITALIC) style = PANGO_STYLE_ITALIC; else if (fstyle->flags & FONTF_OBLIQUE) style = PANGO_STYLE_OBLIQUE; pango_font_description_set_style(desc, style); pango_font_description_set_weight(desc, (PangoWeight) fstyle->weight); pango_font_description_set_size(desc, size); if (fstyle->flags & FONTF_SMALLCAPS) { pango_font_description_set_variant(desc, PANGO_VARIANT_SMALL_CAPS); } else { pango_font_description_set_variant(desc, PANGO_VARIANT_NORMAL); } return desc; }
static void gst_time_overlay_class_init (GstTimeOverlayClass * klass) { GstTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gsttextoverlay_class = (GstTextOverlayClass *) klass; gsttextoverlay_class->get_text = gst_time_overlay_get_text; g_mutex_lock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); }
JNIEXPORT void JNICALL Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1set_1variant ( JNIEnv* env, jclass cls, jlong _self, jint _variant ) { PangoFontDescription* self; PangoVariant variant; // convert parameter self self = (PangoFontDescription*) _self; // convert parameter variant variant = (PangoVariant) _variant; // call function pango_font_description_set_variant(self, variant); // cleanup parameter self // cleanup parameter variant }
static void gst_time_overlay_init (GstTimeOverlay * overlay, GstTimeOverlayClass * klass) { PangoFontDescription *font_description; GstTextOverlay *textoverlay; PangoContext *context; textoverlay = GST_TEXT_OVERLAY (overlay); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); textoverlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP; textoverlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT; }
void start() { cairo_surface_t* cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_width, m_height); cairo_t* cr = cairo_create(cairo_surface); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); cairo_paint(cr); PangoFontDescription *font_description = pango_font_description_new(); pango_font_description_set_family(font_description, m_font.Family.c_str()); pango_font_description_set_style(font_description, m_font.Style); pango_font_description_set_weight(font_description, m_font.Weight); pango_font_description_set_variant(font_description, m_font.Variant); pango_font_description_set_size(font_description, m_font.Size * PANGO_SCALE); PangoLayout *layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_description); pango_layout_set_text(layout, m_text_file.file_content_p(), -1); unsigned char* color = m_font.ColorRGB; // shortcut cairo_set_source_rgb(cr, color[0] / 255.0, color[1] / 255.0, color[2] / 255.0); cairo_move_to(cr, 0.0, 0.0); pango_cairo_show_layout(cr, layout); // To texture { cairo_surface_flush(cairo_surface); std::vector<unsigned char> rgba_data; rgba_from_cairo_ARGB32( cairo_image_surface_get_data(cairo_surface) , m_width , m_height , cairo_image_surface_get_stride(cairo_surface) , rgba_data ); glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); m_texture.bind(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &(rgba_data[0])); assert(glGetError() == GL_NO_ERROR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); assert(glGetError() == GL_NO_ERROR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); assert(glGetError() == GL_NO_ERROR); } g_object_unref(layout); pango_font_description_free(font_description); cairo_destroy(cr); cairo_surface_destroy(cairo_surface); }
font_instance *font_factory::Face(char const *family, int variant, int style, int weight, int stretch, int /*size*/, int /*spacing*/) { PangoFontDescription *temp_descr = pango_font_description_new(); pango_font_description_set_family(temp_descr,family); pango_font_description_set_weight(temp_descr,(PangoWeight)weight); pango_font_description_set_stretch(temp_descr,(PangoStretch)stretch); pango_font_description_set_style(temp_descr,(PangoStyle)style); pango_font_description_set_variant(temp_descr,(PangoVariant)variant); font_instance *res = Face(temp_descr); pango_font_description_free(temp_descr); return res; }
static void gst_imx_g2d_time_overlay_class_init (GstImxG2DTimeOverlayClass * klass) { GstElementClass *gstelement_class; GstImxG2DBaseTextOverlayClass *gsttextoverlay_class; GObjectClass *gobject_class; PangoContext *context; PangoFontDescription *font_description; gsttextoverlay_class = (GstImxG2DBaseTextOverlayClass *) klass; gstelement_class = (GstElementClass *) klass; gobject_class = (GObjectClass *) klass; gst_element_class_set_static_metadata (gstelement_class, "Time overlay", "Filter/Editor/Video", "Overlays buffer time stamps on a video stream", "Tim-Philipp Müller <*****@*****.**>"); gsttextoverlay_class->get_text = gst_imx_g2d_time_overlay_get_text; gobject_class->set_property = gst_imx_g2d_time_overlay_set_property; gobject_class->get_property = gst_imx_g2d_time_overlay_get_property; g_object_class_install_property (gobject_class, PROP_TIME_LINE, g_param_spec_enum ("time-mode", "Time Mode", "What time to show", GST_TYPE_IMX_G2D_TIME_OVERLAY_TIME_LINE, DEFAULT_TIME_LINE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_TIMEALIGNMENT, g_param_spec_enum ("time-alignment", "Time alignment", "Time alignment of the text", GST_TYPE_IMX_G2D_TIME_OVERLAY_TIMEALIGN, DEFAULT_PROP_TIMEALIGNMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_mutex_lock (gsttextoverlay_class->pango_lock); context = gsttextoverlay_class->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (gsttextoverlay_class->pango_lock); }
static void gst_clock_overlay_class_init (GstClockOverlayClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; GstBaseTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; gsttextoverlay_class = (GstBaseTextOverlayClass *) klass; gobject_class->finalize = gst_clock_overlay_finalize; gobject_class->set_property = gst_clock_overlay_set_property; gobject_class->get_property = gst_clock_overlay_get_property; gst_element_class_set_static_metadata (gstelement_class, "Clock overlay", "Filter/Editor/Video", "Overlays the current clock time on a video stream", "Tim-Philipp Müller <*****@*****.**>"); gsttextoverlay_class->get_text = gst_clock_overlay_get_text; g_object_class_install_property (gobject_class, PROP_TIMEFORMAT, g_param_spec_string ("time-format", "Date/Time Format", "Format to use for time and date value, as in strftime.", DEFAULT_PROP_TIMEFORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_mutex_lock (gsttextoverlay_class->pango_lock); context = gsttextoverlay_class->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (gsttextoverlay_class->pango_lock); }
void set_style (GtkWidget *entry, gpointer data) { char *str = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); PangoFontDescription *tmp_desc; tmp_desc = pango_font_description_from_string (str); pango_font_description_set_style(font_description, pango_font_description_get_style(tmp_desc)); pango_font_description_set_variant(font_description, pango_font_description_get_variant(tmp_desc)); pango_font_description_set_weight(font_description, pango_font_description_get_weight(tmp_desc)); pango_font_description_set_stretch(font_description, pango_font_description_get_stretch(tmp_desc)); pango_font_description_free (tmp_desc); g_free (str); reload_font (); }
PangoFontDescription *Layout::InputStreamTextSource::styleGetFontDescription() const { if (style->text == NULL) return NULL; PangoFontDescription *descr = pango_font_description_new(); // Pango can't cope with spaces before or after the commas - let's remove them. // this code is not exactly unicode-safe, but it's similar to what's done in // pango, so it's not the limiting factor Glib::ustring family; if (style->text->font_family.value == NULL) { family = "Sans"; } else { gchar **families = g_strsplit(style->text->font_family.value, ",", -1); if (families) { for (gchar **f = families ; *f ; ++f) { g_strstrip(*f); if (!family.empty()) family += ','; family += *f; } } g_strfreev(families); } pango_font_description_set_family(descr,family.c_str()); pango_font_description_set_weight(descr,(PangoWeight)_enum_converter(style->font_weight.computed, enum_convert_spstyle_weight_to_pango_weight, sizeof(enum_convert_spstyle_weight_to_pango_weight)/sizeof(enum_convert_spstyle_weight_to_pango_weight[0]))); pango_font_description_set_style(descr,(PangoStyle)_enum_converter(style->font_style.computed, enum_convert_spstyle_style_to_pango_style, sizeof(enum_convert_spstyle_style_to_pango_style)/sizeof(enum_convert_spstyle_style_to_pango_style[0]))); pango_font_description_set_variant(descr,(PangoVariant)_enum_converter(style->font_variant.computed, enum_convert_spstyle_variant_to_pango_variant, sizeof(enum_convert_spstyle_variant_to_pango_variant)/sizeof(enum_convert_spstyle_variant_to_pango_variant[0]))); #ifdef USE_PANGO_WIN32 // damn Pango fudges the size, so we need to unfudge. See source of pango_win32_font_map_init() pango_font_description_set_size(descr, (int) ((font_factory::Default())->fontSize*PANGO_SCALE*72/GetDeviceCaps(pango_win32_get_dc(),LOGPIXELSY))); // mandatory huge size (hinting workaround) // we don't set stretch on Win32, because pango-win32 has no concept of it // (Windows doesn't really provide any useful field it could use). // If we did set stretch, then any text with a font-stretch attribute would // end up falling back to Arial. #else pango_font_description_set_size(descr, (int) ((font_factory::Default())->fontSize*PANGO_SCALE)); // mandatory huge size (hinting workaround) pango_font_description_set_stretch(descr,(PangoStretch)_enum_converter(style->font_stretch.computed, enum_convert_spstyle_stretch_to_pango_stretch, sizeof(enum_convert_spstyle_stretch_to_pango_stretch)/sizeof(enum_convert_spstyle_stretch_to_pango_stretch[0]))); #endif return descr; }
GTKFont *GLBase::SetupGLFont(const char *FontName, int Size, int Start, int Num) { PangoFontDescription *PFD; GTKFont *Font = new GTKFont(); PangoFont *PF; PFD = pango_font_description_new(); pango_font_description_set_family(PFD, FontName); #ifdef _WINDOWS pango_font_description_set_size(PFD, (Size - 2) * PANGO_SCALE); #else pango_font_description_set_size(PFD, Size * PANGO_SCALE); #endif pango_font_description_set_weight(PFD, PANGO_WEIGHT_NORMAL); pango_font_description_set_variant(PFD, PANGO_VARIANT_NORMAL); pango_font_description_set_style(PFD, PANGO_STYLE_NORMAL); pango_font_description_set_stretch(PFD, PANGO_STRETCH_NORMAL); glBegin(); Font->DisplayBase = glGenLists(Num); PF = gdk_gl_font_use_pango_font(PFD, Start, Num, Font->DisplayBase); if (PF == NULL) { printf("Cannot get a font from Pango with name and size %s %dpt, exiting.....\n\n", FontName, Size); exit(1); } Font->Font = PF; Font->NumEntries = Num; Font->FontSize = Size; Fonts.push_back(Font); Font->Parent = this; glEnd(); pango_font_description_free(PFD); return Font; }
static void gst_clock_overlay_class_init (GstClockOverlayClass * klass) { GObjectClass *gobject_class; GstTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gobject_class = (GObjectClass *) klass; gsttextoverlay_class = (GstTextOverlayClass *) klass; gobject_class->finalize = gst_clock_overlay_finalize; gobject_class->set_property = gst_clock_overlay_set_property; gobject_class->get_property = gst_clock_overlay_get_property; gsttextoverlay_class->get_text = gst_clock_overlay_get_text; g_object_class_install_property (gobject_class, PROP_TIMEFORMAT, g_param_spec_string ("time-format", "Date/Time Format", "Format to use for time and date value, as in strftime.", DEFAULT_PROP_TIMEFORMAT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_mutex_lock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); }
/** * gwy_color_axis_new: * @orientation: The orientation of the axis. * @min: The minimum. * @max: The maximum. * @pal: The palette the color axis should use. * * Creates a new color axis. * * Returns: The newly created color axis as a #GtkWidget. **/ GtkWidget* gwy_color_axis_new(GtkOrientation orientation, gdouble min, gdouble max, GwyPalette *pal) { GwyColorAxis *axis; gwy_debug(""); g_return_val_if_fail(GWY_IS_PALETTE(pal), NULL); axis = gtk_type_new(gwy_color_axis_get_type()); axis->orientation = orientation; /* TODO: use some font properties, at least */ if (orientation == GTK_ORIENTATION_VERTICAL) axis->par.textarea = 70; else axis->par.textarea = 20; axis->min = min; axis->max = max; /* XXX */ axis->par.font = pango_font_description_new(); pango_font_description_set_family(axis->par.font, "Helvetica"); pango_font_description_set_style(axis->par.font, PANGO_STYLE_NORMAL); pango_font_description_set_variant(axis->par.font, PANGO_VARIANT_NORMAL); pango_font_description_set_weight(axis->par.font, PANGO_WEIGHT_NORMAL); pango_font_description_set_size(axis->par.font, 10*PANGO_SCALE); axis->gradient = gwy_gradients_get_gradient(GWY_GRADIENT_DEFAULT); g_object_ref(axis->gradient); /* XXX: remove */ axis->palette = (GwyPalette*)gwy_palette_new(NULL); gwy_color_axis_set_palette(axis, pal); axis->siunit = GWY_SI_UNIT(gwy_si_unit_new("m")); return GTK_WIDGET(axis); }
/* This is copied straight from make_alias_description in pango, plus * the gimp_font_list_add_font bits. */ static void gimp_font_list_make_alias (GimpFontList *list, PangoContext *context, const gchar *family, gboolean bold, gboolean italic) { PangoFontDescription *desc = pango_font_description_new (); pango_font_description_set_family (desc, family); pango_font_description_set_style (desc, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_variant (desc, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (desc, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (desc, PANGO_STRETCH_NORMAL); gimp_font_list_add_font (list, context, desc); pango_font_description_free (desc); }
static PangoLayout * rsvg_text_create_layout (RsvgDrawingCtx * ctx, RsvgState * state, const char *text, PangoContext * context) { PangoFontDescription *font_desc; PangoLayout *layout; PangoAttrList *attr_list; PangoAttribute *attribute; if (state->lang) pango_context_set_language (context, pango_language_from_string (state->lang)); if (state->unicode_bidi == UNICODE_BIDI_OVERRIDE || state->unicode_bidi == UNICODE_BIDI_EMBED) pango_context_set_base_dir (context, state->text_dir); font_desc = pango_font_description_copy (pango_context_get_font_description (context)); if (state->font_family) pango_font_description_set_family_static (font_desc, state->font_family); pango_font_description_set_style (font_desc, state->font_style); pango_font_description_set_variant (font_desc, state->font_variant); pango_font_description_set_weight (font_desc, state->font_weight); pango_font_description_set_stretch (font_desc, state->font_stretch); pango_font_description_set_size (font_desc, _rsvg_css_normalize_font_size (state, ctx) * PANGO_SCALE / ctx->dpi_y * 72); layout = pango_layout_new (context); pango_layout_set_font_description (layout, font_desc); pango_font_description_free (font_desc); attr_list = pango_attr_list_new (); attribute = pango_attr_letter_spacing_new (_rsvg_css_normalize_length (&state->letter_spacing, ctx, 'h') * PANGO_SCALE); attribute->start_index = 0; attribute->end_index = G_MAXINT; pango_attr_list_insert (attr_list, attribute); if (state->has_font_decor && text) { if (state->font_decor & TEXT_UNDERLINE) { attribute = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); attribute->start_index = 0; attribute->end_index = -1; pango_attr_list_insert (attr_list, attribute); } if (state->font_decor & TEXT_STRIKE) { attribute = pango_attr_strikethrough_new (TRUE); attribute->start_index = 0; attribute->end_index = -1; pango_attr_list_insert (attr_list, attribute); } } pango_layout_set_attributes (layout, attr_list); pango_attr_list_unref (attr_list); if (text) pango_layout_set_text (layout, text, -1); else pango_layout_set_text (layout, NULL, 0); pango_layout_set_alignment (layout, (state->text_dir == PANGO_DIRECTION_LTR || state->text_dir == PANGO_DIRECTION_TTB_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); return layout; }
static void pf_setVariant(JNIEnv*, jclass, jlong obj, jint variant) { if (!obj) return; PangoFontDescription* desc = reinterpret_cast<PangoFontDescription*>(obj); pango_font_description_set_variant(desc, (PangoVariant) variant); }
unsigned Gosu::pango::textWidth(const std::wstring& text, const std::wstring& fontFace, unsigned fontHeight, unsigned fontFlags) { g_type_init(); int dpi_x = 100, dpi_y = 100; context = pango_ft2_get_context(dpi_x, dpi_y); pango_context_set_language(context, pango_language_from_string ("en_US")); PangoDirection init_dir = PANGO_DIRECTION_LTR; pango_context_set_base_dir(context, init_dir); // static PangoFontDescription *font_description; font_description = pango_font_description_new(); pango_font_description_set_family(font_description, g_strdup(narrow(fontFace).c_str())); pango_font_description_set_style(font_description, (fontFlags & ffItalic) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_variant(font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight(font_description, (fontFlags & ffBold) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch(font_description, PANGO_STRETCH_NORMAL); int init_scale = int(fontHeight/2.0 + 0.5); pango_font_description_set_size(font_description, init_scale * PANGO_SCALE); pango_context_set_font_description(context, font_description); layout = pango_layout_new(context); if(fontFlags & ffUnderline) { // PangoAttribute *attr; attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); attr->start_index = 0; attr->end_index = text.length(); // PangoAttrList* attrList; attrList = pango_attr_list_new(); pango_attr_list_insert(attrList, attr); pango_layout_set_attributes(layout, attrList); pango_attr_list_unref(attrList); } // IMPR: Catch errors? (Last NULL-Pointer) gchar* utf8Str = g_ucs4_to_utf8((gunichar*)text.c_str(), text.length(), NULL, NULL, NULL); pango_layout_set_text(layout, utf8Str, -1); g_free(utf8Str); PangoDirection base_dir = pango_context_get_base_dir(context); pango_layout_set_alignment(layout, base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); pango_layout_set_width(layout, -1); PangoRectangle logical_rect; pango_layout_get_pixel_extents(layout, NULL, &logical_rect); height = logical_rect.height; width = logical_rect.width; return width; }
font_instance *font_factory::Face(char const *family, NRTypePosDef apos) { PangoFontDescription *temp_descr = pango_font_description_new(); pango_font_description_set_family(temp_descr, family); if ( apos.variant == NR_POS_VARIANT_SMALLCAPS ) { pango_font_description_set_variant(temp_descr, PANGO_VARIANT_SMALL_CAPS); } else { pango_font_description_set_variant(temp_descr, PANGO_VARIANT_NORMAL); } if ( apos.italic ) { pango_font_description_set_style(temp_descr, PANGO_STYLE_ITALIC); } else if ( apos.oblique ) { pango_font_description_set_style(temp_descr, PANGO_STYLE_OBLIQUE); } else { pango_font_description_set_style(temp_descr, PANGO_STYLE_NORMAL); } if ( apos.weight <= NR_POS_WEIGHT_THIN ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_THIN); } else if ( apos.weight <= NR_POS_WEIGHT_ULTRA_LIGHT ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRALIGHT); } else if ( apos.weight <= NR_POS_WEIGHT_LIGHT ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_LIGHT); } else if ( apos.weight <= NR_POS_WEIGHT_BOOK ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOOK); } else if ( apos.weight <= NR_POS_WEIGHT_NORMAL ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_NORMAL); } else if ( apos.weight <= NR_POS_WEIGHT_MEDIUM ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_MEDIUM); } else if ( apos.weight <= NR_POS_WEIGHT_SEMIBOLD ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_SEMIBOLD); } else if ( apos.weight <= NR_POS_WEIGHT_BOLD ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOLD); } else if ( apos.weight <= NR_POS_WEIGHT_ULTRA_BOLD ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRABOLD); } else { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_HEAVY); } // PANGO_WIEGHT_ULTRAHEAVY not used (not CSS2) if ( apos.stretch <= NR_POS_STRETCH_ULTRA_CONDENSED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_CONDENSED); } else if ( apos.stretch <= NR_POS_STRETCH_CONDENSED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_CONDENSED); } else if ( apos.stretch <= NR_POS_STRETCH_SEMI_CONDENSED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_CONDENSED); } else if ( apos.stretch <= NR_POS_STRETCH_NORMAL ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_NORMAL); } else if ( apos.stretch <= NR_POS_STRETCH_SEMI_EXPANDED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_EXPANDED); } else if ( apos.stretch <= NR_POS_STRETCH_EXPANDED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXPANDED); } else { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_EXPANDED); } font_instance *res = Face(temp_descr); pango_font_description_free(temp_descr); return res; }