Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2009 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkFontLCDConfig.h" |
michael@0 | 9 | #include "SkOnce.h" |
michael@0 | 10 | |
michael@0 | 11 | static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation; |
michael@0 | 12 | static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder; |
michael@0 | 13 | |
michael@0 | 14 | SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() { |
michael@0 | 15 | return gLCDOrientation; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) { |
michael@0 | 19 | gLCDOrientation = orientation; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | SkFontLCDConfig::LCDOrder SkFontLCDConfig::GetSubpixelOrder() { |
michael@0 | 23 | return gLCDOrder; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | void SkFontLCDConfig::SetSubpixelOrder(LCDOrder order) { |
michael@0 | 27 | gLCDOrder = order; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 31 | // Legacy wrappers : remove from SkFontHost when webkit switches to new API |
michael@0 | 32 | |
michael@0 | 33 | #include "SkFontHost.h" |
michael@0 | 34 | |
michael@0 | 35 | SkFontHost::LCDOrientation SkFontHost::GetSubpixelOrientation() { |
michael@0 | 36 | return (SkFontHost::LCDOrientation)SkFontLCDConfig::GetSubpixelOrientation(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | void SkFontHost::SetSubpixelOrientation(LCDOrientation orientation) { |
michael@0 | 40 | SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)orientation); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() { |
michael@0 | 44 | return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void SkFontHost::SetSubpixelOrder(LCDOrder order) { |
michael@0 | 48 | SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 52 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 53 | |
michael@0 | 54 | #include "SkFontStyle.h" |
michael@0 | 55 | |
michael@0 | 56 | SkFontStyle::SkFontStyle() { |
michael@0 | 57 | fUnion.fU32 = 0; |
michael@0 | 58 | fUnion.fR.fWeight = kNormal_Weight; |
michael@0 | 59 | fUnion.fR.fWidth = kNormal_Width; |
michael@0 | 60 | fUnion.fR.fSlant = kUpright_Slant; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | SkFontStyle::SkFontStyle(int weight, int width, Slant slant) { |
michael@0 | 64 | fUnion.fU32 = 0; |
michael@0 | 65 | fUnion.fR.fWeight = SkPin32(weight, kThin_Weight, kBlack_Weight); |
michael@0 | 66 | fUnion.fR.fWidth = SkPin32(width, kUltraCondensed_Width, kUltaExpanded_Width); |
michael@0 | 67 | fUnion.fR.fSlant = SkPin32(slant, kUpright_Slant, kItalic_Slant); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | #include "SkFontMgr.h" |
michael@0 | 71 | |
michael@0 | 72 | class SkEmptyFontStyleSet : public SkFontStyleSet { |
michael@0 | 73 | public: |
michael@0 | 74 | virtual int count() SK_OVERRIDE { return 0; } |
michael@0 | 75 | virtual void getStyle(int, SkFontStyle*, SkString*) SK_OVERRIDE { |
michael@0 | 76 | SkDEBUGFAIL("SkFontStyleSet::getStyle called on empty set"); |
michael@0 | 77 | } |
michael@0 | 78 | virtual SkTypeface* createTypeface(int index) SK_OVERRIDE { |
michael@0 | 79 | SkDEBUGFAIL("SkFontStyleSet::createTypeface called on empty set"); |
michael@0 | 80 | return NULL; |
michael@0 | 81 | } |
michael@0 | 82 | virtual SkTypeface* matchStyle(const SkFontStyle&) SK_OVERRIDE { |
michael@0 | 83 | return NULL; |
michael@0 | 84 | } |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | SkFontStyleSet* SkFontStyleSet::CreateEmpty() { |
michael@0 | 88 | return SkNEW(SkEmptyFontStyleSet); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 92 | |
michael@0 | 93 | class SkEmptyFontMgr : public SkFontMgr { |
michael@0 | 94 | protected: |
michael@0 | 95 | virtual int onCountFamilies() const SK_OVERRIDE { |
michael@0 | 96 | return 0; |
michael@0 | 97 | } |
michael@0 | 98 | virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE { |
michael@0 | 99 | SkDEBUGFAIL("onGetFamilyName called with bad index"); |
michael@0 | 100 | } |
michael@0 | 101 | virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE { |
michael@0 | 102 | SkDEBUGFAIL("onCreateStyleSet called with bad index"); |
michael@0 | 103 | return NULL; |
michael@0 | 104 | } |
michael@0 | 105 | virtual SkFontStyleSet* onMatchFamily(const char[]) const SK_OVERRIDE { |
michael@0 | 106 | return SkFontStyleSet::CreateEmpty(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | virtual SkTypeface* onMatchFamilyStyle(const char[], |
michael@0 | 110 | const SkFontStyle&) const SK_OVERRIDE { |
michael@0 | 111 | return NULL; |
michael@0 | 112 | } |
michael@0 | 113 | virtual SkTypeface* onMatchFaceStyle(const SkTypeface*, |
michael@0 | 114 | const SkFontStyle&) const SK_OVERRIDE { |
michael@0 | 115 | return NULL; |
michael@0 | 116 | } |
michael@0 | 117 | virtual SkTypeface* onCreateFromData(SkData*, int) const SK_OVERRIDE { |
michael@0 | 118 | return NULL; |
michael@0 | 119 | } |
michael@0 | 120 | virtual SkTypeface* onCreateFromStream(SkStream*, int) const SK_OVERRIDE { |
michael@0 | 121 | return NULL; |
michael@0 | 122 | } |
michael@0 | 123 | virtual SkTypeface* onCreateFromFile(const char[], int) const SK_OVERRIDE { |
michael@0 | 124 | return NULL; |
michael@0 | 125 | } |
michael@0 | 126 | virtual SkTypeface* onLegacyCreateTypeface(const char [], unsigned) const SK_OVERRIDE { |
michael@0 | 127 | return NULL; |
michael@0 | 128 | } |
michael@0 | 129 | }; |
michael@0 | 130 | |
michael@0 | 131 | static SkFontStyleSet* emptyOnNull(SkFontStyleSet* fsset) { |
michael@0 | 132 | if (NULL == fsset) { |
michael@0 | 133 | fsset = SkFontStyleSet::CreateEmpty(); |
michael@0 | 134 | } |
michael@0 | 135 | return fsset; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | int SkFontMgr::countFamilies() const { |
michael@0 | 139 | return this->onCountFamilies(); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | void SkFontMgr::getFamilyName(int index, SkString* familyName) const { |
michael@0 | 143 | this->onGetFamilyName(index, familyName); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | SkFontStyleSet* SkFontMgr::createStyleSet(int index) const { |
michael@0 | 147 | return emptyOnNull(this->onCreateStyleSet(index)); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | SkFontStyleSet* SkFontMgr::matchFamily(const char familyName[]) const { |
michael@0 | 151 | return emptyOnNull(this->onMatchFamily(familyName)); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[], |
michael@0 | 155 | const SkFontStyle& fs) const { |
michael@0 | 156 | return this->onMatchFamilyStyle(familyName, fs); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face, |
michael@0 | 160 | const SkFontStyle& fs) const { |
michael@0 | 161 | return this->onMatchFaceStyle(face, fs); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | SkTypeface* SkFontMgr::createFromData(SkData* data, int ttcIndex) const { |
michael@0 | 165 | if (NULL == data) { |
michael@0 | 166 | return NULL; |
michael@0 | 167 | } |
michael@0 | 168 | return this->onCreateFromData(data, ttcIndex); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | SkTypeface* SkFontMgr::createFromStream(SkStream* stream, int ttcIndex) const { |
michael@0 | 172 | if (NULL == stream) { |
michael@0 | 173 | return NULL; |
michael@0 | 174 | } |
michael@0 | 175 | return this->onCreateFromStream(stream, ttcIndex); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const { |
michael@0 | 179 | if (NULL == path) { |
michael@0 | 180 | return NULL; |
michael@0 | 181 | } |
michael@0 | 182 | return this->onCreateFromFile(path, ttcIndex); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], |
michael@0 | 186 | unsigned styleBits) const { |
michael@0 | 187 | return this->onLegacyCreateTypeface(familyName, styleBits); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | void set_up_default(SkFontMgr** singleton) { |
michael@0 | 191 | *singleton = SkFontMgr::Factory(); |
michael@0 | 192 | // we never want to return NULL |
michael@0 | 193 | if (NULL == *singleton) { |
michael@0 | 194 | *singleton = SkNEW(SkEmptyFontMgr); |
michael@0 | 195 | } |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | SkFontMgr* SkFontMgr::RefDefault() { |
michael@0 | 199 | static SkFontMgr* gFM = NULL; |
michael@0 | 200 | SK_DECLARE_STATIC_ONCE(once); |
michael@0 | 201 | SkOnce(&once, set_up_default, &gFM); |
michael@0 | 202 | return SkRef(gFM); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | ////////////////////////////////////////////////////////////////////////// |
michael@0 | 206 | |
michael@0 | 207 | #ifndef SK_FONTHOST_DOES_NOT_USE_FONTMGR |
michael@0 | 208 | |
michael@0 | 209 | #if 0 |
michael@0 | 210 | static SkFontStyle TypefaceStyleBitsToFontStyle(SkTypeface::Style styleBits) { |
michael@0 | 211 | SkFontStyle::Weight weight = (styleBits & SkTypeface::kBold) ? |
michael@0 | 212 | SkFontStyle::kBold_Weight : |
michael@0 | 213 | SkFontStyle::kNormal_Weight; |
michael@0 | 214 | SkFontStyle::Width width = SkFontStyle::kNormal_Width; |
michael@0 | 215 | SkFontStyle::Slant slant = (styleBits & SkTypeface::kItalic) ? |
michael@0 | 216 | SkFontStyle::kUpright_Slant : |
michael@0 | 217 | SkFontStyle::kItalic_Slant; |
michael@0 | 218 | return SkFontStyle(weight, width, slant); |
michael@0 | 219 | } |
michael@0 | 220 | #endif |
michael@0 | 221 | |
michael@0 | 222 | SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
michael@0 | 223 | const char familyName[], |
michael@0 | 224 | SkTypeface::Style style) { |
michael@0 | 225 | SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
michael@0 | 226 | if (familyFace) { |
michael@0 | 227 | bool bold = style & SkTypeface::kBold; |
michael@0 | 228 | bool italic = style & SkTypeface::kItalic; |
michael@0 | 229 | SkFontStyle newStyle = SkFontStyle(bold ? SkFontStyle::kBold_Weight |
michael@0 | 230 | : SkFontStyle::kNormal_Weight, |
michael@0 | 231 | SkFontStyle::kNormal_Width, |
michael@0 | 232 | italic ? SkFontStyle::kItalic_Slant |
michael@0 | 233 | : SkFontStyle::kUpright_Slant); |
michael@0 | 234 | return fm->matchFaceStyle(familyFace, newStyle); |
michael@0 | 235 | } else { |
michael@0 | 236 | return fm->legacyCreateTypeface(familyName, style); |
michael@0 | 237 | } |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
michael@0 | 241 | SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
michael@0 | 242 | return fm->createFromFile(path); |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
michael@0 | 246 | SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); |
michael@0 | 247 | return fm->createFromStream(stream); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | #endif |