| OLD | NEW |
| 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 "SkFont.h" | 8 #include "SkFont.h" |
| 9 #include "SkTypeface.h" | 9 #include "SkTypeface.h" |
| 10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 { | 24 { |
| 25 SkASSERT(size > 0); | 25 SkASSERT(size > 0); |
| 26 SkASSERT(scaleX > 0); | 26 SkASSERT(scaleX > 0); |
| 27 SkASSERT(SkScalarIsFinite(skewX)); | 27 SkASSERT(SkScalarIsFinite(skewX)); |
| 28 SkASSERT(0 == (flags & ~kAllFlags)); | 28 SkASSERT(0 == (flags & ~kAllFlags)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScala
r skewX, | 31 SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScala
r skewX, |
| 32 MaskType mt, uint32_t flags) { | 32 MaskType mt, uint32_t flags) { |
| 33 if (size <= 0 || !SkScalarIsFinite(size)) { | 33 if (size <= 0 || !SkScalarIsFinite(size)) { |
| 34 return NULL; | 34 return nullptr; |
| 35 } | 35 } |
| 36 if (scaleX <= 0 || !SkScalarIsFinite(scaleX)) { | 36 if (scaleX <= 0 || !SkScalarIsFinite(scaleX)) { |
| 37 return NULL; | 37 return nullptr; |
| 38 } | 38 } |
| 39 if (!SkScalarIsFinite(skewX)) { | 39 if (!SkScalarIsFinite(skewX)) { |
| 40 return NULL; | 40 return nullptr; |
| 41 } | 41 } |
| 42 flags &= kAllFlags; | 42 flags &= kAllFlags; |
| 43 return new SkFont(face, size, scaleX, skewX, mt, flags); | 43 return new SkFont(face, size, scaleX, skewX, mt, flags); |
| 44 } | 44 } |
| 45 | 45 |
| 46 SkFont* SkFont::Create(SkTypeface* face, SkScalar size, MaskType mt, uint32_t fl
ags) { | 46 SkFont* SkFont::Create(SkTypeface* face, SkScalar size, MaskType mt, uint32_t fl
ags) { |
| 47 return SkFont::Create(face, size, 1, 0, mt, flags); | 47 return SkFont::Create(face, size, 1, 0, mt, flags); |
| 48 } | 48 } |
| 49 | 49 |
| 50 SkFont* SkFont::cloneWithSize(SkScalar newSize) const { | 50 SkFont* SkFont::cloneWithSize(SkScalar newSize) const { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 75 case kUTF16_SkTextEncoding: | 75 case kUTF16_SkTextEncoding: |
| 76 count = SkUTF16_CountUnichars((const uint16_t*)text, SkToInt(byteLen
gth >> 1)); | 76 count = SkUTF16_CountUnichars((const uint16_t*)text, SkToInt(byteLen
gth >> 1)); |
| 77 break; | 77 break; |
| 78 case kUTF32_SkTextEncoding: | 78 case kUTF32_SkTextEncoding: |
| 79 count = SkToInt(byteLength >> 2); | 79 count = SkToInt(byteLength >> 2); |
| 80 break; | 80 break; |
| 81 case kGlyphID_SkTextEncoding: | 81 case kGlyphID_SkTextEncoding: |
| 82 count = SkToInt(byteLength >> 1); | 82 count = SkToInt(byteLength >> 1); |
| 83 break; | 83 break; |
| 84 } | 84 } |
| 85 if (NULL == glyphs) { | 85 if (nullptr == glyphs) { |
| 86 return count; | 86 return count; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // TODO: unify/eliminate SkTypeface::Encoding with SkTextEncoding | 89 // TODO: unify/eliminate SkTypeface::Encoding with SkTextEncoding |
| 90 SkTypeface::Encoding typeface_encoding; | 90 SkTypeface::Encoding typeface_encoding; |
| 91 switch (encoding) { | 91 switch (encoding) { |
| 92 case kUTF8_SkTextEncoding: | 92 case kUTF8_SkTextEncoding: |
| 93 typeface_encoding = SkTypeface::kUTF8_Encoding; | 93 typeface_encoding = SkTypeface::kUTF8_Encoding; |
| 94 break; | 94 break; |
| 95 case kUTF16_SkTextEncoding: | 95 case kUTF16_SkTextEncoding: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 MaskType maskType = SkFont::kBW_MaskType; | 148 MaskType maskType = SkFont::kBW_MaskType; |
| 149 if (paint.isAntiAlias()) { | 149 if (paint.isAntiAlias()) { |
| 150 maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType; | 150 maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType; |
| 151 } | 151 } |
| 152 | 152 |
| 153 return Create(paint.getTypeface(), | 153 return Create(paint.getTypeface(), |
| 154 paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX
(), | 154 paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX
(), |
| 155 maskType, flags); | 155 maskType, flags); |
| 156 } | 156 } |
| OLD | NEW |