OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkTypes.h" // Keep this before any #ifdef ... | 9 #include "SkTypes.h" // Keep this before any #ifdef ... |
10 | 10 |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 bool fGeneratedFBoundingBoxes; | 708 bool fGeneratedFBoundingBoxes; |
709 const bool fDoSubPosition; | 709 const bool fDoSubPosition; |
710 const bool fVertical; | 710 const bool fVertical; |
711 | 711 |
712 friend class Offscreen; | 712 friend class Offscreen; |
713 | 713 |
714 typedef SkScalerContext INHERITED; | 714 typedef SkScalerContext INHERITED; |
715 }; | 715 }; |
716 | 716 |
717 // CTFontCreateCopyWithAttributes or CTFontCreateCopyWithSymbolicTraits cannot b
e used on 10.10 | 717 // CTFontCreateCopyWithAttributes or CTFontCreateCopyWithSymbolicTraits cannot b
e used on 10.10 |
718 // as they appear to be buggy with respect to the default font. It is not possib
le to use | 718 // and later, as they will return different underlying fonts depending on the si
ze requested. |
719 // descriptors with CTFontCreateWithFontDescriptor, since that does not work wit
h non-system | 719 // It is not possible to use descriptors with CTFontCreateWithFontDescriptor, si
nce that does not |
720 // fonts. As a result, create the strike specific CTFonts from the underlying CG
Font. | 720 // work with non-system fonts. As a result, create the strike specific CTFonts f
rom the underlying |
| 721 // CGFont. |
721 static CTFontRef ctfont_create_exact_copy(CTFontRef baseFont, CGFloat textSize, | 722 static CTFontRef ctfont_create_exact_copy(CTFontRef baseFont, CGFloat textSize, |
722 const CGAffineTransform* transform, bo
ol setVertical) | 723 const CGAffineTransform* transform) |
723 { | 724 { |
724 AutoCFRelease<CTFontDescriptorRef> baseExtraDescriptor; | 725 AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(baseFont, nullptr
)); |
725 AutoCFRelease<CGFontRef> baseCGFont(CTFontCopyGraphicsFont(baseFont, &baseEx
traDescriptor)); | |
726 | 726 |
727 // Make a mutable copy of baseExtraDescriptor attributes. | 727 // The last parameter (CTFontDescriptorRef attributes) *must* be nullptr. |
728 AutoCFRelease<CFMutableDictionaryRef> newAttributes([](CTFontDescriptorRef d
escriptor) -> | 728 // If non-nullptr then with fonts with variation axes, the copy will fail in |
729 CFMutableDictionaryRef { | 729 // CGFontVariationFromDictCallback when it assumes kCGFontVariationAxisName
is CFNumberRef |
730 if (nullptr == descriptor) { | 730 // which it quite obviously is not. |
731 return CFDictionaryCreateMutable(kCFAllocatorDefault, 0, | |
732 &kCFTypeDictionaryKeyCallBacks, | |
733 &kCFTypeDictionaryValueCallBacks); | |
734 } | |
735 AutoCFRelease<CFDictionaryRef> attributes(CTFontDescriptorCopyAttributes
(descriptor)); | |
736 return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, attributes)
; | |
737 }(baseExtraDescriptor)); | |
738 | 731 |
739 // Copy all of the attributes out of the CTFont. | 732 // Because we cannot setup the CTFont descriptor to match, the same restrict
ion applies here |
740 AutoCFRelease<CTFontDescriptorRef> baseDescriptor(CTFontCopyFontDescriptor(b
aseFont)); | 733 // as other uses of CTFontCreateWithGraphicsFont which is that such CTFonts
should not escape |
741 AutoCFRelease<CFDictionaryRef> baseAttributes(CTFontDescriptorCopyAttributes
(baseDescriptor)); | 734 // the scaler context, since they aren't 'normal'. |
742 CFDictionaryApplyFunction(baseAttributes, [](CFTypeRef key, CFTypeRef value,
void* context) { | 735 return CTFontCreateWithGraphicsFont(baseCGFont, textSize, transform, nullptr
); |
743 CFMutableDictionaryRef self = static_cast<CFMutableDictionaryRef>(contex
t); | |
744 CFDictionarySetValue(self, key, value); | |
745 }, newAttributes.get()); | |
746 | |
747 // Set the text size in attributes. | |
748 AutoCFRelease<CFNumberRef> cfTextSize( | |
749 CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &textSize)); | |
750 CFDictionarySetValue(newAttributes, kCTFontSizeAttribute, cfTextSize); | |
751 | |
752 // Set the transform in attributes. | |
753 if (nullptr == transform) { | |
754 CFDictionaryRemoveValue(newAttributes, kCTFontMatrixAttribute); | |
755 } else { | |
756 AutoCFRelease<CFDataRef> cfMatrixData(CFDataCreate( | |
757 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(transform), size
of(*transform))); | |
758 CFDictionarySetValue(newAttributes, kCTFontMatrixAttribute, cfMatrixData
); | |
759 } | |
760 | |
761 // Set vertical orientation to attributes if requested. | |
762 if (setVertical) { | |
763 CTFontOrientation ctOrientation = kCTFontVerticalOrientation; | |
764 AutoCFRelease<CFNumberRef> cfVertical( | |
765 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientat
ion)); | |
766 CFDictionarySetValue(newAttributes, kCTFontOrientationAttribute, cfVerti
cal); | |
767 } | |
768 | |
769 // Create the new CTFont from the baseCGFont. | |
770 AutoCFRelease<CTFontDescriptorRef> newDescriptor( | |
771 CTFontDescriptorCreateWithAttributes(newAttributes)); | |
772 return CTFontCreateWithGraphicsFont(baseCGFont, textSize, transform, newDesc
riptor); | |
773 | |
774 } | 736 } |
775 | 737 |
776 SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface, | 738 SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface, |
777 const SkDescriptor* desc) | 739 const SkDescriptor* desc) |
778 : INHERITED(typeface, desc) | 740 : INHERITED(typeface, desc) |
779 , fFBoundingBoxes() | 741 , fFBoundingBoxes() |
780 , fFBoundingBoxesGlyphOffset(0) | 742 , fFBoundingBoxesGlyphOffset(0) |
781 , fGeneratedFBoundingBoxes(false) | 743 , fGeneratedFBoundingBoxes(false) |
782 , fDoSubPosition(SkToBool(fRec.fFlags & kSubpixelPositioning_Flag)) | 744 , fDoSubPosition(SkToBool(fRec.fFlags & kSubpixelPositioning_Flag)) |
783 , fVertical(SkToBool(fRec.fFlags & kVertical_Flag)) | 745 , fVertical(SkToBool(fRec.fFlags & kVertical_Flag)) |
(...skipping 12 matching lines...) Expand all Loading... |
796 SkMatrix skTransform; | 758 SkMatrix skTransform; |
797 fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale, &scale, &
skTransform, | 759 fRec.computeMatrices(SkScalerContextRec::kVertical_PreMatrixScale, &scale, &
skTransform, |
798 nullptr, nullptr, &fFUnitMatrix); | 760 nullptr, nullptr, &fFUnitMatrix); |
799 fTransform = MatrixToCGAffineTransform(skTransform); | 761 fTransform = MatrixToCGAffineTransform(skTransform); |
800 fInvTransform = CGAffineTransformInvert(fTransform); | 762 fInvTransform = CGAffineTransformInvert(fTransform); |
801 | 763 |
802 // The transform contains everything except the requested text size. | 764 // The transform contains everything except the requested text size. |
803 // Some properties, like 'trak', are based on the text size (before applying
the matrix). | 765 // Some properties, like 'trak', are based on the text size (before applying
the matrix). |
804 CGFloat textSize = ScalarToCG(scale.y()); | 766 CGFloat textSize = ScalarToCG(scale.y()); |
805 | 767 |
806 fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, &fTransform, fVerti
cal)); | 768 fCTFont.reset(ctfont_create_exact_copy(ctFont, textSize, &fTransform)); |
807 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); | 769 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); |
808 fCTUnrotatedFont.reset(ctfont_create_exact_copy(ctFont, textSize, nullptr, f
alse)); | 770 fCTUnrotatedFont.reset(ctfont_create_exact_copy(ctFont, textSize, nullptr)); |
809 | 771 |
810 // The fUnitMatrix includes the text size (and em) as it is used to scale th
e raw font data. | 772 // The fUnitMatrix includes the text size (and em) as it is used to scale th
e raw font data. |
811 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo
nt))); | 773 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo
nt))); |
812 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); | 774 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); |
813 } | 775 } |
814 | 776 |
815 /** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in
10.7. */ | 777 /** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in
10.7. */ |
816 static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGP
oint points[], | 778 static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGP
oint points[], |
817 size_t count, CGContextRef cg) { | 779 size_t count, CGContextRef cg) { |
818 CGContextShowGlyphsAtPositions(cg, glyphs, points, count); | 780 CGContextShowGlyphsAtPositions(cg, glyphs, points, count); |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 scaleY = SK_Scalar1; // want hinting in the Y direction | 1361 scaleY = SK_Scalar1; // want hinting in the Y direction |
1400 break; | 1362 break; |
1401 case kY_SkAxisAlignment: | 1363 case kY_SkAxisAlignment: |
1402 scaleX = SK_Scalar1; // want hinting in the X direction | 1364 scaleX = SK_Scalar1; // want hinting in the X direction |
1403 break; | 1365 break; |
1404 default: | 1366 default: |
1405 break; | 1367 break; |
1406 } | 1368 } |
1407 | 1369 |
1408 CGAffineTransform xform = MatrixToCGAffineTransform(m, scaleX, scaleY); | 1370 CGAffineTransform xform = MatrixToCGAffineTransform(m, scaleX, scaleY); |
1409 font = ctfont_create_exact_copy(fCTFont, 1, &xform, false); | 1371 font = ctfont_create_exact_copy(fCTFont, 1, &xform); |
1410 } | 1372 } |
1411 | 1373 |
1412 CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID(); | 1374 CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID(); |
1413 AutoCFRelease<CGPathRef> cgPath(CTFontCreatePathForGlyph(font, cgGlyph, null
ptr)); | 1375 AutoCFRelease<CGPathRef> cgPath(CTFontCreatePathForGlyph(font, cgGlyph, null
ptr)); |
1414 | 1376 |
1415 path->reset(); | 1377 path->reset(); |
1416 if (cgPath != nullptr) { | 1378 if (cgPath != nullptr) { |
1417 CGPathApply(cgPath, path, SkScalerContext_Mac::CTPathElement); | 1379 CGPathApply(cgPath, path, SkScalerContext_Mac::CTPathElement); |
1418 } | 1380 } |
1419 | 1381 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 | 1558 |
1597 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( | 1559 SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( |
1598 PerGlyphInfo perGlyphInfo, | 1560 PerGlyphInfo perGlyphInfo, |
1599 const uint32_t* glyphIDs, | 1561 const uint32_t* glyphIDs, |
1600 uint32_t glyphIDsCount) const { | 1562 uint32_t glyphIDsCount) const { |
1601 | 1563 |
1602 AUTO_CG_LOCK(); | 1564 AUTO_CG_LOCK(); |
1603 | 1565 |
1604 CTFontRef originalCTFont = fFontRef.get(); | 1566 CTFontRef originalCTFont = fFontRef.get(); |
1605 AutoCFRelease<CTFontRef> ctFont(ctfont_create_exact_copy( | 1567 AutoCFRelease<CTFontRef> ctFont(ctfont_create_exact_copy( |
1606 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr, false)
); | 1568 originalCTFont, CTFontGetUnitsPerEm(originalCTFont), nullptr)); |
1607 | 1569 |
1608 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; | 1570 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; |
1609 | 1571 |
1610 { | 1572 { |
1611 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); | 1573 AutoCFRelease<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont)); |
1612 if (fontName.get()) { | 1574 if (fontName.get()) { |
1613 CFStringToSkString(fontName, &info->fFontName); | 1575 CFStringToSkString(fontName, &info->fFontName); |
1614 } | 1576 } |
1615 } | 1577 } |
1616 | 1578 |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 face->ref(); | 2478 face->ref(); |
2517 } | 2479 } |
2518 } | 2480 } |
2519 return face; | 2481 return face; |
2520 } | 2482 } |
2521 }; | 2483 }; |
2522 | 2484 |
2523 /////////////////////////////////////////////////////////////////////////////// | 2485 /////////////////////////////////////////////////////////////////////////////// |
2524 | 2486 |
2525 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2487 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
OLD | NEW |