gfx/cairo/dwrite-font-printing.patch

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/cairo/dwrite-font-printing.patch	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     1.4 +diff --git a/gfx/cairo/cairo/src/cairo-dwrite-font.cpp b/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
     1.5 +--- a/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
     1.6 ++++ b/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
     1.7 +@@ -37,16 +37,17 @@
     1.8 + #include "cairoint.h"
     1.9 + 
    1.10 + #include "cairo-win32-private.h"
    1.11 + #include "cairo-surface-private.h"
    1.12 + #include "cairo-clip-private.h"
    1.13 + 
    1.14 + #include "cairo-d2d-private.h"
    1.15 + #include "cairo-dwrite-private.h"
    1.16 ++#include "cairo-truetype-subset-private.h"
    1.17 + #include <float.h>
    1.18 + 
    1.19 + typedef HRESULT (WINAPI*D2D1CreateFactoryFunc)(
    1.20 +     D2D1_FACTORY_TYPE factoryType,
    1.21 +     REFIID iid,
    1.22 +     CONST D2D1_FACTORY_OPTIONS *pFactoryOptions,
    1.23 +     void **factory
    1.24 + );
    1.25 +@@ -1036,17 +1037,17 @@ cairo_int_status_t
    1.26 + {
    1.27 +     cairo_dwrite_scaled_font_t *dwritesf = static_cast<cairo_dwrite_scaled_font_t*>(scaled_font);
    1.28 +     cairo_dwrite_font_face_t *face = reinterpret_cast<cairo_dwrite_font_face_t*>(dwritesf->base.font_face);
    1.29 + 
    1.30 +     const void *data;
    1.31 +     UINT32 size;
    1.32 +     void *tableContext;
    1.33 +     BOOL exists;
    1.34 +-    face->dwriteface->TryGetFontTable(tag,
    1.35 ++    face->dwriteface->TryGetFontTable(be32_to_cpu (tag),
    1.36 + 				      &data,
    1.37 + 				      &size,
    1.38 + 				      &tableContext,
    1.39 + 				      &exists);
    1.40 + 
    1.41 +     if (!exists) {
    1.42 + 	return CAIRO_INT_STATUS_UNSUPPORTED;
    1.43 +     }
    1.44 +@@ -1476,16 +1477,59 @@ DWriteFactory::CreateRenderingParams()
    1.45 +     Instance()->CreateCustomRenderingParams(gamma, contrast, clearTypeLevel,
    1.46 + 	pixelGeometry, renderingMode,
    1.47 + 	&mCustomClearTypeRenderingParams);
    1.48 +     Instance()->CreateCustomRenderingParams(gamma, contrast, clearTypeLevel,
    1.49 +         pixelGeometry, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC,
    1.50 +         &mForceGDIClassicRenderingParams);
    1.51 + }
    1.52 + 
    1.53 ++static cairo_bool_t
    1.54 ++_name_tables_match (cairo_scaled_font_t *font1,
    1.55 ++                    cairo_scaled_font_t *font2)
    1.56 ++{
    1.57 ++    unsigned long size1;
    1.58 ++    unsigned long size2;
    1.59 ++    cairo_int_status_t status1;
    1.60 ++    cairo_int_status_t status2;
    1.61 ++    unsigned char *buffer1;
    1.62 ++    unsigned char *buffer2;
    1.63 ++    cairo_bool_t result = false;
    1.64 ++
    1.65 ++    if (!font1->backend->load_truetype_table ||
    1.66 ++        !font2->backend->load_truetype_table)
    1.67 ++        return false;
    1.68 ++
    1.69 ++    status1 = font1->backend->load_truetype_table (font1,
    1.70 ++                                                   TT_TAG_name, 0, NULL, &size1);
    1.71 ++    status2 = font2->backend->load_truetype_table (font2,
    1.72 ++                                                   TT_TAG_name, 0, NULL, &size2);
    1.73 ++    if (status1 || status2)
    1.74 ++        return false;
    1.75 ++    if (size1 != size2)
    1.76 ++        return false;
    1.77 ++
    1.78 ++    buffer1 = (unsigned char*)malloc (size1);
    1.79 ++    buffer2 = (unsigned char*)malloc (size2);
    1.80 ++
    1.81 ++    if (buffer1 && buffer2) {
    1.82 ++        status1 = font1->backend->load_truetype_table (font1,
    1.83 ++                                                       TT_TAG_name, 0, buffer1, &size1);
    1.84 ++        status2 = font2->backend->load_truetype_table (font2,
    1.85 ++                                                       TT_TAG_name, 0, buffer2, &size2);
    1.86 ++        if (!status1 && !status2) {
    1.87 ++            result = memcmp (buffer1, buffer2, size1) == 0;
    1.88 ++        }
    1.89 ++    }
    1.90 ++
    1.91 ++    free (buffer1);
    1.92 ++    free (buffer2);
    1.93 ++    return result;
    1.94 ++}
    1.95 ++
    1.96 + // Helper for _cairo_win32_printing_surface_show_glyphs to create a win32 equivalent
    1.97 + // of a dwrite scaled_font so that we can print using ExtTextOut instead of drawing
    1.98 + // paths or blitting glyph bitmaps.
    1.99 + cairo_int_status_t
   1.100 + _cairo_dwrite_scaled_font_create_win32_scaled_font (cairo_scaled_font_t *scaled_font,
   1.101 +                                                     cairo_scaled_font_t **new_font)
   1.102 + {
   1.103 +     if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_DWRITE) {
   1.104 +@@ -1528,19 +1572,18 @@ cairo_int_status_t
   1.105 + 			                                  &ctm,
   1.106 + 			                                  &options);
   1.107 +     cairo_font_face_destroy (win32_face);
   1.108 + 
   1.109 +     if (!font) {
   1.110 +         return CAIRO_INT_STATUS_UNSUPPORTED;
   1.111 +     }
   1.112 + 
   1.113 +-    if (_cairo_win32_scaled_font_is_type1 (font) || _cairo_win32_scaled_font_is_bitmap (font)) {
   1.114 +-        // If we somehow got a Type1 or bitmap font, it can't be the same physical font
   1.115 +-        // as directwrite was using, so glyph IDs will not match; best we can do is to
   1.116 +-        // throw it away and fall back on rendering paths or blitting bitmaps instead.
   1.117 ++    if (!_name_tables_match (font, scaled_font)) {
   1.118 ++        // If the font name tables aren't equal, then GDI may have failed to
   1.119 ++        // find the right font and substituted a different font.
   1.120 +         cairo_scaled_font_destroy (font);
   1.121 +         return CAIRO_INT_STATUS_UNSUPPORTED;
   1.122 +     }
   1.123 + 
   1.124 +     *new_font = font;
   1.125 +     return CAIRO_INT_STATUS_SUCCESS;
   1.126 + }
   1.127 +diff --git a/gfx/cairo/cairo/src/cairo-truetype-subset-private.h b/gfx/cairo/cairo/src/cairo-truetype-subset-private.h
   1.128 +--- a/gfx/cairo/cairo/src/cairo-truetype-subset-private.h
   1.129 ++++ b/gfx/cairo/cairo/src/cairo-truetype-subset-private.h
   1.130 +@@ -34,16 +34,18 @@
   1.131 +  *	Adrian Johnson <ajohnson@redneon.com>
   1.132 +  */
   1.133 + 
   1.134 + #ifndef CAIRO_TRUETYPE_SUBSET_PRIVATE_H
   1.135 + #define CAIRO_TRUETYPE_SUBSET_PRIVATE_H
   1.136 + 
   1.137 + #include "cairoint.h"
   1.138 + 
   1.139 ++CAIRO_BEGIN_DECLS
   1.140 ++
   1.141 + #if CAIRO_HAS_FONT_SUBSET
   1.142 + 
   1.143 + /* The structs defined here should strictly follow the TrueType
   1.144 +  * specification and not be padded.  We use only 16-bit integer
   1.145 +  * in their definition to guarantee that.  The fields of type
   1.146 +  * "FIXED" in the TT spec are broken into two *_1 and *_2 16-bit
   1.147 +  * parts, and 64-bit members are broken into four.
   1.148 +  *
   1.149 +@@ -191,9 +193,11 @@ typedef struct _tt_composite_glyph {
   1.150 + typedef struct _tt_glyph_data {
   1.151 +     int16_t           num_contours;
   1.152 +     int8_t            data[8];
   1.153 +     tt_composite_glyph_t glyph;
   1.154 + } tt_glyph_data_t;
   1.155 + 
   1.156 + #endif /* CAIRO_HAS_FONT_SUBSET */
   1.157 + 
   1.158 ++CAIRO_END_DECLS
   1.159 ++
   1.160 + #endif /* CAIRO_TRUETYPE_SUBSET_PRIVATE_H */

mercurial