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