summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-11-30 04:29:58 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-11-30 04:29:58 +0000
commita8e3d34ea91d80b5032ae0029cdcd7e97f83da7f (patch)
tree97d0dfb5c0017e44c1b596da1ef954d12a24f863
parentf802d542d6c1ab729cabd90a9c72891f1c2c8ee8 (diff)
downloadpango-a8e3d34ea91d80b5032ae0029cdcd7e97f83da7f.tar.gz
Bug 485536 – underline_position can be zero
2007-11-29 Behdad Esfahbod <behdad@gnome.org> Bug 485536 – underline_position can be zero * pango/pango-utils.c (pango_cairo_quantize_line_geometry): Document that returned position may be zero. * pango/pangocairo-win32font.c (pango_cairo_win32_font_create_metrics_for_context): * pango/pangofc-font.c (get_face_metrics): Handle case of underline_position==0 after rounding. svn path=/trunk/; revision=2506
-rw-r--r--ChangeLog12
-rw-r--r--examples/cairoshape.c31
-rw-r--r--examples/cairosimple.c2
-rw-r--r--examples/cairotwisted.c12
-rw-r--r--pango/opentype/harfbuzz-impl.c2
-rw-r--r--pango/pango-utils.c3
-rw-r--r--pango/pangocairo-win32font.c3
-rw-r--r--pango/pangofc-font.c42
8 files changed, 87 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index fd490e6e..f2c4635e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2007-11-29 Behdad Esfahbod <behdad@gnome.org>
+ Bug 485536 – underline_position can be zero
+
+ * pango/pango-utils.c (pango_cairo_quantize_line_geometry):
+ Document that returned position may be zero.
+
+ * pango/pangocairo-win32font.c
+ (pango_cairo_win32_font_create_metrics_for_context):
+ * pango/pangofc-font.c (get_face_metrics):
+ Handle case of underline_position==0 after rounding.
+
+2007-11-29 Behdad Esfahbod <behdad@gnome.org>
+
Bug 500549 – pangocairo.h should include pango.h and cairo.h
* pango/pangocairo.h: #include <pango/pango.h>
diff --git a/examples/cairoshape.c b/examples/cairoshape.c
index addde87e..0845c587 100644
--- a/examples/cairoshape.c
+++ b/examples/cairoshape.c
@@ -1,4 +1,25 @@
-/* example to use pangocairo to render arbitrary shapes inside a text layout */
+/* Example code to show how to use pangocairo to render arbitrary shapes
+ * inside a text layout, positioned by Pango. This has become possibly
+ * using the following API added in Pango 1.18:
+ *
+ * pango_cairo_context_set_shape_renderer ()
+ *
+ * This examples uses a small parser to convert shapes in the format of
+ * SVG paths to cairo instructions. You can typically extract these from
+ * the SVG file's <path> elements directly.
+ *
+ * The code then searches for the Unicode bullet character in the layout
+ * text and automatically adds PangoAttribtues to the layout to replace
+ * each of the with a rendering of the GNOME Foot logo.
+ *
+ *
+ * Written by Behdad Esfahbod, 2007
+ *
+ * Permission to use, copy, modify, distribute, and sell this example
+ * for any purpose is hereby granted without fee.
+ * It is provided "as is" without express or implied warranty.
+ */
+
#include <stdio.h>
#include <string.h>
@@ -120,7 +141,7 @@ get_layout (cairo_t *cr)
attrs = pango_attr_list_new ();
- /* set gnome shape attributes for bullets */
+ /* Set gnome shape attributes for all bullets */
for (p = text; (p = strstr (p, BULLET)); p += strlen (BULLET))
{
PangoAttribute *attr;
@@ -148,6 +169,8 @@ draw_text (cairo_t *cr, int *width, int *height)
PangoLayout *layout = get_layout (cr);
+ /* Adds a fixed 10-pixel margin on the sides. */
+
if (width || height)
{
pango_layout_get_pixel_size (layout, width, height);
@@ -179,6 +202,8 @@ int main (int argc, char **argv)
filename = argv[1];
+ /* First create and use a 0x0 surface, to measure how large
+ * the final surface needs to be */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
0, 0);
cr = cairo_create (surface);
@@ -186,6 +211,7 @@ int main (int argc, char **argv)
cairo_destroy (cr);
cairo_surface_destroy (surface);
+ /* Now create the final surface and draw to it. */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width, height);
cr = cairo_create (surface);
@@ -196,6 +222,7 @@ int main (int argc, char **argv)
draw_text (cr, NULL, NULL);
cairo_destroy (cr);
+ /* Write out the surface as PNG */
status = cairo_surface_write_to_png (surface, filename);
cairo_surface_destroy (surface);
diff --git a/examples/cairosimple.c b/examples/cairosimple.c
index d07f004c..faef3267 100644
--- a/examples/cairosimple.c
+++ b/examples/cairosimple.c
@@ -1,4 +1,4 @@
-/* simple example to use pangocairo to render rotated text */
+/* Simple example to use pangocairo to render rotated text */
#include <math.h>
#include <pango/pangocairo.h>
diff --git a/examples/cairotwisted.c b/examples/cairotwisted.c
index 180cd447..47d1e3d9 100644
--- a/examples/cairotwisted.c
+++ b/examples/cairotwisted.c
@@ -1,5 +1,13 @@
-/* example to use pangocairo to render text projected on a path */
-/* Written by Behdad Esfahbod, 2006. Not copyrighted, in public domain. */
+/* Example code to show how to use pangocairo to render text
+ * projected on a path.
+ *
+ *
+ * Written by Behdad Esfahbod, 2006..2007
+ *
+ * Permission to use, copy, modify, distribute, and sell this example
+ * for any purpose is hereby granted without fee.
+ * It is provided "as is" without express or implied warranty.
+ */
#include <math.h>
#include <stdlib.h>
diff --git a/pango/opentype/harfbuzz-impl.c b/pango/opentype/harfbuzz-impl.c
index 79b837de..4ba70ed4 100644
--- a/pango/opentype/harfbuzz-impl.c
+++ b/pango/opentype/harfbuzz-impl.c
@@ -65,5 +65,7 @@ _hb_free( HB_Pointer block )
HB_INTERNAL HB_Error
_hb_err (HB_Error code)
{
+ static int numerr = 0;
+ numerr++;
return code;
}
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index 51d8fd01..1776ab9f 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -1593,6 +1593,9 @@ pango_is_zero_width (gunichar ch)
* multiples of %PANGO_SCALE. The purpose of this function is to avoid
* such lines looking blurry.
*
+ * Care is taken to make sure @thickness is at least 1 when this function
+ * returns, but returned @position may become zero as a result of rounding.
+ *
* Since: 1.12
*/
void
diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c
index af4e1d07..d01e6f0b 100644
--- a/pango/pangocairo-win32font.c
+++ b/pango/pangocairo-win32font.c
@@ -140,6 +140,9 @@ pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font,
&metrics->underline_position);
pango_quantize_line_geometry (&metrics->strikethrough_thickness,
&metrics->strikethrough_position);
+ /* Quantizing may have pushed underline_position to 0. Not good */
+ if (metrics->underline_position == 0)
+ metrics->underline_position = - metrics->underline_thickness;
layout = pango_layout_new (context);
font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font);
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index d2c395ff..bd185bd8 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -304,7 +304,7 @@ get_face_metrics (PangoFcFont *fcfont,
TT_OS2 *os2;
gboolean have_transform = FALSE;
- if (!face)
+ if (G_UNLIKELY (!face))
{
metrics->descent = 0;
metrics->ascent = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT;
@@ -358,27 +358,32 @@ get_face_metrics (PangoFcFont *fcfont,
metrics->ascent = PANGO_UNITS_26_6 (ascender);
}
- /* Versions of FreeType < 2.1.8 get underline thickness wrong
- * for Postscript fonts (always zero), so we need a fallback
- */
- if (face->underline_thickness == 0)
+
+ metrics->underline_thickness = 0;
+ metrics->underline_position = 0;
+
+ {
+ FT_Fixed ft_thickness, ft_position;
+
+ ft_thickness = FT_MulFix (face->underline_thickness, face->size->metrics.y_scale);
+ metrics->underline_thickness = PANGO_UNITS_26_6 (ft_thickness);
+
+ ft_position = FT_MulFix (face->underline_position, face->size->metrics.y_scale);
+ metrics->underline_position = PANGO_UNITS_26_6 (ft_position);
+ }
+
+ if (metrics->underline_thickness == 0 || metrics->underline_position == 0)
{
metrics->underline_thickness = (PANGO_SCALE * face->size->metrics.y_ppem) / 14;
metrics->underline_position = - metrics->underline_thickness;
}
- else
- {
- FT_Fixed ft_thickness, ft_position;
- ft_thickness = FT_MulFix (face->underline_thickness, face->size->metrics.y_scale);
- metrics->underline_thickness = PANGO_UNITS_26_6 (ft_thickness);
- ft_position = FT_MulFix (face->underline_position, face->size->metrics.y_scale);
- metrics->underline_position = PANGO_UNITS_26_6 (ft_position);
- }
+ metrics->strikethrough_thickness = 0;
+ metrics->strikethrough_position = 0;
os2 = FT_Get_Sfnt_Table (face, ft_sfnt_os2);
- if (os2 && os2->version != 0xFFFF && os2->yStrikeoutSize != 0)
+ if (os2 && os2->version != 0xFFFF)
{
FT_Fixed ft_thickness, ft_position;
@@ -388,12 +393,14 @@ get_face_metrics (PangoFcFont *fcfont,
ft_position = FT_MulFix (os2->yStrikeoutPosition, face->size->metrics.y_scale);
metrics->strikethrough_position = PANGO_UNITS_26_6 (ft_position);
}
- else
+
+ if (metrics->strikethrough_thickness == 0 || metrics->strikethrough_position == 0)
{
metrics->strikethrough_thickness = metrics->underline_thickness;
metrics->strikethrough_position = (PANGO_SCALE * face->size->metrics.y_ppem) / 4;
}
+
/* If hinting is on for this font, quantize the underline and strikethrough position
* to integer values.
*/
@@ -403,8 +410,13 @@ get_face_metrics (PangoFcFont *fcfont,
&metrics->underline_position);
pango_quantize_line_geometry (&metrics->strikethrough_thickness,
&metrics->strikethrough_position);
+
+ /* Quantizing may have pushed underline_position to 0. Not good */
+ if (metrics->underline_position == 0)
+ metrics->underline_position = - metrics->underline_thickness;
}
+
PANGO_FC_FONT_UNLOCK_FACE (fcfont);
}