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 #ifdef SK_BUILD_FOR_MAC | 9 #ifdef SK_BUILD_FOR_MAC |
10 #import <ApplicationServices/ApplicationServices.h> | 10 #import <ApplicationServices/ApplicationServices.h> |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 , fGeneratedFBoundingBoxes(false) | 710 , fGeneratedFBoundingBoxes(false) |
711 , fDoSubPosition(SkToBool(fRec.fFlags & kSubpixelPositioning_Flag)) | 711 , fDoSubPosition(SkToBool(fRec.fFlags & kSubpixelPositioning_Flag)) |
712 , fVertical(SkToBool(fRec.fFlags & kVertical_Flag)) | 712 , fVertical(SkToBool(fRec.fFlags & kVertical_Flag)) |
713 | 713 |
714 { | 714 { |
715 CTFontRef ctFont = typeface->fFontRef.get(); | 715 CTFontRef ctFont = typeface->fFontRef.get(); |
716 CFIndex numGlyphs = CTFontGetGlyphCount(ctFont); | 716 CFIndex numGlyphs = CTFontGetGlyphCount(ctFont); |
717 SkASSERT(numGlyphs >= 1 && numGlyphs <= 0xFFFF); | 717 SkASSERT(numGlyphs >= 1 && numGlyphs <= 0xFFFF); |
718 fGlyphCount = SkToU16(numGlyphs); | 718 fGlyphCount = SkToU16(numGlyphs); |
719 | 719 |
720 fRec.getSingleMatrix(&fFUnitMatrix); | 720 SkMatrix skTransform; |
721 CGAffineTransform transform = MatrixToCGAffineTransform(fFUnitMatrix); | 721 fRec.getSingleMatrixWithoutTextSize(&skTransform); |
| 722 CGAffineTransform transform = MatrixToCGAffineTransform(skTransform); |
722 | 723 |
723 AutoCFRelease<CTFontDescriptorRef> ctFontDesc; | 724 AutoCFRelease<CTFontDescriptorRef> ctFontDesc; |
724 if (fVertical) { | 725 if (fVertical) { |
725 AutoCFRelease<CFMutableDictionaryRef> cfAttributes(CFDictionaryCreateMut
able( | 726 AutoCFRelease<CFMutableDictionaryRef> cfAttributes(CFDictionaryCreateMut
able( |
726 kCFAllocatorDefault, 0, | 727 kCFAllocatorDefault, 0, |
727 &kCFTypeDictionaryKeyCallBacks, | 728 &kCFTypeDictionaryKeyCallBacks, |
728 &kCFTypeDictionaryValueCallBacks)); | 729 &kCFTypeDictionaryValueCallBacks)); |
729 if (cfAttributes) { | 730 if (cfAttributes) { |
730 CTFontOrientation ctOrientation = kCTFontVerticalOrientation; | 731 CTFontOrientation ctOrientation = kCTFontVerticalOrientation; |
731 AutoCFRelease<CFNumberRef> cfVertical(CFNumberCreate( | 732 AutoCFRelease<CFNumberRef> cfVertical(CFNumberCreate( |
732 kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientation)); | 733 kCFAllocatorDefault, kCFNumberSInt32Type, &ctOrientation)); |
733 CFDictionaryAddValue(cfAttributes, kCTFontOrientationAttribute, cfVe
rtical); | 734 CFDictionaryAddValue(cfAttributes, kCTFontOrientationAttribute, cfVe
rtical); |
734 ctFontDesc.reset(CTFontDescriptorCreateWithAttributes(cfAttributes))
; | 735 ctFontDesc.reset(CTFontDescriptorCreateWithAttributes(cfAttributes))
; |
735 } | 736 } |
736 } | 737 } |
737 // Since our matrix includes everything, we pass 1 for size. | 738 |
738 fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, 1, &transform, ctFontDe
sc)); | 739 // The transform contains everything except the requested text size. |
| 740 // Some properties, like 'trak', are based on the text size (before applying
the matrix). |
| 741 CGFloat textSize = ScalarToCG(fRec.fTextSize); |
| 742 |
| 743 // If a text size of 0 is requested, CoreGraphics will use 12 instead. |
| 744 // If the text size is 0, set it to something tiny. |
| 745 if (textSize < CGFLOAT_MIN) { |
| 746 textSize = CGFLOAT_MIN; |
| 747 } |
| 748 |
| 749 fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &transform, c
tFontDesc)); |
739 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, NULL)); | 750 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, NULL)); |
740 if (fVertical) { | 751 if (fVertical) { |
741 CGAffineTransform rotateLeft = CGAffineTransformMake(0, -1, 1, 0, 0, 0); | 752 CGAffineTransform rotateLeft = CGAffineTransformMake(0, -1, 1, 0, 0, 0); |
742 transform = CGAffineTransformConcat(rotateLeft, transform); | 753 transform = CGAffineTransformConcat(rotateLeft, transform); |
743 fCTVerticalFont.reset(CTFontCreateCopyWithAttributes(ctFont, 1, &transfo
rm, NULL)); | 754 fCTVerticalFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &
transform, NULL)); |
744 } | 755 } |
745 | 756 |
| 757 // The fUnitMatrix includes the text size (and em) as it is used to scale th
e raw font data. |
| 758 fRec.getSingleMatrix(&fFUnitMatrix); |
746 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo
nt))); | 759 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo
nt))); |
747 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); | 760 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); |
748 } | 761 } |
749 | 762 |
750 CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
glyph, | 763 CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
glyph, |
751 CGGlyph glyphID, size_t* rowBytesPtr, | 764 CGGlyph glyphID, size_t* rowBytesPtr, |
752 bool generateA8FromLCD) { | 765 bool generateA8FromLCD) { |
753 if (!fRGBSpace) { | 766 if (!fRGBSpace) { |
754 //It doesn't appear to matter what color space is specified. | 767 //It doesn't appear to matter what color space is specified. |
755 //Regular blends and antialiased text are always (s*a + d*(1-a)) | 768 //Regular blends and antialiased text are always (s*a + d*(1-a)) |
(...skipping 30 matching lines...) Expand all Loading... |
786 fCG.reset(CGBitmapContextCreate(image, fSize.fWidth, fSize.fHeight, 8, | 799 fCG.reset(CGBitmapContextCreate(image, fSize.fWidth, fSize.fHeight, 8, |
787 rowBytes, fRGBSpace, BITMAP_INFO_RGB)); | 800 rowBytes, fRGBSpace, BITMAP_INFO_RGB)); |
788 | 801 |
789 // skia handles quantization itself, so we disable this for cg to get | 802 // skia handles quantization itself, so we disable this for cg to get |
790 // full fractional data from them. | 803 // full fractional data from them. |
791 CGContextSetAllowsFontSubpixelQuantization(fCG, false); | 804 CGContextSetAllowsFontSubpixelQuantization(fCG, false); |
792 CGContextSetShouldSubpixelQuantizeFonts(fCG, false); | 805 CGContextSetShouldSubpixelQuantizeFonts(fCG, false); |
793 | 806 |
794 CGContextSetTextDrawingMode(fCG, kCGTextFill); | 807 CGContextSetTextDrawingMode(fCG, kCGTextFill); |
795 CGContextSetFont(fCG, context.fCGFont); | 808 CGContextSetFont(fCG, context.fCGFont); |
796 CGContextSetFontSize(fCG, 1 /*CTFontGetSize(context.fCTFont)*/); | 809 CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont)); |
797 CGContextSetTextMatrix(fCG, CTFontGetMatrix(context.fCTFont)); | 810 CGContextSetTextMatrix(fCG, CTFontGetMatrix(context.fCTFont)); |
798 | 811 |
799 // Because CG always draws from the horizontal baseline, | 812 // Because CG always draws from the horizontal baseline, |
800 // if there is a non-integral translation from the horizontal origin to
the vertical origin, | 813 // if there is a non-integral translation from the horizontal origin to
the vertical origin, |
801 // then CG cannot draw the glyph in the correct location without subpixe
l positioning. | 814 // then CG cannot draw the glyph in the correct location without subpixe
l positioning. |
802 CGContextSetAllowsFontSubpixelPositioning(fCG, context.fDoSubPosition ||
context.fVertical); | 815 CGContextSetAllowsFontSubpixelPositioning(fCG, context.fDoSubPosition ||
context.fVertical); |
803 CGContextSetShouldSubpixelPositionFonts(fCG, context.fDoSubPosition || c
ontext.fVertical); | 816 CGContextSetShouldSubpixelPositionFonts(fCG, context.fDoSubPosition || c
ontext.fVertical); |
804 | 817 |
805 // Draw white on black to create mask. | 818 // Draw white on black to create mask. |
806 // TODO: Draw black on white and invert, CG has a special case codepath. | 819 // TODO: Draw black on white and invert, CG has a special case codepath. |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2214 } | 2227 } |
2215 return face; | 2228 return face; |
2216 } | 2229 } |
2217 }; | 2230 }; |
2218 | 2231 |
2219 /////////////////////////////////////////////////////////////////////////////// | 2232 /////////////////////////////////////////////////////////////////////////////// |
2220 | 2233 |
2221 SkFontMgr* SkFontMgr::Factory() { | 2234 SkFontMgr* SkFontMgr::Factory() { |
2222 return SkNEW(SkFontMgr_Mac); | 2235 return SkNEW(SkFontMgr_Mac); |
2223 } | 2236 } |
OLD | NEW |