Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: src/ports/SkFontHost_fontconfig.cpp

Issue 667023002: Revert of Replace SkTypeface::Style with SkFontStyle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkFontHost_FreeType_common.h ('k') | src/ports/SkFontHost_linux.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2008 Google Inc. 2 * Copyright 2008 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 // export this to SkFontMgr_fontconfig.cpp until this file just goes away. 54 // export this to SkFontMgr_fontconfig.cpp until this file just goes away.
55 SkFontConfigInterface* SkFontHost_fontconfig_ref_global(); 55 SkFontConfigInterface* SkFontHost_fontconfig_ref_global();
56 SkFontConfigInterface* SkFontHost_fontconfig_ref_global() { 56 SkFontConfigInterface* SkFontHost_fontconfig_ref_global() {
57 return RefFCI(); 57 return RefFCI();
58 } 58 }
59 59
60 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
61 61
62 struct FindRec { 62 struct FindRec {
63 FindRec(const char* name, const SkFontStyle& style) 63 FindRec(const char* name, SkTypeface::Style style)
64 : fFamilyName(name) // don't need to make a deep copy 64 : fFamilyName(name) // don't need to make a deep copy
65 , fStyle(style) {} 65 , fStyle(style) {}
66 66
67 const char* fFamilyName; 67 const char* fFamilyName;
68 SkFontStyle fStyle; 68 SkTypeface::Style fStyle;
69 }; 69 };
70 70
71 static bool find_proc(SkTypeface* cachedTypeface, const SkFontStyle& cachedStyle , void* ctx) { 71 static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) {
72 FontConfigTypeface* cachedFCTypeface = (FontConfigTypeface*)cachedTypeface; 72 FontConfigTypeface* fci = (FontConfigTypeface*)face;
73 const FindRec* rec = static_cast<const FindRec*>(ctx); 73 const FindRec* rec = (const FindRec*)ctx;
74 74
75 return rec->fStyle == cachedStyle && 75 return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName);
76 cachedFCTypeface->isFamilyName(rec->fFamilyName);
77 } 76 }
78 77
79 SkTypeface* FontConfigTypeface::LegacyCreateTypeface( 78 SkTypeface* FontConfigTypeface::LegacyCreateTypeface(
80 const SkTypeface* familyFace, 79 const SkTypeface* familyFace,
81 const char familyName[], 80 const char familyName[],
82 SkTypeface::Style style) { 81 SkTypeface::Style style) {
83 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 82 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
84 if (NULL == fci.get()) { 83 if (NULL == fci.get()) {
85 return NULL; 84 return NULL;
86 } 85 }
87 86
88 if (familyFace) { 87 if (familyFace) {
89 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; 88 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace;
90 familyName = fct->getFamilyName(); 89 familyName = fct->getFamilyName();
91 } 90 }
92 91
93 SkFontStyle requestedStyle(style); 92 FindRec rec(familyName, style);
94 FindRec rec(familyName, requestedStyle);
95 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); 93 SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec);
96 if (face) { 94 if (face) {
97 //SkDebugf("found cached face <%s> <%s> %p [%d]\n", 95 // SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontCo nfigTypeface*)face)->getFamilyName(), face, face->getRefCnt());
98 // familyName, ((FontConfigTypeface*)face)->getFamilyName(),
99 // face, face->getRefCnt());
100 return face; 96 return face;
101 } 97 }
102 98
103 SkFontConfigInterface::FontIdentity indentity; 99 SkFontConfigInterface::FontIdentity indentity;
104 SkString outFamilyName; 100 SkString outFamilyName;
105 SkTypeface::Style outStyle; 101 SkTypeface::Style outStyle;
106 if (!fci->matchFamilyName(familyName, style, &indentity, &outFamilyName, &ou tStyle)) { 102
103 if (!fci->matchFamilyName(familyName, style,
104 &indentity, &outFamilyName, &outStyle)) {
107 return NULL; 105 return NULL;
108 } 106 }
109 107
110 // check if we, in fact, already have this. perhaps fontconfig aliased the 108 // check if we, in fact, already have this. perhaps fontconfig aliased the
111 // requested name to some other name we actually have... 109 // requested name to some other name we actually have...
112 rec.fFamilyName = outFamilyName.c_str(); 110 rec.fFamilyName = outFamilyName.c_str();
113 rec.fStyle = SkFontStyle(outStyle); 111 rec.fStyle = outStyle;
114 face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec); 112 face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec);
115 if (face) { 113 if (face) {
116 return face; 114 return face;
117 } 115 }
118 116
119 face = FontConfigTypeface::Create(SkFontStyle(outStyle), indentity, outFamil yName); 117 face = FontConfigTypeface::Create(outStyle, indentity, outFamilyName);
120 SkTypefaceCache::Add(face, requestedStyle); 118 SkTypefaceCache::Add(face, style);
121 //SkDebugf("add face <%s> <%s> %p [%d]\n", 119 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str() , face, face->getRefCnt());
122 // familyName, outFamilyName.c_str(),
123 // face, face->getRefCnt());
124 return face; 120 return face;
125 } 121 }
126 122
127 /////////////////////////////////////////////////////////////////////////////// 123 ///////////////////////////////////////////////////////////////////////////////
128 124
129 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { 125 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
130 SkStream* stream = this->getLocalStream(); 126 SkStream* stream = this->getLocalStream();
131 if (stream) { 127 if (stream) {
132 // should have been provided by CreateFromStream() 128 // should have been provided by CreateFromStream()
133 *ttcIndex = 0; 129 *ttcIndex = 0;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { 165 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const {
170 *familyName = this->getFamilyName(); 166 *familyName = this->getFamilyName();
171 } 167 }
172 168
173 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 169 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
174 bool* isLocalStream) const { 170 bool* isLocalStream) const {
175 desc->setFamilyName(this->getFamilyName()); 171 desc->setFamilyName(this->getFamilyName());
176 desc->setFontIndex(this->getIdentity().fTTCIndex); 172 desc->setFontIndex(this->getIdentity().fTTCIndex);
177 *isLocalStream = SkToBool(this->getLocalStream()); 173 *isLocalStream = SkToBool(this->getLocalStream());
178 } 174 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_FreeType_common.h ('k') | src/ports/SkFontHost_linux.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698