summaryrefslogtreecommitdiff
path: root/src/cairo-win32-printing-surface.c
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2008-08-10 14:24:16 +0930
committerAdrian Johnson <ajohnson@redneon.com>2008-08-10 14:24:16 +0930
commit4c8317941815971f1d060243e1f6153df06866ca (patch)
treedf6ecd1c8824d0125e941cd4c33b5c1238c1ddc6 /src/cairo-win32-printing-surface.c
parentb34c248b92b2d1544a23c20ecaa12f64792cb1d3 (diff)
Win32-printing: Fix Type 1 font printing so fallback is not used
Using glyph indices with Type 1 fonts on a printer DC does not work. Previously there was a temporary fix where Type 1 fonts were printed as filled paths. Now that _cairo_scaled_font_subsets_map_glyph() provides the reverse mapping of the glyph index fix this by converting the glyph indices back to the unicode values when printing Type 1 fonts.
Diffstat (limited to 'src/cairo-win32-printing-surface.c')
-rw-r--r--src/cairo-win32-printing-surface.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/src/cairo-win32-printing-surface.c b/src/cairo-win32-printing-surface.c
index 0846daa4..55d5b196 100644
--- a/src/cairo-win32-printing-surface.c
+++ b/src/cairo-win32-printing-surface.c
@@ -51,6 +51,7 @@
#include "cairo-clip-private.h"
#include "cairo-win32-private.h"
#include "cairo-meta-surface-private.h"
+#include "cairo-scaled-font-subsets-private.h"
#include <windows.h>
@@ -1313,16 +1314,14 @@ _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.
+ /* When printing bitmap fonts to a printer DC, Windows may
+ * substitute an outline font for bitmap font. As the win32
+ * font backend always uses a screen DC when obtaining the
+ * font metrics the metrics of the substituted font will not
+ * match the metrics that the win32 font backend returns.
*
- * 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 we are printing a bitmap font, use fallback images to
+ * ensure the font is not substituted.
*/
if (cairo_scaled_font_get_type (scaled_font) == CAIRO_FONT_TYPE_WIN32) {
if (_cairo_win32_scaled_font_is_bitmap (scaled_font))
@@ -1364,10 +1363,46 @@ _cairo_win32_printing_surface_show_glyphs (void *abstract_surfac
}
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)
{
cairo_matrix_t ctm;
+ cairo_glyph_t *type1_glyphs = NULL;
+ cairo_scaled_font_subsets_glyph_t subset_glyph;
+
+ /* Calling ExtTextOutW() with ETO_GLYPH_INDEX and a Type 1
+ * font on a printer DC prints garbled text. The text displays
+ * correctly on a display DC. When using a printer
+ * DC, ExtTextOutW() only works with characters and not glyph
+ * indices.
+ *
+ * For Type 1 fonts the glyph indices are converted back to
+ * unicode characters before calling _cairo_win32_surface_show_glyphs().
+ *
+ * As _cairo_win32_scaled_font_index_to_ucs4() is a slow
+ * operation, the font subsetting function
+ * _cairo_scaled_font_subsets_map_glyph() is used to obtain
+ * the unicode value because it caches the reverse mapping in
+ * the subsets.
+ */
+ if (_cairo_win32_scaled_font_is_type1 (scaled_font)) {
+ type1_glyphs = _cairo_malloc_ab (num_glyphs, sizeof (cairo_glyph_t));
+ if (type1_glyphs == NULL)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
+ memcpy (type1_glyphs, glyphs, num_glyphs * sizeof (cairo_glyph_t));
+ for (i = 0; i < num_glyphs; i++) {
+ status = _cairo_scaled_font_subsets_map_glyph (surface->font_subsets,
+ scaled_font,
+ type1_glyphs[i].index,
+ NULL, 0,
+ &subset_glyph);
+ if (status)
+ return status;
+
+ type1_glyphs[i].index = subset_glyph.unicode;
+ }
+ glyphs = type1_glyphs;
+ }
if (surface->has_ctm) {
for (i = 0; i < num_glyphs; i++)
@@ -1385,6 +1420,9 @@ _cairo_win32_printing_surface_show_glyphs (void *abstract_surfac
if (surface->has_ctm)
cairo_scaled_font_destroy (scaled_font);
+ if (type1_glyphs != NULL)
+ free (type1_glyphs);
+
return status;
}
@@ -1531,6 +1569,11 @@ cairo_win32_printing_surface_create (HDC hdc)
surface->saved_dc_bitmap = NULL;
surface->brush = NULL;
surface->old_brush = NULL;
+ surface->font_subsets = _cairo_scaled_font_subsets_create_scaled ();
+ if (surface->font_subsets == NULL) {
+ free (surface);
+ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+ }
GetClipBox(hdc, &rect);
surface->extents.x = rect.left;