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

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

Issue 488143002: Replace SkTypeface::Style with SkFontStyle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add expectations, remove whitespace. 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/SkFontMgr_android.cpp ('k') | src/ports/SkFontMgr_win_dw.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 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 "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost_FreeType_common.h" 10 #include "SkFontHost_FreeType_common.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 { SkTFixed<SkFS::kExtraExpanded_Width>::value, SkTFixed<FC_WIDTH_EXTRAE XPANDED>::value }, 366 { SkTFixed<SkFS::kExtraExpanded_Width>::value, SkTFixed<FC_WIDTH_EXTRAE XPANDED>::value },
367 { SkTFixed<SkFS::kUltaExpanded_Width>::value, SkTFixed<FC_WIDTH_ULTRAE XPANDED>::value }, 367 { SkTFixed<SkFS::kUltaExpanded_Width>::value, SkTFixed<FC_WIDTH_ULTRAE XPANDED>::value },
368 }; 368 };
369 int width = map_ranges(style.width(), widthRanges, SK_ARRAY_COUNT(widthRange s)); 369 int width = map_ranges(style.width(), widthRanges, SK_ARRAY_COUNT(widthRange s));
370 370
371 FcPatternAddInteger(pattern, FC_WEIGHT, weight); 371 FcPatternAddInteger(pattern, FC_WEIGHT, weight);
372 FcPatternAddInteger(pattern, FC_WIDTH, width); 372 FcPatternAddInteger(pattern, FC_WIDTH, width);
373 FcPatternAddInteger(pattern, FC_SLANT, style.isItalic() ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); 373 FcPatternAddInteger(pattern, FC_SLANT, style.isItalic() ? FC_SLANT_ITALIC : FC_SLANT_ROMAN);
374 } 374 }
375 375
376 static SkTypeface::Style sktypefacestyle_from_fcpattern(FcPattern* pattern) {
377 int fcweight = get_int(pattern, FC_WEIGHT, FC_WEIGHT_REGULAR);
378 int fcslant = get_int(pattern, FC_SLANT, FC_SLANT_ROMAN);
379 return (SkTypeface::Style)((fcweight >= FC_WEIGHT_BOLD ? SkTypeface::kBold : 0) |
380 (fcslant > FC_SLANT_ROMAN ? SkTypeface::kItalic : 0));
381 }
382
383 class SkTypeface_stream : public SkTypeface_FreeType { 376 class SkTypeface_stream : public SkTypeface_FreeType {
384 public: 377 public:
385 /** @param stream does not take ownership of the reference, does take owners hip of the stream.*/ 378 /** @param stream does not take ownership of the reference, does take owners hip of the stream.*/
386 SkTypeface_stream(SkTypeface::Style style, bool fixedWidth, int ttcIndex, Sk StreamAsset* stream) 379 SkTypeface_stream(const SkFontStyle& style, bool fixedWidth, int index, SkSt reamAsset* stream)
387 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth) 380 : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
388 , fStream(SkRef(stream)) 381 , fStream(SkRef(stream))
389 , fIndex(ttcIndex) 382 , fIndex(index)
390 { }; 383 { };
391 384
392 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { 385 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
393 familyName->reset(); 386 familyName->reset();
394 } 387 }
395 388
396 virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) co nst SK_OVERRIDE { 389 virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) co nst SK_OVERRIDE {
397 desc->setFontIndex(fIndex); 390 desc->setFontIndex(fIndex);
398 *serialize = true; 391 *serialize = true;
399 } 392 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 433
441 virtual ~SkTypeface_fontconfig() { 434 virtual ~SkTypeface_fontconfig() {
442 // Hold the lock while unrefing the pattern. 435 // Hold the lock while unrefing the pattern.
443 FCLocker lock; 436 FCLocker lock;
444 fPattern.reset(); 437 fPattern.reset();
445 } 438 }
446 439
447 private: 440 private:
448 /** @param pattern takes ownership of the reference. */ 441 /** @param pattern takes ownership of the reference. */
449 SkTypeface_fontconfig(FcPattern* pattern) 442 SkTypeface_fontconfig(FcPattern* pattern)
450 : INHERITED(sktypefacestyle_from_fcpattern(pattern), 443 : INHERITED(skfontstyle_from_fcpattern(pattern),
451 SkTypefaceCache::NewFontID(), 444 SkTypefaceCache::NewFontID(),
452 FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIO NAL)) 445 FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIO NAL))
453 , fPattern(pattern) 446 , fPattern(pattern)
454 { }; 447 { };
455 448
456 typedef SkTypeface_FreeType INHERITED; 449 typedef SkTypeface_FreeType INHERITED;
457 }; 450 };
458 451
459 class SkFontMgr_fontconfig : public SkFontMgr { 452 class SkFontMgr_fontconfig : public SkFontMgr {
460 mutable SkAutoFcConfig fFC; 453 mutable SkAutoFcConfig fFC;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 *sizes.append() = strlen(familyName) + 1; 557 *sizes.append() = strlen(familyName) + 1;
565 } 558 }
566 } 559 }
567 } 560 }
568 } 561 }
569 562
570 return SkDataTable::NewCopyArrays((void const *const *)names.begin(), 563 return SkDataTable::NewCopyArrays((void const *const *)names.begin(),
571 sizes.begin(), names.count()); 564 sizes.begin(), names.count());
572 } 565 }
573 566
574 static bool FindByFcPattern(SkTypeface* cached, SkTypeface::Style, void* ctx ) { 567 static bool FindByFcPattern(SkTypeface* cached, const SkFontStyle&, void* ct x) {
575 SkTypeface_fontconfig* cshFace = static_cast<SkTypeface_fontconfig*>(cac hed); 568 SkTypeface_fontconfig* cshFace = static_cast<SkTypeface_fontconfig*>(cac hed);
576 FcPattern* ctxPattern = static_cast<FcPattern*>(ctx); 569 FcPattern* ctxPattern = static_cast<FcPattern*>(ctx);
577 return FcTrue == FcPatternEqual(cshFace->fPattern, ctxPattern); 570 return FcTrue == FcPatternEqual(cshFace->fPattern, ctxPattern);
578 } 571 }
579 572
580 mutable SkMutex fTFCacheMutex; 573 mutable SkMutex fTFCacheMutex;
581 mutable SkTypefaceCache fTFCache; 574 mutable SkTypefaceCache fTFCache;
582 /** Creates a typeface using a typeface cache. 575 /** Creates a typeface using a typeface cache.
583 * @param pattern a complete pattern from FcFontRenderPrepare. 576 * @param pattern a complete pattern from FcFontRenderPrepare.
584 */ 577 */
585 SkTypeface* createTypefaceFromFcPattern(FcPattern* pattern) const { 578 SkTypeface* createTypefaceFromFcPattern(FcPattern* pattern) const {
586 FCLocker::AssertHeld(); 579 FCLocker::AssertHeld();
587 SkAutoMutexAcquire ama(fTFCacheMutex); 580 SkAutoMutexAcquire ama(fTFCacheMutex);
588 SkTypeface* face = fTFCache.findByProcAndRef(FindByFcPattern, pattern); 581 SkTypeface* face = fTFCache.findByProcAndRef(FindByFcPattern, pattern);
589 if (NULL == face) { 582 if (NULL == face) {
590 FcPatternReference(pattern); 583 FcPatternReference(pattern);
591 face = SkTypeface_fontconfig::Create(pattern); 584 face = SkTypeface_fontconfig::Create(pattern);
592 if (face) { 585 if (face) {
593 fTFCache.add(face, SkTypeface::kNormal, true); 586 fTFCache.add(face, SkFontStyle(), true);
594 } 587 }
595 } 588 }
596 return face; 589 return face;
597 } 590 }
598 591
599 public: 592 public:
600 SkFontMgr_fontconfig() 593 SkFontMgr_fontconfig()
601 : fFC(FcInitLoadConfigAndFonts()) 594 : fFC(FcInitLoadConfigAndFonts())
602 , fFamilyNames(GetFamilyNames(fFC)) { } 595 , fFamilyNames(GetFamilyNames(fFC)) { }
603 596
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY ), style); 804 return this->matchFamilyStyle(get_string(fcTypeface->fPattern, FC_FAMILY ), style);
812 } 805 }
813 806
814 /** @param stream does not take ownership of the reference. */ 807 /** @param stream does not take ownership of the reference. */
815 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE { 808 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
816 const size_t length = stream->getLength(); 809 const size_t length = stream->getLength();
817 if (length <= 0 || (1u << 30) < length) { 810 if (length <= 0 || (1u << 30) < length) {
818 return NULL; 811 return NULL;
819 } 812 }
820 813
821 SkTypeface::Style style = SkTypeface::kNormal; 814 SkFontStyle style;
822 bool isFixedWidth = false; 815 bool isFixedWidth = false;
823 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, NULL, &style, &isFi xedWidth)) { 816 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, NULL, &style, &isFi xedWidth)) {
824 return NULL; 817 return NULL;
825 } 818 }
826 819
827 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex, 820 return SkNEW_ARGS(SkTypeface_stream, (style, isFixedWidth, ttcIndex,
828 static_cast<SkStreamAsset*>(stream ))); 821 static_cast<SkStreamAsset*>(stream )));
829 } 822 }
830 823
831 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE { 824 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE {
(...skipping 20 matching lines...) Expand all
852 return typeface.detach(); 845 return typeface.detach();
853 } 846 }
854 847
855 return this->matchFamilyStyle(NULL, style); 848 return this->matchFamilyStyle(NULL, style);
856 } 849 }
857 }; 850 };
858 851
859 SkFontMgr* SkFontMgr::Factory() { 852 SkFontMgr* SkFontMgr::Factory() {
860 return SkNEW(SkFontMgr_fontconfig); 853 return SkNEW(SkFontMgr_fontconfig);
861 } 854 }
OLDNEW
« no previous file with comments | « src/ports/SkFontMgr_android.cpp ('k') | src/ports/SkFontMgr_win_dw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698