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 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 10 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 if (sizeof(CGFloat) == sizeof(float)) { | 269 if (sizeof(CGFloat) == sizeof(float)) { |
270 return SkScalarToFloat(scalar); | 270 return SkScalarToFloat(scalar); |
271 } else { | 271 } else { |
272 SkASSERT(sizeof(CGFloat) == sizeof(double)); | 272 SkASSERT(sizeof(CGFloat) == sizeof(double)); |
273 return (CGFloat) SkScalarToDouble(scalar); | 273 return (CGFloat) SkScalarToDouble(scalar); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 static SkScalar CGToScalar(CGFloat cgFloat) { | 277 static SkScalar CGToScalar(CGFloat cgFloat) { |
278 if (sizeof(CGFloat) == sizeof(float)) { | 278 if (sizeof(CGFloat) == sizeof(float)) { |
279 return cgFloat; | 279 return SkFloatToScalar(cgFloat); |
280 } else { | 280 } else { |
281 SkASSERT(sizeof(CGFloat) == sizeof(double)); | 281 SkASSERT(sizeof(CGFloat) == sizeof(double)); |
282 return SkDoubleToScalar(cgFloat); | 282 return SkDoubleToScalar(cgFloat); |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
| 286 static float CGToFloat(CGFloat cgFloat) { |
| 287 if (sizeof(CGFloat) == sizeof(float)) { |
| 288 return cgFloat; |
| 289 } else { |
| 290 SkASSERT(sizeof(CGFloat) == sizeof(double)); |
| 291 return static_cast<float>(cgFloat); |
| 292 } |
| 293 } |
| 294 |
286 static CGAffineTransform MatrixToCGAffineTransform(const SkMatrix& matrix, | 295 static CGAffineTransform MatrixToCGAffineTransform(const SkMatrix& matrix, |
287 SkScalar sx = SK_Scalar1, | 296 SkScalar sx = SK_Scalar1, |
288 SkScalar sy = SK_Scalar1) { | 297 SkScalar sy = SK_Scalar1) { |
289 return CGAffineTransformMake( ScalarToCG(matrix[SkMatrix::kMScaleX] * sx), | 298 return CGAffineTransformMake( ScalarToCG(matrix[SkMatrix::kMScaleX] * sx), |
290 -ScalarToCG(matrix[SkMatrix::kMSkewY] * sy), | 299 -ScalarToCG(matrix[SkMatrix::kMSkewY] * sy), |
291 -ScalarToCG(matrix[SkMatrix::kMSkewX] * sx), | 300 -ScalarToCG(matrix[SkMatrix::kMSkewX] * sx), |
292 ScalarToCG(matrix[SkMatrix::kMScaleY] * sy), | 301 ScalarToCG(matrix[SkMatrix::kMScaleY] * sy), |
293 ScalarToCG(matrix[SkMatrix::kMTransX] * sx), | 302 ScalarToCG(matrix[SkMatrix::kMTransX] * sx), |
294 ScalarToCG(matrix[SkMatrix::kMTransY] * sy)); | 303 ScalarToCG(matrix[SkMatrix::kMTransY] * sy)); |
295 } | 304 } |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 CTFontGetAdvancesForGlyphs(fCTFont, kCTFontVerticalOrientation, | 1044 CTFontGetAdvancesForGlyphs(fCTFont, kCTFontVerticalOrientation, |
1036 &cgGlyph, &cgAdvance, 1); | 1045 &cgGlyph, &cgAdvance, 1); |
1037 // Vertical advances are returned as widths instead of heights. | 1046 // Vertical advances are returned as widths instead of heights. |
1038 SkTSwap(cgAdvance.height, cgAdvance.width); | 1047 SkTSwap(cgAdvance.height, cgAdvance.width); |
1039 cgAdvance.height = -cgAdvance.height; | 1048 cgAdvance.height = -cgAdvance.height; |
1040 } else { | 1049 } else { |
1041 CTFontGetAdvancesForGlyphs(fCTFont, kCTFontHorizontalOrientation, | 1050 CTFontGetAdvancesForGlyphs(fCTFont, kCTFontHorizontalOrientation, |
1042 &cgGlyph, &cgAdvance, 1); | 1051 &cgGlyph, &cgAdvance, 1); |
1043 } | 1052 } |
1044 cgAdvance = CGSizeApplyAffineTransform(cgAdvance, fTransform); | 1053 cgAdvance = CGSizeApplyAffineTransform(cgAdvance, fTransform); |
1045 glyph->fAdvanceX = SkFloatToFixed_Check(cgAdvance.width); | 1054 glyph->fAdvanceX = CGToFloat(cgAdvance.width); |
1046 glyph->fAdvanceY = -SkFloatToFixed_Check(cgAdvance.height); | 1055 glyph->fAdvanceY = -CGToFloat(cgAdvance.height); |
1047 | 1056 |
1048 // The following produces skBounds in SkGlyph units (pixels, y down), | 1057 // The following produces skBounds in SkGlyph units (pixels, y down), |
1049 // or returns early if skBounds would be empty. | 1058 // or returns early if skBounds would be empty. |
1050 SkRect skBounds; | 1059 SkRect skBounds; |
1051 | 1060 |
1052 // On Mountain Lion, CTFontGetBoundingRectsForGlyphs with kCTFontVerticalOri
entation and | 1061 // On Mountain Lion, CTFontGetBoundingRectsForGlyphs with kCTFontVerticalOri
entation and |
1053 // CTFontGetVerticalTranslationsForGlyphs do not agree when using OTF CFF fo
nts. | 1062 // CTFontGetVerticalTranslationsForGlyphs do not agree when using OTF CFF fo
nts. |
1054 // For TTF fonts these two do agree and we can use CTFontGetBoundingRectsFor
Glyphs to get | 1063 // For TTF fonts these two do agree and we can use CTFontGetBoundingRectsFor
Glyphs to get |
1055 // the bounding box and CTFontGetVerticalTranslationsForGlyphs to then draw
the glyph | 1064 // the bounding box and CTFontGetVerticalTranslationsForGlyphs to then draw
the glyph |
1056 // inside that bounding box. However, with OTF CFF fonts this does not work.
It appears that | 1065 // inside that bounding box. However, with OTF CFF fonts this does not work.
It appears that |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2624 } | 2633 } |
2625 return face; | 2634 return face; |
2626 } | 2635 } |
2627 }; | 2636 }; |
2628 | 2637 |
2629 /////////////////////////////////////////////////////////////////////////////// | 2638 /////////////////////////////////////////////////////////////////////////////// |
2630 | 2639 |
2631 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } | 2640 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } |
2632 | 2641 |
2633 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 2642 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |