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.

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

mercurial