1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/ScaledFontCairo.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "ScaledFontCairo.h" 1.10 +#include "Logging.h" 1.11 + 1.12 +#ifdef MOZ_ENABLE_FREETYPE 1.13 +#include <ft2build.h> 1.14 +#include FT_FREETYPE_H 1.15 +#include "cairo-ft.h" 1.16 +#endif 1.17 + 1.18 +#if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE) 1.19 +#include "skia/SkTypeface.h" 1.20 +#include "skia/SkTypeface_cairo.h" 1.21 +#endif 1.22 + 1.23 +#include <string> 1.24 + 1.25 +typedef struct FT_FaceRec_* FT_Face; 1.26 + 1.27 +using namespace std; 1.28 + 1.29 +namespace mozilla { 1.30 +namespace gfx { 1.31 + 1.32 +// On Linux and Android our "platform" font is a cairo_scaled_font_t and we use 1.33 +// an SkFontHost implementation that allows Skia to render using this. 1.34 +// This is mainly because FT_Face is not good for sharing between libraries, which 1.35 +// is a requirement when we consider runtime switchable backends and so on 1.36 +ScaledFontCairo::ScaledFontCairo(cairo_scaled_font_t* aScaledFont, Float aSize) 1.37 + : ScaledFontBase(aSize) 1.38 +{ 1.39 + SetCairoScaledFont(aScaledFont); 1.40 +} 1.41 + 1.42 +#if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE) 1.43 +SkTypeface* ScaledFontCairo::GetSkTypeface() 1.44 +{ 1.45 + if (!mTypeface) { 1.46 + cairo_font_face_t* fontFace = cairo_scaled_font_get_font_face(mScaledFont); 1.47 + FT_Face face = cairo_ft_scaled_font_lock_face(mScaledFont); 1.48 + 1.49 + int style = SkTypeface::kNormal; 1.50 + 1.51 + if (face->style_flags & FT_STYLE_FLAG_ITALIC) 1.52 + style |= SkTypeface::kItalic; 1.53 + 1.54 + if (face->style_flags & FT_STYLE_FLAG_BOLD) 1.55 + style |= SkTypeface::kBold; 1.56 + 1.57 + bool isFixedWidth = face->face_flags & FT_FACE_FLAG_FIXED_WIDTH; 1.58 + cairo_ft_scaled_font_unlock_face(mScaledFont); 1.59 + 1.60 + mTypeface = SkCreateTypefaceFromCairoFont(fontFace, (SkTypeface::Style)style, isFixedWidth); 1.61 + } 1.62 + 1.63 + return mTypeface; 1.64 +} 1.65 +#endif 1.66 + 1.67 +} 1.68 +}