gfx/cairo/dwrite-font-printing.patch

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 diff --git a/gfx/cairo/cairo/src/cairo-dwrite-font.cpp b/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
michael@0 2 --- a/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
michael@0 3 +++ b/gfx/cairo/cairo/src/cairo-dwrite-font.cpp
michael@0 4 @@ -37,16 +37,17 @@
michael@0 5 #include "cairoint.h"
michael@0 6
michael@0 7 #include "cairo-win32-private.h"
michael@0 8 #include "cairo-surface-private.h"
michael@0 9 #include "cairo-clip-private.h"
michael@0 10
michael@0 11 #include "cairo-d2d-private.h"
michael@0 12 #include "cairo-dwrite-private.h"
michael@0 13 +#include "cairo-truetype-subset-private.h"
michael@0 14 #include <float.h>
michael@0 15
michael@0 16 typedef HRESULT (WINAPI*D2D1CreateFactoryFunc)(
michael@0 17 D2D1_FACTORY_TYPE factoryType,
michael@0 18 REFIID iid,
michael@0 19 CONST D2D1_FACTORY_OPTIONS *pFactoryOptions,
michael@0 20 void **factory
michael@0 21 );
michael@0 22 @@ -1036,17 +1037,17 @@ cairo_int_status_t
michael@0 23 {
michael@0 24 cairo_dwrite_scaled_font_t *dwritesf = static_cast<cairo_dwrite_scaled_font_t*>(scaled_font);
michael@0 25 cairo_dwrite_font_face_t *face = reinterpret_cast<cairo_dwrite_font_face_t*>(dwritesf->base.font_face);
michael@0 26
michael@0 27 const void *data;
michael@0 28 UINT32 size;
michael@0 29 void *tableContext;
michael@0 30 BOOL exists;
michael@0 31 - face->dwriteface->TryGetFontTable(tag,
michael@0 32 + face->dwriteface->TryGetFontTable(be32_to_cpu (tag),
michael@0 33 &data,
michael@0 34 &size,
michael@0 35 &tableContext,
michael@0 36 &exists);
michael@0 37
michael@0 38 if (!exists) {
michael@0 39 return CAIRO_INT_STATUS_UNSUPPORTED;
michael@0 40 }
michael@0 41 @@ -1476,16 +1477,59 @@ DWriteFactory::CreateRenderingParams()
michael@0 42 Instance()->CreateCustomRenderingParams(gamma, contrast, clearTypeLevel,
michael@0 43 pixelGeometry, renderingMode,
michael@0 44 &mCustomClearTypeRenderingParams);
michael@0 45 Instance()->CreateCustomRenderingParams(gamma, contrast, clearTypeLevel,
michael@0 46 pixelGeometry, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC,
michael@0 47 &mForceGDIClassicRenderingParams);
michael@0 48 }
michael@0 49
michael@0 50 +static cairo_bool_t
michael@0 51 +_name_tables_match (cairo_scaled_font_t *font1,
michael@0 52 + cairo_scaled_font_t *font2)
michael@0 53 +{
michael@0 54 + unsigned long size1;
michael@0 55 + unsigned long size2;
michael@0 56 + cairo_int_status_t status1;
michael@0 57 + cairo_int_status_t status2;
michael@0 58 + unsigned char *buffer1;
michael@0 59 + unsigned char *buffer2;
michael@0 60 + cairo_bool_t result = false;
michael@0 61 +
michael@0 62 + if (!font1->backend->load_truetype_table ||
michael@0 63 + !font2->backend->load_truetype_table)
michael@0 64 + return false;
michael@0 65 +
michael@0 66 + status1 = font1->backend->load_truetype_table (font1,
michael@0 67 + TT_TAG_name, 0, NULL, &size1);
michael@0 68 + status2 = font2->backend->load_truetype_table (font2,
michael@0 69 + TT_TAG_name, 0, NULL, &size2);
michael@0 70 + if (status1 || status2)
michael@0 71 + return false;
michael@0 72 + if (size1 != size2)
michael@0 73 + return false;
michael@0 74 +
michael@0 75 + buffer1 = (unsigned char*)malloc (size1);
michael@0 76 + buffer2 = (unsigned char*)malloc (size2);
michael@0 77 +
michael@0 78 + if (buffer1 && buffer2) {
michael@0 79 + status1 = font1->backend->load_truetype_table (font1,
michael@0 80 + TT_TAG_name, 0, buffer1, &size1);
michael@0 81 + status2 = font2->backend->load_truetype_table (font2,
michael@0 82 + TT_TAG_name, 0, buffer2, &size2);
michael@0 83 + if (!status1 && !status2) {
michael@0 84 + result = memcmp (buffer1, buffer2, size1) == 0;
michael@0 85 + }
michael@0 86 + }
michael@0 87 +
michael@0 88 + free (buffer1);
michael@0 89 + free (buffer2);
michael@0 90 + return result;
michael@0 91 +}
michael@0 92 +
michael@0 93 // Helper for _cairo_win32_printing_surface_show_glyphs to create a win32 equivalent
michael@0 94 // of a dwrite scaled_font so that we can print using ExtTextOut instead of drawing
michael@0 95 // paths or blitting glyph bitmaps.
michael@0 96 cairo_int_status_t
michael@0 97 _cairo_dwrite_scaled_font_create_win32_scaled_font (cairo_scaled_font_t *scaled_font,
michael@0 98 cairo_scaled_font_t **new_font)
michael@0 99 {
michael@0 100 if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_DWRITE) {
michael@0 101 @@ -1528,19 +1572,18 @@ cairo_int_status_t
michael@0 102 &ctm,
michael@0 103 &options);
michael@0 104 cairo_font_face_destroy (win32_face);
michael@0 105
michael@0 106 if (!font) {
michael@0 107 return CAIRO_INT_STATUS_UNSUPPORTED;
michael@0 108 }
michael@0 109
michael@0 110 - if (_cairo_win32_scaled_font_is_type1 (font) || _cairo_win32_scaled_font_is_bitmap (font)) {
michael@0 111 - // If we somehow got a Type1 or bitmap font, it can't be the same physical font
michael@0 112 - // as directwrite was using, so glyph IDs will not match; best we can do is to
michael@0 113 - // throw it away and fall back on rendering paths or blitting bitmaps instead.
michael@0 114 + if (!_name_tables_match (font, scaled_font)) {
michael@0 115 + // If the font name tables aren't equal, then GDI may have failed to
michael@0 116 + // find the right font and substituted a different font.
michael@0 117 cairo_scaled_font_destroy (font);
michael@0 118 return CAIRO_INT_STATUS_UNSUPPORTED;
michael@0 119 }
michael@0 120
michael@0 121 *new_font = font;
michael@0 122 return CAIRO_INT_STATUS_SUCCESS;
michael@0 123 }
michael@0 124 diff --git a/gfx/cairo/cairo/src/cairo-truetype-subset-private.h b/gfx/cairo/cairo/src/cairo-truetype-subset-private.h
michael@0 125 --- a/gfx/cairo/cairo/src/cairo-truetype-subset-private.h
michael@0 126 +++ b/gfx/cairo/cairo/src/cairo-truetype-subset-private.h
michael@0 127 @@ -34,16 +34,18 @@
michael@0 128 * Adrian Johnson <ajohnson@redneon.com>
michael@0 129 */
michael@0 130
michael@0 131 #ifndef CAIRO_TRUETYPE_SUBSET_PRIVATE_H
michael@0 132 #define CAIRO_TRUETYPE_SUBSET_PRIVATE_H
michael@0 133
michael@0 134 #include "cairoint.h"
michael@0 135
michael@0 136 +CAIRO_BEGIN_DECLS
michael@0 137 +
michael@0 138 #if CAIRO_HAS_FONT_SUBSET
michael@0 139
michael@0 140 /* The structs defined here should strictly follow the TrueType
michael@0 141 * specification and not be padded. We use only 16-bit integer
michael@0 142 * in their definition to guarantee that. The fields of type
michael@0 143 * "FIXED" in the TT spec are broken into two *_1 and *_2 16-bit
michael@0 144 * parts, and 64-bit members are broken into four.
michael@0 145 *
michael@0 146 @@ -191,9 +193,11 @@ typedef struct _tt_composite_glyph {
michael@0 147 typedef struct _tt_glyph_data {
michael@0 148 int16_t num_contours;
michael@0 149 int8_t data[8];
michael@0 150 tt_composite_glyph_t glyph;
michael@0 151 } tt_glyph_data_t;
michael@0 152
michael@0 153 #endif /* CAIRO_HAS_FONT_SUBSET */
michael@0 154
michael@0 155 +CAIRO_END_DECLS
michael@0 156 +
michael@0 157 #endif /* CAIRO_TRUETYPE_SUBSET_PRIVATE_H */

mercurial