void tooltip_update_geometry() { Panel *panel = g_tooltip.panel; int screen_width = server.monitors[panel->monitor].x + server.monitors[panel->monitor].width; cairo_surface_t *cs = cairo_xlib_surface_create(server.display, g_tooltip.window, server.visual, width, height); cairo_t *c = cairo_create(cs); PangoLayout *layout = pango_cairo_create_layout(c); pango_layout_set_font_description(layout, g_tooltip.font_desc); PangoRectangle r1, r2; pango_layout_set_text(layout, "1234567890", -1); pango_layout_get_pixel_extents(layout, &r1, &r2); int max_width = MIN(r2.width * 7, screen_width * 2 / 3); pango_layout_set_width(layout, max_width * PANGO_SCALE); pango_layout_set_text(layout, g_tooltip.tooltip_text, -1); pango_layout_set_wrap(layout, PANGO_WRAP_WORD); pango_layout_get_pixel_extents(layout, &r1, &r2); width = 2 * g_tooltip.bg->border.width + 2 * g_tooltip.paddingx + r2.width; height = 2 * g_tooltip.bg->border.width + 2 * g_tooltip.paddingy + r2.height; if (panel_horizontal && panel_position & BOTTOM) y = panel->posy - height; else if (panel_horizontal && panel_position & TOP) y = panel->posy + panel->area.height; else if (panel_position & LEFT) x = panel->posx + panel->area.width; else x = panel->posx - width; g_object_unref(layout); cairo_destroy(c); cairo_surface_destroy(cs); }
/* clean entries */ gtk_entry_set_text(GTK_ENTRY(lib->gui.plabel), ""); gtk_entry_set_text(GTK_ENTRY(lib->gui.pname), ""); } } } static void _toggle_capture_mode_clicked(GtkWidget *widget, gpointer user_data) { dt_lib_camera_t *lib = (dt_lib_camera_t *)user_data; GtkWidget *w = NULL; if(widget == GTK_WIDGET(lib->gui.tb1)) w = lib->gui.sb1; else if(widget == GTK_WIDGET(lib->gui.tb2)) w = lib->gui.sb2; else if(widget == GTK_WIDGET(lib->gui.tb3)) { gtk_widget_set_sensitive(lib->gui.sb3, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); gtk_widget_set_sensitive(lib->gui.sb4, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); } if(w) gtk_widget_set_sensitive(w, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); } #define BAR_HEIGHT DT_PIXEL_APPLY_DPI(18) /* also change in views/tethering.c */ static void _expose_info_bar(dt_lib_module_t *self, cairo_t *cr, int32_t width, int32_t height, int32_t pointerx, int32_t pointery) { dt_lib_camera_t *lib = (dt_lib_camera_t *)self->data; // Draw infobar background at top cairo_set_source_rgb(cr, .0, .0, .0); cairo_rectangle(cr, 0, 0, width, BAR_HEIGHT); cairo_fill(cr); cairo_set_source_rgb(cr, .8, .8, .8); // Draw left aligned value camera model value PangoLayout *layout; PangoRectangle ink; PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); layout = pango_cairo_create_layout(cr); const int fontsize = DT_PIXEL_APPLY_DPI(11.5); pango_font_description_set_absolute_size(desc, fontsize * PANGO_SCALE); pango_layout_set_font_description(layout, desc); char model[4096] = { 0 }; sprintf(model + strlen(model), "%s", lib->data.camera_model); pango_layout_set_text(layout, model, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, DT_PIXEL_APPLY_DPI(5), DT_PIXEL_APPLY_DPI(1) + BAR_HEIGHT - ink.height / 2 - fontsize); pango_cairo_show_layout(cr, layout); // Draw right aligned battery value const char *battery_value = dt_camctl_camera_get_property(darktable.camctl, NULL, "batterylevel"); char battery[4096] = { 0 }; snprintf(battery, sizeof(battery), "%s: %s", _("battery"), battery_value ? battery_value : _("n/a")); pango_layout_set_text(layout, battery, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, width - ink.width - DT_PIXEL_APPLY_DPI(5), DT_PIXEL_APPLY_DPI(1) + BAR_HEIGHT - ink.height / 2 - fontsize); pango_cairo_show_layout(cr, layout); // Let's cook up the middle part of infobar gchar center[1024] = { 0 }; for(guint i = 0; i < g_list_length(lib->gui.properties); i++) { dt_lib_camera_property_t *prop = (dt_lib_camera_property_t *)g_list_nth_data(lib->gui.properties, i); if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prop->osd)) == TRUE) { g_strlcat(center, " ", sizeof(center)); g_strlcat(center, prop->name, sizeof(center)); g_strlcat(center, ": ", sizeof(center)); g_strlcat(center, dt_bauhaus_combobox_get_text(prop->values), sizeof(center)); } } g_strlcat(center, " ", sizeof(center)); // Now lets put it in center view... pango_layout_set_text(layout, center, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, (width / 2) - (ink.width / 2), DT_PIXEL_APPLY_DPI(1) + BAR_HEIGHT - ink.height / 2 - fontsize); pango_cairo_show_layout(cr, layout); pango_font_description_free(desc); g_object_unref(layout); }
static gboolean gtk_switch_snapshot_trough (GtkCssGadget *gadget, GtkSnapshot *snapshot, int x, int y, int width, int height, gpointer data) { GtkWidget *widget = gtk_css_gadget_get_owner (gadget); GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv; GtkStyleContext *context = gtk_widget_get_style_context (widget); PangoRectangle rect; gint label_x, label_y; pango_layout_get_pixel_extents (priv->on_layout, NULL, &rect); label_x = x + ((width / 2) - rect.width) / 2; label_y = y + (height - rect.height) / 2; gtk_snapshot_render_layout (snapshot, context, label_x, label_y, priv->on_layout); pango_layout_get_pixel_extents (priv->off_layout, NULL, &rect); label_x = x + (width / 2) + ((width / 2) - rect.width) / 2; label_y = y + (height - rect.height) / 2; gtk_snapshot_render_layout (snapshot, context, label_x, label_y, priv->off_layout); gtk_css_gadget_snapshot (priv->slider_gadget, snapshot); return FALSE; }
static void i7_cell_renderer_transcript_get_size(GtkCellRenderer *self, GtkWidget *widget, GdkRectangle *cell_area, int *x_offset, int *y_offset, int *width, int *height) { I7_CELL_RENDERER_TRANSCRIPT_USE_PRIVATE; PangoRectangle command_rect, transcript_rect, expected_rect; PangoLayout *layout; unsigned xpad, ypad, transcript_width, calc_width, calc_height; g_object_get(self, "xpad", &xpad, "ypad", &ypad, NULL); transcript_width = (priv->default_width / 2) - xpad; /* Get size of command */ layout = gtk_widget_create_pango_layout(widget, priv->command); pango_layout_get_pixel_extents(layout, NULL, &command_rect); g_object_unref(layout); /* Get size of transcript text */ layout = gtk_widget_create_pango_layout(widget, priv->transcript_text); pango_layout_set_width(layout, (int)(transcript_width - priv->text_padding * 2) * PANGO_SCALE); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_get_pixel_extents(layout, NULL, &transcript_rect); g_object_unref(layout); /* Get size of expected text */ layout = gtk_widget_create_pango_layout(widget, priv->expected_text); pango_layout_set_width(layout, (int)(transcript_width - priv->text_padding * 2) * PANGO_SCALE); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_get_pixel_extents(layout, NULL, &expected_rect); g_object_unref (layout); /* Calculate the required width and height for the cell */ calc_width = priv->default_width; calc_height = (unsigned)(command_rect.height + MAX(transcript_rect.height, expected_rect.height)) + ypad * 2 + priv->text_padding * 4; /* Set the passed-in parameters; if the available cell area is larger than the required width and height, just use that instead */ if(cell_area) { if(width) *width = MAX(cell_area->width, (int)calc_width); if(height) *height = MAX(cell_area->height, (int)calc_height); } else { if(width) *width = (int)calc_width; if(height) *height = (int)calc_height; } if(x_offset) *x_offset = 0; if(y_offset) *y_offset = 0; }
//__________________________________________________________________ _HYRect _HYPullDown::_SuggestDimensions (void) { _HYRect res = {25,100,25,100,HY_COMPONENT_NO_SCROLL}; if (theMenu) { long naturalWidth = 0; PangoLayout * fontMeasurer = nil; for (long k=0; k<widgetList.lLength; k+=2) { GtkWidget * dropWidget = GTK_WIDGET (widgetList(k)); if (!fontMeasurer) { fontMeasurer = pango_layout_new (gtk_widget_get_pango_context (dropWidget)); } pango_layout_set_text(fontMeasurer,GetMenuItem(k/2)->sData ,GetMenuItem(k/2)->sLength); PangoRectangle extents, log_ext; pango_layout_get_pixel_extents (fontMeasurer,&extents,nil); if (extents.width > naturalWidth) { naturalWidth = extents.width; } } if (fontMeasurer) { g_object_unref (fontMeasurer); } res.right = res.left = naturalWidth+25; } return res; }
void get_font_size(term_data* td) { PangoRectangle r; PangoLayout *temp; PangoFontDescription* temp_font; cairo_t *cr; cairo_surface_t *surface; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200); cr = cairo_create(surface); temp = pango_cairo_create_layout(cr); /* Draw an @, and measure it */ temp_font = pango_font_description_from_string(td->font.name); pango_layout_set_font_description(temp, temp_font); pango_layout_set_text(temp, "@", 1); pango_cairo_show_layout(cr, temp); pango_layout_get_pixel_extents(temp, NULL, &r); td->font.w = r.width; td->font.h = r.height; pango_font_description_free(temp_font); cairo_destroy(cr); g_object_unref(temp); td->win.w = td->font.w * td->cols; td->win.h = td->font.h * td->rows; // printf("font width == %d, height = %d.\n", td->font.w, td->font.h); }
static void shell_search_renderer_render (GtkCellRenderer *cell, cairo_t *cr, GtkWidget *widget, const GdkRectangle *background_area, const GdkRectangle *cell_area, GtkCellRendererState flags) { ShellSearchRendererPrivate *priv = SHELL_SEARCH_RENDERER (cell)->priv; PangoRectangle rect; GtkStyleContext *context; gint layout_height; gint vcenter_offset; context = gtk_widget_get_style_context (widget); shell_search_renderer_set_layout (SHELL_SEARCH_RENDERER (cell), widget); pango_layout_get_pixel_extents (priv->layout, NULL, &rect); pango_layout_get_pixel_size (priv->layout, NULL, &layout_height); vcenter_offset = (cell_area->height - layout_height) / 2; cairo_save (cr); gtk_render_layout (context, cr, cell_area->x, cell_area->y + vcenter_offset, priv->layout); cairo_restore (cr); }
static void gimp_ruler_size_request (GtkWidget *widget, GtkRequisition *requisition) { GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget); GtkStyleContext *context = gtk_widget_get_style_context (widget); PangoLayout *layout; PangoRectangle ink_rect; GtkBorder border; gint size; layout = gimp_ruler_get_layout (widget, "0123456789"); pango_layout_get_pixel_extents (layout, &ink_rect, NULL); size = 2 + ink_rect.height * 1.7; gtk_style_context_get_border (context, 0, &border); requisition->width = border.left + border.right; requisition->height = border.top + border.bottom; if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { requisition->width += 1; requisition->height += size; } else { requisition->width += size; requisition->height += 1; } }
MCGFloat __MCGContextMeasurePlatformText(MCGContextRef self, const unichar_t *p_text, uindex_t p_length, const MCGFont &p_font) { // MW-2013-12-19: [[ Bug 11559 ]] Do nothing if no text support. if (!s_has_text_support) return 0.0; bool t_success; t_success = true; if (t_success) t_success = s_layout != NULL; char *t_text; t_text = nil; if (t_success) t_success = MCCStringFromUnicodeSubstring(p_text, p_length / 2, t_text); MCGFloat t_width; t_width = 0.0; if (t_success) { pango_layout_set_text(s_layout, t_text, -1); pango_layout_set_font_description(s_layout, (PangoFontDescription *) p_font . fid); PangoRectangle t_bounds; pango_layout_get_pixel_extents(s_layout, NULL, &t_bounds); t_width = t_bounds . width; } MCCStringFree(t_text); return t_width; }
/*! \brief draw_valtext() draws the dynamic values for the traces on the left hand side of the logviewer. This is optimized so that if the value becomes temporarily static, it won't keep blindly updating the screen and wasting CPU time. \param force_draw when true to write the values to screen for all controls no matter if hte previous value is the same or not. */ G_MODULE_EXPORT void draw_valtext(gboolean force_draw) { gint last_index = 0; gfloat val = 0.0; gfloat last_val = 0.0; gint val_x = 0; gint val_y = 0; gint info_ctr = 0; gint h = 0; gint i = 0; GArray *array = NULL; Viewable_Value *v_value = NULL; PangoLayout *layout; GdkPixmap *pixmap = lv_data->pixmap; GtkAllocation allocation; gtk_widget_get_allocation(lv_data->darea,&allocation); h = allocation.height; if (!lv_data->font_desc) { lv_data->font_desc = pango_font_description_from_string("courier"); pango_font_description_set_size(lv_data->font_desc,(10)*PANGO_SCALE); } val_x = 7; for (i=0;i<lv_data->active_traces;i++) { v_value = (Viewable_Value *)g_list_nth_data(lv_data->tlist,i); info_ctr = (lv_data->spread * (i+1))- (lv_data->spread/2); val_y = info_ctr + 1; last_index = v_value->last_index; array = DATA_GET(v_value->object,v_value->data_source); val = g_array_index(array,gfloat,last_index); if (array->len > 1) last_val = g_array_index(array,gfloat,last_index-1); /* IF this value matches the last one, don't bother * updating the text as there's no point... */ if ((val == last_val) && (!force_draw) && (!v_value->force_update)) continue; v_value->force_update = FALSE; gdk_draw_rectangle(pixmap, gtk_widget_get_style(lv_data->darea)->black_gc, TRUE, v_value->ink_rect->x+val_x, v_value->ink_rect->y+val_y, lv_data->info_width-1-v_value->ink_rect->x-val_x, v_value->ink_rect->height); layout = gtk_widget_create_pango_layout(lv_data->darea,g_strdup_printf("%1$.*2$f",val,v_value->precision)); pango_layout_set_font_description(layout,lv_data->font_desc); pango_layout_get_pixel_extents(layout,v_value->ink_rect,v_value->log_rect); gdk_draw_layout(pixmap,v_value->font_gc,val_x,val_y,layout); } }
static void _paint_text (OlScrollWindow *scroll, cairo_t *cr) { ol_log_func (); ol_assert (OL_IS_SCROLL_WINDOW (scroll)); ol_assert (cr != NULL); GtkWidget *widget = GTK_WIDGET (scroll); OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll); gint width, height; PangoRectangle extent; PangoLayout *layout; gint x, y; gdk_drawable_get_size (gtk_widget_get_window (widget), &width, &height); /* set the font */ cairo_save (cr); cairo_set_source_rgb (cr, priv->inactive_color.r, priv->inactive_color.g, priv->inactive_color.b); layout = _get_pango (scroll, cr); pango_layout_set_text (layout, priv->text, -1); pango_layout_get_pixel_extents (layout, NULL, &extent); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); x = (width - extent.width) / 2; y = (height - extent.height) / 2; if (x < 0) x = 0; if (y < 0) y = 0; cairo_move_to (cr, x, y); pango_cairo_update_layout (cr, layout); pango_cairo_show_layout (cr, layout); }
void tooltip_update() { if (!g_tooltip.tooltip_text) { tooltip_hide(0); return; } tooltip_update_geometry(); if (just_shown) { if (!panel_horizontal) y -= height / 2; // center vertically just_shown = FALSE; } tooltip_adjust_geometry(); XMoveResizeWindow(server.display, g_tooltip.window, x, y, width, height); // Stuff for drawing the tooltip cairo_surface_t *cs = cairo_xlib_surface_create(server.display, g_tooltip.window, server.visual, width, height); cairo_t *c = cairo_create(cs); Color bc = g_tooltip.bg->fill_color; Border b = g_tooltip.bg->border; if (server.real_transparency) { clear_pixmap(g_tooltip.window, 0, 0, width, height); draw_rect(c, b.width, b.width, width - 2 * b.width, height - 2 * b.width, b.radius - b.width / 1.571); cairo_set_source_rgba(c, bc.rgb[0], bc.rgb[1], bc.rgb[2], bc.alpha); } else { cairo_rectangle(c, 0., 0, width, height); cairo_set_source_rgb(c, bc.rgb[0], bc.rgb[1], bc.rgb[2]); } cairo_fill(c); cairo_set_line_width(c, b.width); if (server.real_transparency) draw_rect(c, b.width / 2.0, b.width / 2.0, width - b.width, height - b.width, b.radius); else cairo_rectangle(c, b.width / 2.0, b.width / 2.0, width - b.width, height - b.width); cairo_set_source_rgba(c, b.color.rgb[0], b.color.rgb[1], b.color.rgb[2], b.color.alpha); cairo_stroke(c); Color fc = g_tooltip.font_color; cairo_set_source_rgba(c, fc.rgb[0], fc.rgb[1], fc.rgb[2], fc.alpha); PangoLayout *layout = pango_cairo_create_layout(c); pango_layout_set_font_description(layout, g_tooltip.font_desc); pango_layout_set_wrap(layout, PANGO_WRAP_WORD); pango_layout_set_text(layout, g_tooltip.tooltip_text, -1); PangoRectangle r1, r2; pango_layout_get_pixel_extents(layout, &r1, &r2); pango_layout_set_width(layout, width * PANGO_SCALE); pango_layout_set_height(layout, height * PANGO_SCALE); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); // I do not know why this is the right way, but with the below cairo_move_to it seems to be centered (horiz. and // vert.) cairo_move_to(c, -r1.x / 2 + g_tooltip.bg->border.width + g_tooltip.paddingx, -r1.y / 2 + 1 + g_tooltip.bg->border.width + g_tooltip.paddingy); pango_cairo_show_layout(c, layout); g_object_unref(layout); cairo_destroy(c); cairo_surface_destroy(cs); }
static void gimp_ruler_size_request (GtkWidget *widget, GtkRequisition *requisition) { GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget); GtkStyle *style = gtk_widget_get_style (widget); PangoLayout *layout; PangoRectangle ink_rect; gint size; layout = gimp_ruler_get_layout (widget, "0123456789"); pango_layout_get_pixel_extents (layout, &ink_rect, NULL); size = 2 + ink_rect.height * 1.7; if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { requisition->width = style->xthickness * 2 + 1; requisition->height = style->ythickness * 2 + size; } else { requisition->width = style->xthickness * 2 + size; requisition->height = style->ythickness * 2 + 1; } }
TextAsset::Size TextAsset::computeSizeOfText(cairo_t* cairoContext, const std::string textString, int bounds, PangoFontDescription* font, Rect* tight, float* lineHeightOut) { PangoLayout* layout = pango_cairo_create_layout(cairoContext); // Kerning PangoAttrList* attr_list = pango_attr_list_new(); PangoAttribute* spacing_attr = pango_attr_letter_spacing_new(pango_units_from_double(_kern)); pango_attr_list_insert(attr_list, spacing_attr); pango_layout_set_attributes(layout, attr_list); pango_cairo_context_set_resolution(pango_layout_get_context(layout), DISPLAY_RESOLUTION); pango_layout_set_text(layout, textString.c_str(), (int)textString.length()); pango_layout_set_alignment(layout, _alignment); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); const Size maxTextureSize(bounds, 1024); pango_layout_set_width(layout, pango_units_from_double(maxTextureSize.width)); pango_layout_set_height(layout, pango_units_from_double(maxTextureSize.height)); pango_layout_set_font_description(layout, font); applyLeading(cairoContext, layout, font); PangoRectangle estimateSize; PangoRectangle ink; pango_layout_get_pixel_extents(layout, &ink, &estimateSize); // If the text is right or center aligned the offsets will contain all the // leading space. We ignore that for the size because drawText will draw // in the larger box. The tight box below will get the offsets so we know // where to draw so the text lands in the same tight box. Size res(estimateSize.width, estimateSize.height); if (tight != NULL) { float lineHeight; float xHeight = charHeight(cairoContext, font, 'x', &lineHeight); if (lineHeightOut != NULL) { *lineHeightOut = lineHeight; } const float capHeight = charHeight(cairoContext, font, 'Y'); const float ascender = pango_units_to_double(pango_layout_get_baseline(layout)); const float topSpace = ascender - capHeight; const float bottomSpace = MAX(lineHeight - ascender - (capHeight - xHeight), 0); if (res.height > topSpace + bottomSpace) { *tight = Rect(estimateSize.x, estimateSize.y + topSpace, res.width, res.height - topSpace - bottomSpace); } else { *tight = Rect(0, 0, res.width, res.height); } } g_object_unref(layout); return res; }
void shoes_plot_draw_label(cairo_t *cr, shoes_plot *plot, int x, int y, char *str, int where) { // TODO: Font was previously set to Helvetica 12 and color was setup // keep them for now cairo_font_extents_t ft; // TODO: pangocairo way cairo_font_extents(cr, &ft); int str_h = (int) ceil(ft.height); PangoLayout *layout = pango_cairo_create_layout (cr); pango_layout_set_font_description (layout , plot->label_pfd); pango_layout_set_text (layout, str, -1); PangoRectangle ct; pango_layout_get_pixel_extents (layout, NULL, &ct); int str_w = ct.width; int newx = 0; int newy = 0; if (where == LEFT) { // left side y-axis newx = x - (str_w + 3) - 1 ; newy = y - (str_h / 2); } else if (where == RIGHT) { // right side y-axis newx = x; newy = y - (str_h / 2); //printf("lbl rightx: %i, y: %i, %s\n", (int)newx, (int)newy, str); } else if (where == BELOW) { // bottom side x axis newx = x - (str_w / 2); newy = y + (str_h / 2); } else { printf("FAIL: shoes_plot_draw_label 'where ?'\n"); } cairo_move_to(cr, newx, newy); pango_cairo_show_layout(cr, layout); g_object_unref(layout); // printf("TODO: shoes_plot_draw_label called\n"); }
/* Updates the pango layout width */ static void update_pango_layout (MateIconTextItem *iti) { MateIconTextItemPrivate *priv; PangoRectangle bounds; const char *text; priv = iti->_priv; if (iti->editing) { text = gtk_entry_get_text (GTK_ENTRY (priv->entry)); } else { text = iti->text; } pango_layout_set_wrap (priv->layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_text (priv->layout, text, strlen (text)); pango_layout_set_width (priv->layout, iti->width * PANGO_SCALE); /* In PANGO_WRAP_WORD mode, words wider than a line of text make * PangoLayout overflow the layout width. If this happens, switch to * character-based wrapping. */ pango_layout_get_pixel_extents (iti->_priv->layout, NULL, &bounds); priv->layout_width = bounds.width; priv->layout_height = bounds.height; }
void get_font_size(font_info *font) { #ifndef USE_PANGO get_toy_font_size(font); #else PangoRectangle r; PangoLayout *temp; PangoFontDescription *temp_font; cairo_t *cr; cairo_surface_t *surface; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200); cr = cairo_create(surface); temp = pango_cairo_create_layout(cr); temp_font = pango_font_description_from_string(font->name); /* Draw an @, and measure it */ pango_layout_set_font_description(temp, temp_font); pango_layout_set_text(temp, "@", 1); pango_cairo_show_layout(cr, temp); pango_layout_get_pixel_extents(temp, NULL, &r); font->w = r.width; font->h = r.height; pango_font_description_free(temp_font); cairo_destroy(cr); cairo_surface_destroy(surface); g_object_unref(temp); #endif }
void tooltip_update_geometry() { cairo_surface_t *cs; cairo_t *c; PangoLayout* layout; cs = cairo_xlib_surface_create(server.dsp, g_tooltip.window, server.visual, width, height); c = cairo_create(cs); layout = pango_cairo_create_layout(c); pango_layout_set_font_description(layout, g_tooltip.font_desc); pango_layout_set_text(layout, g_tooltip.tooltip_text, -1); PangoRectangle r1, r2; pango_layout_get_pixel_extents(layout, &r1, &r2); width = 2*g_tooltip.bg->border.width + 2*g_tooltip.paddingx + r2.width; height = 2*g_tooltip.bg->border.width + 2*g_tooltip.paddingy + r2.height; Panel* panel = g_tooltip.panel; if (panel_horizontal && panel_position & BOTTOM) y = panel->posy-height; else if (panel_horizontal && panel_position & TOP) y = panel->posy + panel->area.height; else if (panel_position & LEFT) x = panel->posx + panel->area.width; else x = panel->posx - width; g_object_unref(layout); cairo_destroy(c); cairo_surface_destroy(cs); }
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring) { GdkPixbuf* glyph_pixbuf; cairo_surface_t *surface; PangoLayout* layout; PangoRectangle ink, logic; PangoContext* pango_context; gint w = gdk_pixbuf_get_width(base); gint h = gdk_pixbuf_get_height(base); cairo_t *cr; surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h); pango_context = gtk_widget_get_pango_context(widget); layout = pango_layout_new(pango_context); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, glyphstring, -1); cr = cairo_create (surface); gdk_cairo_set_source_color (cr, bg); cairo_paint (cr); gdk_cairo_set_source_color (cr, fg); pango_layout_get_pixel_extents(layout, &ink, &logic); cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2); pango_cairo_show_layout (cr, layout); cairo_destroy (cr); g_object_unref(layout); glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h); cairo_surface_destroy (surface); return glyph_pixbuf; }
//________________________________________________________ long GetVisibleStringWidth (_String& s, _HYFont& f) { static PangoLayout* textLayout = pango_layout_new (screenPContext); static PangoFontDescription * fd = pango_font_description_new (); static _HYFont stashedFont; if (s.sLength) { if (stashedFont.size!=f.size || stashedFont.style != f.style || stashedFont.face != f.face) { HYFont2PangoFontDesc(f,fd); pango_layout_set_width (textLayout,-1); pango_layout_set_font_description(textLayout,fd); stashedFont = f; } pango_layout_set_text (textLayout, s.sData,s.sLength); //PangoRectangle charPos; //pango_layout_index_to_pos (textLayout,s.sLength-1,&charPos); //return PANGO_PIXELS(charPos.x+charPos.width); PangoRectangle extents, logical_ext; pango_layout_get_pixel_extents (textLayout,&extents,&logical_ext); return logical_ext.width; } else { return 0; } }
static gint matewnck_selector_get_width (GtkWidget *widget, const char *text) { GtkStyle *style; PangoContext *context; PangoFontMetrics *metrics; gint char_width; PangoLayout *layout; PangoRectangle natural; gint max_width; gint screen_width; gint width; gtk_widget_ensure_style (widget); style = gtk_widget_get_style (widget); context = gtk_widget_get_pango_context (widget); metrics = pango_context_get_metrics (context, style->font_desc, pango_context_get_language (context)); char_width = pango_font_metrics_get_approximate_char_width (metrics); pango_font_metrics_unref (metrics); max_width = PANGO_PIXELS (SELECTOR_MAX_WIDTH * char_width); layout = gtk_widget_create_pango_layout (widget, text); pango_layout_get_pixel_extents (layout, NULL, &natural); g_object_unref (G_OBJECT (layout)); screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget)); width = MIN (natural.width, max_width); width = MIN (width, 3 * (screen_width / 4)); return width; }
void MapPainterSVG::GetTextDimension(const Projection& projection, const MapParameter& parameter, double fontSize, const std::string& text, double& xOff, double& yOff, double& width, double& height) { #if defined(OSMSCOUT_MAP_SVG_HAVE_LIB_PANGO) PangoFontDescription *font; PangoLayout *layout=pango_layout_new(pangoContext); PangoRectangle extends; font=GetFont(projection, parameter, fontSize); pango_layout_set_font_description(layout,font); pango_layout_set_text(layout,text.c_str(),text.length()); pango_layout_get_pixel_extents(layout,&extends,NULL); xOff=extends.x; yOff=extends.y; width=extends.width; height=pango_font_description_get_size(font)/PANGO_SCALE; g_object_unref(layout); #endif }
/* FIXME: It seems to overestimate the height a bit, it's visible on labels * with many curves. It also seems to strangely underestimate the width * for curve descriptions under certain length. */ static void gwy_graph_label_calculate_size(GwyGraphLabel *label) { gint i, nc; PangoLayout *layout; PangoRectangle rect; GwyGraphCurveModel *curvemodel; GwyGraphModel *model; label->reqheight = 0; label->reqwidth = 0; model = GWY_GRAPH_MODEL(label->graph_model); nc = gwy_graph_model_get_n_curves(model); for (i = 0; i < nc; i++) { curvemodel = gwy_graph_model_get_curve(model, i); layout = gtk_widget_create_pango_layout(GTK_WIDGET(label), NULL); pango_layout_set_font_description(layout, label->font_desc); pango_layout_set_markup(layout, curvemodel->description->str, curvemodel->description->len); pango_layout_get_pixel_extents(layout, NULL, &rect); if (label->reqwidth < rect.width) label->reqwidth = rect.width + 30 + model->label_frame_thickness; label->reqheight += rect.height + 5 + model->label_frame_thickness; g_object_unref(layout); } if (label->reqwidth == 0) label->reqwidth = 30; if (label->reqheight == 0) label->reqheight = 30; }
static void git_source_view_calculate_line_height (GitSourceView *sview) { GitSourceViewPrivate *priv = sview->priv; if (priv->line_height == 0 && GTK_WIDGET_REALIZED (sview) && priv->paint_source) { PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (sview), NULL); int line_num; PangoRectangle logical_rect; guint line_height = 1, max_line_width = 1, max_hash_length = 1; for (line_num = 0; line_num < git_annotated_source_get_n_lines (priv->paint_source); line_num++) { const GitAnnotatedSourceLine *line = git_annotated_source_get_line (priv->paint_source, line_num); git_source_view_set_text_for_line (layout, line); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); if (logical_rect.height > line_height) line_height = logical_rect.height; if (logical_rect.width > max_line_width) max_line_width = logical_rect.width; git_source_view_set_text_for_commit (layout, line->commit); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); if (logical_rect.height > line_height) line_height = logical_rect.height; if (logical_rect.width > max_hash_length) max_hash_length = logical_rect.width; } priv->line_height = line_height; priv->max_line_width = max_line_width; priv->max_hash_length = max_hash_length + GIT_SOURCE_VIEW_GAP * 2; g_object_unref (layout); git_source_view_update_scroll_adjustments (sview); } }
// force_width = -1 means no width restriction void textext(DC *dc, const char *text, int force_width, int breaklines, int *w, int *h) { PangoRectangle r; set_text(dc, text, force_width, breaklines); pango_layout_get_pixel_extents(dc->plo, 0, &r); if (w) *w = r.width; if (h) *h = r.height; }
static void internal_text_get_size_layout(GtkCellRenderer *cell, GtkWidget *widget, PangoLayout *layout, const GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height) { CustomCellRendererFlexi *cellflexi = CUSTOM_CELL_RENDERER_FLEXI (cell); PangoRectangle rect; gint calc_width; gint calc_height; gint xpad; gint ypad; gfloat yalign; if (layout==NULL) layout = internal_text_create_layout(widget,cellflexi); else g_object_ref(layout); g_assert(layout!=NULL); pango_layout_get_pixel_extents(layout,NULL,&rect); gtk_cell_renderer_get_padding(cell,&xpad,&ypad); calc_width = xpad * 2 + rect.width; calc_height = ypad * 2 + rect.height; if (width) { *width = calc_width; } if (height) { *height = calc_height; } if (cell_area) { if (x_offset) { *x_offset = 0; } if (y_offset) { gtk_cell_renderer_get_alignment(cell,NULL,&yalign); *y_offset = yalign * (cell_area->height - calc_height); *y_offset = MAX (*y_offset, 0); } } g_object_unref(layout); }
void aff_element_draw (AffElement *elem, gboolean selected, gint width, gint height, cairo_t *cr, GdkColor *color, PangoLayout *layout) { PangoRectangle rect; gint i; pango_layout_set_text (layout, elem->name, -1); pango_layout_get_pixel_extents (layout, NULL, &rect); gdk_cairo_set_source_color (cr, color); cairo_move_to (cr, elem->v.x * width - rect.width / 2, elem->v.y * width + rect.height / 2); pango_cairo_show_layout (cr, layout); cairo_fill (cr); cairo_set_line_width (cr, 1.0); if (elem->click_boundary != elem->draw_boundary) { cairo_move_to (cr, elem->click_boundary->points[0].x, elem->click_boundary->points[0].y); for (i = 1; i < elem->click_boundary->npoints; i++) cairo_line_to (cr, elem->click_boundary->points[i].x, elem->click_boundary->points[i].y); cairo_close_path (cr); cairo_stroke (cr); } if (selected) cairo_set_line_width (cr, 3.0); cairo_move_to (cr, elem->draw_boundary->points[0].x, elem->draw_boundary->points[0].y); for (i = 1; i < elem->draw_boundary->npoints; i++) cairo_line_to (cr, elem->draw_boundary->points[i].x, elem->draw_boundary->points[i].y); cairo_close_path (cr); cairo_stroke (cr); }
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring) { GdkPixbuf* glyph_pixbuf; #if GTK_CHECK_VERSION (3, 0, 0) cairo_surface_t *surface; #else GdkPixbuf *alpha_pixbuf; GdkPixmap* pixmap; #endif PangoLayout* layout; PangoRectangle ink, logic; PangoContext* pango_context; gint w = gdk_pixbuf_get_width(base); gint h = gdk_pixbuf_get_height(base); cairo_t *cr; #if GTK_CHECK_VERSION (3, 0, 0) surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h); #else pixmap = gdk_pixmap_new(gdk_get_default_root_window (),w, h, -1); #endif pango_context = gtk_widget_get_pango_context(widget); layout = pango_layout_new(pango_context); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, glyphstring, -1); #if GTK_CHECK_VERSION (3, 0, 0) cr = cairo_create (surface); #else cr = gdk_cairo_create (pixmap); #endif gdk_cairo_set_source_color (cr, bg); cairo_paint (cr); gdk_cairo_set_source_color (cr, fg); pango_layout_get_pixel_extents(layout, &ink, &logic); cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2); pango_cairo_show_layout (cr, layout); cairo_destroy (cr); g_object_unref(layout); #if GTK_CHECK_VERSION (3, 0, 0) glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h); cairo_surface_destroy (surface); return glyph_pixbuf; #else glyph_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, w, h); g_object_unref(pixmap); alpha_pixbuf = gdk_pixbuf_add_alpha(glyph_pixbuf, TRUE, bg->red >> 8, bg->green >> 8, bg->blue >> 8); g_object_unref(G_OBJECT(glyph_pixbuf)); return alpha_pixbuf; #endif }
static VALUE rg_pixel_extents(VALUE self) { PangoRectangle rink = {0, 0, 0, 0}; PangoRectangle rlog = {0, 0, 0, 0}; pango_layout_get_pixel_extents(_SELF(self), &rink, &rlog); return rb_assoc_new(BOXED2RVAL(&rink, PANGO_TYPE_RECTANGLE), BOXED2RVAL(&rlog, PANGO_TYPE_RECTANGLE)); }
/* area returns the union of the previous and new ink rectangles */ static void splash_position_layouts (GimpSplash *splash, const gchar *text1, const gchar *text2, GdkRectangle *area) { PangoRectangle ink; PangoRectangle logical; if (text1) { pango_layout_get_pixel_extents (splash->upper, &ink, NULL); if (area) splash_rectangle_union (area, &ink, splash->upper_x, splash->upper_y); pango_layout_set_text (splash->upper, text1, -1); pango_layout_get_pixel_extents (splash->upper, &ink, &logical); splash->upper_x = (splash->width - logical.width) / 2; splash->upper_y = splash->height - (2 * logical.height + 6); if (area) splash_rectangle_union (area, &ink, splash->upper_x, splash->upper_y); } if (text2) { pango_layout_get_pixel_extents (splash->lower, &ink, NULL); if (area) splash_rectangle_union (area, &ink, splash->lower_x, splash->lower_y); pango_layout_set_text (splash->lower, text2, -1); pango_layout_get_pixel_extents (splash->lower, &ink, &logical); splash->lower_x = (splash->width - logical.width) / 2; splash->lower_y = splash->height - (logical.height + 6); if (area) splash_rectangle_union (area, &ink, splash->lower_x, splash->lower_y); } }