static gboolean util_split_font_string(const gchar *font_name, gchar **name, gint *size) { PangoFontDescription *desc; PangoFontMask mask; gboolean retval = FALSE; if (font_name == NULL) { return FALSE; } mask = (PangoFontMask) (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE); desc = pango_font_description_from_string(font_name); if (!desc) { return FALSE; } if ((pango_font_description_get_set_fields(desc) & mask) == mask) { *size = PANGO_PIXELS(pango_font_description_get_size (desc)); *name = g_strdup(pango_font_description_get_family (desc)); retval = TRUE; } pango_font_description_free(desc); return retval; }
static int _pango_xft_Load(TextState * ts, const char *name) { FontCtxPangoXft *fdc; PangoFontDescription *font; PangoFontMask flags; if (!_pango_ctx) _pango_ctx = pango_xft_get_context(disp, Dpy.screen); if (!_pango_ctx) return -1; font = pango_font_description_from_string(name); if (!font) return -1; flags = pango_font_description_get_set_fields(font); if ((flags & PANGO_FONT_MASK_FAMILY) == 0) pango_font_description_set_family(font, "sans"); if ((flags & PANGO_FONT_MASK_SIZE) == 0) pango_font_description_set_size(font, 10 * PANGO_SCALE); fdc = EMALLOC(FontCtxPangoXft, 1); if (!fdc) return -1; fdc->font = font; ts->fdc = fdc; ts->need_utf8 = 1; ts->type = FONT_TYPE_PANGO_XFT; ts->ops = &FontOps_pango; return 0; }
JNIEXPORT jint JNICALL Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1get_1set_1fields ( JNIEnv* env, jclass cls, jlong _self ) { PangoFontMask result; jint _result; PangoFontDescription* self; // convert parameter self self = (PangoFontDescription*) _self; // call function result = pango_font_description_get_set_fields(self); // cleanup parameter self // translate return value to JNI type _result = (jint) result; // and finally return _result; }
static GtkCssValue * gtk_css_value_initial_compute (GtkCssValue *value, guint property_id, GtkStyleProviderPrivate *provider, GtkCssStyle *style, GtkCssStyle *parent_style) { GtkSettings *settings; switch (property_id) { case GTK_CSS_PROPERTY_DPI: settings = _gtk_style_provider_private_get_settings (provider); if (settings) { GdkScreen *screen = _gtk_settings_get_screen (settings); double resolution = gdk_screen_get_resolution (screen); if (resolution > 0.0) return _gtk_css_number_value_new (resolution, GTK_CSS_NUMBER); } break; case GTK_CSS_PROPERTY_FONT_FAMILY: settings = _gtk_style_provider_private_get_settings (provider); if (settings) { PangoFontDescription *description; char *font_name; GtkCssValue *value; g_object_get (settings, "gtk-font-name", &font_name, NULL); description = pango_font_description_from_string (font_name); g_free (font_name); if (description == NULL) break; if (pango_font_description_get_set_fields (description) & PANGO_FONT_MASK_FAMILY) { value = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (description))); pango_font_description_free (description); return value; } pango_font_description_free (description); } break; default: break; } return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)), property_id, provider, style, parent_style); }
/* returns 0 if the font is safe, otherwise returns the size in points. */ static gint font_dangerous (const char *font) { PangoFontDescription *pfd; gboolean retval = 0; pfd = pango_font_description_from_string (font); if (pfd == NULL) /* an invalid font was passed in. This isn't our problem. */ return 0; if ((pango_font_description_get_set_fields (pfd) & PANGO_FONT_MASK_SIZE) && (pango_font_description_get_size (pfd) >= MAX_FONT_SIZE_WITHOUT_WARNING)) { retval = pango_font_description_get_size (pfd)/1024; } pango_font_description_free (pfd); return retval; }
gboolean _gtk_text_tag_affects_size (GtkTextTag *tag) { GtkTextTagPrivate *priv = tag->priv; return (priv->values->font && pango_font_description_get_set_fields (priv->values->font) != 0) || priv->scale_set || priv->justification_set || priv->left_margin_set || priv->indent_set || priv->rise_set || priv->right_margin_set || priv->pixels_above_lines_set || priv->pixels_below_lines_set || priv->pixels_inside_wrap_set || priv->tabs_set || priv->underline_set || priv->wrap_mode_set || priv->invisible_set; }
static gboolean font_description_value_parse (GtkCssParser *parser, GValue *value) { PangoFontDescription *font_desc; guint mask; char *str; str = _gtk_css_parser_read_value (parser); if (str == NULL) return FALSE; font_desc = pango_font_description_from_string (str); mask = pango_font_description_get_set_fields (font_desc); /* These values are not really correct, * but the fields must be set, so we set them to something */ if ((mask & PANGO_FONT_MASK_FAMILY) == 0) pango_font_description_set_family_static (font_desc, "Sans"); if ((mask & PANGO_FONT_MASK_SIZE) == 0) pango_font_description_set_size (font_desc, 10 * PANGO_SCALE); g_free (str); g_value_take_boxed (value, font_desc); return TRUE; }
wxFontWeight wxNativeFontInfo::GetWeight() const { #if 0 // We seem to currently initialize only by string. // In that case PANGO_FONT_MASK_WEIGHT is always set. if (!(pango_font_description_get_set_fields(description) & PANGO_FONT_MASK_WEIGHT)) return wxFONTWEIGHT_NORMAL; #endif PangoWeight pango_weight = pango_font_description_get_weight( description ); // Until the API can be changed the following ranges of weight values are used: // wxFONTWEIGHT_LIGHT: 100 .. 349 - range of 250 // wxFONTWEIGHT_NORMAL: 350 .. 599 - range of 250 // wxFONTWEIGHT_BOLD: 600 .. 900 - range of 301 (600 is "semibold" already) if (pango_weight >= 600) return wxFONTWEIGHT_BOLD; if (pango_weight < 350) return wxFONTWEIGHT_LIGHT; return wxFONTWEIGHT_NORMAL; }
static gboolean cb_pref_font_hf_has_changed (GOFontSel *fs, G_GNUC_UNUSED PangoAttrList *attrs, PrefState *state) { PangoFontDescription *desc = go_font_sel_get_font_desc (fs); PangoFontMask fields = pango_font_description_get_set_fields (desc); if (fields & PANGO_FONT_MASK_FAMILY) gnm_conf_set_printsetup_hf_font_name (pango_font_description_get_family (desc)); if (fields & PANGO_FONT_MASK_SIZE) gnm_conf_set_printsetup_hf_font_size (pango_font_description_get_size (desc) / (double)PANGO_SCALE); if (fields & PANGO_FONT_MASK_WEIGHT) gnm_conf_set_printsetup_hf_font_bold (pango_font_description_get_weight (desc) >= PANGO_WEIGHT_BOLD); if (fields & PANGO_FONT_MASK_STYLE) gnm_conf_set_printsetup_hf_font_italic (pango_font_description_get_style (desc) != PANGO_STYLE_NORMAL); pango_font_description_free (desc); return TRUE; }
/* This function is used by gtk_text_cell_accessible_get_offset_at_point() * and gtk_text_cell_accessible_get_character_extents(). There is no * cached PangoLayout so we must create a temporary one using this function. */ static PangoLayout * create_pango_layout (GtkTextCellAccessible *text) { GdkRGBA *foreground_rgba; PangoAttrList *attr_list, *attributes; PangoLayout *layout; PangoUnderline uline, underline; PangoFontMask mask; PangoFontDescription *font_desc; gboolean foreground_set, strikethrough_set, strikethrough; gboolean scale_set, underline_set, rise_set; gchar *renderer_text; gdouble scale; gint rise; GtkRendererCellAccessible *gail_renderer; GtkCellRendererText *gtk_renderer; gail_renderer = GTK_RENDERER_CELL_ACCESSIBLE (text); gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer); g_object_get (gtk_renderer, "text", &renderer_text, "attributes", &attributes, "foreground-set", &foreground_set, "foreground-rgba", &foreground_rgba, "strikethrough-set", &strikethrough_set, "strikethrough", &strikethrough, "font-desc", &font_desc, "scale-set", &scale_set, "scale", &scale, "underline-set", &underline_set, "underline", &underline, "rise-set", &rise_set, "rise", &rise, NULL); layout = gtk_widget_create_pango_layout (get_widget (text), renderer_text); if (attributes) attr_list = pango_attr_list_copy (attributes); else attr_list = pango_attr_list_new (); if (foreground_set) { add_attr (attr_list, pango_attr_foreground_new (foreground_rgba->red * 65535, foreground_rgba->green * 65535, foreground_rgba->blue * 65535)); } if (strikethrough_set) add_attr (attr_list, pango_attr_strikethrough_new (strikethrough)); mask = pango_font_description_get_set_fields (font_desc); if (mask & PANGO_FONT_MASK_FAMILY) add_attr (attr_list, pango_attr_family_new (pango_font_description_get_family (font_desc))); if (mask & PANGO_FONT_MASK_STYLE) add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (font_desc))); if (mask & PANGO_FONT_MASK_VARIANT) add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (font_desc))); if (mask & PANGO_FONT_MASK_WEIGHT) add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (font_desc))); if (mask & PANGO_FONT_MASK_STRETCH) add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (font_desc))); if (mask & PANGO_FONT_MASK_SIZE) add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (font_desc))); if (scale_set && scale != 1.0) add_attr (attr_list, pango_attr_scale_new (scale)); if (underline_set) uline = underline; else uline = PANGO_UNDERLINE_NONE; if (uline != PANGO_UNDERLINE_NONE) add_attr (attr_list, pango_attr_underline_new (underline)); if (rise_set) add_attr (attr_list, pango_attr_rise_new (rise)); pango_layout_set_attributes (layout, attr_list); pango_layout_set_width (layout, -1); pango_attr_list_unref (attr_list); pango_font_description_free (font_desc); pango_attr_list_unref (attributes); g_free (renderer_text); gdk_rgba_free (foreground_rgba); return layout; }
/** * This function is orignally written in gtk/gtkfontbutton.c of gtk+ project. */ gchar * pango_font_description_to_css (PangoFontDescription *desc) { GString *s; PangoFontMask set; s = g_string_new ("{ "); set = pango_font_description_get_set_fields (desc); if (set & PANGO_FONT_MASK_FAMILY) { g_string_append (s, "font-family: "); g_string_append (s, pango_font_description_get_family (desc)); g_string_append (s, "; "); } if (set & PANGO_FONT_MASK_STYLE) { switch (pango_font_description_get_style (desc)) { case PANGO_STYLE_NORMAL: g_string_append (s, "font-style: normal; "); break; case PANGO_STYLE_OBLIQUE: g_string_append (s, "font-style: oblique; "); break; case PANGO_STYLE_ITALIC: g_string_append (s, "font-style: italic; "); break; } } if (set & PANGO_FONT_MASK_VARIANT) { switch (pango_font_description_get_variant (desc)) { case PANGO_VARIANT_NORMAL: g_string_append (s, "font-variant: normal; "); break; case PANGO_VARIANT_SMALL_CAPS: g_string_append (s, "font-variant: small-caps; "); break; } } if (set & PANGO_FONT_MASK_WEIGHT) { switch (pango_font_description_get_weight (desc)) { case PANGO_WEIGHT_THIN: g_string_append (s, "font-weight: 100; "); break; case PANGO_WEIGHT_ULTRALIGHT: g_string_append (s, "font-weight: 200; "); break; case PANGO_WEIGHT_LIGHT: case PANGO_WEIGHT_SEMILIGHT: g_string_append (s, "font-weight: 300; "); break; case PANGO_WEIGHT_BOOK: case PANGO_WEIGHT_NORMAL: g_string_append (s, "font-weight: 400; "); break; case PANGO_WEIGHT_MEDIUM: g_string_append (s, "font-weight: 500; "); break; case PANGO_WEIGHT_SEMIBOLD: g_string_append (s, "font-weight: 600; "); break; case PANGO_WEIGHT_BOLD: g_string_append (s, "font-weight: 700; "); break; case PANGO_WEIGHT_ULTRABOLD: g_string_append (s, "font-weight: 800; "); break; case PANGO_WEIGHT_HEAVY: case PANGO_WEIGHT_ULTRAHEAVY: g_string_append (s, "font-weight: 900; "); break; } } if (set & PANGO_FONT_MASK_STRETCH) { switch (pango_font_description_get_stretch (desc)) { case PANGO_STRETCH_ULTRA_CONDENSED: g_string_append (s, "font-stretch: ultra-condensed; "); break; case PANGO_STRETCH_EXTRA_CONDENSED: g_string_append (s, "font-stretch: extra-condensed; "); break; case PANGO_STRETCH_CONDENSED: g_string_append (s, "font-stretch: condensed; "); break; case PANGO_STRETCH_SEMI_CONDENSED: g_string_append (s, "font-stretch: semi-condensed; "); break; case PANGO_STRETCH_NORMAL: g_string_append (s, "font-stretch: normal; "); break; case PANGO_STRETCH_SEMI_EXPANDED: g_string_append (s, "font-stretch: semi-expanded; "); break; case PANGO_STRETCH_EXPANDED: g_string_append (s, "font-stretch: expanded; "); break; case PANGO_STRETCH_EXTRA_EXPANDED: g_string_append (s, "font-stretch: extra-expanded; "); break; case PANGO_STRETCH_ULTRA_EXPANDED: g_string_append (s, "font-stretch: ultra-expanded; "); break; } } if (set & PANGO_FONT_MASK_SIZE) { g_string_append_printf (s, "font-size: %dpt", pango_font_description_get_size (desc) / PANGO_SCALE); } g_string_append (s, "}"); return g_string_free (s, FALSE); }
/* * This function is used by gail_text_cell_get_offset_at_point() * and gail_text_cell_get_character_extents(). There is no * cached PangoLayout for gailtextcell so we must create a temporary * one using this function. */ static PangoLayout* create_pango_layout(GtkCellRendererText *gtk_renderer, GtkWidget *widget) { PangoAttrList *attr_list; PangoLayout *layout; PangoUnderline uline; PangoFontMask mask; layout = gtk_widget_create_pango_layout (widget, gtk_renderer->text); if (gtk_renderer->extra_attrs) attr_list = pango_attr_list_copy (gtk_renderer->extra_attrs); else attr_list = pango_attr_list_new (); if (gtk_renderer->foreground_set) { PangoColor color; color = gtk_renderer->foreground; add_attr (attr_list, pango_attr_foreground_new (color.red, color.green, color.blue)); } if (gtk_renderer->strikethrough_set) add_attr (attr_list, pango_attr_strikethrough_new (gtk_renderer->strikethrough)); mask = pango_font_description_get_set_fields (gtk_renderer->font); if (mask & PANGO_FONT_MASK_FAMILY) add_attr (attr_list, pango_attr_family_new (pango_font_description_get_family (gtk_renderer->font))); if (mask & PANGO_FONT_MASK_STYLE) add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (gtk_renderer->font))); if (mask & PANGO_FONT_MASK_VARIANT) add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (gtk_renderer->font))); if (mask & PANGO_FONT_MASK_WEIGHT) add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (gtk_renderer->font))); if (mask & PANGO_FONT_MASK_STRETCH) add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (gtk_renderer->font))); if (mask & PANGO_FONT_MASK_SIZE) add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (gtk_renderer->font))); if (gtk_renderer->scale_set && gtk_renderer->font_scale != 1.0) add_attr (attr_list, pango_attr_scale_new (gtk_renderer->font_scale)); if (gtk_renderer->underline_set) uline = gtk_renderer->underline_style; else uline = PANGO_UNDERLINE_NONE; if (uline != PANGO_UNDERLINE_NONE) add_attr (attr_list, pango_attr_underline_new (gtk_renderer->underline_style)); if (gtk_renderer->rise_set) add_attr (attr_list, pango_attr_rise_new (gtk_renderer->rise)); pango_layout_set_attributes (layout, attr_list); pango_layout_set_width (layout, -1); pango_attr_list_unref (attr_list); return layout; }
gchar * gb_pango_font_description_to_css (const PangoFontDescription *font_desc) { PangoFontMask mask; GString *str; #define ADD_KEYVAL(key,fmt) \ g_string_append(str,key":"fmt";") #define ADD_KEYVAL_PRINTF(key,fmt,...) \ g_string_append_printf(str,key":"fmt";", __VA_ARGS__) g_return_val_if_fail (font_desc, NULL); str = g_string_new (NULL); mask = pango_font_description_get_set_fields (font_desc); if ((mask & PANGO_FONT_MASK_FAMILY) != 0) { const gchar *family; family = pango_font_description_get_family (font_desc); ADD_KEYVAL_PRINTF (FONT_FAMILY, "\"%s\"", family); } if ((mask & PANGO_FONT_MASK_STYLE) != 0) { PangoVariant variant; variant = pango_font_description_get_variant (font_desc); switch (variant) { case PANGO_VARIANT_NORMAL: ADD_KEYVAL (FONT_VARIANT, "normal"); break; case PANGO_VARIANT_SMALL_CAPS: ADD_KEYVAL (FONT_VARIANT, "small-caps"); break; default: break; } } if ((mask & PANGO_FONT_MASK_WEIGHT)) { gint weight; weight = pango_font_description_get_weight (font_desc); ADD_KEYVAL_PRINTF ("font-weight", "%d", weight); } if ((mask & PANGO_FONT_MASK_STRETCH)) { switch (pango_font_description_get_stretch (font_desc)) { case PANGO_STRETCH_ULTRA_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "untra-condensed"); break; case PANGO_STRETCH_EXTRA_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "extra-condensed"); break; case PANGO_STRETCH_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "condensed"); break; case PANGO_STRETCH_SEMI_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "semi-condensed"); break; case PANGO_STRETCH_NORMAL: ADD_KEYVAL (FONT_STRETCH, "normal"); break; case PANGO_STRETCH_SEMI_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "semi-expanded"); break; case PANGO_STRETCH_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "expanded"); break; case PANGO_STRETCH_EXTRA_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "extra-expanded"); break; case PANGO_STRETCH_ULTRA_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "untra-expanded"); break; default: break; } } if ((mask & PANGO_FONT_MASK_SIZE)) { gint font_size; font_size = pango_font_description_get_size (font_desc) / PANGO_SCALE; ADD_KEYVAL_PRINTF ("font-size", "%dpx", font_size); } return g_string_free (str, FALSE); #undef ADD_KEYVAL #undef ADD_KEYVAL_PRINTF }
gchar * ide_pango_font_description_to_css (const PangoFontDescription *font_desc) { PangoFontMask mask; GString *str; #define ADD_KEYVAL(key,fmt) \ g_string_append(str,key":"fmt";") #define ADD_KEYVAL_PRINTF(key,fmt,...) \ g_string_append_printf(str,key":"fmt";", __VA_ARGS__) g_return_val_if_fail (font_desc, NULL); str = g_string_new (NULL); mask = pango_font_description_get_set_fields (font_desc); if ((mask & PANGO_FONT_MASK_FAMILY) != 0) { const gchar *family; family = pango_font_description_get_family (font_desc); ADD_KEYVAL_PRINTF (FONT_FAMILY, "\"%s\"", family); } if ((mask & PANGO_FONT_MASK_STYLE) != 0) { PangoVariant variant; variant = pango_font_description_get_variant (font_desc); switch (variant) { case PANGO_VARIANT_NORMAL: ADD_KEYVAL (FONT_VARIANT, "normal"); break; case PANGO_VARIANT_SMALL_CAPS: ADD_KEYVAL (FONT_VARIANT, "small-caps"); break; default: break; } } if ((mask & PANGO_FONT_MASK_WEIGHT)) { gint weight; weight = pango_font_description_get_weight (font_desc); /* * WORKAROUND: * * font-weight with numbers does not appear to be working as expected * right now. So for the common (bold/normal), let's just use the string * and let gtk warn for the other values, which shouldn't really be * used for this. */ switch (weight) { case PANGO_WEIGHT_SEMILIGHT: /* * 350 is not actually a valid css font-weight, so we will just round * up to 400. */ case PANGO_WEIGHT_NORMAL: ADD_KEYVAL (FONT_WEIGHT, "normal"); break; case PANGO_WEIGHT_BOLD: ADD_KEYVAL (FONT_WEIGHT, "bold"); break; case PANGO_WEIGHT_THIN: case PANGO_WEIGHT_ULTRALIGHT: case PANGO_WEIGHT_LIGHT: case PANGO_WEIGHT_BOOK: case PANGO_WEIGHT_MEDIUM: case PANGO_WEIGHT_SEMIBOLD: case PANGO_WEIGHT_ULTRABOLD: case PANGO_WEIGHT_HEAVY: case PANGO_WEIGHT_ULTRAHEAVY: default: /* round to nearest hundred */ weight = round (weight / 100.0) * 100; ADD_KEYVAL_PRINTF ("font-weight", "%d", weight); break; } } #ifndef GDK_WINDOWING_QUARTZ /* * We seem to get "Condensed" for fonts on the Quartz backend, * which is rather annoying as it results in us always hitting * fallback (stretch) paths. So let's cheat and just disable * stretch support for now on Quartz. */ if ((mask & PANGO_FONT_MASK_STRETCH)) { switch (pango_font_description_get_stretch (font_desc)) { case PANGO_STRETCH_ULTRA_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "untra-condensed"); break; case PANGO_STRETCH_EXTRA_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "extra-condensed"); break; case PANGO_STRETCH_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "condensed"); break; case PANGO_STRETCH_SEMI_CONDENSED: ADD_KEYVAL (FONT_STRETCH, "semi-condensed"); break; case PANGO_STRETCH_NORMAL: ADD_KEYVAL (FONT_STRETCH, "normal"); break; case PANGO_STRETCH_SEMI_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "semi-expanded"); break; case PANGO_STRETCH_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "expanded"); break; case PANGO_STRETCH_EXTRA_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "extra-expanded"); break; case PANGO_STRETCH_ULTRA_EXPANDED: ADD_KEYVAL (FONT_STRETCH, "untra-expanded"); break; default: break; } } #endif if ((mask & PANGO_FONT_MASK_SIZE)) { gint font_size; font_size = pango_font_description_get_size (font_desc) / PANGO_SCALE; ADD_KEYVAL_PRINTF ("font-size", "%dpx", font_size); } return g_string_free (str, FALSE); #undef ADD_KEYVAL #undef ADD_KEYVAL_PRINTF }