static void dump_font_sizes (PangoContext *context, FILE *f, guint flags) { PangoFont *font; PangoFontDescription *pfd; int nf; real height; fprintf (f, "height/cm"); for (nf = 0; test_families[nf] != NULL; ++nf) fprintf (f, "\t%s", test_families[nf]); fprintf (f, "\n"); for (height = 0.1; height <= 10.0; height += 0.1) { fprintf (f, "%g", height); for (nf = 0; test_families[nf] != NULL; ++nf) { pfd = pango_font_description_new (); pango_font_description_set_family (pfd, test_families[nf]); //pango_font_description_set_size (pfd, height * pixels_per_cm * PANGO_SCALE); if (flags & DUMP_ABSOLUTE) pango_font_description_set_absolute_size (pfd, height * pixels_per_cm * PANGO_SCALE); else pango_font_description_set_size (pfd, height * pixels_per_cm * PANGO_SCALE); font = pango_context_load_font (context, pfd); if (font) { PangoFontMetrics *metrics = pango_font_get_metrics (font, NULL); /* now make a font-size where the font/line-height matches the given pixel size */ real total = ((double)pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; real factor = height*pixels_per_cm/total; real line_height; if (flags & DUMP_ABSOLUTE) pango_font_description_set_absolute_size (pfd, factor * height * pixels_per_cm * PANGO_SCALE); else pango_font_description_set_size (pfd, factor * height * pixels_per_cm * PANGO_SCALE); pango_font_metrics_unref (metrics); g_object_unref (font); font = pango_context_load_font (context, pfd); metrics = pango_font_get_metrics (font, NULL); line_height = ((double)pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; fprintf (f, "\t%.3g", flags & DUMP_FACTORS ? factor : line_height); g_object_unref (font); } pango_font_description_free (pfd); } fprintf (f, "\n"); } }
static gboolean _lib_darktable_draw_callback(GtkWidget *widget, cairo_t *cr, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_darktable_t *d = (dt_lib_darktable_t *)self->data; /* get the current style */ GdkRGBA color; PangoFontDescription *font_desc = NULL; GtkStateFlags state = gtk_widget_get_state_flags(widget); GtkStyleContext *context = gtk_widget_get_style_context(widget); gtk_style_context_get_background_color(context, state, &color); gtk_style_context_get(context, state, "font", &font_desc, NULL); /* fill background */ gdk_cairo_set_source_rgba(cr, &color); cairo_paint(cr); /* paint icon image */ if(d->image) { cairo_set_source_surface(cr, d->image, 0, (int)DT_PIXEL_APPLY_DPI(7)); cairo_rectangle(cr, 0, 0, d->image_width + (int)DT_PIXEL_APPLY_DPI(8), d->image_height + (int)DT_PIXEL_APPLY_DPI(8)); cairo_fill(cr); } /* create a pango layout and print fancy name/version string */ PangoLayout *layout; layout = gtk_widget_create_pango_layout(widget, NULL); pango_font_description_set_weight(font_desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(font_desc, DT_PIXEL_APPLY_DPI(25) * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); pango_layout_set_text(layout, PACKAGE_NAME, -1); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); cairo_move_to(cr, d->image_width + DT_PIXEL_APPLY_DPI(2.0), DT_PIXEL_APPLY_DPI(5.0)); pango_cairo_show_layout(cr, layout); /* print version */ pango_font_description_set_absolute_size(font_desc, DT_PIXEL_APPLY_DPI(10) * PANGO_SCALE); pango_layout_set_font_description(layout, font_desc); pango_layout_set_text(layout, PACKAGE_VERSION, -1); cairo_move_to(cr, d->image_width + DT_PIXEL_APPLY_DPI(4.0), DT_PIXEL_APPLY_DPI(30.0)); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.3); pango_cairo_show_layout(cr, layout); /* cleanup */ g_object_unref(layout); return TRUE; }
GtkWidget * create_welcome_dialog(void) { I7App *theapp = i7_app_get(); GFile *file = i7_app_get_data_file_va(theapp, "ui", "welcomedialog.ui", NULL); GtkBuilder *builder = create_new_builder(file, theapp); g_object_unref(file); GtkWidget *retval = GTK_WIDGET(load_object(builder, "welcomedialog")); /* Set the background pixmap for this window */ GtkRcStyle *newstyle = gtk_widget_get_modifier_style(retval); file = i7_app_get_data_file_va(theapp, "Resources", "Welcome Background.png", NULL); newstyle->bg_pixmap_name[GTK_STATE_NORMAL] = g_file_get_path(file); /* take ownership */ g_object_unref(file); gtk_widget_modify_style(retval, newstyle); /* Set the font size to 12 pixels for the widgets in this window */ PangoFontDescription *font = pango_font_description_new(); pango_font_description_set_absolute_size(font, 12.0 * PANGO_SCALE); gtk_widget_modify_font(GTK_WIDGET(load_object(builder, "welcome_label")), font); pango_font_description_free(font); /* If there is no "last project", make the reopen button inactive */ GFile *last_project = i7_app_get_last_opened_project(theapp); if(last_project) { gtk_widget_set_sensitive(GTK_WIDGET(load_object(builder, "welcome_reopen_button")), TRUE); g_object_unref(last_project); } g_object_unref(builder); return retval; }
JNIEXPORT void JNICALL Java_org_gnome_pango_PangoFontDescription_pango_1font_1description_1set_1absolute_1size ( JNIEnv* env, jclass cls, jlong _self, jdouble _size ) { PangoFontDescription* self; double size; // convert parameter self self = (PangoFontDescription*) _self; // convert parameter size size = (double) _size; // call function pango_font_description_set_absolute_size(self, size); // cleanup parameter self // cleanup parameter size }
void Text::SetString(const string& String) { cairo_surface_t* TempSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); cairo_t* LayoutContext = cairo_create(TempSurface); cairo_surface_destroy(TempSurface); PangoLayout* Layout = pango_cairo_create_layout(LayoutContext); pango_layout_set_width(Layout, LayoutWidth * PANGO_SCALE); pango_layout_set_wrap(Layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_text(Layout, String.c_str(), -1); PangoFontDescription* Desc = pango_font_description_from_string("Sans 18"); pango_font_description_set_absolute_size(Desc, Size * PANGO_SCALE); pango_font_description_set_weight(Desc, PANGO_WEIGHT_MEDIUM); pango_layout_set_font_description(Layout, Desc); pango_font_description_free(Desc); pango_layout_get_pixel_size(Layout, &Width, &Height); uint8_t* pData = (uint8_t*)calloc(4 * Width * Height, sizeof(uint8_t)); cairo_surface_t* Surface = cairo_image_surface_create_for_data(pData, CAIRO_FORMAT_ARGB32, Width, Height, 4 * Width); cairo_t* RenderContext = cairo_create(Surface); cairo_set_source_rgba(RenderContext, Color & 0xFF, (Color >> 8) & 0xFF, (Color >> 16) & 0xFF, Color >> 24); pango_cairo_show_layout(RenderContext, Layout); Create(pData, GL_RGBA, Width, Height); free(pData); g_object_unref(Layout); cairo_destroy(LayoutContext); cairo_destroy(RenderContext); cairo_surface_destroy(Surface); }
/* 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 void set_font(DiaRenderer *self, DiaFont *font, real height) { DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self); /* 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 if (renderer->cr) { DiaFontStyle style = dia_font_get_style (font); const char *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); DIAG_STATE(renderer->cr) }
static void add_text(cairo_surface_t* surface, int x, int y, int size, const char* text) { cairo_t* cr = cairo_create(surface); cairo_set_source_rgb(cr, 1., 1., 1.); PangoLayout* layout = pango_cairo_create_layout(cr); pango_layout_set_text(layout, text, -1); PangoFontDescription* desc = pango_font_description_new(); pango_font_description_set_family(desc, "sans"); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(desc, size * PANGO_SCALE); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); int w = 0; int h = 0; pango_layout_get_pixel_size(layout, &w, &h); cairo_move_to(cr, (x >= 0) ? x : -(x + (double)w), (y >= 0) ? y : -(y + (double)h)); pango_cairo_show_layout(cr, layout); g_object_unref(layout); cairo_destroy(cr); }
static gboolean _lib_darktable_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_darktable_t *d = (dt_lib_darktable_t *)self->data; /* get the current style */ GtkStyle *style=gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL,"GtkWidget", GTK_TYPE_WIDGET); if(!style) style = gtk_rc_get_style(widget); cairo_t *cr = gdk_cairo_create(widget->window); /* fill background */ cairo_set_source_rgb(cr, style->bg[0].red/65535.0, style->bg[0].green/65535.0, style->bg[0].blue/65535.0); cairo_paint(cr); /* paint icon image */ cairo_set_source_surface(cr, d->image, 0, 7); cairo_rectangle(cr,0,0,48,48); cairo_fill(cr); /* create a pango layout and print fancy name/version string */ PangoLayout *layout; layout = gtk_widget_create_pango_layout (widget,NULL); pango_font_description_set_weight (style->font_desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size (style->font_desc, 25 * PANGO_SCALE); pango_layout_set_font_description (layout,style->font_desc); pango_layout_set_text (layout,PACKAGE_NAME,-1); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); cairo_move_to (cr, 42.0, 5.0); pango_cairo_show_layout (cr, layout); /* print version */ pango_font_description_set_absolute_size (style->font_desc, 10 * PANGO_SCALE); pango_layout_set_font_description (layout,style->font_desc); pango_layout_set_text (layout,PACKAGE_VERSION,-1); cairo_move_to (cr, 44.0, 30.0); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.3); pango_cairo_show_layout (cr, layout); /* cleanup */ g_object_unref (layout); cairo_destroy(cr); return TRUE; }
void TextView::updatePangoFont(PangoLayout * layout, Text * t) { PangoFontDescription * desc = pango_font_description_from_string(t->getFont().getName().c_str()); pango_font_description_set_absolute_size(desc, t->getFont().getSize() * PANGO_SCALE); // pango_font_description_set_size(desc, t->getFont().getSize() * PANGO_SCALE); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); }
void Picture::set_font(const char *family, int height) { if (font_description == NULL) { font_description = pango_font_description_new( ); } pango_font_description_set_family(font_description, family); pango_font_description_set_weight(font_description, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(font_description, height * PANGO_SCALE); }
static PangoFontDescription * pango_cairo_core_text_font_describe_absolute (PangoFont *font) { PangoFontDescription *desc; PangoCairoCoreTextFont *cafont = (PangoCairoCoreTextFont *) font; desc = pango_font_describe (font); pango_font_description_set_absolute_size (desc, cafont->abs_size); return desc; }
PangoFontDescription* GetPangoFontDescription(const char* font, int size, int dpi) { PangoFontDescription* desc; desc = pango_font_description_new(); if (dpi) pango_font_description_set_size(desc, size * PANGO_SCALE); else pango_font_description_set_absolute_size(desc, size * PANGO_SCALE); pango_font_description_set_family(desc, font); return desc; }
void gwrgtk_button_set_label_font( GtkWidget* _button, const gchar* _fontname, PangoStyle _style, PangoWeight _weight, guint32 _absolute_size_in_device_units) { GtkWidget * l = gtk_bin_get_child( GTK_BIN(_button) ); PangoAttrList * pal = pango_attr_list_new(); PangoFontDescription * pfd = pango_font_description_new(); pango_font_description_set_family (pfd, _fontname ); pango_font_description_set_style (pfd, _style ); pango_font_description_set_weight (pfd, _weight ); pango_font_description_set_absolute_size(pfd, _absolute_size_in_device_units * PANGO_SCALE); PangoAttribute * pat = pango_attr_font_desc_new( pfd ); pango_attr_list_insert( pal, pat ); gtk_label_set_attributes( GTK_LABEL(l), pal ); }
static gboolean cairo_menu_item_expose (GtkWidget *widget,GdkEventExpose *event) { CairoMenuItemPrivate * priv = GET_PRIVATE(widget); if (priv->cairo_style) { PangoLayout *layout; double x,y,width,height; gchar * label; g_object_get (widget, "label",&label, NULL); cairo_t * cr = gdk_cairo_create (widget->window); g_debug ("%s: bit depth = %d",__func__,gdk_drawable_get_depth (widget->window)); // g_debug ("Region %d,%d: %dx%d",event->area.x, event->area.y,event->area.width, event->area.height); x = event->area.x; y = event->area.y; width = event->area.width; height = event->area.height; cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba (cr,0.0,1.0,0.0,0.1); cairo_rectangle (cr, x,y,width,height); cairo_fill (cr); layout = pango_cairo_create_layout (cr); pango_font_description_set_absolute_size (priv->font_description, height * 0.8 * PANGO_SCALE); pango_layout_set_font_description (layout, priv->font_description); pango_layout_set_text (layout, label, -1); cairo_set_source_rgba (cr,1.0,1.0,1.0,0.3); cairo_move_to (cr,x+height * 1.1,y+height*0.1); pango_cairo_show_layout (cr, layout); cairo_destroy (cr); g_object_unref (layout); g_free (label); return TRUE; } else { return FALSE; } }
PangoFontDescription* MapPainterSVG::GetFont(const Projection& projection, const MapParameter& parameter, double fontSize) { FontMap::const_iterator f; fontSize=fontSize*projection.ConvertWidthToPixel(parameter.GetFontSize()); f=fonts.find(fontSize); if (f!=fonts.end()) { return f->second; } PangoFontDescription* font=pango_font_description_new(); pango_font_description_set_family(font,parameter.GetFontName().c_str()); pango_font_description_set_absolute_size(font,fontSize*PANGO_SCALE); return fonts.insert(std::make_pair(fontSize,font)).first->second; }
static void hippo_canvas_context_win_init(HippoCanvasContextWin *canvas_win) { PangoFontDescription *desc; canvas_win->pointer = HIPPO_CANVAS_POINTER_UNSET; /* canvas_win->pango = pango_win32_get_context(); */ PangoCairoFontMap *font_map = (PangoCairoFontMap*) pango_cairo_font_map_get_default(); canvas_win->pango = pango_cairo_font_map_create_context(font_map); g_object_unref((void*) font_map); desc = pango_font_description_new(); // Sans is resolved in the pango.aliases we install; since the first element // is already "Arial", we specify just Sans here, rather than the "Arial,sans-serif" // we use in site.css. pango_font_description_set_family_static(desc, "Sans"); pango_font_description_set_absolute_size(desc, 12 * PANGO_SCALE); // FIXME on my laptop (Visual Studio 2005) this has crashed Pango with a g_error(), // but it seems to have mysteriously gone away. pango_context_set_font_description(canvas_win->pango, desc); pango_font_description_free(desc); }
static void hippo_canvas_context_win_init(HippoCanvasContextWin *canvas_win) { PangoFontDescription *desc; canvas_win->pointer = HIPPO_CANVAS_POINTER_UNSET; /* canvas_win->pango = pango_win32_get_context(); */ PangoCairoFontMap *font_map = (PangoCairoFontMap*) pango_cairo_font_map_get_default(); canvas_win->pango = pango_cairo_font_map_create_context(font_map); g_object_unref((void*) font_map); desc = pango_font_description_new(); // Note that this matches the web font in our site.css // We only set Arial instead of Arial, sans-serif because // pango cairo doesn't like a font list here. pango_font_description_set_family_static(desc, "Arial"); pango_font_description_set_absolute_size(desc, 12 * PANGO_SCALE); // FIXME on my laptop (Visual Studio 2005) this has crashed Pango with a g_error(), // but it seems to have mysteriously gone away. pango_context_set_font_description(canvas_win->pango, desc); pango_font_description_free(desc); }
lumi_world_t * lumi_world_alloc() { lumi_world_t *world = SHOE_ALLOC(lumi_world_t); SHOE_MEMZERO(world, lumi_world_t, 1); world->apps = rb_ary_new(); world->msgs = rb_ary_new(); world->mainloop = FALSE; world->image_cache = st_init_strtable(); world->blank_image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); world->blank_cache = SHOE_ALLOC(lumi_cached_image); world->blank_cache->surface = world->blank_image; world->blank_cache->pattern = NULL; world->blank_cache->width = 1; world->blank_cache->height = 1; world->blank_cache->mtime = 0; world->default_font = pango_font_description_new(); pango_font_description_set_family(world->default_font, "Arial"); pango_font_description_set_absolute_size(world->default_font, 14. * PANGO_SCALE * (96./72.)); rb_gc_register_address(&world->apps); rb_gc_register_address(&world->msgs); return world; }
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 dia_pfd_set_height(PangoFontDescription* pfd, real height) { /* ONLY place for the magic factor! */ pango_font_description_set_absolute_size(pfd, dcm_to_pdu(height) * 0.8); }
static PangoCairoFontHexBoxInfo * _pango_cairo_font_private_get_hex_box_info (PangoCairoFontPrivate *cf_priv) { static const char hexdigits[] = "0123456789ABCDEF"; char c[2] = {0, 0}; PangoFont *mini_font; PangoCairoFontHexBoxInfo *hbi; /* for metrics hinting */ double scale_x = 1., scale_x_inv = 1., scale_y = 1., scale_y_inv = 1.; gboolean is_hinted; int i; int rows; double pad; double width = 0; double height = 0; cairo_font_options_t *font_options; cairo_font_extents_t font_extents; double size, mini_size; PangoFontDescription *desc; cairo_scaled_font_t *scaled_font, *scaled_mini_font; PangoMatrix pango_ctm; cairo_matrix_t cairo_ctm; PangoGravity gravity; if (!cf_priv) return NULL; if (cf_priv->hbi) return cf_priv->hbi; scaled_font = _pango_cairo_font_private_get_scaled_font (cf_priv); if (G_UNLIKELY (scaled_font == NULL || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS)) return NULL; is_hinted = cf_priv->is_hinted; font_options = cairo_font_options_create (); desc = pango_font_describe_with_absolute_size ((PangoFont *)cf_priv->cfont); size = pango_font_description_get_size (desc) / (1.*PANGO_SCALE); gravity = pango_font_description_get_gravity (desc); cairo_scaled_font_get_ctm (scaled_font, &cairo_ctm); cairo_scaled_font_get_font_options (scaled_font, font_options); /* I started adding support for vertical hexboxes here, but it's too much * work. Easier to do with cairo user fonts and vertical writing mode * support in cairo. */ /*cairo_matrix_rotate (&cairo_ctm, pango_gravity_to_rotation (gravity));*/ pango_ctm.xx = cairo_ctm.xx; pango_ctm.yx = cairo_ctm.yx; pango_ctm.xy = cairo_ctm.xy; pango_ctm.yy = cairo_ctm.yy; pango_ctm.x0 = cairo_ctm.x0; pango_ctm.y0 = cairo_ctm.y0; if (is_hinted) { /* prepare for some hinting */ double x, y; x = 1.; y = 0.; cairo_matrix_transform_distance (&cairo_ctm, &x, &y); scale_x = sqrt (x*x + y*y); scale_x_inv = 1 / scale_x; x = 0.; y = 1.; cairo_matrix_transform_distance (&cairo_ctm, &x, &y); scale_y = sqrt (x*x + y*y); scale_y_inv = 1 / scale_y; } /* we hint to the nearest device units */ #define HINT(value, scale, scale_inv) (ceil ((value-1e-5) * scale) * scale_inv) #define HINT_X(value) HINT ((value), scale_x, scale_x_inv) #define HINT_Y(value) HINT ((value), scale_y, scale_y_inv) /* create mini_font description */ { PangoFontMap *fontmap; PangoContext *context; /* XXX this is racy. need a ref'ing getter... */ fontmap = pango_font_get_font_map ((PangoFont *)cf_priv->cfont); if (!fontmap) return NULL; fontmap = g_object_ref (fontmap); /* we inherit most font properties for the mini font. just * change family and size. means, you get bold hex digits * in the hexbox for a bold font. */ /* We should rotate the box, not glyphs */ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_GRAVITY); pango_font_description_set_family_static (desc, "monospace"); rows = 2; mini_size = size / 2.2; if (is_hinted) { mini_size = HINT_Y (mini_size); if (mini_size < 6.0) { rows = 1; mini_size = MIN (MAX (size - 1, 0), 6.0); } } pango_font_description_set_absolute_size (desc, pango_units_from_double (mini_size)); /* load mini_font */ context = pango_font_map_create_context (fontmap); pango_context_set_matrix (context, &pango_ctm); pango_context_set_language (context, pango_script_get_sample_language (PANGO_SCRIPT_LATIN)); pango_cairo_context_set_font_options (context, font_options); mini_font = pango_font_map_load_font (fontmap, context, desc); g_object_unref (context); g_object_unref (fontmap); } pango_font_description_free (desc); cairo_font_options_destroy (font_options); scaled_mini_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *) mini_font); for (i = 0 ; i < 16 ; i++) { cairo_text_extents_t extents; c[0] = hexdigits[i]; cairo_scaled_font_text_extents (scaled_mini_font, c, &extents); width = MAX (width, extents.width); height = MAX (height, extents.height); } cairo_scaled_font_extents (scaled_font, &font_extents); if (font_extents.ascent + font_extents.descent <= 0) { font_extents.ascent = PANGO_UNKNOWN_GLYPH_HEIGHT; font_extents.descent = 0; } pad = (font_extents.ascent + font_extents.descent) / 43; pad = MIN (pad, mini_size); hbi = g_slice_new (PangoCairoFontHexBoxInfo); hbi->font = (PangoCairoFont *) mini_font; hbi->rows = rows; hbi->digit_width = width; hbi->digit_height = height; hbi->pad_x = pad; hbi->pad_y = pad; if (is_hinted) { hbi->digit_width = HINT_X (hbi->digit_width); hbi->digit_height = HINT_Y (hbi->digit_height); hbi->pad_x = HINT_X (hbi->pad_x); hbi->pad_y = HINT_Y (hbi->pad_y); } hbi->line_width = MIN (hbi->pad_x, hbi->pad_y); hbi->box_height = 3 * hbi->pad_y + rows * (hbi->pad_y + hbi->digit_height); if (rows == 1 || hbi->box_height <= font_extents.ascent) { hbi->box_descent = 2 * hbi->pad_y; } else if (hbi->box_height <= font_extents.ascent + font_extents.descent - 2 * hbi->pad_y) { hbi->box_descent = 2 * hbi->pad_y + hbi->box_height - font_extents.ascent; } else { hbi->box_descent = font_extents.descent * hbi->box_height / (font_extents.ascent + font_extents.descent); } if (is_hinted) { hbi->box_descent = HINT_Y (hbi->box_descent); } cf_priv->hbi = hbi; return hbi; }
static gboolean _lib_histogram_draw_callback(GtkWidget *widget, cairo_t *crf, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_histogram_t *d = (dt_lib_histogram_t *)self->data; dt_develop_t *dev = darktable.develop; uint32_t *hist = dev->histogram; float hist_max = dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR ? dev->histogram_max : logf(1.0 + dev->histogram_max); const int inset = DT_HIST_INSET; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); int width = allocation.width, height = allocation.height; cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(cst); gtk_render_background(gtk_widget_get_style_context(widget), cr, 0, 0, allocation.width, allocation.height); cairo_translate(cr, 4 * inset, inset); width -= 2 * 4 * inset; height -= 2 * inset; if(d->mode_x == 0) { d->color_w = 0.06 * width; d->button_spacing = 0.01 * width; d->button_h = 0.06 * width; d->button_y = d->button_spacing; d->mode_w = d->color_w; d->mode_x = width - 3 * (d->color_w + d->button_spacing) - (d->mode_w + d->button_spacing); d->red_x = width - 3 * (d->color_w + d->button_spacing); d->green_x = width - 2 * (d->color_w + d->button_spacing); d->blue_x = width - (d->color_w + d->button_spacing); } // TODO: probably this should move to the configure-event callback! That would be future proof if we ever // (again) allow to resize the side panels. const gint stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); // this code assumes that the first expose comes before the first (preview) pipe is processed and that the // size of the widget doesn't change! if(dev->histogram_waveform_width == 0) { dev->histogram_waveform = (uint32_t *)calloc(height * stride / 4, sizeof(uint32_t)); dev->histogram_waveform_stride = stride; dev->histogram_waveform_height = height; dev->histogram_waveform_width = width; // return TRUE; // there are enough expose events following ... } #if 1 // draw shadow around float alpha = 1.0f; cairo_set_line_width(cr, 0.2); for(int k = 0; k < inset; k++) { cairo_rectangle(cr, -k, -k, width + 2 * k, height + 2 * k); cairo_set_source_rgba(cr, 0, 0, 0, alpha); alpha *= 0.5f; cairo_fill(cr); } cairo_set_line_width(cr, 1.0); #else cairo_set_line_width(cr, 1.0); cairo_set_source_rgb(cr, .1, .1, .1); cairo_rectangle(cr, 0, 0, width, height); cairo_stroke(cr); #endif cairo_rectangle(cr, 0, 0, width, height); cairo_clip(cr); cairo_set_source_rgb(cr, .3, .3, .3); cairo_rectangle(cr, 0, 0, width, height); cairo_fill(cr); if(d->highlight == 1) { cairo_set_source_rgb(cr, .5, .5, .5); cairo_rectangle(cr, 0, 0, .2 * width, height); cairo_fill(cr); } else if(d->highlight == 2) { cairo_set_source_rgb(cr, .5, .5, .5); cairo_rectangle(cr, 0.2 * width, 0, width, height); cairo_fill(cr); } // draw grid cairo_set_line_width(cr, .4); cairo_set_source_rgb(cr, .1, .1, .1); if(dev->histogram_type == DT_DEV_HISTOGRAM_WAVEFORM) dt_draw_waveform_lines(cr, 0, 0, width, height); else dt_draw_grid(cr, 4, 0, 0, width, height); if(hist_max > 0.0f) { cairo_save(cr); if(dev->histogram_type == DT_DEV_HISTOGRAM_WAVEFORM) { // make the color channel selector work: uint8_t *buf = (uint8_t *)malloc(sizeof(uint8_t) * height * stride); uint8_t mask[3] = { d->blue, d->green, d->red }; memcpy(buf, dev->histogram_waveform, sizeof(uint8_t) * height * stride); for(int y = 0; y < height; y++) for(int x = 0; x < width; x++) for(int k = 0; k < 3; k++) { buf[y * stride + x * 4 + k] *= mask[k]; } cairo_surface_t *source = cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_ARGB32, width, height, stride); cairo_set_source_surface(cr, source, 0.0, 0.0); cairo_set_operator(cr, CAIRO_OPERATOR_ADD); cairo_paint(cr); cairo_surface_destroy(source); free(buf); } else { // cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); cairo_translate(cr, 0, height); cairo_scale(cr, width / 63.0, -(height - 10) / hist_max); cairo_set_operator(cr, CAIRO_OPERATOR_ADD); // cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_line_width(cr, 1.); if(d->red) { cairo_set_source_rgba(cr, 1., 0., 0., 0.2); dt_draw_histogram_8(cr, hist, 0, dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR); } if(d->green) { cairo_set_source_rgba(cr, 0., 1., 0., 0.2); dt_draw_histogram_8(cr, hist, 1, dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR); } if(d->blue) { cairo_set_source_rgba(cr, 0., 0., 1., 0.2); dt_draw_histogram_8(cr, hist, 2, dev->histogram_type == DT_DEV_HISTOGRAM_LINEAR); } cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); // cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); } cairo_restore(cr); } cairo_set_source_rgb(cr, .25, .25, .25); cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); 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); pango_font_description_set_absolute_size(desc, .1 * height * PANGO_SCALE); pango_layout_set_font_description(layout, desc); char exifline[50]; dt_image_print_exif(&dev->image_storage, exifline, 50); pango_layout_set_text(layout, exifline, -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .02 * width, .98 * height - ink.height - ink.y); cairo_save(cr); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.0)); cairo_set_source_rgba(cr, 1, 1, 1, 0.3); pango_cairo_layout_path(cr, layout); cairo_stroke_preserve(cr); cairo_set_source_rgb(cr, .25, .25, .25); cairo_fill(cr); cairo_restore(cr); // buttons to control the display of the histogram: linear/log, r, g, b if(d->highlight != 0) { _draw_mode_toggle(cr, d->mode_x, d->button_y, d->mode_w, d->button_h, dev->histogram_type); cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.4); _draw_color_toggle(cr, d->red_x, d->button_y, d->color_w, d->button_h, d->red); cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 0.4); _draw_color_toggle(cr, d->green_x, d->button_y, d->color_w, d->button_h, d->green); cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 0.4); _draw_color_toggle(cr, d->blue_x, d->button_y, d->color_w, d->button_h, d->blue); } cairo_destroy(cr); cairo_set_source_surface(crf, cst, 0, 0); cairo_paint(crf); cairo_surface_destroy(cst); pango_font_description_free(desc); g_object_unref(layout); return TRUE; }
static gboolean lowlight_draw(GtkWidget *widget, cairo_t *crf, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_lowlight_gui_data_t *c = (dt_iop_lowlight_gui_data_t *)self->gui_data; dt_iop_lowlight_params_t p = *(dt_iop_lowlight_params_t *)self->params; dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); const int inset = DT_IOP_LOWLIGHT_INSET; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); int width = allocation.width, height = allocation.height; cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(cst); cairo_set_source_rgb(cr, .2, .2, .2); cairo_paint(cr); cairo_translate(cr, inset, inset); width -= 2 * inset; height -= 2 * inset; cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.0)); cairo_set_source_rgb(cr, .1, .1, .1); cairo_rectangle(cr, 0, 0, width, height); cairo_stroke(cr); cairo_set_source_rgb(cr, .3, .3, .3); cairo_rectangle(cr, 0, 0, width, height); cairo_fill(cr); // draw grid cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(.4)); cairo_set_source_rgb(cr, .1, .1, .1); dt_draw_grid(cr, 8, 0, 0, width, height); if(c->mouse_y > 0 || c->dragging) { // draw min/max curves: dt_iop_lowlight_get_params(&p, c->mouse_x, 1., c->mouse_radius); dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_min_xs, c->draw_min_ys); p = *(dt_iop_lowlight_params_t *)self->params; dt_iop_lowlight_get_params(&p, c->mouse_x, .0, c->mouse_radius); dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_max_xs, c->draw_max_ys); } cairo_save(cr); // draw x positions cairo_set_source_rgb(cr, 0.6, 0.6, 0.6); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.)); const float arrw = DT_PIXEL_APPLY_DPI(7.0f); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) { cairo_move_to(cr, width * p.transition_x[k], height + inset - DT_PIXEL_APPLY_DPI(1)); cairo_rel_line_to(cr, -arrw * .5f, 0); cairo_rel_line_to(cr, arrw * .5f, -arrw); cairo_rel_line_to(cr, arrw * .5f, arrw); cairo_close_path(cr); if(c->x_move == k) cairo_fill(cr); else cairo_stroke(cr); } // draw selected cursor cairo_translate(cr, 0, height); // cairo_set_operator(cr, CAIRO_OPERATOR_ADD); // cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.)); cairo_set_source_rgba(cr, .7, .7, .7, 1.0); p = *(dt_iop_lowlight_params_t *)self->params; dt_draw_curve_set_point(c->transition_curve, 0, p.transition_x[DT_IOP_LOWLIGHT_BANDS - 2] - 1.0, p.transition_y[0]); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) dt_draw_curve_set_point(c->transition_curve, k + 1, p.transition_x[k], p.transition_y[k]); dt_draw_curve_set_point(c->transition_curve, DT_IOP_LOWLIGHT_BANDS + 1, p.transition_x[1] + 1.0, p.transition_y[DT_IOP_LOWLIGHT_BANDS - 1]); dt_draw_curve_calc_values(c->transition_curve, 0.0, 1.0, DT_IOP_LOWLIGHT_RES, c->draw_xs, c->draw_ys); cairo_move_to(cr, 0 * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_ys[0]); for(int k = 1; k < DT_IOP_LOWLIGHT_RES; k++) cairo_line_to(cr, k * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_ys[k]); cairo_stroke(cr); // draw dots on knots cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1.)); for(int k = 0; k < DT_IOP_LOWLIGHT_BANDS; k++) { cairo_arc(cr, width * p.transition_x[k], -height * p.transition_y[k], DT_PIXEL_APPLY_DPI(3.0), 0.0, 2.0 * M_PI); if(c->x_move == k) cairo_fill(cr); else cairo_stroke(cr); } if(c->mouse_y > 0 || c->dragging) { // draw min/max, if selected cairo_set_source_rgba(cr, .7, .7, .7, .6); cairo_move_to(cr, 0, -height * c->draw_min_ys[0]); for(int k = 1; k < DT_IOP_LOWLIGHT_RES; k++) cairo_line_to(cr, k * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_min_ys[k]); for(int k = DT_IOP_LOWLIGHT_RES - 1; k >= 0; k--) cairo_line_to(cr, k * width / (float)(DT_IOP_LOWLIGHT_RES - 1), -height * c->draw_max_ys[k]); cairo_close_path(cr); cairo_fill(cr); // draw mouse focus circle cairo_set_source_rgba(cr, .9, .9, .9, .5); const float pos = DT_IOP_LOWLIGHT_RES * c->mouse_x; int k = (int)pos; const float f = k - pos; if(k >= DT_IOP_LOWLIGHT_RES - 1) k = DT_IOP_LOWLIGHT_RES - 2; float ht = -height * (f * c->draw_ys[k] + (1 - f) * c->draw_ys[k + 1]); cairo_arc(cr, c->mouse_x * width, ht, c->mouse_radius * width, 0, 2. * M_PI); cairo_stroke(cr); } cairo_restore(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); // draw labels: 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); pango_font_description_set_absolute_size(desc,(.06 * height) * PANGO_SCALE); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, desc); cairo_set_source_rgb(cr, .1, .1, .1); pango_layout_set_text(layout, _("dark"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .02 * width - ink.y, .5 * (height + ink.width)); cairo_save(cr); cairo_rotate(cr, -M_PI * .5f); pango_cairo_show_layout(cr, layout); cairo_restore(cr); pango_layout_set_text(layout, _("bright"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .98 * width - ink.height, .5 * (height + ink.width)); cairo_save(cr); cairo_rotate(cr, -M_PI * .5f); pango_cairo_show_layout(cr, layout); cairo_restore(cr); pango_layout_set_text(layout, _("day vision"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .5 * (width - ink.width), .08 * height - ink.height); pango_cairo_show_layout(cr, layout); pango_layout_set_text(layout, _("night vision"), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); cairo_move_to(cr, .5 * (width - ink.width), .97 * height - ink.height); pango_cairo_show_layout(cr, layout); pango_font_description_free(desc); g_object_unref(layout); cairo_destroy(cr); cairo_set_source_surface(crf, cst, 0, 0); cairo_paint(crf); cairo_surface_destroy(cst); return TRUE; }
void Font::setPixelSize(int size) { pango_font_description_set_absolute_size(desc_, size); }
void GuiSolidLabelElementRenderer::OnElementStateChanged() { FontProperties font = element->GetFont(); Color color = element->GetColor(); int layoutWidth, layoutHeight; AString family = wtoa(font.fontFamily); pango_font_description_set_family(pangoFontDesc, family.Buffer()); pango_font_description_set_absolute_size(pangoFontDesc, font.size * PANGO_SCALE); if(font.italic) pango_font_description_set_style(pangoFontDesc, PANGO_STYLE_ITALIC); else pango_font_description_set_style(pangoFontDesc, PANGO_STYLE_NORMAL); if(attrList) { pango_attr_list_unref(attrList); } attrList = pango_attr_list_new(); pango_attr_list_insert(attrList, pango_attr_underline_new( font.underline ? PANGO_UNDERLINE_SINGLE : PANGO_UNDERLINE_NONE) ); pango_attr_list_insert(attrList, pango_attr_strikethrough_new ( font.strikeline ? TRUE : FALSE ) ); pango_attr_list_insert(attrList, pango_attr_weight_new ( font.bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_MEDIUM ) ); if(layout) { g_object_unref(layout); layout = NULL; } if(cairoContext) { layout = pango_cairo_create_layout(cairoContext); WString wtext = (font.fontFamily == L"Webdings") ? helpers::WebdingsMap(element->GetText()) : element->GetText(); AString text = wtoa(wtext); pango_layout_set_font_description(layout, pangoFontDesc); pango_layout_set_attributes(layout, attrList); pango_layout_set_text(layout, text.Buffer(), text.Length()); pango_layout_set_alignment(layout, element->GetHorizontalAlignment() == Alignment::Left ? PANGO_ALIGN_LEFT : element->GetHorizontalAlignment() == Alignment::Center ? PANGO_ALIGN_CENTER : element->GetHorizontalAlignment() == Alignment::Right ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT ); pango_cairo_update_layout(cairoContext, layout); pango_layout_get_pixel_size( layout, &layoutWidth, &layoutHeight); minSize.x = layoutWidth; minSize.y = layoutHeight; } }
FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) : m_context(0) , m_font(0) , m_size(fontDescription.computedSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_scaledFont(0) { FontPlatformData::init(); CString stored_family = familyName.string().utf8(); char const* families[] = { stored_family.data(), NULL }; switch (fontDescription.genericFamily()) { case FontDescription::SerifFamily: families[1] = "serif"; break; case FontDescription::SansSerifFamily: families[1] = "sans"; break; case FontDescription::MonospaceFamily: families[1] = "monospace"; break; case FontDescription::NoFamily: case FontDescription::StandardFamily: default: families[1] = "sans"; break; } PangoFontDescription* description = pango_font_description_new(); pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE); // FIXME: Map all FontWeight values to Pango font weights. if (fontDescription.weight() >= FontWeight600) pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); if (fontDescription.italic()) pango_font_description_set_style(description, PANGO_STYLE_ITALIC); #if PANGO_VERSION_CHECK(1,21,5) // deprecated in 1.21 m_context = pango_font_map_create_context(m_fontMap); #else m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap)); #endif for (unsigned int i = 0; !m_font && i < G_N_ELEMENTS(families); i++) { pango_font_description_set_family(description, families[i]); pango_context_set_font_description(m_context, description); m_font = pango_font_map_load_font(m_fontMap, m_context, description); } #if PANGO_VERSION_CHECK(1,18,0) if (m_font) m_scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font))); #else // This compatibility code for older versions of Pango is not well-tested. if (m_font) { PangoFcFont* fcfont = PANGO_FC_FONT(m_font); cairo_font_face_t* face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern); double size; if (FcPatternGetDouble(fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch) size = 12.0; cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_font_options_t* fontOptions; if (pango_cairo_context_get_font_options(m_context)) fontOptions = cairo_font_options_copy(pango_cairo_context_get_font_options(m_context)); else fontOptions = cairo_font_options_create(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); m_scaledFont = cairo_scaled_font_create(face, &fontMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); cairo_font_face_destroy(face); } #endif pango_font_description_free(description); }
gboolean hitori_draw_cb (GtkWidget *drawing_area, cairo_t *cr, Hitori *hitori) { gint area_width, area_height; HitoriVector iter; guint board_width, board_height; gfloat cell_size; gdouble x_pos, y_pos; GtkStyleContext *style_context; area_width = gdk_window_get_width (gtk_widget_get_window (hitori->drawing_area)); area_height = gdk_window_get_height (gtk_widget_get_window (hitori->drawing_area)); style_context = gtk_widget_get_style_context (hitori->drawing_area); /* Clamp the width/height to the minimum */ if (area_height < area_width) { board_width = area_height; board_height = area_height; } else { board_width = area_width; board_height = area_width; } /* Work out the cell size and scale all text accordingly */ cell_size = board_width / hitori->board_size; pango_font_description_set_absolute_size (hitori->normal_font_desc, cell_size * NORMAL_FONT_SCALE * 0.8 * PANGO_SCALE); pango_font_description_set_absolute_size (hitori->painted_font_desc, cell_size * PAINTED_FONT_SCALE * 0.8 * PANGO_SCALE); /* Centre the board */ hitori->drawing_area_x_offset = (area_width - board_width) / 2; hitori->drawing_area_y_offset = (area_height - board_height) / 2; cairo_translate (cr, hitori->drawing_area_x_offset, hitori->drawing_area_y_offset); /* Draw the unpainted cells first. */ for (iter.x = 0, x_pos = 0; iter.x < hitori->board_size; iter.x++, x_pos += cell_size) { /* columns (X) */ for (iter.y = 0, y_pos = 0; iter.y < hitori->board_size; iter.y++, y_pos += cell_size) { /* rows (Y) */ if (!(hitori->board[iter.x][iter.y].status & CELL_PAINTED)) { draw_cell (hitori, style_context, cr, cell_size, x_pos, y_pos, iter); } } } /* Next draw the painted cells (so that their borders are painted over those of the unpainted cells).. */ for (iter.x = 0, x_pos = 0; iter.x < hitori->board_size; iter.x++, x_pos += cell_size) { /* columns (X) */ for (iter.y = 0, y_pos = 0; iter.y < hitori->board_size; iter.y++, y_pos += cell_size) { /* rows (Y) */ if (hitori->board[iter.x][iter.y].status & CELL_PAINTED) { draw_cell (hitori, style_context, cr, cell_size, x_pos, y_pos, iter); } } } /* Draw a hint if applicable */ if (hitori->hint_status % 2 == 1) { gfloat line_width = BORDER_LEFT * 2.5; GdkRGBA colour; lookup_color (style_context, "hint-border-color", &colour); gdk_cairo_set_source_rgba (cr, &colour); cairo_set_line_width (cr, line_width); cairo_rectangle (cr, hitori->hint_position.x * cell_size + line_width / 2, hitori->hint_position.y * cell_size + line_width / 2, cell_size - line_width, cell_size - line_width); cairo_stroke (cr); } return FALSE; }
void *dt_control_expose(void *voidptr) { int width, height, pointerx, pointery; if(!darktable.gui->surface) return NULL; width = dt_cairo_image_surface_get_width(darktable.gui->surface); height = dt_cairo_image_surface_get_height(darktable.gui->surface); GtkWidget *widget = dt_ui_center(darktable.gui->ui); GdkDevice *device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget))); gdk_window_get_device_position(gtk_widget_get_window(widget), device, &pointerx, &pointery, NULL); // create a gtk-independent surface to draw on cairo_surface_t *cst = dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(cst); // TODO: control_expose: only redraw the part not overlapped by temporary control panel show! // float tb = 8; // fmaxf(10, width/100.0); darktable.control->tabborder = tb; darktable.control->width = width; darktable.control->height = height; GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(widget); gboolean color_found = gtk_style_context_lookup_color (context, "bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_set_line_width(cr, tb); cairo_rectangle(cr, tb / 2., tb / 2., width - tb, height - tb); cairo_stroke(cr); cairo_set_line_width(cr, 1.5); color_found = gtk_style_context_lookup_color (context, "really_dark_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_rectangle(cr, tb, tb, width - 2 * tb, height - 2 * tb); cairo_stroke(cr); cairo_save(cr); cairo_translate(cr, tb, tb); cairo_rectangle(cr, 0, 0, width - 2 * tb, height - 2 * tb); cairo_clip(cr); cairo_new_path(cr); // draw view dt_view_manager_expose(darktable.view_manager, cr, width - 2 * tb, height - 2 * tb, pointerx - tb, pointery - tb); cairo_restore(cr); // draw log message, if any dt_pthread_mutex_lock(&darktable.control->log_mutex); if(darktable.control->log_ack != darktable.control->log_pos) { PangoRectangle ink; PangoLayout *layout; PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc); const float fontsize = DT_PIXEL_APPLY_DPI(14); pango_font_description_set_absolute_size(desc, fontsize * PANGO_SCALE); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, darktable.control->log_message[darktable.control->log_ack], -1); pango_layout_get_pixel_extents(layout, &ink, NULL); const float pad = DT_PIXEL_APPLY_DPI(20.0f), xc = width / 2.0; const float yc = height * 0.85 + DT_PIXEL_APPLY_DPI(10), wd = pad + ink.width * .5f; float rad = DT_PIXEL_APPLY_DPI(14); cairo_set_line_width(cr, 1.); cairo_move_to(cr, xc - wd, yc + rad); for(int k = 0; k < 5; k++) { cairo_arc(cr, xc - wd, yc, rad, M_PI / 2.0, 3.0 / 2.0 * M_PI); cairo_line_to(cr, xc + wd, yc - rad); cairo_arc(cr, xc + wd, yc, rad, 3.0 * M_PI / 2.0, M_PI / 2.0); cairo_line_to(cr, xc - wd, yc + rad); if(k == 0) { color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_fill_preserve(cr); } cairo_set_source_rgba(cr, 0., 0., 0., 1.0 / (1 + k)); cairo_stroke(cr); rad += .5f; } color_found = gtk_style_context_lookup_color (context, "fg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } gdk_cairo_set_source_rgba(cr, &color); cairo_move_to(cr, xc - wd + .5f * pad, (yc + 1. / 3. * fontsize) - fontsize); pango_cairo_show_layout(cr, layout); pango_font_description_free(desc); g_object_unref(layout); } // draw busy indicator if(darktable.control->log_busy > 0) { PangoRectangle ink; PangoLayout *layout; PangoFontDescription *desc = pango_font_description_copy_static(darktable.bauhaus->pango_font_desc); const float fontsize = DT_PIXEL_APPLY_DPI(14); pango_font_description_set_absolute_size(desc, fontsize * PANGO_SCALE); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, _("working.."), -1); pango_layout_get_pixel_extents(layout, &ink, NULL); const float xc = width / 2.0, yc = height * 0.85 - DT_PIXEL_APPLY_DPI(30), wd = ink.width * .5f; cairo_move_to(cr, xc - wd, yc + 1. / 3. * fontsize - fontsize); pango_cairo_layout_path(cr, layout); cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); cairo_fill_preserve(cr); cairo_set_line_width(cr, 0.7); cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); cairo_stroke(cr); pango_font_description_free(desc); g_object_unref(layout); } dt_pthread_mutex_unlock(&darktable.control->log_mutex); cairo_destroy(cr); cairo_t *cr_pixmap = cairo_create(darktable.gui->surface); cairo_set_source_surface(cr_pixmap, cst, 0, 0); cairo_paint(cr_pixmap); cairo_destroy(cr_pixmap); cairo_surface_destroy(cst); return NULL; }
extern struct view_s* window_new(const char* name, long* pos, const long dims[DIMS], const complex float* x) { struct view_s* v = create_view(name, pos, dims, x); GtkBuilder* builder = gtk_builder_new(); // gtk_builder_add_from_file(builder, "viewer.ui", NULL); gtk_builder_add_from_string(builder, viewer_gui, -1, NULL); v->gtk_drawingarea = GTK_WIDGET(gtk_builder_get_object(builder, "drawingarea1")); v->gtk_viewport = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow1")); v->gtk_winlow = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "winlow")); v->gtk_winhigh = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "winhigh")); v->gtk_entry = GTK_ENTRY(gtk_builder_get_object(builder, "entry")); PangoFontDescription* desc = pango_font_description_new(); pango_font_description_set_family(desc, "mono"); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(desc, 10 * PANGO_SCALE); gtk_widget_override_font(GTK_WIDGET(v->gtk_entry), desc); pango_font_description_free(desc); v->gtk_zoom = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "zoom")); v->gtk_aniso = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "aniso")); v->gtk_mode = GTK_COMBO_BOX(gtk_builder_get_object(builder, "mode")); gtk_combo_box_set_active(v->gtk_mode, 0); v->gtk_flip = GTK_COMBO_BOX(gtk_builder_get_object(builder, "flip")); gtk_combo_box_set_active(v->gtk_flip, 0); v->gtk_transpose = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(builder, "transpose")); for (int j = 0; j < DIMS; j++) { char pname[10]; snprintf(pname, 10, "pos%02d", j); v->gtk_posall[j] = GTK_ADJUSTMENT(gtk_builder_get_object(builder, pname)); gtk_adjustment_set_upper(v->gtk_posall[j], v->dims[j] - 1); gtk_adjustment_set_value(v->gtk_posall[j], 0); snprintf(pname, 10, "check%02d", j); v->gtk_checkall[j] = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, pname)); } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->xdim]), TRUE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(v->gtk_checkall[v->ydim]), TRUE); gtk_builder_connect_signals(builder, v); GtkWindow* window = GTK_WINDOW(gtk_builder_get_object(builder, "window1")); g_object_unref(G_OBJECT(builder)); gtk_window_set_title(window, name); gtk_widget_show(GTK_WIDGET(window)); nr_windows++; refresh_callback(NULL, v); geom_callback(NULL, v); window_callback(NULL, v); return v; }