|
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/. */ |
|
5 |
|
6 #include "ScaledFontCairo.h" |
|
7 #include "Logging.h" |
|
8 |
|
9 #ifdef MOZ_ENABLE_FREETYPE |
|
10 #include <ft2build.h> |
|
11 #include FT_FREETYPE_H |
|
12 #include "cairo-ft.h" |
|
13 #endif |
|
14 |
|
15 #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE) |
|
16 #include "skia/SkTypeface.h" |
|
17 #include "skia/SkTypeface_cairo.h" |
|
18 #endif |
|
19 |
|
20 #include <string> |
|
21 |
|
22 typedef struct FT_FaceRec_* FT_Face; |
|
23 |
|
24 using namespace std; |
|
25 |
|
26 namespace mozilla { |
|
27 namespace gfx { |
|
28 |
|
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 } |
|
38 |
|
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); |
|
45 |
|
46 int style = SkTypeface::kNormal; |
|
47 |
|
48 if (face->style_flags & FT_STYLE_FLAG_ITALIC) |
|
49 style |= SkTypeface::kItalic; |
|
50 |
|
51 if (face->style_flags & FT_STYLE_FLAG_BOLD) |
|
52 style |= SkTypeface::kBold; |
|
53 |
|
54 bool isFixedWidth = face->face_flags & FT_FACE_FLAG_FIXED_WIDTH; |
|
55 cairo_ft_scaled_font_unlock_face(mScaledFont); |
|
56 |
|
57 mTypeface = SkCreateTypefaceFromCairoFont(fontFace, (SkTypeface::Style)style, isFixedWidth); |
|
58 } |
|
59 |
|
60 return mTypeface; |
|
61 } |
|
62 #endif |
|
63 |
|
64 } |
|
65 } |