]> granicus.if.org Git - graphviz/commitdiff
back out previous change -- too much for one change
authorellson <devnull@localhost>
Sat, 12 Feb 2011 16:00:00 +0000 (16:00 +0000)
committerellson <devnull@localhost>
Sat, 12 Feb 2011 16:00:00 +0000 (16:00 +0000)
contrib/pangotest/pangotest.c
plugin/pango/gvtextlayout_pango.c

index 912ed5406eaf5179468790cee3647fd02a06367b..f474497dbf198f3d6ab034006cc2d9065631670c 100644 (file)
 #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;
+       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;
 
        if (!context) {
                fontmap = pango_cairo_font_map_new();
                context = pango_font_map_create_context (fontmap);
-#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
+               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);
                pango_cairo_context_set_resolution(context, FONT_DPI);
+               cairo_font_options_destroy(options);
                g_object_unref(fontmap);
        }
        
@@ -42,121 +42,77 @@ 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);
-
-#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
+       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);
 
+       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);
-
-       /* 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 logical_rect - purple */
+       pango_layout_get_extents (layout, &ink_rect, &logical_rect);
 
-#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
+       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);
+
+       /* 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);
 
+       /* 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 */
-       {
-               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);
-       }
+       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
 
-#if 1
-       {
-               int baseline;
+       /* 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);
 
-               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
+       /* draw ascent - yellow */
+       cairo_set_source_rgb(cr,1.0,1.0,0.0);
+       fontmetrics = pango_context_get_metrics(context, NULL, NULL);
 
+       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
 
-               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);
-       }
+       /* 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);
 #endif
 
-       g_object_unref(layout);
+       pango_font_metrics_unref(fontmetrics);
 
-fprintf(stderr,"\n");
+       g_object_unref(layout);
 }
 
 static cairo_status_t
index 6367fee2fb7731a0e734d007cdfee08b2c6b9a97..a657551f06f880e375d80f7019f4b04732667156 100644 (file)
@@ -220,17 +220,6 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath)
     para->width = (int)(logical_rect.width * textlayout_scale + 1);    /* round up so that width/height are never too small */
     para->height = (int)(logical_rect.height * textlayout_scale + 1);
 
-#ifdef ENABLE_PANGO_MARKUP
-    /* FIXME  -- Horrible kluge !!! */
-
-    /* For now we are using pango for single line blocks only.
-     * The logical_rect.height seems to be too high from the font metrics on some platforms.
-     * Use an assumed height based on the point size.
-     */
-
-    para->height = (int)(para->fontsize * 1.3);
-#endif
-
     /* The y offset from baseline to 0,0 of the bitmap representation */
     para->yoffset_layout = pango_layout_get_baseline (layout) * textlayout_scale;