static gboolean font_description_style_equal (const PangoFontDescription *a, const PangoFontDescription *b) { return (pango_font_description_get_weight (a) == pango_font_description_get_weight (b) && pango_font_description_get_style (a) == pango_font_description_get_style (b) && pango_font_description_get_stretch (a) == pango_font_description_get_stretch (b) && pango_font_description_get_variant (a) == pango_font_description_get_variant (b)); }
bool font_descr_equal::operator()( PangoFontDescription *const&a, PangoFontDescription *const &b) const { //if ( pango_font_description_equal(a,b) ) return true; char const *fa = sp_font_description_get_family(a); char const *fb = sp_font_description_get_family(b); if ( ( fa && fb == NULL ) || ( fb && fa == NULL ) ) return false; if ( fa && fb && strcmp(fa,fb) != 0 ) return false; if ( pango_font_description_get_style(a) != pango_font_description_get_style(b) ) return false; if ( pango_font_description_get_variant(a) != pango_font_description_get_variant(b) ) return false; if ( pango_font_description_get_weight(a) != pango_font_description_get_weight(b) ) return false; if ( pango_font_description_get_stretch(a) != pango_font_description_get_stretch(b) ) return false; return true; }
JNIEXPORT jint JNICALL Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1get_1style ( JNIEnv* env, jclass cls, jlong _self ) { PangoStyle result; jint _result; PangoFontDescription* self; // convert parameter self self = (PangoFontDescription*) _self; // call function result = pango_font_description_get_style(self); // cleanup parameter self // translate return value to JNI type _result = (jint) result; // and finally return _result; }
bool GtkToolkitUiSettings::GetDefaultFont(FontDetails& font) { gchararray font_face = 0; g_object_get(m_settings, "gtk-font-name", &font_face, NULL); PangoFontDescription* font_desc = pango_font_description_from_string(font_face); g_free(font_face); if (!font_desc) return false; const char* family = pango_font_description_get_family(font_desc); if (family) { if (strcmp(family, "Sans") == 0) font.type = SANSSERIF; else if (strcmp(family, "Serif") == 0) font.type = SERIF; else if (strcmp(family, "Monospace") == 0) font.type = MONOSPACE; font.family = strdup(family); } font.weight = pango_font_description_get_weight(font_desc) / 100; font.italic = pango_font_description_get_style(font_desc) == PANGO_STYLE_ITALIC; font.smallcaps = pango_font_description_get_variant(font_desc) == PANGO_VARIANT_SMALL_CAPS; double size = pango_font_description_get_size(font_desc) / PANGO_SCALE; font.size = size; pango_font_description_free(font_desc); return true; }
bool PangoFontInfo::ParseFontDescription(const PangoFontDescription *desc) { Clear(); const char* family = pango_font_description_get_family(desc); if (!family) { char* desc_str = pango_font_description_to_string(desc); tprintf("WARNING: Could not parse family name from description: '%s'\n", desc_str); g_free(desc_str); return false; } family_name_ = string(family); desc_ = pango_font_description_copy(desc); is_monospace_ = IsMonospaceFontFamily(family); // Set font size in points font_size_ = pango_font_description_get_size(desc); if (!pango_font_description_get_size_is_absolute(desc)) { font_size_ /= PANGO_SCALE; } PangoStyle style = pango_font_description_get_style(desc); is_italic_ = (PANGO_STYLE_ITALIC == style || PANGO_STYLE_OBLIQUE == style); is_smallcaps_ = (pango_font_description_get_variant(desc) == PANGO_VARIANT_SMALL_CAPS); is_bold_ = (pango_font_description_get_weight(desc) >= PANGO_WEIGHT_BOLD); // We dont have a way to detect whether a font is of type Fraktur. The fonts // we currently use all have "Fraktur" in their family name, so we do a // fragile but functional check for that here. is_fraktur_ = (strcasestr(family, "Fraktur") != NULL); return true; }
DiaFontStyle dia_font_get_style(const DiaFont* font) { guint style; static int weight_map[] = { DIA_FONT_ULTRALIGHT, DIA_FONT_LIGHT, DIA_FONT_WEIGHT_NORMAL, /* intentionaly ==0 */ DIA_FONT_MEDIUM, DIA_FONT_DEMIBOLD, /* not yet in Pango */ DIA_FONT_BOLD, DIA_FONT_ULTRABOLD, DIA_FONT_HEAVY }; PangoStyle pango_style = pango_font_description_get_style(font->pfd); PangoWeight pango_weight = pango_font_description_get_weight(font->pfd); g_assert(PANGO_WEIGHT_ULTRALIGHT <= pango_weight && pango_weight <= PANGO_WEIGHT_HEAVY); g_assert(PANGO_WEIGHT_ULTRALIGHT == 200); g_assert(PANGO_WEIGHT_NORMAL == 400); g_assert(PANGO_WEIGHT_BOLD == 700); style = weight_map[(pango_weight - PANGO_WEIGHT_ULTRALIGHT) / 100]; style |= (pango_style << 2); return style; }
// Calculate a Style "value" based on CSS values for ordering styles. static int StyleNameValue( const Glib::ustring &style ) { PangoFontDescription *pfd = pango_font_description_from_string ( style.c_str() ); int value = pango_font_description_get_weight ( pfd ) * 1000000 + pango_font_description_get_style ( pfd ) * 10000 + pango_font_description_get_stretch( pfd ) * 100 + pango_font_description_get_variant( pfd ); pango_font_description_free ( pfd ); return value; }
static int compare_font_descriptions (const PangoFontDescription *a, const PangoFontDescription *b) { int val = strcmp (pango_font_description_get_family(a), pango_font_description_get_family(b)); if (val != 0) return val; if (pango_font_description_get_weight(a) != pango_font_description_get_weight(b)) return pango_font_description_get_weight(a) - pango_font_description_get_weight(b); if (pango_font_description_get_style(a) != pango_font_description_get_style(b)) return pango_font_description_get_style(a) - pango_font_description_get_style(b); if (pango_font_description_get_stretch(a) != pango_font_description_get_stretch(b)) return pango_font_description_get_stretch(a) - pango_font_description_get_stretch(b); if (pango_font_description_get_stretch(a) != pango_font_description_get_stretch(b)) return pango_font_description_get_stretch(a) - pango_font_description_get_stretch(b); return 0; }
// need to avoid using the size field size_t font_descr_hash::operator()( PangoFontDescription *const &x) const { int h = 0; char const *theF = sp_font_description_get_family(x); h += (theF)?g_str_hash(theF):0; h *= 1128467; h += (int)pango_font_description_get_style(x); h *= 1128467; h += (int)pango_font_description_get_variant(x); h *= 1128467; h += (int)pango_font_description_get_weight(x); h *= 1128467; h += (int)pango_font_description_get_stretch(x); return h; }
void mucharmap_mini_font_selection_set_font_desc (MucharmapMiniFontSelection *fontsel, PangoFontDescription *font_desc) { GObject *object = G_OBJECT (fontsel); PangoFontDescription *new_font_desc; const char *new_font_family; g_return_if_fail (MUCHARMAP_IS_MINI_FONT_SELECTION (fontsel)); g_return_if_fail (font_desc != NULL); g_object_freeze_notify (object); new_font_desc = pango_font_description_copy (font_desc); new_font_family = pango_font_description_get_family (new_font_desc); if (!new_font_family) { pango_font_description_set_family (new_font_desc, "Sans"); new_font_family = pango_font_description_get_family (new_font_desc); } if ((!fontsel->font_desc || strcmp (pango_font_description_get_family (fontsel->font_desc), new_font_family) != 0) && pango_font_description_get_size (new_font_desc) > 0) fontsel->default_size = pango_font_description_get_size (new_font_desc) / PANGO_SCALE; if (fontsel->font_desc) pango_font_description_free (fontsel->font_desc); fontsel->font_desc = new_font_desc; update_font_family_combo (fontsel); /* treat oblique and italic both as italic */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->italic), pango_font_description_get_style (fontsel->font_desc) == PANGO_STYLE_ITALIC || pango_font_description_get_style (fontsel->font_desc) == PANGO_STYLE_OBLIQUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->bold), pango_font_description_get_weight (fontsel->font_desc) > PANGO_WEIGHT_NORMAL); gtk_adjustment_set_value ( GTK_ADJUSTMENT (fontsel->size_adj), pango_font_description_get_size (fontsel->font_desc) / PANGO_SCALE); g_object_notify (G_OBJECT (fontsel), "font-desc"); g_object_thaw_notify (object); }
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 (); }
wxFontStyle wxNativeFontInfo::GetStyle() const { wxFontStyle m_style = wxFONTSTYLE_NORMAL; switch (pango_font_description_get_style( description )) { case PANGO_STYLE_NORMAL: m_style = wxFONTSTYLE_NORMAL; break; case PANGO_STYLE_ITALIC: m_style = wxFONTSTYLE_ITALIC; break; case PANGO_STYLE_OBLIQUE: m_style = wxFONTSTYLE_SLANT; break; } return m_style; }
/** * rpt_common_rptfont_from_pango_description: * @description: a #PangoFontDescription. * * Returns: a new allocated #RptFont from a #PangoFontDescription. */ RptFont *rpt_common_rptfont_from_pango_description (const PangoFontDescription *description) { RptFont *font; font = rpt_common_rptfont_new (); font->name = (gchar *)pango_font_description_get_family (description); font->size = pango_font_description_get_size (description) / PANGO_SCALE; font->bold = (pango_font_description_get_weight (description) == PANGO_WEIGHT_BOLD); font->italic = (pango_font_description_get_style (description) == PANGO_STYLE_ITALIC); font->underline = PANGO_UNDERLINE_NONE; font->strike = FALSE; font->color = rpt_common_rptcolor_new (); font->color->a = 1.0; return font; }
void ZLGtkPaintContext::setFont(const std::string &family, int size, bool bold, bool italic) { bool fontChanged = false; if (myFontDescription == 0) { myFontDescription = pango_font_description_new(); fontChanged = true; } const char *oldFamily = pango_font_description_get_family(myFontDescription); if ((oldFamily == 0) || (family != oldFamily)) { pango_font_description_set_family(myFontDescription, family.c_str()); fontChanged = true; } int newSize = size * PANGO_SCALE; if (pango_font_description_get_size(myFontDescription) != newSize) { pango_font_description_set_size(myFontDescription, newSize); fontChanged = true; } PangoWeight newWeight = bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL; if (pango_font_description_get_weight(myFontDescription) != newWeight) { pango_font_description_set_weight(myFontDescription, newWeight); fontChanged = true; } PangoStyle newStyle = italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL; if (pango_font_description_get_style(myFontDescription) != newStyle) { pango_font_description_set_style(myFontDescription, newStyle); fontChanged = true; } if (fontChanged) { if (myContext != 0) { myAnalysis.font = pango_context_load_font(myContext, myFontDescription); myAnalysis.shape_engine = pango_font_find_shaper(myAnalysis.font, 0, 0); PangoFontMetrics *metrics = pango_font_get_metrics(myAnalysis.font, myAnalysis.language); myDescent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; } myStringHeight = -1; mySpaceWidth = -1; } }
PP_Bool ppb_browser_font_trusted_describe(PP_Resource font, struct PP_BrowserFont_Trusted_Description *description, struct PP_BrowserFont_Trusted_Metrics *metrics) { struct pp_browser_font_s *bf = pp_resource_acquire(font, PP_RESOURCE_BROWSER_FONT); if (!bf) return PP_FALSE; memset(description, 0, sizeof(*description)); memset(metrics, 0, sizeof(*metrics)); const char *s_family = pango_font_description_get_family(bf->font_desc); description->face = PP_MakeString(s_family); description->family = bf->family >= 0 ? bf->family : 0; description->size = pango_font_description_get_size(bf->font_desc) / PANGO_SCALE; description->weight = pango_font_description_get_weight(bf->font_desc)/100 - 1; description->italic = (pango_font_description_get_style(bf->font_desc) != PANGO_STYLE_NORMAL); description->small_caps = (pango_font_description_get_variant(bf->font_desc) == PANGO_VARIANT_SMALL_CAPS); description->letter_spacing = bf->letter_spacing; description->word_spacing = bf->word_spacing; PangoFontMetrics *m = pango_font_get_metrics(bf->font, NULL); // TODO: use fontconfig-specific structures in pango to determine height and x-height metrics->ascent = pango_font_metrics_get_ascent(m) / PANGO_SCALE; metrics->descent = pango_font_metrics_get_descent(m) / PANGO_SCALE; metrics->height = (pango_font_metrics_get_ascent(m) + pango_font_metrics_get_descent(m)) / PANGO_SCALE; metrics->line_spacing = 1; // TODO: get actual line spacing metrics->x_height = metrics->height; // TODO: find out actual x-height pango_font_metrics_unref(m); pp_resource_release(font); return PP_TRUE; }
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; }
void wxFontRefData::InitFromNative() { #if wxUSE_UNICODE // Get native info PangoFontDescription *desc = m_nativeFontInfo.description; // init fields m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) ); m_pointSize = static_cast<float>(pango_font_description_get_size( desc )) / PANGO_SCALE; switch (pango_font_description_get_style( desc )) { case PANGO_STYLE_NORMAL: m_style = wxFONTSTYLE_NORMAL; break; case PANGO_STYLE_ITALIC: m_style = wxFONTSTYLE_ITALIC; break; case PANGO_STYLE_OBLIQUE: m_style = wxFONTSTYLE_SLANT; break; } m_weight = pango_font_description_get_weight( desc ); #else // X11 // get the font parameters from the XLFD // ------------------------------------- m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY); wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper(); if ( !w.empty() && w != wxT('*') ) m_weight = ParseWeightString(w); else m_weight = wxFONTWEIGHT_NORMAL; switch ( wxToupper( m_nativeFontInfo. GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() ) { case wxT('I'): // italique m_style = wxFONTSTYLE_ITALIC; break; case wxT('O'): // oblique m_style = wxFONTSTYLE_SLANT; break; default: m_style = wxFONTSTYLE_NORMAL; } long ptSize; if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) ) { // size in XLFD is in 10 point units m_pointSize = (int)(ptSize / 10); } else { m_pointSize = wxDEFAULT_FONT_SIZE; } // examine the spacing: if the font is monospaced, assume wxFONTFAMILY_TELETYPE // family for compatibility with the old code which used it instead of // IsFixedWidth() if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING).Upper() == wxT('M') ) { m_family = wxFONTFAMILY_TELETYPE; } else // not monospaceed { // don't even try guessing it, it doesn't work for too many fonts // anyhow m_family = wxFONTFAMILY_UNKNOWN; } // X fonts are never underlined... m_underlined = false; // deal with font encoding wxString registry = m_nativeFontInfo.GetXFontComponent(wxXLFD_REGISTRY).Upper(), encoding = m_nativeFontInfo.GetXFontComponent(wxXLFD_ENCODING).Upper(); if ( registry == wxT("ISO8859") ) { int cp; if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); } } else if ( registry == wxT("MICROSOFT") ) { int cp; if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); } } else if ( registry == wxT("KOI8") ) { m_encoding = wxFONTENCODING_KOI8; } else // unknown encoding { // may be give a warning here? or use wxFontMapper? m_encoding = wxFONTENCODING_SYSTEM; } #endif // Pango/X11 }
static gchar *_watermark_get_svgdoc(dt_iop_module_t *self, dt_iop_watermark_data_t *data, const dt_image_t *image) { gsize length; gchar *svgdoc = NULL; gchar configdir[PATH_MAX] = { 0 }; gchar datadir[PATH_MAX] = { 0 }; gchar *filename; dt_loc_get_datadir(datadir, sizeof(datadir)); dt_loc_get_user_config_dir(configdir, sizeof(configdir)); g_strlcat(datadir, "/watermarks/", sizeof(datadir)); g_strlcat(configdir, "/watermarks/", sizeof(configdir)); g_strlcat(datadir, data->filename, sizeof(datadir)); g_strlcat(configdir, data->filename, sizeof(configdir)); if(g_file_test(configdir, G_FILE_TEST_EXISTS)) filename = configdir; else if(g_file_test(datadir, G_FILE_TEST_EXISTS)) filename = datadir; else return NULL; gchar *svgdata = NULL; char datetime[200]; // EXIF datetime struct tm tt_exif = { 0 }; if(sscanf(image->exif_datetime_taken, "%d:%d:%d %d:%d:%d", &tt_exif.tm_year, &tt_exif.tm_mon, &tt_exif.tm_mday, &tt_exif.tm_hour, &tt_exif.tm_min, &tt_exif.tm_sec) == 6) { tt_exif.tm_year -= 1900; tt_exif.tm_mon--; } // Current datetime struct tm tt_cur = { 0 }; time_t t = time(NULL); (void)localtime_r(&t, &tt_cur); if(g_file_get_contents(filename, &svgdata, &length, NULL)) { // File is loaded lets substitute strings if found... // Darktable internal svgdoc = _string_substitute(svgdata, "$(DARKTABLE.NAME)", PACKAGE_NAME); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } svgdoc = _string_substitute(svgdata, "$(DARKTABLE.VERSION)", PACKAGE_VERSION); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // Simple text from watermark module gchar buffer[1024]; if (data->font[0] && data->text[0]) { g_snprintf(buffer, sizeof(buffer), "%s", data->text); svgdoc = _string_substitute(svgdata, "$(WATERMARK_TEXT)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } PangoFontDescription *font = pango_font_description_from_string(data->font); const PangoStyle font_style = pango_font_description_get_style(font); const int font_weight = (int)pango_font_description_get_weight(font); g_snprintf(buffer, sizeof(buffer), "%s", pango_font_description_get_family(font)); svgdoc = _string_substitute(svgdata, "$(WATERMARK_FONT_FAMILY)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } switch (font_style) { case PANGO_STYLE_OBLIQUE: g_strlcpy(buffer, "oblique", sizeof(buffer)); break; case PANGO_STYLE_ITALIC: g_strlcpy(buffer, "italic", sizeof(buffer)); break; default: g_strlcpy(buffer, "normal", sizeof(buffer)); break; } svgdoc = _string_substitute(svgdata, "$(WATERMARK_FONT_STYLE)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } g_snprintf(buffer, sizeof(buffer), "%d", font_weight); svgdoc = _string_substitute(svgdata, "$(WATERMARK_FONT_WEIGHT)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } pango_font_description_free(font); } // watermark color GdkRGBA c = { data->color[0], data->color[1], data->color[2], 1.0f }; g_snprintf(buffer, sizeof(buffer), "%s", gdk_rgba_to_string(&c)); svgdoc = _string_substitute(svgdata, "$(WATERMARK_COLOR)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // Current image ID g_snprintf(buffer, sizeof(buffer), "%d", image->id); svgdoc = _string_substitute(svgdata, "$(IMAGE.ID)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // Current image dt_image_print_exif(image, buffer, sizeof(buffer)); svgdoc = _string_substitute(svgdata, "$(IMAGE.EXIF)", buffer); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // Image exif // EXIF date svgdoc = _string_substitute(svgdata, "$(EXIF.DATE)", image->exif_datetime_taken); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.SECOND) -- 00..60 strftime(datetime, sizeof(datetime), "%S", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.SECOND)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.MINUTE) -- 00..59 strftime(datetime, sizeof(datetime), "%M", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.MINUTE)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.HOUR) -- 00..23 strftime(datetime, sizeof(datetime), "%H", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.HOUR)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.HOUR_AMPM) -- 01..12 strftime(datetime, sizeof(datetime), "%I %p", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.HOUR_AMPM)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.DAY) -- 01..31 strftime(datetime, sizeof(datetime), "%d", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.DAY)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.MONTH) -- 01..12 strftime(datetime, sizeof(datetime), "%m", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.MONTH)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.SHORT_MONTH) -- Jan, Feb, .., Dec, localized strftime(datetime, sizeof(datetime), "%b", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.SHORT_MONTH)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.LONG_MONTH) -- January, February, .., December, localized strftime(datetime, sizeof(datetime), "%B", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.LONG_MONTH)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.SHORT_YEAR) -- 12 strftime(datetime, sizeof(datetime), "%y", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.SHORT_YEAR)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(EXIF.DATE.LONG_YEAR) -- 2012 strftime(datetime, sizeof(datetime), "%Y", &tt_exif); svgdoc = _string_substitute(svgdata, "$(EXIF.DATE.LONG_YEAR)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // Current date // $(DATE) -- YYYY: dt_gettime_t(datetime, sizeof(datetime), t); svgdoc = _string_substitute(svgdata, "$(DATE)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.SECOND) -- 00..60 strftime(datetime, sizeof(datetime), "%S", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.SECOND)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.MINUTE) -- 00..59 strftime(datetime, sizeof(datetime), "%M", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.MINUTE)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.HOUR) -- 00..23 strftime(datetime, sizeof(datetime), "%H", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.HOUR)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.HOUR_AMPM) -- 01..12 strftime(datetime, sizeof(datetime), "%I %p", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.HOUR_AMPM)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.DAY) -- 01..31 strftime(datetime, sizeof(datetime), "%d", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.DAY)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.MONTH) -- 01..12 strftime(datetime, sizeof(datetime), "%m", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.MONTH)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.SHORT_MONTH) -- Jan, Feb, .., Dec, localized strftime(datetime, sizeof(datetime), "%b", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.SHORT_MONTH)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.LONG_MONTH) -- January, February, .., December, localized strftime(datetime, sizeof(datetime), "%B", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.LONG_MONTH)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.SHORT_YEAR) -- 12 strftime(datetime, sizeof(datetime), "%y", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.SHORT_YEAR)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } // $(DATE.LONG_YEAR) -- 2012 strftime(datetime, sizeof(datetime), "%Y", &tt_cur); svgdoc = _string_substitute(svgdata, "$(DATE.LONG_YEAR)", datetime); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } svgdoc = _string_substitute(svgdata, "$(EXIF.MAKER)", image->camera_maker); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } svgdoc = _string_substitute(svgdata, "$(EXIF.MODEL)", image->camera_model); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } svgdoc = _string_substitute(svgdata, "$(EXIF.LENS)", image->exif_lens); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } svgdoc = _string_substitute(svgdata, "$(IMAGE.FILENAME)", image->filename); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } gchar *basename = g_path_get_basename(image->filename); if(g_strrstr(basename, ".")) *(g_strrstr(basename, ".")) = '\0'; svgdoc = _string_substitute(svgdata, "$(IMAGE.BASENAME)", basename); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } g_free(basename); // TODO: auto generate that code? GList *res; res = dt_metadata_get(image->id, "Xmp.dc.creator", NULL); svgdoc = _string_substitute(svgdata, "$(Xmp.dc.creator)", (res ? res->data : "")); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } if(res) { g_list_free_full(res, &g_free); } res = dt_metadata_get(image->id, "Xmp.dc.publisher", NULL); svgdoc = _string_substitute(svgdata, "$(Xmp.dc.publisher)", (res ? res->data : "")); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } if(res) { g_list_free_full(res, &g_free); } res = dt_metadata_get(image->id, "Xmp.dc.title", NULL); svgdoc = _string_substitute(svgdata, "$(Xmp.dc.title)", (res ? res->data : "")); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } if(res) { g_list_free_full(res, &g_free); } res = dt_metadata_get(image->id, "Xmp.dc.description", NULL); svgdoc = _string_substitute(svgdata, "$(Xmp.dc.description)", (res ? res->data : "")); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } if(res) { g_list_free_full(res, &g_free); } res = dt_metadata_get(image->id, "Xmp.dc.rights", NULL); svgdoc = _string_substitute(svgdata, "$(Xmp.dc.rights)", (res ? res->data : "")); if(svgdoc != svgdata) { g_free(svgdata); svgdata = svgdoc; } if(res) { g_list_free_full(res, &g_free); } } return svgdoc; }
/** * 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); }
void wxFontRefData::InitFromNative() { #if wxUSE_UNICODE // Get native info PangoFontDescription *desc = m_nativeFontInfo.description; // init fields m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) ); m_pointSize = pango_font_description_get_size( desc ) / PANGO_SCALE; switch (pango_font_description_get_style( desc )) { case PANGO_STYLE_NORMAL: m_style = wxFONTSTYLE_NORMAL; break; case PANGO_STYLE_ITALIC: m_style = wxFONTSTYLE_ITALIC; break; case PANGO_STYLE_OBLIQUE: m_style = wxFONTSTYLE_SLANT; break; } // Not defined in some Pango versions #define wxPANGO_WEIGHT_SEMIBOLD 600 switch (pango_font_description_get_weight( desc )) { case PANGO_WEIGHT_ULTRALIGHT: case PANGO_WEIGHT_LIGHT: m_weight = wxFONTWEIGHT_LIGHT; break; default: wxFAIL_MSG(wxT("unknown Pango font weight")); // fall through case PANGO_WEIGHT_NORMAL: m_weight = wxFONTWEIGHT_NORMAL; break; case wxPANGO_WEIGHT_SEMIBOLD: case PANGO_WEIGHT_BOLD: case PANGO_WEIGHT_ULTRABOLD: case PANGO_WEIGHT_HEAVY: m_weight = wxFONTWEIGHT_BOLD; break; } if (m_faceName == wxT("monospace")) { m_family = wxFONTFAMILY_TELETYPE; } else if (m_faceName == wxT("sans")) { m_family = wxFONTFAMILY_SWISS; } else { m_family = wxFONTFAMILY_UNKNOWN; } // Pango description are never underlined (?) m_underlined = false; // Cannot we choose that m_encoding = wxFONTENCODING_SYSTEM; #else // X11 // get the font parameters from the XLFD // ------------------------------------- m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY); m_weight = wxFONTWEIGHT_NORMAL; wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper(); if ( !w.empty() && w != wxT('*') ) { // the test below catches all of BOLD, EXTRABOLD, DEMIBOLD, ULTRABOLD // and BLACK if ( ((w[0u] == wxT('B') && (!wxStrcmp(w.c_str() + 1, wxT("OLD")) || !wxStrcmp(w.c_str() + 1, wxT("LACK"))))) || wxStrstr(w.c_str() + 1, wxT("BOLD")) ) { m_weight = wxFONTWEIGHT_BOLD; } else if ( w == wxT("LIGHT") || w == wxT("THIN") ) { m_weight = wxFONTWEIGHT_LIGHT; } } switch ( wxToupper( m_nativeFontInfo. GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() ) { case wxT('I'): // italique m_style = wxFONTSTYLE_ITALIC; break; case wxT('O'): // oblique m_style = wxFONTSTYLE_SLANT; break; default: m_style = wxFONTSTYLE_NORMAL; } long ptSize; if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) ) { // size in XLFD is in 10 point units m_pointSize = (int)(ptSize / 10); } else { m_pointSize = wxDEFAULT_FONT_SIZE; } // examine the spacing: if the font is monospaced, assume wxTELETYPE // family for compatibility with the old code which used it instead of // IsFixedWidth() if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING).Upper() == wxT('M') ) { m_family = wxFONTFAMILY_TELETYPE; } else // not monospaceed { // don't even try guessing it, it doesn't work for too many fonts // anyhow m_family = wxFONTFAMILY_UNKNOWN; } // X fonts are never underlined... m_underlined = false; // deal with font encoding wxString registry = m_nativeFontInfo.GetXFontComponent(wxXLFD_REGISTRY).Upper(), encoding = m_nativeFontInfo.GetXFontComponent(wxXLFD_ENCODING).Upper(); if ( registry == wxT("ISO8859") ) { int cp; if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); } } else if ( registry == wxT("MICROSOFT") ) { int cp; if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 ) { m_encoding = (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); } } else if ( registry == wxT("KOI8") ) { m_encoding = wxFONTENCODING_KOI8; } else // unknown encoding { // may be give a warning here? or use wxFontMapper? m_encoding = wxFONTENCODING_SYSTEM; } #endif // Pango/X11 }
/* * 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; }
bool Font::isItalic() const { return pango_font_description_get_style(desc_) == PANGO_STYLE_ITALIC; }
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; }
/** * gail_misc_get_default_attributes: * @attrib_set: The #AtkAttributeSet to add the attribute to * @layout: The PangoLayout from which the attributes will be obtained * @widget: The GtkWidget for which the default attributes are required. * * Adds the default attributes to the specified attribute set. * * Returns: A pointer to the #AtkAttributeSet. **/ AtkAttributeSet* gail_misc_get_default_attributes (AtkAttributeSet *attrib_set, PangoLayout *layout, GtkWidget *widget) { PangoContext *context; GtkStyleContext *style_context; gint int_value; PangoWrapMode mode; GdkRGBA color; gchar *value; attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_DIRECTION, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_DIRECTION, gtk_widget_get_direction (widget)))); context = pango_layout_get_context (layout); if (context) { PangoLanguage* language; PangoFontDescription* font; language = pango_context_get_language (context); if (language) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LANGUAGE, g_strdup (pango_language_to_string (language))); } font = pango_context_get_font_description (context); if (font) { attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STYLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STYLE, pango_font_description_get_style (font)))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_VARIANT, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_VARIANT, pango_font_description_get_variant (font)))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRETCH, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRETCH, pango_font_description_get_stretch (font)))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FAMILY_NAME, g_strdup (pango_font_description_get_family (font))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WEIGHT, g_strdup_printf ("%d", pango_font_description_get_weight (font))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SIZE, g_strdup_printf ("%i", pango_font_description_get_size (font) / PANGO_SCALE)); } } if (pango_layout_get_justify (layout)) { int_value = 3; } else { PangoAlignment align; align = pango_layout_get_alignment (layout); if (align == PANGO_ALIGN_LEFT) int_value = 0; else if (align == PANGO_ALIGN_CENTER) int_value = 2; else /* if (align == PANGO_ALIGN_RIGHT) */ int_value = 1; } attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_JUSTIFICATION, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_JUSTIFICATION, int_value))); mode = pango_layout_get_wrap (layout); if (mode == PANGO_WRAP_WORD) int_value = 2; else /* if (mode == PANGO_WRAP_CHAR) */ int_value = 1; attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WRAP_MODE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_WRAP_MODE, int_value))); style_context = gtk_widget_get_style_context (widget); gtk_style_context_get_background_color (style_context, 0, &color); value = g_strdup_printf ("%u,%u,%u", (guint) ceil (color.red * 65536 - color.red), (guint) ceil (color.green * 65536 - color.green), (guint) ceil (color.blue * 65536 - color.blue)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_COLOR, value); gtk_style_context_get_color (style_context, 0, &color); value = g_strdup_printf ("%u,%u,%u", (guint) ceil (color.red * 65536 - color.red), (guint) ceil (color.green * 65536 - color.green), (guint) ceil (color.blue * 65536 - color.blue)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_COLOR, value); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_STIPPLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_FG_STIPPLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_STIPPLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_BG_STIPPLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_STRIKETHROUGH, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_STRIKETHROUGH, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_UNDERLINE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_UNDERLINE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RISE, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SCALE, g_strdup_printf ("%g", 1.0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_FULL_HEIGHT, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_BELOW_LINES, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_ABOVE_LINES, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_EDITABLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_EDITABLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INVISIBLE, g_strdup (atk_text_attribute_get_value (ATK_TEXT_ATTR_INVISIBLE, 0))); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INDENT, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RIGHT_MARGIN, g_strdup_printf ("%i", 0)); attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LEFT_MARGIN, g_strdup_printf ("%i", 0)); return attrib_set; }