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

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