michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ScaledFontCairo.h" michael@0: #include "Logging.h" michael@0: michael@0: #ifdef MOZ_ENABLE_FREETYPE michael@0: #include michael@0: #include FT_FREETYPE_H michael@0: #include "cairo-ft.h" michael@0: #endif michael@0: michael@0: #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE) michael@0: #include "skia/SkTypeface.h" michael@0: #include "skia/SkTypeface_cairo.h" michael@0: #endif michael@0: michael@0: #include michael@0: michael@0: typedef struct FT_FaceRec_* FT_Face; michael@0: michael@0: using namespace std; michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: // On Linux and Android our "platform" font is a cairo_scaled_font_t and we use michael@0: // an SkFontHost implementation that allows Skia to render using this. michael@0: // This is mainly because FT_Face is not good for sharing between libraries, which michael@0: // is a requirement when we consider runtime switchable backends and so on michael@0: ScaledFontCairo::ScaledFontCairo(cairo_scaled_font_t* aScaledFont, Float aSize) michael@0: : ScaledFontBase(aSize) michael@0: { michael@0: SetCairoScaledFont(aScaledFont); michael@0: } michael@0: michael@0: #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE) michael@0: SkTypeface* ScaledFontCairo::GetSkTypeface() michael@0: { michael@0: if (!mTypeface) { michael@0: cairo_font_face_t* fontFace = cairo_scaled_font_get_font_face(mScaledFont); michael@0: FT_Face face = cairo_ft_scaled_font_lock_face(mScaledFont); michael@0: michael@0: int style = SkTypeface::kNormal; michael@0: michael@0: if (face->style_flags & FT_STYLE_FLAG_ITALIC) michael@0: style |= SkTypeface::kItalic; michael@0: michael@0: if (face->style_flags & FT_STYLE_FLAG_BOLD) michael@0: style |= SkTypeface::kBold; michael@0: michael@0: bool isFixedWidth = face->face_flags & FT_FACE_FLAG_FIXED_WIDTH; michael@0: cairo_ft_scaled_font_unlock_face(mScaledFont); michael@0: michael@0: mTypeface = SkCreateTypefaceFromCairoFont(fontFace, (SkTypeface::Style)style, isFixedWidth); michael@0: } michael@0: michael@0: return mTypeface; michael@0: } michael@0: #endif michael@0: michael@0: } michael@0: }