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

Side by Side Diff: src/core/SkFont.cpp

Issue 2163633002: Make SkFont a bit more useable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bug Created 4 years, 5 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/core/SkDraw.cpp ('k') | src/core/SkPaint.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 "SkFont.h" 8 #include "SkFont.h"
9 #include "SkTypeface.h" 9 #include "SkTypeface.h"
10 #include "SkUtils.h" 10 #include "SkUtils.h"
(...skipping 30 matching lines...) Expand all
41 41
42 sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, MaskType mt, u int32_t flags) { 42 sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, MaskType mt, u int32_t flags) {
43 return SkFont::Make(std::move(face), size, 1, 0, mt, flags); 43 return SkFont::Make(std::move(face), size, 1, 0, mt, flags);
44 } 44 }
45 45
46 sk_sp<SkFont> SkFont::makeWithSize(SkScalar newSize) const { 46 sk_sp<SkFont> SkFont::makeWithSize(SkScalar newSize) const {
47 return SkFont::Make(sk_ref_sp(this->getTypeface()), newSize, this->getScaleX (), 47 return SkFont::Make(sk_ref_sp(this->getTypeface()), newSize, this->getScaleX (),
48 this->getSkewX(), this->getMaskType(), this->getFlags()) ; 48 this->getSkewX(), this->getMaskType(), this->getFlags()) ;
49 } 49 }
50 50
51 sk_sp<SkFont> SkFont::makeWithFlags(uint32_t newFlags) const {
52 return SkFont::Make(sk_ref_sp(this->getTypeface()), this->getSize(), this->g etScaleX(),
53 this->getSkewX(), this->getMaskType(), newFlags);
54 }
51 //////////////////////////////////////////////////////////////////////////////// /////////////////// 55 //////////////////////////////////////////////////////////////////////////////// ///////////////////
52 56
53 int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding enc oding, 57 int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding enc oding,
54 uint16_t glyphs[], int maxGlyphCount) const { 58 uint16_t glyphs[], int maxGlyphCount) const {
55 if (0 == byteLength) { 59 if (0 == byteLength) {
56 return 0; 60 return 0;
57 } 61 }
58 62
59 SkASSERT(text); 63 SkASSERT(text);
60 64
61 int count = 0; // fix uninitialized warning (even though the switch is comp lete!) 65 int count = 0; // fix uninitialized warning (even though the switch is comp lete!)
62 66
63 switch (encoding) { 67 switch (encoding) {
64 case kUTF8_SkTextEncoding: 68 case kUTF8_SkTextEncoding:
65 count = SkUTF8_CountUnichars((const char*)text, byteLength); 69 count = SkUTF8_CountUnichars((const char*)text, byteLength);
66 break; 70 break;
67 case kUTF16_SkTextEncoding: 71 case kUTF16_SkTextEncoding:
68 count = SkUTF16_CountUnichars((const uint16_t*)text, SkToInt(byteLen gth >> 1)); 72 count = SkUTF16_CountUnichars((const uint16_t*)text, SkToInt(byteLen gth >> 1));
69 break; 73 break;
70 case kUTF32_SkTextEncoding: 74 case kUTF32_SkTextEncoding:
71 count = SkToInt(byteLength >> 2); 75 count = SkToInt(byteLength >> 2);
72 break; 76 break;
73 case kGlyphID_SkTextEncoding: 77 case kGlyphID_SkTextEncoding:
74 count = SkToInt(byteLength >> 1); 78 count = SkToInt(byteLength >> 1);
75 break; 79 break;
76 } 80 }
77 if (nullptr == glyphs) { 81 if (!glyphs) {
78 return count; 82 return count;
79 } 83 }
80 84
81 // TODO: unify/eliminate SkTypeface::Encoding with SkTextEncoding 85 // TODO: unify/eliminate SkTypeface::Encoding with SkTextEncoding
82 SkTypeface::Encoding typeface_encoding; 86 SkTypeface::Encoding typefaceEncoding;
83 switch (encoding) { 87 switch (encoding) {
84 case kUTF8_SkTextEncoding: 88 case kUTF8_SkTextEncoding:
85 typeface_encoding = SkTypeface::kUTF8_Encoding; 89 typefaceEncoding = SkTypeface::kUTF8_Encoding;
86 break; 90 break;
87 case kUTF16_SkTextEncoding: 91 case kUTF16_SkTextEncoding:
88 typeface_encoding = SkTypeface::kUTF16_Encoding; 92 typefaceEncoding = SkTypeface::kUTF16_Encoding;
89 break; 93 break;
90 case kUTF32_SkTextEncoding: 94 case kUTF32_SkTextEncoding:
91 typeface_encoding = SkTypeface::kUTF32_Encoding; 95 typefaceEncoding = SkTypeface::kUTF32_Encoding;
92 break; 96 break;
93 default: 97 default:
94 SkASSERT(kGlyphID_SkTextEncoding == encoding); 98 SkASSERT(kGlyphID_SkTextEncoding == encoding);
95 // we can early exit, since we already have glyphIDs 99 // we can early exit, since we already have glyphIDs
96 memcpy(glyphs, text, count << 1); 100 memcpy(glyphs, text, count << 1);
97 return count; 101 return count;
98 } 102 }
99 103
100 (void)fTypeface->charsToGlyphs(text, typeface_encoding, glyphs, count); 104 (void)fTypeface->charsToGlyphs(text, typefaceEncoding, glyphs, count);
101 return count; 105 return count;
102 } 106 }
103 107
104 SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding encoding) const { 108 SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding encoding) const {
105 // TODO: need access to the cache 109 // TODO: need access to the cache
106 return -1; 110 return -1;
107 } 111 }
108 112
109 //////////////////////////////////////////////////////////////////////////////// /////////////////// 113 //////////////////////////////////////////////////////////////////////////////// ///////////////////
110 114
(...skipping 27 matching lines...) Expand all
138 } 142 }
139 143
140 MaskType maskType = SkFont::kBW_MaskType; 144 MaskType maskType = SkFont::kBW_MaskType;
141 if (paint.isAntiAlias()) { 145 if (paint.isAntiAlias()) {
142 maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType; 146 maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType;
143 } 147 }
144 148
145 return Make(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTe xtScaleX(), 149 return Make(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTe xtScaleX(),
146 paint.getTextSkewX(), maskType, flags); 150 paint.getTextSkewX(), maskType, flags);
147 } 151 }
OLDNEW
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698