gboolean create_tray(gpointer data) { if (tray_icon) return FALSE; destroy_other_tray(); tray_icon = gtk_status_icon_new(); g_signal_connect (G_OBJECT (tray_icon), "button-press-event", G_CALLBACK (tray_button_press_event_cb), NULL); g_signal_connect (G_OBJECT (tray_icon), "size-changed", G_CALLBACK (tray_size_changed_cb), NULL); g_signal_connect (G_OBJECT (tray_icon), "notify::embedded", G_CALLBACK (tray_embedded_cb), NULL); #if GTK_CHECK_VERSION(2,12,0) gtk_status_icon_set_tooltip_text (tray_icon, _("左:中英切換 中:小鍵盤 右:選項")); #else GtkTooltips *tips = gtk_tooltips_new (); gtk_status_icon_set_tooltip (GTK_TOOLTIPS (tips), tray_icon, _("左:中英切換 中:小鍵盤 右:選項"), NULL); #endif // Initiate Pango for drawing texts from default setting GtkWidget *wi = gtk_label_new (NULL); // for reference PangoContext *context = gtk_widget_get_pango_context(wi); PangoFontDescription* desc = pango_font_description_copy(pango_context_get_font_description(context)); // Copy one from wi for pango pango_font_description_set_size(desc, 9 * PANGO_SCALE); pango = gtk_widget_create_pango_layout(wi, NULL); pango_layout_set_font_description(pango, desc); gdk_color_parse("red", &red_color_fg); gdk_color_parse("blue", &blue_color_fg); gtk_widget_destroy(wi); load_tray_icon(); return FALSE; }
static void set_font(DiaRenderer *self, DiaFont *font, real height) { DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self); #ifndef HAVE_PANGOCAIRO_H DiaFontStyle style = dia_font_get_style (font); const char *family_name; #endif /* pango/cairo wants the font size, not the (line-) height */ real size = dia_font_get_size (font) * (height / dia_font_get_height (font)); PangoFontDescription *pfd = pango_font_description_copy (dia_font_get_description (font)); DIAG_NOTE(g_message("set_font %f %s", height, dia_font_get_family(font))); #ifdef HAVE_PANGOCAIRO_H /* select font and size */ pango_font_description_set_absolute_size (pfd, (int)(size * PANGO_SCALE)); pango_layout_set_font_description (renderer->layout, pfd); pango_font_description_free (pfd); #else family_name = dia_font_get_family(font); cairo_select_font_face ( renderer->cr, family_name, DIA_FONT_STYLE_GET_SLANT(style) == DIA_FONT_NORMAL ? CAIRO_FONT_SLANT_NORMAL : CAIRO_FONT_SLANT_ITALIC, DIA_FONT_STYLE_GET_WEIGHT(style) < DIA_FONT_MEDIUM ? CAIRO_FONT_WEIGHT_NORMAL : CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (renderer->cr, size); #endif DIAG_STATE(renderer->cr) /* for the interactive case we must maintain the font field in the base class */ if (self->is_interactive) { dia_font_ref(font); if (self->font) dia_font_unref(self->font); self->font = font; self->font_height = height; } }
manipulation manipulation_watermark_new() { manipulation watermark; watermark = (manipulation) g_malloc(sizeof(struct manip_str)); watermark->type = MANIP_WATERMARK; watermark->icon = &pixdata_watermark; watermark->settings = (watermark_settings) g_malloc(sizeof(struct manip_watermark_set)); ((watermark_settings)watermark->settings)->mode = TRUE; ((watermark_settings)watermark->settings)->text = ""; ((watermark_settings)watermark->settings)->font = pango_font_description_copy(pango_font_description_from_string("Sans 16px")); gdk_color_parse("black", &(((watermark_settings)watermark->settings)->color)); gdk_colormap_alloc_color(gdk_colormap_get_system(), &(((watermark_settings)watermark->settings)->color), TRUE, TRUE); ((watermark_settings)watermark->settings)->image_file = NULL; ((watermark_settings)watermark->settings)->image_sizemode = WM_IMG_NOSIZE; ((watermark_settings)watermark->settings)->image_size_percent = 25.0; ((watermark_settings)watermark->settings)->opacity = 100.0; ((watermark_settings)watermark->settings)->edge_distance = 0; ((watermark_settings)watermark->settings)->position = WM_POS_BR; return watermark; }
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; }
PangoLayout* dia_font_build_layout(const char* string, DiaFont* font, real height) { PangoLayout* layout; PangoAttrList* list; PangoAttribute* attr; guint length; PangoFontDescription *pfd; real factor; layout = pango_layout_new(dia_font_get_context()); length = string ? strlen(string) : 0; pango_layout_set_text(layout, string, length); list = pango_attr_list_new(); pfd = pango_font_description_copy (font->pfd); /* account for difference between size and height as well as between font height and given one */ factor = dia_font_get_size(font) / dia_font_get_height (font); pango_font_description_set_absolute_size (pfd, dcm_to_pdu (height) * factor); attr = pango_attr_font_desc_new(pfd); pango_font_description_free (pfd); attr->start_index = 0; attr->end_index = length; pango_attr_list_insert(list,attr); /* eats attr */ pango_layout_set_attributes(layout,list); pango_attr_list_unref(list); pango_layout_set_indent(layout,0); pango_layout_set_justify(layout,FALSE); pango_layout_set_alignment(layout,PANGO_ALIGN_LEFT); return layout; }
static void adjust_font_size (GtkWidget *widget, gpointer data, gint howmuch) { DEBUG_FUNCTION ("adjust_font_size"); DEBUG_ASSERT (widget != NULL); DEBUG_ASSERT (data != NULL); VteTerminal *terminal; PangoFontDescription *desired; gint newsize; gint columns, rows, owidth, oheight; /* Read the screen dimensions in cells. */ terminal = VTE_TERMINAL(widget); columns = vte_terminal_get_column_count (terminal); rows = vte_terminal_get_row_count (terminal); /* Take into account padding and border overhead. */ gtk_window_get_size(GTK_WINDOW(data), &owidth, &oheight); owidth -= vte_terminal_get_char_width (terminal) * columns; oheight -= vte_terminal_get_char_height (terminal) * rows; /* Calculate the new font size. */ desired = pango_font_description_copy (vte_terminal_get_font(terminal)); newsize = pango_font_description_get_size (desired) / PANGO_SCALE; newsize += howmuch; pango_font_description_set_size (desired, CLAMP(newsize, 4, 144) * PANGO_SCALE); /* Change the font, then resize the window so that we have the same * number of rows and columns. */ vte_terminal_set_font (terminal, desired); /*gtk_window_resize (GTK_WINDOW(data), columns * terminal->char_width + owidth, rows * terminal->char_height + oheight);*/ pango_font_description_free (desired); }
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; }
void _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest, GtkTextTag** tags, guint n_tags) { guint n = 0; guint left_margin_accumulative = 0; guint right_margin_accumulative = 0; while (n < n_tags) { GtkTextTag *tag = tags[n]; GtkTextAttributes *vals = tag->priv->values; g_assert (tag->priv->table != NULL); if (n > 0) g_assert (tags[n]->priv->priority > tags[n-1]->priv->priority); if (tag->priv->bg_color_set) { dest->appearance.bg_color = vals->appearance.bg_color; dest->appearance.draw_bg = TRUE; } if (tag->priv->fg_color_set) dest->appearance.fg_color = vals->appearance.fg_color; if (tag->priv->pg_bg_color_set) { dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color); } if (vals->font) { if (dest->font) pango_font_description_merge (dest->font, vals->font, TRUE); else dest->font = pango_font_description_copy (vals->font); } /* multiply all the scales together to get a composite */ if (tag->priv->scale_set) dest->font_scale *= vals->font_scale; if (tag->priv->justification_set) dest->justification = vals->justification; if (vals->direction != GTK_TEXT_DIR_NONE) dest->direction = vals->direction; if (tag->priv->left_margin_set) { if (tag->priv->accumulative_margin) left_margin_accumulative += vals->left_margin; else dest->left_margin = vals->left_margin; } if (tag->priv->indent_set) dest->indent = vals->indent; if (tag->priv->rise_set) dest->appearance.rise = vals->appearance.rise; if (tag->priv->right_margin_set) { if (tag->priv->accumulative_margin) right_margin_accumulative += vals->right_margin; else dest->right_margin = vals->right_margin; } if (tag->priv->pixels_above_lines_set) dest->pixels_above_lines = vals->pixels_above_lines; if (tag->priv->pixels_below_lines_set) dest->pixels_below_lines = vals->pixels_below_lines; if (tag->priv->pixels_inside_wrap_set) dest->pixels_inside_wrap = vals->pixels_inside_wrap; if (tag->priv->tabs_set) { if (dest->tabs) pango_tab_array_free (dest->tabs); dest->tabs = pango_tab_array_copy (vals->tabs); } if (tag->priv->wrap_mode_set) dest->wrap_mode = vals->wrap_mode; if (tag->priv->underline_set) dest->appearance.underline = vals->appearance.underline; if (tag->priv->strikethrough_set) dest->appearance.strikethrough = vals->appearance.strikethrough; if (tag->priv->invisible_set) dest->invisible = vals->invisible; if (tag->priv->editable_set) dest->editable = vals->editable; if (tag->priv->bg_full_height_set) dest->bg_full_height = vals->bg_full_height; if (tag->priv->language_set) dest->language = vals->language; ++n; } dest->left_margin += left_margin_accumulative; dest->right_margin += right_margin_accumulative; }
static void mucharmap_mini_font_selection_init (MucharmapMiniFontSelection *fontsel) { GtkCellRenderer *renderer; GtkStyle *style; AtkObject *accessib; gtk_widget_ensure_style (GTK_WIDGET (fontsel)); style = gtk_widget_get_style (GTK_WIDGET (fontsel)); fontsel->font_desc = pango_font_description_copy (style->font_desc); fontsel->default_size = -1; fontsel->size_adj = gtk_adjustment_new (MIN_FONT_SIZE, MIN_FONT_SIZE, MAX_FONT_SIZE, 1, 8, 0); accessib = gtk_widget_get_accessible (GTK_WIDGET (fontsel)); atk_object_set_name (accessib, _("Font")); gtk_box_set_spacing (GTK_BOX (fontsel), 6); fontsel->family = gtk_combo_box_new (); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (fontsel->family), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (fontsel->family), renderer, "text", COL_FAMILIY, NULL); gtk_widget_show (fontsel->family); accessib = gtk_widget_get_accessible (fontsel->family); atk_object_set_name (accessib, _("Font Family")); fontsel->bold = gtk_toggle_button_new_with_mnemonic (GTK_STOCK_BOLD); gtk_button_set_use_stock (GTK_BUTTON (fontsel->bold), TRUE); gtk_widget_show (fontsel->bold); g_signal_connect (fontsel->bold, "toggled", G_CALLBACK (bold_toggled), fontsel); fontsel->italic = gtk_toggle_button_new_with_mnemonic (GTK_STOCK_ITALIC); gtk_button_set_use_stock (GTK_BUTTON (fontsel->italic), TRUE); gtk_widget_show (fontsel->italic); g_signal_connect (fontsel->italic, "toggled", G_CALLBACK (italic_toggled), fontsel); fontsel->size = gtk_spin_button_new (GTK_ADJUSTMENT (fontsel->size_adj), 0, 0); gtk_widget_show (fontsel->size); accessib = gtk_widget_get_accessible (fontsel->size); atk_object_set_name (accessib, _("Font Size")); g_signal_connect (fontsel->size_adj, "value-changed", G_CALLBACK (font_size_changed), fontsel); fill_font_families_combo (fontsel); gtk_combo_box_set_active (GTK_COMBO_BOX (fontsel->family), -1); g_signal_connect (fontsel->family, "changed", G_CALLBACK (family_combo_changed), fontsel); gtk_box_pack_start (GTK_BOX (fontsel), fontsel->family, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (fontsel), fontsel->bold, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (fontsel), fontsel->italic, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (fontsel), fontsel->size, FALSE, FALSE, 0); gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (fontsel->family), FALSE); gtk_button_set_focus_on_click (GTK_BUTTON (fontsel->bold), FALSE); gtk_button_set_focus_on_click (GTK_BUTTON (fontsel->italic), FALSE); gtk_container_set_border_width (GTK_CONTAINER (fontsel), 6); gtk_widget_show_all (GTK_WIDGET (fontsel)); }
static PangoLayout* create_layout(HippoCanvasText *text, int allocation_width) { HippoCanvasBox *box = HIPPO_CANVAS_BOX(text); PangoLayout *layout; HippoCanvasStyle *style = hippo_canvas_context_get_style(HIPPO_CANVAS_CONTEXT(text)); g_return_val_if_fail(box->context != NULL, NULL); layout = hippo_canvas_context_create_layout(box->context); if (box->font_desc) { PangoFontDescription *merged = pango_font_description_copy(hippo_canvas_style_get_font(style)); pango_font_description_merge(merged, box->font_desc, TRUE); pango_layout_set_font_description(layout, merged); pango_font_description_free(merged); } else { pango_layout_set_font_description(layout, hippo_canvas_style_get_font(style)); } { PangoAttrList *attrs; HippoTextDecoration decoration = hippo_canvas_style_get_text_decoration(style); if (text->attributes) attrs = pango_attr_list_copy(text->attributes); else attrs = pango_attr_list_new(); if (ABS(1.0 - text->font_scale) > .000001) { PangoAttribute *attr = pango_attr_scale_new(text->font_scale); attr->start_index = 0; attr->end_index = G_MAXUINT; pango_attr_list_insert(attrs, attr); } if ((decoration & HIPPO_TEXT_DECORATION_UNDERLINE) != 0) { PangoAttribute *attr = pango_attr_underline_new(TRUE); attr->start_index = 0; attr->end_index = G_MAXUINT; pango_attr_list_insert(attrs, attr); } if ((decoration & HIPPO_TEXT_DECORATION_LINE_THROUGH) != 0) { PangoAttribute *attr = pango_attr_strikethrough_new(TRUE); attr->start_index = 0; attr->end_index = G_MAXUINT; pango_attr_list_insert(attrs, attr); } pango_layout_set_attributes(layout, attrs); pango_attr_list_unref(attrs); } if (text->text != NULL) { pango_layout_set_text(layout, text->text, -1); } if (allocation_width >= 0) { int layout_width, layout_height; pango_layout_get_size(layout, &layout_width, &layout_height); layout_width /= PANGO_SCALE; layout_height /= PANGO_SCALE; /* Force layout smaller if required, but we don't want to make * the layout _wider_ because it breaks alignment, so only do * this if required. */ if (layout_width > allocation_width) { pango_layout_set_width(layout, allocation_width * PANGO_SCALE); /* If we set ellipsize, then it overrides wrapping. If we get * too-small allocation for HIPPO_CANVAS_SIZE_FULL_WIDTH, then * we want to ellipsize instead of wrapping. */ if (text->size_mode == HIPPO_CANVAS_SIZE_WRAP_WORD) { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); } else { pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); } /* For now if we say ellipsize end, we always just want one line. * Maybe this should be an orthogonal property? */ if (text->size_mode == HIPPO_CANVAS_SIZE_ELLIPSIZE_END) { pango_layout_set_single_paragraph_mode(layout, TRUE); /* Pango's line separator character in this case is ugly, so we * fix it. Not a very efficient approach, but oh well. */ if (text->text != NULL) { char *new_text = remove_newlines(text->text); /* avoid making the layout recompute everything * if we didn't have newlines anyhow */ if (strcmp(text->text, new_text) != 0) { pango_layout_set_text(layout, new_text, -1); } g_free(new_text); } } } } return layout; }
void _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest, GtkTextTag** tags, guint n_tags) { guint n = 0; guint left_margin_accumulative = 0; guint right_margin_accumulative = 0; while (n < n_tags) { GtkTextTag *tag = tags[n]; GtkTextAttributes *vals = tag->priv->values; g_assert (tag->priv->table != NULL); if (n > 0) g_assert (tags[n]->priv->priority > tags[n-1]->priv->priority); if (tag->priv->bg_color_set) { if (dest->appearance.rgba[0]) { gdk_rgba_free (dest->appearance.rgba[0]); dest->appearance.rgba[0] = NULL; } if (vals->appearance.rgba[0]) dest->appearance.rgba[0] = gdk_rgba_copy (vals->appearance.rgba[0]); dest->appearance.draw_bg = TRUE; } if (tag->priv->fg_color_set) { if (dest->appearance.rgba[1]) { gdk_rgba_free (dest->appearance.rgba[1]); dest->appearance.rgba[1] = NULL; } if (vals->appearance.rgba[1]) dest->appearance.rgba[1] = gdk_rgba_copy (vals->appearance.rgba[1]); } if (tag->priv->pg_bg_color_set) { if (dest->pg_bg_rgba) { gdk_rgba_free (dest->pg_bg_rgba); dest->pg_bg_rgba = NULL; } if (dest->pg_bg_color) { G_GNUC_BEGIN_IGNORE_DEPRECATIONS gdk_color_free (dest->pg_bg_color); dest->pg_bg_color = NULL; G_GNUC_END_IGNORE_DEPRECATIONS } if (vals->pg_bg_rgba) dest->pg_bg_rgba = gdk_rgba_copy (vals->pg_bg_rgba); G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (vals->pg_bg_color) dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color); G_GNUC_END_IGNORE_DEPRECATIONS } if (vals->font) { if (dest->font) pango_font_description_merge (dest->font, vals->font, TRUE); else dest->font = pango_font_description_copy (vals->font); } /* multiply all the scales together to get a composite */ if (tag->priv->scale_set) dest->font_scale *= vals->font_scale; if (tag->priv->justification_set) dest->justification = vals->justification; if (vals->direction != GTK_TEXT_DIR_NONE) dest->direction = vals->direction; if (tag->priv->left_margin_set) { if (tag->priv->accumulative_margin) left_margin_accumulative += vals->left_margin; else dest->left_margin = vals->left_margin; } if (tag->priv->indent_set) dest->indent = vals->indent; if (tag->priv->rise_set) dest->appearance.rise = vals->appearance.rise; if (tag->priv->right_margin_set) { if (tag->priv->accumulative_margin) right_margin_accumulative += vals->right_margin; else dest->right_margin = vals->right_margin; } if (tag->priv->pixels_above_lines_set) dest->pixels_above_lines = vals->pixels_above_lines; if (tag->priv->pixels_below_lines_set) dest->pixels_below_lines = vals->pixels_below_lines; if (tag->priv->pixels_inside_wrap_set) dest->pixels_inside_wrap = vals->pixels_inside_wrap; if (tag->priv->tabs_set) { if (dest->tabs) pango_tab_array_free (dest->tabs); dest->tabs = pango_tab_array_copy (vals->tabs); } if (tag->priv->wrap_mode_set) dest->wrap_mode = vals->wrap_mode; if (tag->priv->underline_set) dest->appearance.underline = vals->appearance.underline; if (GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (&vals->appearance)) { GdkRGBA rgba; GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA (&vals->appearance, &rgba); GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA (&dest->appearance, &rgba); GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA_SET (&dest->appearance, TRUE); } if (tag->priv->strikethrough_set) dest->appearance.strikethrough = vals->appearance.strikethrough; if (GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (&vals->appearance)) { GdkRGBA rgba; GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA (&vals->appearance, &rgba); GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA (&dest->appearance, &rgba); GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA_SET (&dest->appearance, TRUE); } if (tag->priv->invisible_set) dest->invisible = vals->invisible; if (tag->priv->editable_set) dest->editable = vals->editable; if (tag->priv->bg_full_height_set) dest->bg_full_height = vals->bg_full_height; if (tag->priv->language_set) dest->language = vals->language; if (tag->priv->fallback_set) dest->no_fallback = vals->no_fallback; if (tag->priv->letter_spacing_set) dest->letter_spacing = vals->letter_spacing; if (tag->priv->font_features_set) dest->font_features = g_strdup (vals->font_features); ++n; }
static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose* event) { DdbEqualizer * self; gboolean result = FALSE; GdkColor _tmp0_ = {0}; GdkColor fore_bright_color; GdkColor c1; GdkColor _tmp1_ = {0}; GdkColor c2; GdkColor fore_dark_color; gint width; gint height; GdkDrawable* d; GdkGCValues _tmp2_ = {0}; GdkGCValues _tmp3_; GdkGC* gc; double step; gint i = 0; double vstep; PangoLayout* l; PangoContext* ctx; PangoFontDescription* fd; gint fontsize; gboolean _tmp7_ = FALSE; char* tmp; double val; const char* _tmp9_; char* _tmp10_; const char* _tmp11_; char* _tmp12_; GdkRectangle _tmp13_ = {0}; GdkRectangle _tmp14_; gint count; GdkRectangle _tmp16_ = {0}; GdkRectangle _tmp17_; gint bar_w; GdkRectangle _tmp22_ = {0}; GdkRectangle _tmp23_; self = (DdbEqualizer*) base; fore_bright_color = (gtkui_get_bar_foreground_color (&_tmp0_), _tmp0_); c1 = fore_bright_color; c2 = (gtkui_get_bar_background_color (&_tmp1_), _tmp1_); fore_dark_color = c2; fore_dark_color.red = fore_dark_color.red + ((guint16) ((gint16) ((c1.red - c2.red) * 0.5))); fore_dark_color.green = fore_dark_color.green + ((guint16) ((gint16) ((c1.green - c2.green) * 0.5))); fore_dark_color.blue = fore_dark_color.blue + ((guint16) ((gint16) ((c1.blue - c2.blue) * 0.5))); width = ((GtkWidget*) self)->allocation.width; height = ((GtkWidget*) self)->allocation.height; d = _g_object_ref0 ((GdkDrawable*) gtk_widget_get_window ((GtkWidget*) self)); gc = _g_object_ref0 (GDK_DRAWABLE_GET_CLASS (d)->create_gc (d, (_tmp3_ = (memset (&_tmp2_, 0, sizeof (GdkGCValues)), _tmp2_), &_tmp3_), 0)); gdk_gc_set_rgb_fg_color (gc, &c2); gdk_draw_rectangle (d, gc, TRUE, 0, 0, width, height); gdk_gc_set_rgb_fg_color (gc, &fore_dark_color); step = ((double) (width - self->priv->margin_left)) / ((double) (DDB_EQUALIZER_bands + 1)); { gboolean _tmp4_; i = 0; _tmp4_ = TRUE; while (TRUE) { if (!_tmp4_) { i++; } _tmp4_ = FALSE; if (!(i < DDB_EQUALIZER_bands)) { break; } gdk_draw_line (d, gc, ((gint) ((i + 1) * step)) + self->priv->margin_left, 0, ((gint) ((i + 1) * step)) + self->priv->margin_left, height - self->priv->margin_bottom); } } vstep = (double) (height - self->priv->margin_bottom); { double di; di = (double) 0; { gboolean _tmp5_; _tmp5_ = TRUE; while (TRUE) { if (!_tmp5_) { di = di + 0.25; } _tmp5_ = FALSE; if (!(di < 2)) { break; } gdk_draw_line (d, gc, self->priv->margin_left, (gint) ((di - self->priv->preamp) * vstep), width, (gint) ((di - self->priv->preamp) * vstep)); } } } gdk_gc_set_rgb_fg_color (gc, &fore_bright_color); l = gtk_widget_create_pango_layout ((GtkWidget*) self, NULL); ctx = _g_object_ref0 (pango_layout_get_context (l)); fd = pango_font_description_copy (gtk_widget_get_style ((GtkWidget*) self)->font_desc); pango_font_description_set_size (fd, (gint) (pango_font_description_get_size (gtk_widget_get_style ((GtkWidget*) self)->font_desc) * 0.7)); pango_context_set_font_description (ctx, fd); { gboolean _tmp6_; i = 0; _tmp6_ = TRUE; while (TRUE) { PangoRectangle ink = {0}; PangoRectangle log = {0}; gint offs; if (!_tmp6_) { i++; } _tmp6_ = FALSE; if (!(i < DDB_EQUALIZER_bands)) { break; } pango_layout_set_text (l, freqs[i], (gint) g_utf8_strlen (freqs[i], -1)); pango_layout_get_pixel_extents (l, &ink, &log); offs = 2; if ((i % 2) != 0) { offs = offs + 2; } gdk_draw_layout (d, gc, (((gint) ((i + 1) * step)) + self->priv->margin_left) - (ink.width / 2), (height - self->priv->margin_bottom) + offs, l); } } pango_font_description_set_size (fd, (gint) pango_font_description_get_size (gtk_widget_get_style ((GtkWidget*) self)->font_desc)); pango_context_set_font_description (ctx, fd); pango_layout_set_width (l, self->priv->margin_left - 1); pango_layout_set_alignment (l, PANGO_ALIGN_RIGHT); fontsize = (gint) ((pango_units_to_double (pango_font_description_get_size (fd)) * gdk_screen_get_resolution (gdk_screen_get_default ())) / 72); if (self->priv->mouse_y >= 0) { _tmp7_ = self->priv->mouse_y < (height - self->priv->margin_bottom); } else { _tmp7_ = FALSE; } if (_tmp7_) { double db; const char* _tmp8_; char* tmp; db = ddb_equalizer_scale (self, ((double) (self->priv->mouse_y - 1)) / ((double) ((height - self->priv->margin_bottom) - 2))); _tmp8_ = NULL; if (db > 0) { _tmp8_ = "+"; } else { _tmp8_ = ""; } tmp = g_strdup_printf ("%s%.1fdB", _tmp8_, db); pango_layout_set_text (l, tmp, (gint) g_utf8_strlen (tmp, -1)); gdk_draw_layout (d, gc, self->priv->margin_left - 1, self->priv->mouse_y - 3, l); _g_free0 (tmp); } tmp = NULL; val = ddb_equalizer_scale (self, (double) 1); _tmp9_ = NULL; if (val > 0) { _tmp9_ = "+"; } else { _tmp9_ = ""; } tmp = (_tmp10_ = g_strdup_printf ("%s%.1fdB", _tmp9_, val), _g_free0 (tmp), _tmp10_); pango_layout_set_text (l, tmp, (gint) g_utf8_strlen (tmp, -1)); gdk_draw_layout (d, gc, self->priv->margin_left - 1, (height - self->priv->margin_bottom) - fontsize, l); val = ddb_equalizer_scale (self, (double) 0); _tmp11_ = NULL; if (val > 0) { _tmp11_ = "+"; } else { _tmp11_ = ""; } tmp = (_tmp12_ = g_strdup_printf ("%s%.1fdB", _tmp11_, val), _g_free0 (tmp), _tmp12_); pango_layout_set_text (l, tmp, (gint) g_utf8_strlen (tmp, -1)); gdk_draw_layout (d, gc, self->priv->margin_left - 1, 1, l); pango_layout_set_text (l, "+0dB", 4); gdk_draw_layout (d, gc, self->priv->margin_left - 1, ((gint) ((1 - self->priv->preamp) * (height - self->priv->margin_bottom))) - (fontsize / 2), l); pango_layout_set_text (l, "preamp", 6); pango_layout_set_alignment (l, PANGO_ALIGN_LEFT); gdk_draw_layout (d, gc, 1, (height - self->priv->margin_bottom) + 2, l); gdk_draw_rectangle (d, gc, FALSE, self->priv->margin_left, 0, (width - self->priv->margin_left) - 1, (height - self->priv->margin_bottom) - 1); gdk_gc_set_line_attributes (gc, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gdk_gc_set_clip_rectangle (gc, (_tmp14_ = (_tmp13_.x = 0, _tmp13_.y = (gint) (self->priv->preamp * (height - self->priv->margin_bottom)), _tmp13_.width = 11, _tmp13_.height = height, _tmp13_), &_tmp14_)); gdk_gc_set_rgb_fg_color (gc, &fore_bright_color); count = ((gint) ((height - self->priv->margin_bottom) / 6)) + 1; { gint j; j = 0; { gboolean _tmp15_; _tmp15_ = TRUE; while (TRUE) { if (!_tmp15_) { j++; } _tmp15_ = FALSE; if (!(j < count)) { break; } gdk_draw_rectangle (d, gc, TRUE, 1, ((height - self->priv->margin_bottom) - (j * 6)) - 6, 11, 4); } } } gdk_gc_set_clip_rectangle (gc, (_tmp17_ = (_tmp16_.x = self->priv->margin_left + 1, _tmp16_.y = 1, _tmp16_.width = (width - self->priv->margin_left) - 2, _tmp16_.height = (height - self->priv->margin_bottom) - 2, _tmp16_), &_tmp17_)); gdk_gc_set_rgb_fg_color (gc, &fore_bright_color); bar_w = 11; if (step < bar_w) { bar_w = ((gint) step) - 1; } { gboolean _tmp18_; i = 0; _tmp18_ = TRUE; while (TRUE) { GdkRectangle _tmp19_ = {0}; GdkRectangle _tmp20_; if (!_tmp18_) { i++; } _tmp18_ = FALSE; if (!(i < DDB_EQUALIZER_bands)) { break; } gdk_gc_set_clip_rectangle (gc, (_tmp20_ = (_tmp19_.x = (((gint) ((i + 1) * step)) + self->priv->margin_left) - (bar_w / 2), _tmp19_.y = (gint) (self->priv->values[i] * (height - self->priv->margin_bottom)), _tmp19_.width = 11, _tmp19_.height = height, _tmp19_), &_tmp20_)); count = ((gint) (((height - self->priv->margin_bottom) * (1 - self->priv->values[i])) / 6)) + 1; { gint j; j = 0; { gboolean _tmp21_; _tmp21_ = TRUE; while (TRUE) { if (!_tmp21_) { j++; } _tmp21_ = FALSE; if (!(j < count)) { break; } gdk_draw_rectangle (d, gc, TRUE, (((gint) ((i + 1) * step)) + self->priv->margin_left) - (bar_w / 2), ((height - self->priv->margin_bottom) - (j * 6)) - 6, bar_w, 4); } } } } } gdk_gc_set_clip_rectangle (gc, (_tmp23_ = (_tmp22_.x = 0, _tmp22_.y = 0, _tmp22_.width = width, _tmp22_.height = height, _tmp22_), &_tmp23_)); gdk_gc_set_line_attributes (gc, 1, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gdk_draw_line (d, gc, self->priv->margin_left + 1, self->priv->mouse_y, width, self->priv->mouse_y); result = FALSE; _g_free0 (tmp); _pango_font_description_free0 (fd); _g_object_unref0 (ctx); _g_object_unref0 (l); _g_object_unref0 (gc); _g_object_unref0 (d); return result; }
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 e_contact_build_style (EContactPrintStyle *style) { xmlDocPtr styledoc; gchar *filename; style->title = g_strdup(""); style->type = E_CONTACT_PRINT_TYPE_CARDS; style->sections_start_new_page = TRUE; style->num_columns = 2; style->blank_forms = 2; style->letter_headings = FALSE; style->headings_font = pango_font_description_from_string ("Sans Bold 8"); style->body_font = pango_font_description_from_string ("Sans 6"); style->print_using_grey = TRUE; style->paper_type = 0; style->paper_width = 8.5; style->paper_height = 11; style->paper_source = 0; style->top_margin = .5; style->left_margin = .5; style->bottom_margin = .5; style->right_margin = .5; style->page_size = 0; style->page_width = 2.75; style->page_height = 4.25; #if 0 style->page_width = 4.25; style->page_height = 5.5; #endif #if 0 style->page_width = 5.5; style->page_height = 8.5; #endif style->orientation_portrait = FALSE; style->header_font = pango_font_description_copy (style->body_font); style->left_header = g_strdup(""); style->center_header = g_strdup(""); style->right_header = g_strdup(""); style->footer_font = pango_font_description_copy (style->body_font); style->left_footer = g_strdup (""); style->center_footer = g_strdup (""); style->right_footer = g_strdup (""); style->reverse_on_even_pages = FALSE; filename = g_build_filename (EVOLUTION_ECPSDIR, "medbook.ecps", NULL); styledoc = e_xml_parse_file (filename); g_free (filename); if (styledoc) { xmlNodePtr stylenode = xmlDocGetRootElement (styledoc); xmlNodePtr node; for (node = stylenode->children; node; node = node->next) { gchar *data = (gchar *) xmlNodeGetContent ( node ); if (!strcmp( (gchar *)node->name, "title" )) { get_string (data, &(style->title)); } else if (!strcmp( (gchar *)node->name, "type" )) { if (g_ascii_strcasecmp (data, "cards") == 0) style->type = E_CONTACT_PRINT_TYPE_CARDS; else if (g_ascii_strcasecmp (data, "memo_style") == 0) style->type = E_CONTACT_PRINT_TYPE_MEMO_STYLE; else if (g_ascii_strcasecmp (data, "phone_list") == 0) style->type = E_CONTACT_PRINT_TYPE_PHONE_LIST; } else if (!strcmp( (gchar *)node->name, "sections_start_new_page" )) { style->sections_start_new_page = get_bool (data); } else if (!strcmp( (gchar *)node->name, "num_columns" )) { style->num_columns = get_integer (data); } else if (!strcmp( (gchar *)node->name, "blank_forms" )) { style->blank_forms = get_integer (data); } else if (!strcmp( (gchar *)node->name, "letter_headings" )) { style->letter_headings = get_bool (data); } else if (!strcmp( (gchar *)node->name, "headings_font" )) { get_font ( data, &(style->headings_font) ); } else if (!strcmp( (gchar *)node->name, "body_font" )) { get_font ( data, &(style->body_font) ); } else if (!strcmp( (gchar *)node->name, "print_using_grey" )) { style->print_using_grey = get_bool (data); } else if (!strcmp( (gchar *)node->name, "paper_width" )) { style->paper_width = get_float (data); } else if (!strcmp( (gchar *)node->name, "paper_height" )) { style->paper_height = get_float (data); } else if (!strcmp( (gchar *)node->name, "top_margin" )) { style->top_margin = get_float (data); } else if (!strcmp( (gchar *)node->name, "left_margin" )) { style->left_margin = get_float (data); } else if (!strcmp( (gchar *)node->name, "bottom_margin" )) { style->bottom_margin = get_float (data); } else if (!strcmp( (gchar *)node->name, "right_margin" )) { style->right_margin = get_float (data); } else if (!strcmp( (gchar *)node->name, "page_width" )) { style->page_width = get_float (data); } else if (!strcmp( (gchar *)node->name, "page_height" )) { style->page_height = get_float (data); } else if (!strcmp( (gchar *)node->name, "orientation" )) { if (data) { style->orientation_portrait = (g_ascii_strcasecmp (data, "landscape") != 0); } else { style->orientation_portrait = TRUE; } } else if (!strcmp( (gchar *)node->name, "header_font" )) { get_font ( data, &(style->header_font) ); } else if (!strcmp( (gchar *)node->name, "left_header" )) { get_string (data, &(style->left_header)); } else if (!strcmp( (gchar *)node->name, "center_header" )) { get_string (data, &(style->center_header)); } else if (!strcmp( (gchar *)node->name, "right_header" )) { get_string (data, &(style->right_header)); } else if (!strcmp( (gchar *)node->name, "footer_font" )) { get_font ( data, &(style->footer_font) ); } else if (!strcmp( (gchar *)node->name, "left_footer" )) { get_string (data, &(style->left_footer)); } else if (!strcmp( (gchar *)node->name, "center_footer" )) { get_string (data, &(style->center_footer)); } else if (!strcmp( (gchar *)node->name, "right_footer" )) { get_string (data, &(style->right_footer)); } else if (!strcmp( (gchar *)node->name, "reverse_on_even_pages" )) { style->reverse_on_even_pages = get_bool (data); } if (data) xmlFree (data); } xmlFreeDoc (styledoc); } }
/* * 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 _vte_pango_x_set_text_font(struct _vte_draw *draw, const PangoFontDescription *fontdesc, VteTerminalAntiAlias antialias) { PangoContext *ctx; Display *display; PangoLayout *layout; PangoLayoutIter *iter; PangoRectangle ink, logical; gunichar full_codepoints[] = {VTE_DRAW_DOUBLE_WIDE_IDEOGRAPHS}; GString *full_string; gint full_width; guint i; struct _vte_pango_x_data *data; data = (struct _vte_pango_x_data*) draw->impl_data; display = gdk_x11_display_get_xdisplay(gtk_widget_get_display(draw->widget)); if (data->ctx != NULL) { g_object_unref(data->ctx); } ctx = pango_x_get_context(display); layout = pango_layout_new(ctx); if (data->font != NULL) { pango_font_description_free(data->font); } data->font = pango_font_description_copy(fontdesc); pango_layout_set_font_description(layout, data->font); /* Estimate for ASCII characters. */ pango_layout_set_text(layout, VTE_DRAW_SINGLE_WIDE_CHARACTERS, strlen(VTE_DRAW_SINGLE_WIDE_CHARACTERS)); pango_layout_get_extents(layout, &ink, &logical); draw->width = logical.width; draw->width = howmany(draw->width, strlen(VTE_DRAW_SINGLE_WIDE_CHARACTERS)); iter = pango_layout_get_iter(layout); draw->height = PANGO_PIXELS(logical.height); draw->ascent = PANGO_PIXELS(pango_layout_iter_get_baseline(iter)); pango_layout_iter_free(iter); /* Estimate for CJK characters. */ full_string = g_string_new(NULL); for (i = 0; i < G_N_ELEMENTS(full_codepoints); i++) { g_string_append_unichar(full_string, full_codepoints[i]); } pango_layout_set_text(layout, full_string->str, full_string->len); pango_layout_get_extents(layout, &ink, &logical); full_width = howmany(logical.width, G_N_ELEMENTS(full_codepoints)); g_string_free(full_string, TRUE); /* If they're the same, then we have a screwy font. */ if (full_width == draw->width) { /* add 1 to round up when dividing by 2 */ draw->width = (draw->width + 1) / 2; } draw->width = PANGO_PIXELS(draw->width); iter = pango_layout_get_iter(layout); if (draw->height == 0) { draw->height = PANGO_PIXELS(logical.height); } if (draw->ascent == 0) { draw->ascent = PANGO_PIXELS(pango_layout_iter_get_baseline(iter)); } pango_layout_iter_free(iter); _vte_debug_print(VTE_DEBUG_MISC, "VtePangoX font metrics = %dx%d (%d).\n", draw->width, draw->height, draw->ascent); g_object_unref(layout); g_object_unref(ctx); }
static void gtk_set_font(GtkStyle* psStyle, GtkStyle* psValue) { pango_font_description_free(psStyle->font_desc); psStyle->font_desc = pango_font_description_copy(psValue->font_desc); }
// http://library.gnome.org/devel/pango/1.28/pango-Fonts.html#pango-font-description-better-match Glib::ustring font_factory::FontSpecificationBestMatch(const Glib::ustring & fontSpec ) { Glib::ustring newFontSpec; // Look for exact match PangoStringToDescrMap::iterator it = fontInstanceMap.find(fontSpec); // If there is no exact match, look for the best match. if (it != fontInstanceMap.end()) { newFontSpec = fontSpec; } else { PangoFontDescription *fontDescr = pango_font_description_from_string(fontSpec.c_str()); PangoFontDescription *bestMatchDescr = NULL; // Grab the UI Family string from the descr Glib::ustring family = GetUIFamilyString(fontDescr); Glib::ustring bestMatchDescription; bool setFirstFamilyMatch = false; for (it = fontInstanceMap.begin(); it != fontInstanceMap.end(); ++it) { Glib::ustring currentFontSpec = (*it).first; Glib::ustring currentFamily = GetUIFamilyString((*it).second); // Save some time by only looking at the right family. // Must use family name rather than fontSpec // (otherwise DejaVu Sans matches DejaVu Sans Mono). if (currentFamily == family) { if (!setFirstFamilyMatch) { // This ensures that the closest match is at least within the correct // family rather than the first font in the list bestMatchDescr = pango_font_description_copy((*it).second); bestMatchDescription = currentFontSpec; setFirstFamilyMatch = true; } else { // Get the font description that corresponds, and // then see if we've found a better match PangoFontDescription *possibleMatch = pango_font_description_copy((*it).second); if (pango_font_description_better_match( fontDescr, bestMatchDescr, possibleMatch)) { pango_font_description_free(bestMatchDescr); bestMatchDescr = possibleMatch; bestMatchDescription = currentFontSpec; } else { pango_font_description_free(possibleMatch); } } } } // for newFontSpec = bestMatchDescription; // If NULL, then no match found pango_font_description_free(fontDescr); pango_font_description_free(bestMatchDescr); } return newFontSpec; }
font_instance *font_factory::Face(PangoFontDescription *descr, bool canFail) { #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) (fontSize*PANGO_SCALE*72/GetDeviceCaps(pango_win32_get_dc(),LOGPIXELSY))); // mandatory huge size (hinting workaround) #else pango_font_description_set_size(descr, (int) (fontSize*PANGO_SCALE)); // mandatory huge size (hinting workaround) #endif font_instance *res = NULL; FaceMapType& loadedFaces = *static_cast<FaceMapType*>(loadedPtr); if ( loadedFaces.find(descr) == loadedFaces.end() ) { // not yet loaded PangoFont *nFace = NULL; // workaround for bug #1025565. // fonts without families blow up Pango. if (sp_font_description_get_family(descr) != NULL) { nFace = pango_font_map_load_font(fontServer,fontContext,descr); } else { g_warning("%s", _("Ignoring font without family that will crash Pango")); } if ( nFace ) { // duplicate FcPattern, the hard way res = new font_instance(); // store the descr of the font we asked for, since this is the key where we intend // to put the font_instance at in the unordered_map. the descr of the returned // pangofont may differ from what was asked, so we don't know (at this // point) whether loadedFaces[that_descr] is free or not (and overwriting // an entry will bring deallocation problems) res->descr = pango_font_description_copy(descr); res->parent = this; res->InstallFace(nFace); if ( res->pFont == NULL ) { // failed to install face -> bitmap font // printf("face failed\n"); res->parent = NULL; delete res; res = NULL; if ( canFail ) { char *tc = pango_font_description_to_string(descr); PANGO_DEBUG("falling back from %s to 'sans-serif' because InstallFace failed\n",tc); g_free(tc); pango_font_description_set_family(descr,"sans-serif"); res = Face(descr,false); } } else { loadedFaces[res->descr]=res; res->Ref(); AddInCache(res); } } else { // no match if ( canFail ) { PANGO_DEBUG("falling back to 'sans-serif'\n"); descr = pango_font_description_new(); pango_font_description_set_family(descr,"sans-serif"); res = Face(descr,false); pango_font_description_free(descr); } } } else { // already here res = loadedFaces[descr]; res->Ref(); AddInCache(res); } if (res) { res->InitTheFace(); } return res; }
Font::Font(const Font& other) : desc_(pango_font_description_copy(other.desc_)), isStrikeout_(other.isStrikeout_), isUnderline_(other.isUnderline_) { }
/** * gtk_text_attributes_copy_values: * @src: a #GtkTextAttributes * @dest: another #GtkTextAttributes * * Copies the values from @src to @dest so that @dest has * the same values as @src. Frees existing values in @dest. */ void gtk_text_attributes_copy_values (GtkTextAttributes *src, GtkTextAttributes *dest) { guint orig_refcount; if (src == dest) return; /* Remove refs */ if (dest->tabs) pango_tab_array_free (dest->tabs); if (dest->font) pango_font_description_free (dest->font); G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (dest->pg_bg_color) gdk_color_free (dest->pg_bg_color); G_GNUC_END_IGNORE_DEPRECATIONS if (dest->pg_bg_rgba) gdk_rgba_free (dest->pg_bg_rgba); if (dest->appearance.rgba[0]) gdk_rgba_free (dest->appearance.rgba[0]); if (dest->appearance.rgba[1]) gdk_rgba_free (dest->appearance.rgba[1]); if (dest->font_features) g_free (dest->font_features); /* Copy */ orig_refcount = dest->refcount; *dest = *src; if (src->tabs) dest->tabs = pango_tab_array_copy (src->tabs); dest->language = src->language; if (src->font) dest->font = pango_font_description_copy (src->font); G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (src->pg_bg_color) dest->pg_bg_color = gdk_color_copy (src->pg_bg_color); G_GNUC_END_IGNORE_DEPRECATIONS if (src->pg_bg_rgba) dest->pg_bg_rgba = gdk_rgba_copy (src->pg_bg_rgba); if (src->appearance.rgba[0]) dest->appearance.rgba[0] = gdk_rgba_copy (src->appearance.rgba[0]); if (src->appearance.rgba[1]) dest->appearance.rgba[1] = gdk_rgba_copy (src->appearance.rgba[1]); if (src->font_features) dest->font_features = g_strdup (src->font_features); dest->refcount = orig_refcount; }
static void create_gui(MathDisplay *display) { GtkWidget *info_view, *info_box, *main_box; PangoFontDescription *font_desc; int i; GtkStyle *style; main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(display), main_box); g_signal_connect(display, "key-press-event", G_CALLBACK(key_press_cb), display); display->priv->text_view = gtk_text_view_new_with_buffer(GTK_TEXT_BUFFER(display->priv->equation)); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(display->priv->text_view), GTK_WRAP_WORD); gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(display->priv->text_view), FALSE); gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(display->priv->text_view), 8); gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(display->priv->text_view), 2); /* TEMP: Disabled for now as GTK+ doesn't properly render a right aligned right margin, see bug #482688 */ /*gtk_text_view_set_right_margin(GTK_TEXT_VIEW(display->priv->text_view), 6);*/ gtk_text_view_set_justification(GTK_TEXT_VIEW(display->priv->text_view), GTK_JUSTIFY_RIGHT); gtk_widget_ensure_style(display->priv->text_view); font_desc = pango_font_description_copy(gtk_widget_get_style(display->priv->text_view)->font_desc); pango_font_description_set_size(font_desc, 16 * PANGO_SCALE); gtk_widget_modify_font(display->priv->text_view, font_desc); pango_font_description_free(font_desc); gtk_widget_set_name(display->priv->text_view, "displayitem"); atk_object_set_role(gtk_widget_get_accessible(display->priv->text_view), ATK_ROLE_EDITBAR); //FIXME:<property name="AtkObject::accessible-description" translatable="yes" comments="Accessible description for the area in which results are displayed">Result Region</property> g_signal_connect(display->priv->text_view, "key-press-event", G_CALLBACK(display_key_press_cb), display); gtk_box_pack_start(GTK_BOX(main_box), display->priv->text_view, TRUE, TRUE, 0); info_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); gtk_box_pack_start(GTK_BOX(main_box), info_box, FALSE, TRUE, 0); info_view = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(info_view), GTK_WRAP_WORD); gtk_widget_set_can_focus(info_view, TRUE); // FIXME: This should be FALSE but it locks the cursor inside the main view for some reason gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(info_view), FALSE); // FIXME: Just here so when incorrectly gets focus doesn't look editable gtk_text_view_set_editable(GTK_TEXT_VIEW(info_view), FALSE); gtk_text_view_set_justification(GTK_TEXT_VIEW(info_view), GTK_JUSTIFY_RIGHT); /* TEMP: Disabled for now as GTK+ doesn't properly render a right aligned right margin, see bug #482688 */ /*gtk_text_view_set_right_margin(GTK_TEXT_VIEW(info_view), 6);*/ gtk_box_pack_start(GTK_BOX(info_box), info_view, TRUE, TRUE, 0); display->priv->info_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(info_view)); display->priv->spinner = gtk_spinner_new(); gtk_box_pack_end(GTK_BOX(info_box), display->priv->spinner, FALSE, FALSE, 0); style = gtk_widget_get_style(info_view); for (i = 0; i < 5; i++) { gtk_widget_modify_bg(GTK_WIDGET(display), i, &style->base[i]); } gtk_widget_show(info_box); gtk_widget_show(info_view); gtk_widget_show(display->priv->text_view); gtk_widget_show(main_box); g_signal_connect(display->priv->equation, "notify::status", G_CALLBACK(status_changed_cb), display); status_changed_cb(display->priv->equation, NULL, display); }
void hb_export_pdf_listview(GtkTreeView *treeview, gchar *filepath, gchar *accname) { cairo_surface_t *surf; cairo_t *cr; PdfPrintContext ppc; PangoFontDescription *desc; PangoLayout *layout; GtkTreeModel *model; GtkTreeIter iter; gboolean valid; gint i, col; DB( g_print("[gtk-chart] export to pdf\n") ); model = gtk_tree_view_get_model(treeview); papersize(&ppc); //gchar *filename = "/home/max/Desktop/hb-txn-export.pdf"; double width; //=210 * 2.83; double height; //=297 * 2.83; width = ppc.w; height = ppc.h; surf = cairo_pdf_surface_create (filepath, width, height); if( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) //todo: manage error later on return; cr = cairo_create (surf); //cairo_pdf_surface_set_size(surf, width * 2.83, height * 2.83); //g_print("width=%d\n", cairo_image_surface_get_width( surf)); double x1, x2, y1, y2; cairo_clip_extents (cr, &x1, &y1, &x2, &y2); DB( g_print("surface w=%f, h=%f\n", x2 - x1, y2 - y1) ); double pwidth = x2 - x1; /* Create a PangoLayout, set the font and text */ layout = pango_cairo_create_layout (cr); /* get and copy the font from the treeview widget */ gtk_style_context_get(gtk_widget_get_style_context(GTK_WIDGET(treeview)), GTK_STATE_FLAG_NORMAL, "font", &desc, NULL); ppc.desc = pango_font_description_copy(desc); DB( g_print("family: %s\n", pango_font_description_get_family(desc)) ); DB( g_print("size: %d (%d)\n", pango_font_description_get_size (desc), pango_font_description_get_size (desc )/PANGO_SCALE) ); /* header is 1 line for date page number at top, then a title in bold, then 2 empty lines */ gint header_height = PDF_FONT_NORMAL * 2 + PDF_FONT_TITLE; gint nb_lines = gtk_tree_model_iter_n_children(model, NULL); /* should include here the headertitle line */ gint lpp = floor ((height-header_height-ppc.mt-ppc.mb) / (PDF_FONT_NORMAL + PDF_LINE_MARGIN)); gint page, num_pages = (nb_lines - 1) / lpp + 1; DB( g_print("\n - should pdf %d lines, lpp=%d, num_pages=%d\n", nb_lines, lpp, num_pages) ); gint tot_lines = 0; gint cur_page_line = 1; gchar dbuffer[255]; gchar amtbuf[G_ASCII_DTOSTR_BUF_SIZE]; gchar balbuf[G_ASCII_DTOSTR_BUF_SIZE]; GDate *date = g_date_new (); //cairo_set_font_size(cr, PDF_FONT_NORMAL); pango_font_description_set_absolute_size(ppc.desc, PDF_FONT_NORMAL * PANGO_SCALE); pango_layout_set_font_description (layout, ppc.desc); /* reset struct */ hb_pdf_set_col_title(&ppc); for(col=0;col<PDF_NUMCOL;col++) { int tw, th; ppc.column_width[col] = 0; pango_layout_set_text (layout, ppc.column_txt[col], -1); pango_layout_get_size (layout, &tw, &th); ppc.column_width[col] = MAX(ppc.column_width[col], tw / PANGO_SCALE); } DB( g_print(" - compute width\n") ); /* first pass to get max width */ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter); while (valid) { Transaction *txn; int tw, th; gtk_tree_model_get (model, &iter, LST_DSPOPE_DATAS, &txn, -1); i = 0; g_date_set_julian (date, txn->date); g_date_strftime (dbuffer, 255-1, "%x", date); pango_layout_set_text (layout, dbuffer, -1); pango_layout_get_size (layout, &tw, &th); ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE); i = 1; if(txn->info != NULL && strlen(txn->info) > 0) { pango_layout_set_text (layout, txn->info, -1); pango_layout_get_size (layout, &tw, &th); ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE); } i = 4; hb_strfnum(amtbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->amount, txn->kcur, GLOBALS->minor); pango_layout_set_text (layout, amtbuf, -1); pango_layout_get_size (layout, &tw, &th); ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE); i = 5; pango_layout_set_text (layout, "R", -1); pango_layout_get_size (layout, &tw, &th); ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE); i = 6; hb_strfnum(balbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->balance, txn->kcur, GLOBALS->minor); pango_layout_set_text (layout, balbuf, -1); pango_layout_get_size (layout, &tw, &th); ppc.column_width[i] = MAX(ppc.column_width[i], tw / PANGO_SCALE); valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); } /* distribute remaining size */ gdouble tmp = pwidth - ppc.ml - ppc.mr - (PDF_COL_MARGIN*PDF_NUMCOL); DB( g_print(" page width=%f, remain width=%f\n", pwidth, tmp) ); tmp -= ppc.column_width[0]; tmp -= ppc.column_width[4]; tmp -= ppc.column_width[5]; tmp -= ppc.column_width[6]; /* info=1/4 payee=1/4 memo=2/4 */ ppc.column_width[1] = tmp / 4;; ppc.column_width[2] = tmp / 4; ppc.column_width[3] = 2*tmp / 4; DB( g_print(" page width=%f, remain width=%f\n", width, tmp) ); #if MYDEBUG == 1 for(i=0;i<PDF_NUMCOL;i++) g_print(" col%d=%g ", i, ppc.column_width[i]); g_print("\n"); #endif DB( g_print("\n - start printing\n") ); gint y; page = 1; valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter); while (valid) { Transaction *txn; int tw, th; gtk_tree_model_get (model, &iter, LST_DSPOPE_DATAS, &txn, -1); //DB( g_print(" - %d, %d, %s\n", x, y, txn->memo) ); if(cur_page_line == 1) { //helpdraw #if HELPDRAW == 1 //page with margin hb_pdf_draw_help_rect(cr, 0xFF0000FF, ppc.ml+0.5, ppc.mt+0.5, width-(ppc.ml+ppc.mr), height - (ppc.mt+ppc.mb)); hb_pdf_draw_help_rect(cr, 0xFF00FFFF, ppc.ml+0.5, ppc.mt+0.5, width-(ppc.ml+ppc.mr), header_height); #endif cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); // draw account title pango_font_description_set_absolute_size(ppc.desc, PDF_FONT_TITLE * PANGO_SCALE); pango_layout_set_font_description (layout, ppc.desc); pango_layout_set_text (layout, accname, -1); pango_layout_get_pixel_size (layout, &tw, &th); cairo_move_to(cr, pwidth/2 - (tw/2), ppc.mt); pango_cairo_show_layout (cr, layout); // draw column titles pango_font_description_set_absolute_size(ppc.desc, PDF_FONT_NORMAL * PANGO_SCALE); pango_layout_set_font_description (layout, ppc.desc); g_sprintf(dbuffer, "Page %d/%d", page, num_pages); pango_layout_set_text (layout, dbuffer, -1); pango_layout_get_pixel_size (layout, &tw, &th); cairo_move_to(cr, pwidth - ppc.mr - tw, ppc.mt); pango_cairo_show_layout (cr, layout); //x = ppc.ml; y = ppc.mt + header_height - (PDF_FONT_NORMAL + PDF_LINE_MARGIN); hb_pdf_set_col_title(&ppc); hb_pdf_draw_line(&ppc, cr, y, TRUE, FALSE); } /* print a single line */ //x = ppc.ml; y = ppc.mt + header_height + (cur_page_line * (PDF_FONT_NORMAL + PDF_LINE_MARGIN)); /* reset struct */ for(i=0;i<PDF_NUMCOL;i++) { ppc.column_txt[i] = NULL; } i = 0; g_date_set_julian (date, txn->date); g_date_strftime (dbuffer, 255-1, "%x", date); ppc.column_txt[i] = dbuffer; i = 1; ppc.column_txt[i] = txn->info; i = 2; Payee *p = da_pay_get(txn->kpay); if(p) ppc.column_txt[i] = p->name; i = 3; /*Category *c = da_cat_get(txn->kcat); if(c) ppc.column_txt[i] = da_cat_get_fullname(c);*/ ppc.column_txt[i] = txn->memo; i = 4; hb_strfnum(amtbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->amount, txn->kcur, GLOBALS->minor); ppc.column_txt[i] = amtbuf; i = 5; ppc.column_txt[i] = ""; if(txn->status == TXN_STATUS_CLEARED) ppc.column_txt[i] = "c"; else if(txn->status == TXN_STATUS_RECONCILED) ppc.column_txt[i] = "R"; i = 6; hb_strfnum(balbuf, G_ASCII_DTOSTR_BUF_SIZE-1, txn->balance, txn->kcur, GLOBALS->minor); ppc.column_txt[i] = balbuf; hb_pdf_draw_line(&ppc, cr, y, FALSE, (cur_page_line % 2)); /* free any fullcat name */ /*if(ppc.column_txt[3] != NULL) g_free(ppc.column_txt[3]);*/ /* export page */ if(cur_page_line >= lpp) { DB( g_print("\n - next page %d\n", page) ); cairo_show_page(cr); cur_page_line = 0; page++; } cur_page_line++; tot_lines++; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter); } g_date_free(date); g_object_unref (layout); pango_font_description_free (ppc.desc); cairo_destroy (cr); cairo_surface_destroy (surf); }