gfx/2d/ScaledFontCairo.cpp

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: 2 -*-
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 #include "ScaledFontCairo.h"
michael@0 7 #include "Logging.h"
michael@0 8
michael@0 9 #ifdef MOZ_ENABLE_FREETYPE
michael@0 10 #include <ft2build.h>
michael@0 11 #include FT_FREETYPE_H
michael@0 12 #include "cairo-ft.h"
michael@0 13 #endif
michael@0 14
michael@0 15 #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE)
michael@0 16 #include "skia/SkTypeface.h"
michael@0 17 #include "skia/SkTypeface_cairo.h"
michael@0 18 #endif
michael@0 19
michael@0 20 #include <string>
michael@0 21
michael@0 22 typedef struct FT_FaceRec_* FT_Face;
michael@0 23
michael@0 24 using namespace std;
michael@0 25
michael@0 26 namespace mozilla {
michael@0 27 namespace gfx {
michael@0 28
michael@0 29 // On Linux and Android our "platform" font is a cairo_scaled_font_t and we use
michael@0 30 // an SkFontHost implementation that allows Skia to render using this.
michael@0 31 // This is mainly because FT_Face is not good for sharing between libraries, which
michael@0 32 // is a requirement when we consider runtime switchable backends and so on
michael@0 33 ScaledFontCairo::ScaledFontCairo(cairo_scaled_font_t* aScaledFont, Float aSize)
michael@0 34 : ScaledFontBase(aSize)
michael@0 35 {
michael@0 36 SetCairoScaledFont(aScaledFont);
michael@0 37 }
michael@0 38
michael@0 39 #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE)
michael@0 40 SkTypeface* ScaledFontCairo::GetSkTypeface()
michael@0 41 {
michael@0 42 if (!mTypeface) {
michael@0 43 cairo_font_face_t* fontFace = cairo_scaled_font_get_font_face(mScaledFont);
michael@0 44 FT_Face face = cairo_ft_scaled_font_lock_face(mScaledFont);
michael@0 45
michael@0 46 int style = SkTypeface::kNormal;
michael@0 47
michael@0 48 if (face->style_flags & FT_STYLE_FLAG_ITALIC)
michael@0 49 style |= SkTypeface::kItalic;
michael@0 50
michael@0 51 if (face->style_flags & FT_STYLE_FLAG_BOLD)
michael@0 52 style |= SkTypeface::kBold;
michael@0 53
michael@0 54 bool isFixedWidth = face->face_flags & FT_FACE_FLAG_FIXED_WIDTH;
michael@0 55 cairo_ft_scaled_font_unlock_face(mScaledFont);
michael@0 56
michael@0 57 mTypeface = SkCreateTypefaceFromCairoFont(fontFace, (SkTypeface::Style)style, isFixedWidth);
michael@0 58 }
michael@0 59
michael@0 60 return mTypeface;
michael@0 61 }
michael@0 62 #endif
michael@0 63
michael@0 64 }
michael@0 65 }

mercurial