[cairo-commit] 7 commits - src/cairo-win32-font.c src/cairo-win32-printing-surface.c src/cairo-win32-private.h src/cairo-win32-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun May 4 06:36:51 PDT 2008


 src/cairo-win32-font.c             |   24 ++++++++++++++++++------
 src/cairo-win32-printing-surface.c |   15 +++++++++++++++
 src/cairo-win32-private.h          |    3 +++
 src/cairo-win32-surface.c          |   23 ++++++++++++++++++-----
 4 files changed, 54 insertions(+), 11 deletions(-)

New commits:
commit 504132db6d9f08c36c9ae82f472caf422a032dfd
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 23:05:01 2008 +0930

    win32-font: Check status in load_truetype_table

diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index 49212b2..3abfe2d 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -1435,7 +1435,7 @@ _cairo_win32_scaled_font_load_truetype_table (void	       *abstract_font,
                                              unsigned long     *length)
 {
     HDC hdc;
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    cairo_status_t status;
 
     cairo_win32_scaled_font_t *scaled_font = abstract_font;
     hdc = _get_global_font_dc ();
@@ -1444,6 +1444,8 @@ _cairo_win32_scaled_font_load_truetype_table (void	       *abstract_font,
 
     tag = (tag&0x000000ff)<<24 | (tag&0x0000ff00)<<8 | (tag&0x00ff0000)>>8 | (tag&0xff000000)>>24;
     status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
+    if (status)
+	return status;
 
     *length = GetFontData (hdc, tag, offset, buffer, *length);
     if (*length == GDI_ERROR)
commit 2a7c5cd1ee3d3b75e4a65362d33d89c95f8eb03b
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 23:01:48 2008 +0930

    Eliminate warning in win32 load_truetype_table with bitmap fonts
    
    Use cairo_win32_scaled_font_select_font() instead of
    _cairo_win32_scaled_font_select_unscaled_font() to select the font.
    Because _cairo_win32_scaled_font_select_unscaled_font() displays a
    warning when used with a bitmap font.

diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index c38c7bc..49212b2 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -1443,13 +1443,13 @@ _cairo_win32_scaled_font_load_truetype_table (void	       *abstract_font,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     tag = (tag&0x000000ff)<<24 | (tag&0x0000ff00)<<8 | (tag&0x00ff0000)>>8 | (tag&0xff000000)>>24;
-    status = _cairo_win32_scaled_font_select_unscaled_font (&scaled_font->base, hdc);
+    status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
 
     *length = GetFontData (hdc, tag, offset, buffer, *length);
     if (*length == GDI_ERROR)
         status = CAIRO_INT_STATUS_UNSUPPORTED;
 
-    _cairo_win32_scaled_font_done_unscaled_font (&scaled_font->base);
+    cairo_win32_scaled_font_done_font (&scaled_font->base);
 
     return status;
 }
commit 7063e7b0bf1d33c4166dc3b73ec33f6d9a708ce3
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 22:56:50 2008 +0930

    Fix bug in win32 font metrics with bitmap fonts
    
    The glyph width caculation was not compensating for the
    WIN32_FONT_LOGICAL_SCALE resulting in a glyph width and glyph advance
    32 times larger than it should be.

diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index d31a4be..c38c7bc 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -934,7 +934,7 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
 
 	extents.x_bearing = 0;
 	extents.y_bearing = scaled_font->base.ctm.yy * (-font_extents.ascent / scaled_font->y_scale);
-	extents.width = width / scaled_font->x_scale;
+	extents.width = width / (WIN32_FONT_LOGICAL_SCALE * scaled_font->x_scale);
 	extents.height = scaled_font->base.ctm.yy * (font_extents.ascent + font_extents.descent) / scaled_font->y_scale;
 	extents.x_advance = extents.width;
 	extents.y_advance = 0;
commit d35d6eec24c1b7ab0a49149a51bf65ea8e223203
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 22:54:02 2008 +0930

    Fix win32 bitmap font metrics when device scale != 1
    
    158d24412bba9 fixed win32 printing of bitmap fonts by forcing the use
    of fallback images. This exposed a bug in the win32 bitmap font
    metrics when a device scale is used that resulted in clipped glyphs.

diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index 03c487b..d31a4be 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -933,9 +933,9 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
 	cairo_win32_scaled_font_done_font (&scaled_font->base);
 
 	extents.x_bearing = 0;
-	extents.y_bearing = -font_extents.ascent / scaled_font->y_scale;
+	extents.y_bearing = scaled_font->base.ctm.yy * (-font_extents.ascent / scaled_font->y_scale);
 	extents.width = width / scaled_font->x_scale;
-	extents.height = (font_extents.ascent + font_extents.descent) / scaled_font->y_scale;
+	extents.height = scaled_font->base.ctm.yy * (font_extents.ascent + font_extents.descent) / scaled_font->y_scale;
 	extents.x_advance = extents.width;
 	extents.y_advance = 0;
     } else if (scaled_font->preserve_axes && scaled_font->base.options.hint_style != CAIRO_HINT_METRICS_OFF) {
commit 158d24412bba99a4f57907d7fd22a86aae6e87af
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 22:46:41 2008 +0930

    Make win32-printing surface work with bitmap fonts
    
    The win32 printing surface has the same problem with bitmap fonts as
    it does with Type 1 fonts. ie ExtTextOutW() with glyph indices works
    for a display DC but not a printer DC.
    
    Fix this by forcing fallback for bitmap fonts.

diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index eeba47a..03c487b 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -500,6 +500,16 @@ _cairo_win32_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font)
     return win32_scaled_font->is_type1;
 }
 
+cairo_bool_t
+_cairo_win32_scaled_font_is_bitmap (cairo_scaled_font_t *scaled_font)
+{
+    cairo_win32_scaled_font_t *win32_scaled_font;
+
+    win32_scaled_font = (cairo_win32_scaled_font_t *) scaled_font;
+
+    return win32_scaled_font->is_bitmap;
+}
+
 static void
 _cairo_win32_scaled_font_done_unscaled_font (cairo_scaled_font_t *scaled_font)
 {
diff --git a/src/cairo-win32-printing-surface.c b/src/cairo-win32-printing-surface.c
index 22379e2..791eb91 100644
--- a/src/cairo-win32-printing-surface.c
+++ b/src/cairo-win32-printing-surface.c
@@ -1311,6 +1311,20 @@ _cairo_win32_printing_surface_show_glyphs (void                 *abstract_surfac
     }
 
     if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) {
+	/* Calling ExtTextOutW() with ETO_GLYPH_INDEX and a Type 1 or
+	 * bitmap font on a printer DC prints garbled text. The text
+	 * displays correctly on a display DC. It appears that when
+	 * using a printer DC. ExtTextOutW() only works with
+	 * characters and not glyph indices.
+	 *
+	 * For now we don't use ExtTextOutW for Type 1 or bitmap
+	 * fonts. These fonts will go through the fallback path for
+	 * non Windows fonts. ie filled outlines for Type 1 fonts and
+	 * fallback images for bitmap fonts.
+	 */
+	if (_cairo_win32_scaled_font_is_bitmap (scaled_font))
+	    return CAIRO_INT_STATUS_UNSUPPORTED;
+
 	if (!(cairo_scaled_font_get_type (scaled_font) == CAIRO_FONT_TYPE_WIN32 &&
 	      ! _cairo_win32_scaled_font_is_type1 (scaled_font) &&
 	      source->type == CAIRO_PATTERN_TYPE_SOLID)) {
diff --git a/src/cairo-win32-private.h b/src/cairo-win32-private.h
index 0f39ea8..67c115d 100644
--- a/src/cairo-win32-private.h
+++ b/src/cairo-win32-private.h
@@ -184,4 +184,7 @@ _cairo_win32_debug_dump_hrgn (HRGN rgn, char *header);
 cairo_bool_t
 _cairo_win32_scaled_font_is_type1 (cairo_scaled_font_t *scaled_font);
 
+cairo_bool_t
+_cairo_win32_scaled_font_is_bitmap (cairo_scaled_font_t *scaled_font);
+
 #endif /* CAIRO_WIN32_PRIVATE_H */
commit 547e2f552cff264b943803d3a1ff03d05bde35c0
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 22:43:08 2008 +0930

    Fix win32-printing show_glyphs analysis for Type 1 fonts
    
    The analysis code needs to include the Type 1 font check that was
    previously adding the the rendering code.

diff --git a/src/cairo-win32-printing-surface.c b/src/cairo-win32-printing-surface.c
index edb0af4..22379e2 100644
--- a/src/cairo-win32-printing-surface.c
+++ b/src/cairo-win32-printing-surface.c
@@ -1312,6 +1312,7 @@ _cairo_win32_printing_surface_show_glyphs (void                 *abstract_surfac
 
     if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE) {
 	if (!(cairo_scaled_font_get_type (scaled_font) == CAIRO_FONT_TYPE_WIN32 &&
+	      ! _cairo_win32_scaled_font_is_type1 (scaled_font) &&
 	      source->type == CAIRO_PATTERN_TYPE_SOLID)) {
 	    for (i = 0; i < num_glyphs; i++) {
 		status = _cairo_scaled_glyph_lookup (scaled_font,
commit 141bca74ba154d79fab49db74a51cd41f04e3a34
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun May 4 22:40:49 2008 +0930

    Make cairo_win32_surface_get_dc work with win32 printing surface
    
    The win32 printing surface is a paginated surface so we need to get
    the paginated surface target to get to the win32_printing surface.

diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index bfe71b4..d303af8 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -48,6 +48,7 @@
 #include "cairoint.h"
 
 #include "cairo-clip-private.h"
+#include "cairo-paginated-private.h"
 #include "cairo-win32-private.h"
 
 #include <windows.h>
@@ -1873,13 +1874,25 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
 {
     cairo_win32_surface_t *winsurf;
 
-    if (!_cairo_surface_is_win32(surface) &&
-	!_cairo_surface_is_win32_printing(surface))
-	return NULL;
+    if (_cairo_surface_is_win32 (surface)){
+	winsurf = (cairo_win32_surface_t *) surface;
+
+	return winsurf->dc;
+    }
+
+    if (_cairo_surface_is_paginated (surface)) {
+	cairo_surface_t *target;
 
-    winsurf = (cairo_win32_surface_t *) surface;
+	target = _cairo_paginated_surface_get_target (surface);
+
+	if (_cairo_surface_is_win32_printing (target)) {
+	    winsurf = (cairo_win32_surface_t *) target;
+
+	    return winsurf->dc;
+	}
+    }
 
-    return winsurf->dc;
+    return NULL;
 }
 
 /**


More information about the cairo-commit mailing list