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.

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

mercurial