gfx/thebes/gfxFT2Utils.h

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 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef GFX_FT2UTILS_H
     7 #define GFX_FT2UTILS_H
     9 #include "cairo-ft.h"
    10 #include "gfxFT2FontBase.h"
    11 #include "mozilla/Likely.h"
    13 // Rounding and truncation functions for a FreeType fixed point number 
    14 // (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer
    15 // part and low 6 bits for the fractional part. 
    16 #define FLOAT_FROM_26_6(x) ((x) / 64.0)
    17 #define FLOAT_FROM_16_16(x) ((x) / 65536.0)
    18 #define ROUND_26_6_TO_INT(x) ((x) >= 0 ?  ((32 + (x)) >> 6) \
    19                                        : -((32 - (x)) >> 6))
    21 typedef struct FT_FaceRec_* FT_Face;
    23 class gfxFT2LockedFace {
    24 public:
    25     gfxFT2LockedFace(gfxFT2FontBase *aFont) :
    26         mGfxFont(aFont),
    27         mFace(cairo_ft_scaled_font_lock_face(aFont->CairoScaledFont()))
    28     { }
    29     ~gfxFT2LockedFace()
    30     {
    31         if (mFace) {
    32             cairo_ft_scaled_font_unlock_face(mGfxFont->CairoScaledFont());
    33         }
    34     }
    36     FT_Face get() { return mFace; };
    38     /**
    39      * Get the glyph id for a Unicode character representable by a single
    40      * glyph, or return zero if there is no such glyph.  This does no caching,
    41      * so you probably want gfxFcFont::GetGlyph.
    42      */
    43     uint32_t GetGlyph(uint32_t aCharCode);
    44     /**
    45      * Returns 0 if there is no variation selector cmap subtable.
    46      */
    47     uint32_t GetUVSGlyph(uint32_t aCharCode, uint32_t aVariantSelector);
    49     void GetMetrics(gfxFont::Metrics* aMetrics, uint32_t* aSpaceGlyph);
    51     // A scale factor for use in converting horizontal metrics from font units
    52     // to pixels.
    53     gfxFloat XScale()
    54     {
    55         if (MOZ_UNLIKELY(!mFace))
    56             return 0.0;
    58         const FT_Size_Metrics& ftMetrics = mFace->size->metrics;
    60         if (FT_IS_SCALABLE(mFace)) {
    61             // Prefer FT_Size_Metrics::x_scale to x_ppem as x_ppem does not
    62             // have subpixel accuracy.
    63             //
    64             // FT_Size_Metrics::x_scale is in 16.16 fixed point format.  Its
    65             // (fractional) value is a factor that converts vertical metrics
    66             // from design units to units of 1/64 pixels, so that the result
    67             // may be interpreted as pixels in 26.6 fixed point format.
    68             return FLOAT_FROM_26_6(FLOAT_FROM_16_16(ftMetrics.x_scale));
    69         }
    71         // Not scalable.
    72         // FT_Size_Metrics doc says x_scale is "only relevant for scalable
    73         // font formats".
    74         return gfxFloat(ftMetrics.x_ppem) / gfxFloat(mFace->units_per_EM);
    75     }
    77 protected:
    78     /**
    79      * Get extents for a simple character representable by a single glyph.
    80      * The return value is the glyph id of that glyph or zero if no such glyph
    81      * exists.  aExtents is only set when this returns a non-zero glyph id.
    82      */
    83     uint32_t GetCharExtents(char aChar, cairo_text_extents_t* aExtents);
    85     typedef FT_UInt (*CharVariantFunction)(FT_Face  face,
    86                                            FT_ULong charcode,
    87                                            FT_ULong variantSelector);
    88     CharVariantFunction FindCharVariantFunction();
    90     nsRefPtr<gfxFT2FontBase> mGfxFont;
    91     FT_Face mFace;
    92 };
    94 #endif /* GFX_FT2UTILS_H */

mercurial