blob: a3df04d79bbef646ff91981c5a9188085fc0149a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2009 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
reed@google.com1a64a542013-03-12 15:41:18 +00008#include "SkFontLCDConfig.h"
agl@chromium.org309485b2009-07-21 17:41:32 +00009
reed@google.com1a64a542013-03-12 15:41:18 +000010static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation;
11static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder;
agl@chromium.org309485b2009-07-21 17:41:32 +000012
reed@google.com1a64a542013-03-12 15:41:18 +000013SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() {
agl@chromium.org309485b2009-07-21 17:41:32 +000014 return gLCDOrientation;
15}
16
reed@google.com1a64a542013-03-12 15:41:18 +000017void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) {
agl@chromium.org309485b2009-07-21 17:41:32 +000018 gLCDOrientation = orientation;
19}
20
reed@google.com1a64a542013-03-12 15:41:18 +000021SkFontLCDConfig::LCDOrder SkFontLCDConfig::GetSubpixelOrder() {
agl@chromium.org309485b2009-07-21 17:41:32 +000022 return gLCDOrder;
23}
24
reed@google.com1a64a542013-03-12 15:41:18 +000025void SkFontLCDConfig::SetSubpixelOrder(LCDOrder order) {
agl@chromium.org309485b2009-07-21 17:41:32 +000026 gLCDOrder = order;
27}
reed@google.com1a64a542013-03-12 15:41:18 +000028
29///////////////////////////////////////////////////////////////////////////////
30// Legacy wrappers : remove from SkFontHost when webkit switches to new API
31
32#include "SkFontHost.h"
33
34SkFontHost::LCDOrientation SkFontHost::GetSubpixelOrientation() {
35 return (SkFontHost::LCDOrientation)SkFontLCDConfig::GetSubpixelOrientation();
36}
37
38void SkFontHost::SetSubpixelOrientation(LCDOrientation orientation) {
39 SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)orientation);
40}
41
42SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() {
43 return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder();
44}
45
46void SkFontHost::SetSubpixelOrder(LCDOrder order) {
47 SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order);
48}
reed@google.com83787c52013-03-26 17:19:15 +000049
50///////////////////////////////////////////////////////////////////////////////
51///////////////////////////////////////////////////////////////////////////////
52
reed@google.com964988f2013-03-29 14:57:22 +000053#include "SkFontStyle.h"
54
55SkFontStyle::SkFontStyle() {
56 fUnion.fU32 = 0;
57 fUnion.fR.fWeight = kNormal_Weight;
58 fUnion.fR.fWidth = kNormal_Width;
59 fUnion.fR.fSlant = kUpright_Slant;
60}
61
62SkFontStyle::SkFontStyle(int weight, int width, Slant slant) {
63 fUnion.fU32 = 0;
64 fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight);
65 fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width);
66 fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant);
67}
68
reed@google.com83787c52013-03-26 17:19:15 +000069#include "SkFontMgr.h"
70
reed@google.com964988f2013-03-29 14:57:22 +000071class SkEmptyFontStyleSet : public SkFontStyleSet {
72public:
73 virtual int count() SK_OVERRIDE { return 0; }
74 virtual void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE {
75 SkASSERT(!"SkFontStyleSet::getStyle called on empty set");
76 }
77 virtual SkTypeface* createTypeface(int index) SK_OVERRIDE {
78 SkASSERT(!"SkFontStyleSet::createTypeface called on empty set");
79 return NULL;
80 }
81 virtual SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE {
82 return NULL;
83 }
84};
85
86SkFontStyleSet* SkFontStyleSet::CreateEmpty() {
87 return SkNEW(SkEmptyFontStyleSet);
88}
89
90///////////////////////////////////////////////////////////////////////////////
91
reed@google.comdb235092013-03-27 20:12:59 +000092class SkEmptyFontMgr : public SkFontMgr {
93protected:
94 virtual int onCountFamilies() SK_OVERRIDE {
95 return 0;
96 }
97 virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE {
98 SkASSERT(!"onGetFamilyName called with bad index");
99 }
100 virtual SkFontStyleSet* onCreateStyleSet(int index) SK_OVERRIDE {
101 SkASSERT(!"onCreateStyleSet called with bad index");
102 return NULL;
103 }
reed@google.com964988f2013-03-29 14:57:22 +0000104 virtual SkFontStyleSet* onMatchFamily(const char[]) SK_OVERRIDE {
105 return SkFontStyleSet::CreateEmpty();
106 }
107
reed@google.comdb235092013-03-27 20:12:59 +0000108 virtual SkTypeface* onMatchFamilyStyle(const char[],
109 const SkFontStyle&) SK_OVERRIDE {
110 return NULL;
111 }
112 virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
113 const SkFontStyle&) SK_OVERRIDE {
114 return NULL;
115 }
116 virtual SkTypeface* onCreateFromData(SkData*, int) SK_OVERRIDE {
117 return NULL;
118 }
119 virtual SkTypeface* onCreateFromStream(SkStream*, int) SK_OVERRIDE {
120 return NULL;
121 }
122 virtual SkTypeface* onCreateFromFile(const char[], int) SK_OVERRIDE {
123 return NULL;
124 }
125};
126
reed@google.com83787c52013-03-26 17:19:15 +0000127int SkFontMgr::countFamilies() {
128 return this->onCountFamilies();
129}
130
131void SkFontMgr::getFamilyName(int index, SkString* familyName) {
132 this->onGetFamilyName(index, familyName);
133}
134
135SkFontStyleSet* SkFontMgr::createStyleSet(int index) {
136 return this->onCreateStyleSet(index);
137}
138
reed@google.com964988f2013-03-29 14:57:22 +0000139SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) {
140 return this->onMatchFamily(familyName);
141}
142
reed@google.com83787c52013-03-26 17:19:15 +0000143SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[],
144 const SkFontStyle& fs) {
145 return this->onMatchFamilyStyle(familyName, fs);
146}
147
skia.committer@gmail.com37cbc7f2013-03-27 07:01:04 +0000148SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
reed@google.com83787c52013-03-26 17:19:15 +0000149 const SkFontStyle& fs) {
reed@google.com919e9c32013-03-26 19:29:55 +0000150 return this->onMatchFaceStyle(face, fs);
reed@google.com83787c52013-03-26 17:19:15 +0000151}
152
153SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) {
154 return this->onCreateFromData(data, ttcIndex);
155}
156
157SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) {
158 return this->onCreateFromStream(stream, ttcIndex);
159}
160
161SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) {
162 return this->onCreateFromFile(path, ttcIndex);
163}
164
165SkFontMgr* SkFontMgr::RefDefault() {
166 static SkFontMgr* gFM;
167 if (NULL == gFM) {
168 gFM = SkFontMgr::Factory();
reed@google.comdb235092013-03-27 20:12:59 +0000169 // we never want to return NULL
170 if (NULL == gFM) {
171 gFM = SkNEW(SkEmptyFontMgr);
172 }
reed@google.com83787c52013-03-26 17:19:15 +0000173 }
174 return SkRef(gFM);
175}