JNIEXPORT void JNICALL Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1unset_1fields ( JNIEnv* env, jclass cls, jlong _self, jint _toUnset ) { PangoFontDescription* self; PangoFontMask toUnset; // convert parameter self self = (PangoFontDescription*) _self; // convert parameter toUnset toUnset = (PangoFontMask) _toUnset; // call function pango_font_description_unset_fields(self, toUnset); // cleanup parameter self // cleanup parameter toUnset }
Glib::ustring font_factory::ConstructFontSpecification(PangoFontDescription *font) { Glib::ustring pangoString; g_assert(font); if (font) { // Once the format for the font specification is decided, it must be // kept.. if it is absolutely necessary to change it, the attribute // it is written to needs to have a new version so the legacy files // can be read. PangoFontDescription *copy = pango_font_description_copy(font); pango_font_description_unset_fields (copy, PANGO_FONT_MASK_SIZE); char * copyAsString = pango_font_description_to_string(copy); pangoString = copyAsString; g_free(copyAsString); copyAsString = 0; pango_font_description_free(copy); } return pangoString; }
Glib::ustring font_factory::GetUIStyleString(PangoFontDescription const *fontDescr) { Glib::ustring style; g_assert(fontDescr); if (fontDescr) { PangoFontDescription *fontDescrCopy = pango_font_description_copy(fontDescr); pango_font_description_unset_fields(fontDescrCopy, PANGO_FONT_MASK_FAMILY); pango_font_description_unset_fields(fontDescrCopy, PANGO_FONT_MASK_SIZE); // For now, keep it as style name taken from pango char *fontDescrAsString = pango_font_description_to_string(fontDescrCopy); style = fontDescrAsString; g_free(fontDescrAsString); fontDescrAsString = 0; pango_font_description_free(fontDescrCopy); } return style; }
static void gtk_font_button_label_use_font (GtkFontButton *font_button) { PangoFontDescription *desc; if (!font_button->priv->use_font) return; desc = pango_font_description_from_string (font_button->priv->fontname); if (!font_button->priv->use_size) pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); gtk_widget_modify_font (font_button->priv->font_label, desc); pango_font_description_free (desc); }
static void gtk_font_button_label_use_font (GtkFontButton *font_button) { GtkFontButtonPrivate *priv = font_button->priv; GtkStyleContext *context; context = gtk_widget_get_style_context (priv->font_label); if (!priv->use_font) { if (priv->provider) { gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (priv->provider)); g_clear_object (&priv->provider); } } else { PangoFontDescription *desc; gchar *font, *data; if (!priv->provider) { priv->provider = gtk_css_provider_new (); gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (priv->provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } desc = pango_font_description_copy (priv->font_desc); if (!priv->use_size) pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); font = pango_font_description_to_string (desc); data = g_strconcat ("* { font: ", font, "; }", NULL); gtk_css_provider_load_from_data (priv->provider, data, -1, NULL); g_free (data); g_free (font); pango_font_description_free (desc); } }
static void gnm_font_button_label_use_font (GnmFontButton *font_button) { PangoFontDescription *desc; if (font_button->priv->use_font) { desc = pango_font_description_copy (font_button->priv->font_desc); if (!font_button->priv->use_size) pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); } else desc = NULL; gtk_widget_override_font (font_button->priv->font_label, desc); if (desc) pango_font_description_free (desc); }
static void gnm_font_button_update_font_info (GnmFontButton *font_button) { GnmFontButtonPrivate *priv = font_button->priv; gchar *family_style; g_assert (priv->font_desc != NULL); if (priv->show_style) { PangoFontDescription *desc = pango_font_description_copy_static (priv->font_desc); pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); family_style = pango_font_description_to_string (desc); pango_font_description_free (desc); } else family_style = g_strdup (pango_font_description_get_family (priv->font_desc)); gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style); g_free (family_style); if (font_button->priv->show_size) { /* mirror Pango, which doesn't translate this either */ gchar *size = g_strdup_printf ("%g%s", pango_font_description_get_size (priv->font_desc) / (double)PANGO_SCALE, pango_font_description_get_size_is_absolute (priv->font_desc) ? "px" : ""); gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size); g_free (size); } gnm_font_button_label_use_font (font_button); }
GimpLayer * text_render (GimpImage *image, GimpDrawable *drawable, GimpContext *context, gint text_x, gint text_y, const gchar *fontname, const gchar *text, gint border, gboolean antialias) { PangoFontDescription *desc; GimpText *gtext; GimpLayer *layer; GimpRGB color; gchar *font; gdouble size; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (drawable == NULL || gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (fontname != NULL, NULL); g_return_val_if_fail (text != NULL, NULL); if (border < 0) border = 0; desc = pango_font_description_from_string (fontname); size = PANGO_PIXELS (pango_font_description_get_size (desc)); pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE); font = pango_font_description_to_string (desc); pango_font_description_free (desc); gimp_context_get_foreground (context, &color); gtext = g_object_new (GIMP_TYPE_TEXT, "text", text, "font", font, "font-size", size, "antialias", antialias, "border", border, "color", &color, NULL); g_free (font); layer = gimp_text_layer_new (image, gtext); g_object_unref (gtext); if (!layer) return NULL; /* Start a group undo */ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TEXT, _("Add Text Layer")); /* Set the layer offsets */ gimp_item_set_offset (GIMP_ITEM (layer), text_x, text_y); /* If there is a selection mask clear it-- * this might not always be desired, but in general, * it seems like the correct behavior. */ if (! gimp_channel_is_empty (gimp_image_get_mask (image))) gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE); if (drawable == NULL) { /* If the drawable is NULL, create a new layer */ gimp_image_add_layer (image, layer, NULL, -1, TRUE); } else { /* Otherwise, instantiate the text as the new floating selection */ floating_sel_attach (layer, drawable); } /* end the group undo */ gimp_image_undo_group_end (image); return layer; }
/* * Returns the index of the fonts closest style match from the provided list of styles * Used in both the Text dialog and the Text toolbar to set the style combo on selection change */ unsigned int sp_font_selector_get_best_style (font_instance *font, GList *list) { font_instance *tempFont = NULL; unsigned int currentStyleNumber = 0; unsigned int bestStyleNumber = 0; Glib::ustring family = font_factory::Default()->GetUIFamilyString(font->descr); PangoFontDescription *incomingFont = pango_font_description_copy(font->descr); pango_font_description_unset_fields(incomingFont, PANGO_FONT_MASK_SIZE); char *incomingFontString = pango_font_description_to_string(incomingFont); tempFont = (font_factory::Default())->FaceFromUIStrings(family.c_str(), (char*)list->data); PangoFontDescription *bestMatchForFont = NULL; if (tempFont) { bestMatchForFont = pango_font_description_copy(tempFont->descr); tempFont->Unref(); tempFont = NULL; } pango_font_description_unset_fields(bestMatchForFont, PANGO_FONT_MASK_SIZE); list = list->next; while (list) { currentStyleNumber++; tempFont = font_factory::Default()->FaceFromUIStrings(family.c_str(), (char*)list->data); PangoFontDescription *currentMatchForFont = NULL; if (tempFont) { currentMatchForFont = pango_font_description_copy(tempFont->descr); tempFont->Unref(); tempFont = NULL; } if (currentMatchForFont) { pango_font_description_unset_fields(currentMatchForFont, PANGO_FONT_MASK_SIZE); char *currentMatchString = pango_font_description_to_string(currentMatchForFont); if (!strcmp(incomingFontString, currentMatchString) || pango_font_description_better_match(incomingFont, bestMatchForFont, currentMatchForFont)) { // Found a better match for the font we are looking for pango_font_description_free(bestMatchForFont); bestMatchForFont = pango_font_description_copy(currentMatchForFont); bestStyleNumber = currentStyleNumber; } g_free(currentMatchString); pango_font_description_free(currentMatchForFont); } list = list->next; } if (bestMatchForFont) pango_font_description_free(bestMatchForFont); if (incomingFont) pango_font_description_free(incomingFont); g_free(incomingFontString); return bestStyleNumber; }
static void gtk_font_button_update_font_info (GtkFontButton *font_button) { PangoFontDescription *desc; const gchar *family; gchar *style; gchar *family_style; desc = pango_font_description_from_string (font_button->priv->fontname); family = pango_font_description_get_family (desc); #if 0 /* This gives the wrong names, e.g. Italic when the font selection * dialog displayed Oblique. */ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE); style = pango_font_description_to_string (desc); gtk_label_set_text (GTK_LABEL (font_button->priv->style_label), style); #endif style = NULL; if (font_button->priv->show_style && family) { PangoFontFamily **families; PangoFontFace **faces; gint n_families, n_faces, i; n_families = 0; families = NULL; pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)), &families, &n_families); n_faces = 0; faces = NULL; for (i = 0; i < n_families; i++) { const gchar *name = pango_font_family_get_name (families[i]); if (!g_ascii_strcasecmp (name, family)) { pango_font_family_list_faces (families[i], &faces, &n_faces); break; } } g_free (families); for (i = 0; i < n_faces; i++) { PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]); if (font_description_style_equal (tmp_desc, desc)) { style = g_strdup (pango_font_face_get_face_name (faces[i])); pango_font_description_free (tmp_desc); break; } else pango_font_description_free (tmp_desc); } g_free (faces); } if (style == NULL || !g_ascii_strcasecmp (style, "Regular")) family_style = g_strdup (family); else family_style = g_strdup_printf ("%s %s", family, style); gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style); g_free (style); g_free (family_style); if (font_button->priv->show_size) { gchar *size = g_strdup_printf ("%g", pango_font_description_get_size (desc) / (double)PANGO_SCALE); gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size); g_free (size); } gtk_font_button_label_use_font (font_button); pango_font_description_free (desc); }
static PangoCairoFontHexBoxInfo * _pango_cairo_font_private_get_hex_box_info (PangoCairoFontPrivate *cf_priv) { static const char hexdigits[] = "0123456789ABCDEF"; char c[2] = {0, 0}; PangoFont *mini_font; PangoCairoFontHexBoxInfo *hbi; /* for metrics hinting */ double scale_x = 1., scale_x_inv = 1., scale_y = 1., scale_y_inv = 1.; gboolean is_hinted; int i; int rows; double pad; double width = 0; double height = 0; cairo_font_options_t *font_options; cairo_font_extents_t font_extents; double size, mini_size; PangoFontDescription *desc; cairo_scaled_font_t *scaled_font, *scaled_mini_font; PangoMatrix pango_ctm; cairo_matrix_t cairo_ctm; PangoGravity gravity; if (!cf_priv) return NULL; if (cf_priv->hbi) return cf_priv->hbi; scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv); if (G_UNLIKELY (scaled_font == NULL || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS)) return NULL; is_hinted = cf_priv->is_hinted; font_options = cairo_font_options_create (); desc = pango_font_describe_with_absolute_size ((PangoFont *)cf_priv->cfont); size = pango_font_description_get_size (desc) / (1.*PANGO_SCALE); gravity = pango_font_description_get_gravity (desc); cairo_scaled_font_get_ctm (scaled_font, &cairo_ctm); cairo_scaled_font_get_font_options (scaled_font, font_options); /* I started adding support for vertical hexboxes here, but it's too much * work. Easier to do with cairo user fonts and vertical writing mode * support in cairo. */ /*cairo_matrix_rotate (&cairo_ctm, pango_gravity_to_rotation (gravity));*/ pango_ctm.xx = cairo_ctm.xx; pango_ctm.yx = cairo_ctm.yx; pango_ctm.xy = cairo_ctm.xy; pango_ctm.yy = cairo_ctm.yy; pango_ctm.x0 = cairo_ctm.x0; pango_ctm.y0 = cairo_ctm.y0; if (is_hinted) { /* prepare for some hinting */ double x, y; x = 1.; y = 0.; cairo_matrix_transform_distance (&cairo_ctm, &x, &y); scale_x = sqrt (x*x + y*y); scale_x_inv = 1 / scale_x; x = 0.; y = 1.; cairo_matrix_transform_distance (&cairo_ctm, &x, &y); scale_y = sqrt (x*x + y*y); scale_y_inv = 1 / scale_y; } /* we hint to the nearest device units */ #define HINT(value, scale, scale_inv) (ceil ((value-1e-5) * scale) * scale_inv) #define HINT_X(value) HINT ((value), scale_x, scale_x_inv) #define HINT_Y(value) HINT ((value), scale_y, scale_y_inv) /* create mini_font description */ { PangoFontMap *fontmap; PangoContext *context; /* XXX this is racy. need a ref'ing getter... */ fontmap = pango_font_get_font_map ((PangoFont *)cf_priv->cfont); if (!fontmap) return NULL; fontmap = g_object_ref (fontmap); /* we inherit most font properties for the mini font. just * change family and size. means, you get bold hex digits * in the hexbox for a bold font. */ /* We should rotate the box, not glyphs */ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_GRAVITY); pango_font_description_set_family_static (desc, "monospace"); rows = 2; mini_size = size / 2.2; if (is_hinted) { mini_size = HINT_Y (mini_size); if (mini_size < 6.0) { rows = 1; mini_size = MIN (MAX (size - 1, 0), 6.0); } } pango_font_description_set_absolute_size (desc, pango_units_from_double (mini_size)); /* load mini_font */ context = pango_font_map_create_context (fontmap); pango_context_set_matrix (context, &pango_ctm); pango_context_set_language (context, pango_script_get_sample_language (PANGO_SCRIPT_LATIN)); pango_cairo_context_set_font_options (context, font_options); mini_font = pango_font_map_load_font (fontmap, context, desc); g_object_unref (context); g_object_unref (fontmap); } pango_font_description_free (desc); cairo_font_options_destroy (font_options); scaled_mini_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *) mini_font); for (i = 0 ; i < 16 ; i++) { cairo_text_extents_t extents; c[0] = hexdigits[i]; cairo_scaled_font_text_extents (scaled_mini_font, c, &extents); width = MAX (width, extents.width); height = MAX (height, extents.height); } cairo_scaled_font_extents (scaled_font, &font_extents); if (font_extents.ascent + font_extents.descent <= 0) { font_extents.ascent = PANGO_UNKNOWN_GLYPH_HEIGHT; font_extents.descent = 0; } pad = (font_extents.ascent + font_extents.descent) / 43; pad = MIN (pad, mini_size); hbi = g_slice_new (PangoCairoFontHexBoxInfo); hbi->font = (PangoCairoFont *) mini_font; hbi->rows = rows; hbi->digit_width = width; hbi->digit_height = height; hbi->pad_x = pad; hbi->pad_y = pad; if (is_hinted) { hbi->digit_width = HINT_X (hbi->digit_width); hbi->digit_height = HINT_Y (hbi->digit_height); hbi->pad_x = HINT_X (hbi->pad_x); hbi->pad_y = HINT_Y (hbi->pad_y); } hbi->line_width = MIN (hbi->pad_x, hbi->pad_y); hbi->box_height = 3 * hbi->pad_y + rows * (hbi->pad_y + hbi->digit_height); if (rows == 1 || hbi->box_height <= font_extents.ascent) { hbi->box_descent = 2 * hbi->pad_y; } else if (hbi->box_height <= font_extents.ascent + font_extents.descent - 2 * hbi->pad_y) { hbi->box_descent = 2 * hbi->pad_y + hbi->box_height - font_extents.ascent; } else { hbi->box_descent = font_extents.descent * hbi->box_height / (font_extents.ascent + font_extents.descent); } if (is_hinted) { hbi->box_descent = HINT_Y (hbi->box_descent); } cf_priv->hbi = hbi; return hbi; }
static void fill_styles_combo (GtkWidget *combo) { int i; GList *style_list = NULL; PangoFontFace **faces; PangoFontFamily *family, **families; FontDescInfo *info; int n_families; const char *family_name = pango_font_description_get_family(font_description); /* * Now map back the given family name to the family. There are more efficient * ways to handle this but it should not matter much ... */ pango_context_list_families (context, &families, &n_families); g_assert(n_families > 0); family = families[0]; /* just in case */ for (i = 0; i < n_families; i++) { if (0 == g_strcasecmp(pango_font_family_get_name(families[i]), family_name)) { family = families[i]; break; } } g_free (families); info = g_new (FontDescInfo, 1); pango_font_family_list_faces (family, &faces, &info->n_descs); info->descs = g_new0 (PangoFontDescription*, info->n_descs); for (i = 0; i < info->n_descs; i++) { info->descs[i] = pango_font_face_describe(faces[i]); } g_free (faces); gtk_object_set_data_full (GTK_OBJECT (combo), "descs", info, (GtkDestroyNotify)free_info); qsort (info->descs, info->n_descs, sizeof(PangoFontDescription *), font_description_sort_func); for (i=0; i<info->n_descs; i++) { char *str; PangoFontDescription *tmp_desc; tmp_desc = info->descs[i]; pango_font_description_set_family(tmp_desc, NULL); pango_font_description_unset_fields(tmp_desc, PANGO_FONT_MASK_SIZE); str = pango_font_description_to_string (tmp_desc); style_list = g_list_prepend (style_list, str); } style_list = g_list_reverse (style_list); gtk_combo_set_popdown_strings (GTK_COMBO (combo), style_list); g_list_foreach (style_list, (GFunc)g_free, NULL); }
unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int size) { if ( descr == NULL ) { if ( size > 0 ) { str[0]=0; } return 0; } char* res=NULL; bool free_res=false; if ( strcmp(key,"name") == 0 ) { PangoFontDescription* td=pango_font_description_copy(descr); pango_font_description_unset_fields (td, PANGO_FONT_MASK_SIZE); res=pango_font_description_to_string (td); pango_font_description_free(td); free_res=true; } else if ( strcmp(key,"psname") == 0 ) { #ifndef USE_PANGO_WIN32 res = (char *) FT_Get_Postscript_Name (theFace); // that's the main method, seems to always work #endif free_res=false; if (res == NULL) { // a very limited workaround, only bold, italic, and oblique will work PangoStyle style=pango_font_description_get_style(descr); bool i = (style == PANGO_STYLE_ITALIC); bool o = (style == PANGO_STYLE_OBLIQUE); PangoWeight weight=pango_font_description_get_weight(descr); bool b = (weight >= PANGO_WEIGHT_BOLD); res = g_strdup_printf ("%s%s%s%s", pango_font_description_get_family(descr), (b || i || o) ? "-" : "", (b) ? "Bold" : "", (i) ? "Italic" : ((o) ? "Oblique" : "") ); free_res = true; } } else if ( strcmp(key,"family") == 0 ) { res=(char*)pango_font_description_get_family(descr); free_res=false; } else if ( strcmp(key,"style") == 0 ) { PangoStyle v=pango_font_description_get_style(descr); if ( v == PANGO_STYLE_ITALIC ) { res=(char*)"italic"; } else if ( v == PANGO_STYLE_OBLIQUE ) { res=(char*)"oblique"; } else { res=(char*)"normal"; } free_res=false; } else if ( strcmp(key,"weight") == 0 ) { PangoWeight v=pango_font_description_get_weight(descr); if ( v <= PANGO_WEIGHT_THIN ) { res=(char*)"100"; } else if ( v <= PANGO_WEIGHT_ULTRALIGHT ) { res=(char*)"200"; } else if ( v <= PANGO_WEIGHT_LIGHT ) { res=(char*)"300"; } else if ( v <= PANGO_WEIGHT_BOOK ) { res=(char*)"380"; } else if ( v <= PANGO_WEIGHT_NORMAL ) { res=(char*)"normal"; } else if ( v <= PANGO_WEIGHT_MEDIUM ) { res=(char*)"500"; } else if ( v <= PANGO_WEIGHT_SEMIBOLD ) { res=(char*)"600"; } else if ( v <= PANGO_WEIGHT_BOLD ) { res=(char*)"bold"; } else if ( v <= PANGO_WEIGHT_ULTRABOLD ) { res=(char*)"800"; } else { // HEAVY NB: Pango defines ULTRAHEAVY = 1000 but not CSS2 res=(char*)"900"; } free_res=false; } else if ( strcmp(key,"stretch") == 0 ) { PangoStretch v=pango_font_description_get_stretch(descr); if ( v <= PANGO_STRETCH_EXTRA_CONDENSED ) { res=(char*)"extra-condensed"; } else if ( v <= PANGO_STRETCH_CONDENSED ) { res=(char*)"condensed"; } else if ( v <= PANGO_STRETCH_SEMI_CONDENSED ) { res=(char*)"semi-condensed"; } else if ( v <= PANGO_STRETCH_NORMAL ) { res=(char*)"normal"; } else if ( v <= PANGO_STRETCH_SEMI_EXPANDED ) { res=(char*)"semi-expanded"; } else if ( v <= PANGO_STRETCH_EXPANDED ) { res=(char*)"expanded"; } else { res=(char*)"extra-expanded"; } free_res=false; } else if ( strcmp(key,"variant") == 0 ) { PangoVariant v=pango_font_description_get_variant(descr); if ( v == PANGO_VARIANT_SMALL_CAPS ) { res=(char*)"small-caps"; } else { res=(char*)"normal"; } free_res=false; } else { res = NULL; free_res=false; } if ( res == NULL ) { if ( size > 0 ) { str[0] = 0; } return 0; } if (res) { unsigned int len=strlen(res); unsigned int rlen=(size-1<len)?size-1:len; if ( str ) { if ( rlen > 0 ) { memcpy(str, res, rlen); } if ( size > 0 ) { str[rlen] = 0; } } if (free_res) { g_free(res); res = 0; } return len; } return 0; }