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

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

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. Created 4 years, 7 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/animator/SkPaintPart.h ('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"
11 11
12 static SkTypeface* ref_or_default(SkTypeface* face) { 12 SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt,
13 return face ? SkRef(face) : SkTypeface::RefDefault();
14 }
15
16 SkFont::SkFont(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt,
17 uint32_t flags) 13 uint32_t flags)
18 : fTypeface(ref_or_default(face)) 14 : fTypeface(face ? std::move(face) : SkTypeface::MakeDefault())
19 , fSize(size) 15 , fSize(size)
20 , fScaleX(scaleX) 16 , fScaleX(scaleX)
21 , fSkewX(skewX) 17 , fSkewX(skewX)
22 , fFlags(flags) 18 , fFlags(flags)
23 , fMaskType(SkToU8(mt)) 19 , fMaskType(SkToU8(mt))
24 { 20 {
25 SkASSERT(size > 0); 21 SkASSERT(size > 0);
26 SkASSERT(scaleX > 0); 22 SkASSERT(scaleX > 0);
27 SkASSERT(SkScalarIsFinite(skewX)); 23 SkASSERT(SkScalarIsFinite(skewX));
28 SkASSERT(0 == (flags & ~kAllFlags)); 24 SkASSERT(0 == (flags & ~kAllFlags));
29 } 25 }
30 26
31 SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScala r skewX, 27 sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, SkScalar scale X, SkScalar skewX,
32 MaskType mt, uint32_t flags) { 28 MaskType mt, uint32_t flags) {
33 if (size <= 0 || !SkScalarIsFinite(size)) { 29 if (size <= 0 || !SkScalarIsFinite(size)) {
34 return nullptr; 30 return nullptr;
35 } 31 }
36 if (scaleX <= 0 || !SkScalarIsFinite(scaleX)) { 32 if (scaleX <= 0 || !SkScalarIsFinite(scaleX)) {
37 return nullptr; 33 return nullptr;
38 } 34 }
39 if (!SkScalarIsFinite(skewX)) { 35 if (!SkScalarIsFinite(skewX)) {
40 return nullptr; 36 return nullptr;
41 } 37 }
42 flags &= kAllFlags; 38 flags &= kAllFlags;
43 return new SkFont(face, size, scaleX, skewX, mt, flags); 39 return sk_sp<SkFont>(new SkFont(std::move(face), size, scaleX, skewX, mt, fl ags));
44 } 40 }
45 41
46 SkFont* SkFont::Create(SkTypeface* face, SkScalar size, MaskType mt, uint32_t fl ags) { 42 sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, MaskType mt, u int32_t flags) {
47 return SkFont::Create(face, size, 1, 0, mt, flags); 43 return SkFont::Make(std::move(face), size, 1, 0, mt, flags);
48 } 44 }
49 45
50 SkFont* SkFont::cloneWithSize(SkScalar newSize) const { 46 sk_sp<SkFont> SkFont::makeWithSize(SkScalar newSize) const {
51 return SkFont::Create(this->getTypeface(), newSize, this->getScaleX(), this- >getSkewX(), 47 return SkFont::Make(sk_ref_sp(this->getTypeface()), newSize, this->getScaleX (),
52 this->getMaskType(), this->getFlags()); 48 this->getSkewX(), this->getMaskType(), this->getFlags()) ;
53 } 49 }
54 50
55 //////////////////////////////////////////////////////////////////////////////// /////////////////// 51 //////////////////////////////////////////////////////////////////////////////// ///////////////////
56 52
57 SkFont::~SkFont() {
58 SkSafeUnref(fTypeface);
59 }
60
61 int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding enc oding, 53 int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding enc oding,
62 uint16_t glyphs[], int maxGlyphCount) const { 54 uint16_t glyphs[], int maxGlyphCount) const {
63 if (0 == byteLength) { 55 if (0 == byteLength) {
64 return 0; 56 return 0;
65 } 57 }
66 58
67 SkASSERT(text); 59 SkASSERT(text);
68 60
69 int count = 0; // fix uninitialized warning (even though the switch is comp lete!) 61 int count = 0; // fix uninitialized warning (even though the switch is comp lete!)
70 62
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 103
112 SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding encoding) const { 104 SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding encoding) const {
113 // TODO: need access to the cache 105 // TODO: need access to the cache
114 return -1; 106 return -1;
115 } 107 }
116 108
117 //////////////////////////////////////////////////////////////////////////////// /////////////////// 109 //////////////////////////////////////////////////////////////////////////////// ///////////////////
118 110
119 #include "SkPaint.h" 111 #include "SkPaint.h"
120 112
121 SkFont* SkFont::Testing_CreateFromPaint(const SkPaint& paint) { 113 sk_sp<SkFont> SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
122 uint32_t flags = 0; 114 uint32_t flags = 0;
123 if (paint.isVerticalText()) { 115 if (paint.isVerticalText()) {
124 flags |= kVertical_Flag; 116 flags |= kVertical_Flag;
125 } 117 }
126 if (paint.isEmbeddedBitmapText()) { 118 if (paint.isEmbeddedBitmapText()) {
127 flags |= kEmbeddedBitmaps_Flag; 119 flags |= kEmbeddedBitmaps_Flag;
128 } 120 }
129 if (paint.getFlags() & SkPaint::kGenA8FromLCD_Flag) { 121 if (paint.getFlags() & SkPaint::kGenA8FromLCD_Flag) {
130 flags |= kGenA8FromLCD_Flag; 122 flags |= kGenA8FromLCD_Flag;
131 } 123 }
(...skipping 11 matching lines...) Expand all
143 // this is our default 135 // this is our default
144 } else { 136 } else {
145 flags |= kUseNonlinearMetrics_Flag; 137 flags |= kUseNonlinearMetrics_Flag;
146 } 138 }
147 139
148 MaskType maskType = SkFont::kBW_MaskType; 140 MaskType maskType = SkFont::kBW_MaskType;
149 if (paint.isAntiAlias()) { 141 if (paint.isAntiAlias()) {
150 maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType; 142 maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType;
151 } 143 }
152 144
153 return Create(paint.getTypeface(), 145 return Make(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTe xtScaleX(),
154 paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX (), 146 paint.getTextSkewX(), maskType, flags);
155 maskType, flags);
156 } 147 }
OLDNEW
« no previous file with comments | « src/animator/SkPaintPart.h ('k') | src/core/SkPaint.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698