2 * Copyright 2009 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkFontLCDConfig.h"
11 static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation;
12 static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder;
14 SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() {
15 return gLCDOrientation;
18 void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) {
19 gLCDOrientation = orientation;
22 SkFontLCDConfig::LCDOrder SkFontLCDConfig::GetSubpixelOrder() {
26 void SkFontLCDConfig::SetSubpixelOrder(LCDOrder order) {
30 ///////////////////////////////////////////////////////////////////////////////
31 // Legacy wrappers : remove from SkFontHost when webkit switches to new API
33 #include "SkFontHost.h"
35 SkFontHost::LCDOrientation SkFontHost::GetSubpixelOrientation() {
36 return (SkFontHost::LCDOrientation)SkFontLCDConfig::GetSubpixelOrientation();
39 void SkFontHost::SetSubpixelOrientation(LCDOrientation orientation) {
40 SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)orientation);
43 SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() {
44 return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder();
47 void SkFontHost::SetSubpixelOrder(LCDOrder order) {
48 SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order);
51 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
54 #include "SkFontStyle.h"
56 SkFontStyle::SkFontStyle() {
58 fUnion.fR.fWeight = kNormal_Weight;
59 fUnion.fR.fWidth = kNormal_Width;
60 fUnion.fR.fSlant = kUpright_Slant;
63 SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
65 fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight);
66 fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width);
67 fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant);
70 SkFontStyle::SkFontStyle(unsigned oldStyle) {
72 fUnion.fR.fWeight = (oldStyle & SkTypeface::kBold) ? SkFontStyle::kBold_Weight
73 : SkFontStyle::kNormal_Weight;
74 fUnion.fR.fWidth = SkFontStyle::kNormal_Width;
75 fUnion.fR.fSlant = (oldStyle & SkTypeface::kItalic) ? SkFontStyle::kItalic_Slant
76 : SkFontStyle::kUpright_Slant;
79 #include "SkFontMgr.h"
81 class SkEmptyFontStyleSet : public SkFontStyleSet {
83 virtual int count() SK_OVERRIDE { return 0; }
84 virtual void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE {
85 SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set");
87 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
88 SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set");
91 virtual SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE {
96 SkFontStyleSet* SkFontStyleSet::CreateEmpty() {
97 return SkNEW(SkEmptyFontStyleSet);
100 ///////////////////////////////////////////////////////////////////////////////
102 class SkEmptyFontMgr : public SkFontMgr {
104 virtual int onCountFamilies() const SK_OVERRIDE {
107 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE {
108 SkDEBUGFAIL("onGetFamilyName called with bad index");
110 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE {
111 SkDEBUGFAIL("onCreateStyleSet called with bad index");
114 virtual SkFontStyleSet* onMatchFamily(const char[]) const SK_OVERRIDE {
115 return SkFontStyleSet::CreateEmpty();
118 virtual SkTypeface* onMatchFamilyStyle(const char[],
119 const SkFontStyle&) const SK_OVERRIDE {
122 #ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
123 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
124 const SkFontStyle& style,
127 SkUnichar character) const SK_OVERRIDE {
129 virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
130 const SkFontStyle& style,
132 SkUnichar character) const SK_OVERRIDE {
136 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
137 const SkFontStyle&) const SK_OVERRIDE {
140 virtual SkTypeface* onCreateFromData(SkData*, int) const SK_OVERRIDE {
143 virtual SkTypeface* onCreateFromStream(SkStream*, int) const SK_OVERRIDE {
146 virtual SkTypeface* onCreateFromFile(const char[], int) const SK_OVERRIDE {
149 virtual SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const SK_OVERRIDE {
154 static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) {
156 fsset = SkFontStyleSet::CreateEmpty();
161 int SkFontMgr::countFamilies() const {
162 return this->onCountFamilies();
165 void SkFontMgr::getFamilyName(int index, SkString* familyName) const {
166 this->onGetFamilyName(index, familyName);
169 SkFontStyleSet* SkFontMgr::createStyleSet(int index) const {
170 return emptyOnNull(this->onCreateStyleSet(index));
173 SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) const {
174 return emptyOnNull(this->onMatchFamily(familyName));
177 SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[],
178 const SkFontStyle& fs) const {
179 return this->onMatchFamilyStyle(familyName, fs);
182 #ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
183 SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
184 const char* bcp47[], int bcp47Count,
185 SkUnichar character) const {
186 return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character);
189 SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
190 const char bcp47[], SkUnichar character) const {
191 return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, character);
195 SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
196 const SkFontStyle& fs) const {
197 return this->onMatchFaceStyle(face, fs);
200 SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const {
204 return this->onCreateFromData(data, ttcIndex);
207 SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) const {
208 if (NULL == stream) {
211 return this->onCreateFromStream(stream, ttcIndex);
214 SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const {
218 return this->onCreateFromFile(path, ttcIndex);
221 SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[],
222 unsigned styleBits) const {
223 return this->onLegacyCreateTypeface(familyName, styleBits);
226 // As a template argument this must have external linkage.
227 SkFontMgr* sk_fontmgr_create_default() {
228 SkFontMgr* fm = SkFontMgr::Factory();
229 return fm ? fm : SkNEW(SkEmptyFontMgr);
232 SK_DECLARE_STATIC_LAZY_PTR(SkFontMgr, singleton, sk_fontmgr_create_default);
234 SkFontMgr* SkFontMgr::RefDefault() {
235 return SkRef(singleton.get());