OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkDataTable.h" | 8 #include "SkDataTable.h" |
9 #include "SkFixed.h" | 9 #include "SkFixed.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 static int map_range(SkFixed value, | 258 static int map_range(SkFixed value, |
259 SkFixed old_min, SkFixed old_max, | 259 SkFixed old_min, SkFixed old_max, |
260 SkFixed new_min, SkFixed new_max) | 260 SkFixed new_min, SkFixed new_max) |
261 { | 261 { |
262 SkASSERT(old_min < old_max); | 262 SkASSERT(old_min < old_max); |
263 SkASSERT(new_min <= new_max); | 263 SkASSERT(new_min <= new_max); |
264 return new_min + SkMulDiv(value - old_min, new_max - new_min, old_max - old_
min); | 264 return new_min + SkMulDiv(value - old_min, new_max - new_min, old_max - old_
min); |
265 } | 265 } |
266 | 266 |
267 static int ave(SkFixed a, SkFixed b) { | |
268 return SkFixedAve(a, b); | |
269 } | |
270 | |
271 struct MapRanges { | 267 struct MapRanges { |
272 SkFixed old_val; | 268 SkFixed old_val; |
273 SkFixed new_val; | 269 SkFixed new_val; |
274 }; | 270 }; |
275 | 271 |
276 static SkFixed map_ranges_fixed(SkFixed val, MapRanges const ranges[], int range
sCount) { | 272 static SkFixed map_ranges_fixed(SkFixed val, MapRanges const ranges[], int range
sCount) { |
277 // -Inf to [0] | 273 // -Inf to [0] |
278 if (val < ranges[0].old_val) { | 274 if (val < ranges[0].old_val) { |
279 return ranges[0].new_val; | 275 return ranges[0].new_val; |
280 } | 276 } |
281 | 277 |
282 // Linear from [i] to ave([i], [i+1]), then from ave([i], [i+1]) to [i+1] | 278 // Linear from [i] to [i+1] |
283 for (int i = 0; i < rangesCount - 1; ++i) { | 279 for (int i = 0; i < rangesCount - 1; ++i) { |
284 if (val < ave(ranges[i].old_val, ranges[i+1].old_val)) { | |
285 return map_range(val, ranges[i].old_val, ave(ranges[i].old_val, rang
es[i+1].old_val), | |
286 ranges[i].new_val, ave(ranges[i].new_val, rang
es[i+1].new_val)); | |
287 } | |
288 if (val < ranges[i+1].old_val) { | 280 if (val < ranges[i+1].old_val) { |
289 return map_range(val, ave(ranges[i].old_val, ranges[i+1].old_val), r
anges[i+1].old_val, | 281 return map_range(val, ranges[i].old_val, ranges[i+1].old_val, |
290 ave(ranges[i].new_val, ranges[i+1].new_val), r
anges[i+1].new_val); | 282 ranges[i].new_val, ranges[i+1].new_val); |
291 } | 283 } |
292 } | 284 } |
293 | 285 |
294 // From [n] to +Inf | 286 // From [n] to +Inf |
295 // if (fcweight < Inf) | 287 // if (fcweight < Inf) |
296 return ranges[rangesCount-1].new_val; | 288 return ranges[rangesCount-1].new_val; |
297 } | 289 } |
298 | 290 |
299 static int map_ranges(int val, MapRanges const ranges[], int rangesCount) { | 291 static int map_ranges(int val, MapRanges const ranges[], int rangesCount) { |
300 return SkFixedRoundToInt(map_ranges_fixed(SkIntToFixed(val), ranges, rangesC
ount)); | 292 return SkFixedRoundToInt(map_ranges_fixed(SkIntToFixed(val), ranges, rangesC
ount)); |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 const int ttcIndex = fontData->getIndex(); | 867 const int ttcIndex = fontData->getIndex(); |
876 SkFontStyle style; | 868 SkFontStyle style; |
877 bool isFixedWidth = false; | 869 bool isFixedWidth = false; |
878 if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth,
nullptr)) { | 870 if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth,
nullptr)) { |
879 return nullptr; | 871 return nullptr; |
880 } | 872 } |
881 | 873 |
882 return new SkTypeface_stream(fontData, style, isFixedWidth); | 874 return new SkTypeface_stream(fontData, style, isFixedWidth); |
883 } | 875 } |
884 | 876 |
885 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 877 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE |
886 unsigned styleBits) const overrid
e { | 878 SkTypeface* onLegacyCreateTypeface(const char familyName[], unsigned styleBi
ts) const override { |
887 bool bold = styleBits & SkTypeface::kBold; | 879 SkFontStyle style = SkFontStyle::FromOldStyle(styleBits); |
888 bool italic = styleBits & SkTypeface::kItalic; | 880 #else |
889 SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight | 881 SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle styl
e) const override { |
890 : SkFontStyle::kNormal_Weight, | 882 #endif |
891 SkFontStyle::kNormal_Width, | |
892 italic ? SkFontStyle::kItalic_Slant | |
893 : SkFontStyle::kUpright_Slant); | |
894 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty
le)); | 883 SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty
le)); |
895 if (typeface.get()) { | 884 if (typeface.get()) { |
896 return typeface.release(); | 885 return typeface.release(); |
897 } | 886 } |
898 | 887 |
899 return this->matchFamilyStyle(nullptr, style); | 888 return this->matchFamilyStyle(nullptr, style); |
900 } | 889 } |
901 }; | 890 }; |
902 | 891 |
903 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { | 892 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { |
904 return new SkFontMgr_fontconfig(fc); | 893 return new SkFontMgr_fontconfig(fc); |
905 } | 894 } |
OLD | NEW |