From: ellson Date: Sat, 12 Feb 2011 16:01:47 +0000 (+0000) Subject: various hacks on test program - retain in conditional blocks X-Git-Tag: LAST_LIBGRAPH~32^2~1040 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f65bce55a9871c26001e84d8457bcd31a0e79cc5;p=graphviz various hacks on test program - retain in conditional blocks cVS: ---------------------------------------------------------------------- --- diff --git a/contrib/pangotest/pangotest.c b/contrib/pangotest/pangotest.c index f474497db..912ed5406 100644 --- a/contrib/pangotest/pangotest.c +++ b/contrib/pangotest/pangotest.c @@ -11,29 +11,29 @@ #define FONT_DPI 96 static void draw_text(cairo_t *cr, char *text, char *font_family, double font_size){ - static PangoFontMap *fontmap; static PangoContext *context; + PangoFontMap *fontmap; PangoLayout *layout; PangoFontDescription *desc; - PangoRectangle logical_rect, ink_rect; - PangoRectangle pixel_logical_rect, pixel_ink_rect; - PangoFont *font; - PangoFontMetrics *fontmetrics; - cairo_font_options_t *options; - const char *fontclass, *fontdesc; - int baseline, ascent, descent; + PangoRectangle logical_rect; if (!context) { fontmap = pango_cairo_font_map_new(); context = pango_font_map_create_context (fontmap); - options=cairo_font_options_create(); - cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); - cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL); - cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON); - cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR); - pango_cairo_context_set_font_options(context, options); +#if 0 + { + cairo_font_options_t *options; + + options=cairo_font_options_create(); + cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); + cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL); + cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON); + cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR); + pango_cairo_context_set_font_options(context, options); + cairo_font_options_destroy(options); + } +#endif pango_cairo_context_set_resolution(context, FONT_DPI); - cairo_font_options_destroy(options); g_object_unref(fontmap); } @@ -42,77 +42,121 @@ static void draw_text(cairo_t *cr, char *text, char *font_family, double font_si pango_layout_set_text(layout,text,-1); desc = pango_font_description_from_string(font_family); pango_font_description_set_size (desc, (gint)(font_size * PANGO_SCALE)); + pango_layout_set_font_description(layout,desc); - font = pango_font_map_load_font(fontmap, context, desc); - fontclass = G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(font)); - fontdesc = pango_font_description_to_string(pango_font_describe(font)); - fprintf(stderr,"%s: %s %s\n", font_family, fontclass, fontdesc); - g_free((gpointer)fontdesc); +#if 1 + { + PangoFont *font; + const char *fontclass, *fontdesc; + + font = pango_font_map_load_font(fontmap, context, desc); + fontclass = G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(font)); + fontdesc = pango_font_description_to_string(pango_font_describe(font)); + + fprintf(stderr," %s: %s %s", font_family, fontclass, fontdesc); + + g_free((gpointer)fontdesc); + } +#endif - pango_layout_set_font_description(layout,desc); pango_font_description_free(desc); /* draw text - black */ cairo_set_source_rgb(cr,0.0,0.0,0.0); pango_cairo_show_layout(cr,layout); - - /* draw logical_rect - purple */ - pango_layout_get_extents (layout, &ink_rect, &logical_rect); - cairo_set_source_rgb(cr,1.0,0.0,1.0); - cairo_rectangle(cr, - logical_rect.x / PANGO_SCALE, logical_rect.y / PANGO_SCALE, - logical_rect.width / PANGO_SCALE, logical_rect.height / PANGO_SCALE); - cairo_stroke(cr); + /* used in multiple places - do unconditionally */ + pango_layout_get_extents (layout, NULL, &logical_rect); + +#if 1 + { + /* draw logical_rect - purple */ + cairo_set_source_rgb(cr,1.0,0.0,1.0); + cairo_rectangle(cr, + logical_rect.x / PANGO_SCALE, logical_rect.y / PANGO_SCALE, + logical_rect.width / PANGO_SCALE, logical_rect.height / PANGO_SCALE); + cairo_stroke(cr); + + fprintf(stderr," y=%d height=%d", logical_rect.y, logical_rect.height); + } +#endif - /* draw ink_rect - green */ - cairo_set_source_rgb(cr,0.0,1.0,0.0); - cairo_rectangle(cr, - ink_rect.x / PANGO_SCALE, ink_rect.y / PANGO_SCALE, - ink_rect.width / PANGO_SCALE, ink_rect.height / PANGO_SCALE); - cairo_stroke(cr); +#if 0 + { + /* draw ink_rect - green */ + PangoRectangle ink_rect; + + pango_layout_get_extents (layout, &ink_rect, NULL); + cairo_set_source_rgb(cr,0.0,1.0,0.0); + cairo_rectangle(cr, + ink_rect.x / PANGO_SCALE, ink_rect.y / PANGO_SCALE, + ink_rect.width / PANGO_SCALE, ink_rect.height / PANGO_SCALE); + cairo_stroke(cr); + } +#endif - /* draw pixel logical_rect - blue */ - pango_layout_get_pixel_extents (layout, &pixel_ink_rect, &pixel_logical_rect); #if 0 /* results in same rect as non-pixel extents */ - cairo_set_source_rgb(cr,0.0,0.0,1.0); - cairo_rectangle(cr, - pixel_logical_rect.x, pixel_logical_rect.y, - pixel_logical_rect.width, pixel_logical_rect.height); - cairo_stroke(cr); + { + PangoRectangle pixel_logical_rect; + + pango_layout_get_pixel_extents (layout, NULL, &pixel_logical_rect); + + /* draw pixel logical_rect - blue */ + cairo_set_source_rgb(cr,0.0,0.0,1.0); + cairo_rectangle(cr, + pixel_logical_rect.x, pixel_logical_rect.y, + pixel_logical_rect.width, pixel_logical_rect.height); + cairo_stroke(cr); + } #endif - /* draw baseline - red */ - cairo_set_source_rgb(cr,1.0,0.0,0.0); - baseline = pango_layout_get_baseline (layout); - cairo_move_to(cr,logical_rect.x / PANGO_SCALE, baseline / PANGO_SCALE); - cairo_rel_line_to(cr,logical_rect.width / PANGO_SCALE, 0); - cairo_stroke(cr); +#if 1 + { + int baseline; - /* draw ascent - yellow */ - cairo_set_source_rgb(cr,1.0,1.0,0.0); - fontmetrics = pango_context_get_metrics(context, NULL, NULL); + baseline = pango_layout_get_baseline (layout); + + /* draw baseline - red */ + cairo_set_source_rgb(cr,1.0,0.0,0.0); + cairo_move_to(cr,logical_rect.x / PANGO_SCALE, baseline / PANGO_SCALE); + cairo_rel_line_to(cr,logical_rect.width / PANGO_SCALE, 0); + cairo_stroke(cr); + + fprintf(stderr," baseline=%d\n", baseline); + } +#endif - ascent = pango_font_metrics_get_ascent(fontmetrics); #if 0 /* I don't understand this value - needs some partial scaling by font_size */ + { + /* magic didn't work - not portable across font backends */ #define magic (font_size / 16) - cairo_move_to(cr,logical_rect.x / PANGO_SCALE, (baseline - magic * ascent) / PANGO_SCALE); - cairo_rel_line_to(cr,logical_rect.width / PANGO_SCALE, 0); - cairo_stroke(cr); -#endif - /* draw descent - yellow */ - descent = pango_font_metrics_get_descent(fontmetrics); -#if 0 /* I don't understand this value - needs some partial scaling by font_size */ - cairo_move_to(cr,logical_rect.x / PANGO_SCALE, (baseline + magic * descent) / PANGO_SCALE); - cairo_rel_line_to(cr,logical_rect.width / PANGO_SCALE, 0); - cairo_stroke(cr); + PangoFontMetrics *fontmetrics; + int ascent, descent; + + fontmetrics = pango_context_get_metrics(context, NULL, NULL); + + /* draw ascent - yellow */ + cairo_set_source_rgb(cr,1.0,1.0,0.0); + ascent = pango_font_metrics_get_ascent(fontmetrics); + cairo_move_to(cr,logical_rect.x / PANGO_SCALE, (baseline - magic * ascent) / PANGO_SCALE); + cairo_rel_line_to(cr,logical_rect.width / PANGO_SCALE, 0); + cairo_stroke(cr); + + /* draw descent - yellow */ + descent = pango_font_metrics_get_descent(fontmetrics); + cairo_move_to(cr,logical_rect.x / PANGO_SCALE, (baseline + magic * descent) / PANGO_SCALE); + cairo_rel_line_to(cr,logical_rect.width / PANGO_SCALE, 0); + cairo_stroke(cr); + + pango_font_metrics_unref(fontmetrics); + } #endif - pango_font_metrics_unref(fontmetrics); - g_object_unref(layout); + +fprintf(stderr,"\n"); } static cairo_status_t