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

Side by Side Diff: src/fonts/SkFontMgr_fontconfig.cpp

Issue 1921903002: Add oblique as a slant. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase and add test. Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkFontMgr.h" 10 #include "SkFontMgr.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 int old_min, int old_max, int new_min, int new_max) { 161 int old_min, int old_max, int new_min, int new_max) {
162 SkASSERT(old_min < old_max); 162 SkASSERT(old_min < old_max);
163 SkASSERT(new_min < new_max); 163 SkASSERT(new_min < new_max);
164 return new_min + SkMulDiv(value - old_min, 164 return new_min + SkMulDiv(value - old_min,
165 new_max - new_min, old_max - old_min); 165 new_max - new_min, old_max - old_min);
166 } 166 }
167 167
168 static SkFontStyle make_fontconfig_style(FcPattern* match) { 168 static SkFontStyle make_fontconfig_style(FcPattern* match) {
169 int weight = get_int(match, FC_WEIGHT); 169 int weight = get_int(match, FC_WEIGHT);
170 int width = get_int(match, FC_WIDTH); 170 int width = get_int(match, FC_WIDTH);
171 int slant = get_int(match, FC_SLANT); 171 int fcSlant = get_int(match, FC_SLANT);
172 // SkDebugf("old weight %d new weight %d\n", weight, map_range(weight, 0, 80, 0, 400));
173 172
174 // fontconfig weight seems to be 0..200 or so, so we remap it here 173 // fontconfig weight seems to be 0..200 or so, so we remap it here
175 weight = map_range(weight, 0, 80, 0, 400); 174 weight = map_range(weight, 0, 80, 0, 400);
176 width = map_range(width, 0, 200, 0, 9); 175 width = map_range(width, 0, 200, 0, 9);
177 return SkFontStyle(weight, width, slant > 0 ? SkFontStyle::kItalic_Slant 176 SkFontStyle::Slant skSlant = SkFontStyle::kUpright_Slant;
178 : SkFontStyle::kUpright_Slant); 177 switch (fcSlant) {
178 case FC_SLANT_ROMAN: skSlant = SkFontStyle::kUpright_Slant; break;
179 case FC_SLANT_ITALIC : skSlant = SkFontStyle::kItalic_Slant ; break;
180 case FC_SLANT_OBLIQUE: skSlant = SkFontStyle::kOblique_Slant; break;
181 default: SkASSERT(false); break;
182 }
183 return SkFontStyle(weight, width, skSlant);
179 } 184 }
180 185
181 SkFontStyleSet_FC::SkFontStyleSet_FC(FcPattern** matches, int count) { 186 SkFontStyleSet_FC::SkFontStyleSet_FC(FcPattern** matches, int count) {
182 fRecCount = count; 187 fRecCount = count;
183 fRecs = new Rec[count]; 188 fRecs = new Rec[count];
184 for (int i = 0; i < count; ++i) { 189 for (int i = 0; i < count; ++i) {
185 fRecs[i].fStyleName.set(get_name(matches[i], FC_STYLE)); 190 fRecs[i].fStyleName.set(get_name(matches[i], FC_STYLE));
186 fRecs[i].fFileName.set(get_name(matches[i], FC_FILE)); 191 fRecs[i].fFileName.set(get_name(matches[i], FC_FILE));
187 fRecs[i].fStyle = make_fontconfig_style(matches[i]); 192 fRecs[i].fStyle = make_fontconfig_style(matches[i]);
188 } 193 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl e) const override { 326 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl e) const override {
322 FCLocker lock; 327 FCLocker lock;
323 return FontConfigTypeface::LegacyCreateTypeface(familyName, style); 328 return FontConfigTypeface::LegacyCreateTypeface(familyName, style);
324 } 329 }
325 }; 330 };
326 331
327 SkFontMgr* SkFontMgr::Factory() { 332 SkFontMgr* SkFontMgr::Factory() {
328 SkFontConfigInterface* fci = RefFCI(); 333 SkFontConfigInterface* fci = RefFCI();
329 return fci ? new SkFontMgr_fontconfig(fci) : nullptr; 334 return fci ? new SkFontMgr_fontconfig(fci) : nullptr;
330 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698