fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 8 | /* Generated by tools/bookmaker from include/core/SkTextBlob.h and docs/SkTextBlob_Reference.bmh |
| 9 | on 2018-08-10 12:59:44. Additional documentation and examples can be found at: |
| 10 | https://skia.org/user/api/SkTextBlob_Reference |
| 11 | |
| 12 | You may edit either file directly. Structural changes to public interfaces require |
| 13 | editing both files. After editing docs/SkTextBlob_Reference.bmh, run: |
| 14 | bookmaker -b docs -i include/core/SkTextBlob.h -p |
| 15 | to create an updated version of this file. |
| 16 | */ |
| 17 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 18 | #ifndef SkTextBlob_DEFINED |
| 19 | #define SkTextBlob_DEFINED |
| 20 | |
bungeman | bf521ff | 2016-02-17 13:13:44 -0800 | [diff] [blame] | 21 | #include "../private/SkTemplates.h" |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 22 | #include "SkFont.h" |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 23 | #include "SkPaint.h" |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 24 | #include "SkString.h" |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 25 | #include "SkRefCnt.h" |
Hal Canary | c2d0fb1 | 2018-09-19 10:28:59 -0400 | [diff] [blame] | 26 | |
Mike Klein | 015c899 | 2018-08-09 12:23:19 -0400 | [diff] [blame] | 27 | #include <atomic> |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 28 | |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame^] | 29 | struct SkRSXform; |
Mike Reed | 8e74cbc | 2017-12-08 13:20:01 -0500 | [diff] [blame] | 30 | struct SkSerialProcs; |
| 31 | struct SkDeserialProcs; |
| 32 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 33 | /** \class SkTextBlob |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 34 | SkTextBlob combines multiple text runs into an immutable container. Each text |
| 35 | run consists of glyphs, SkPaint, and position. Only parts of SkPaint related to |
| 36 | fonts and text rendering are used by run. |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 37 | */ |
Mike Klein | 408ef21 | 2018-10-30 15:23:00 +0000 | [diff] [blame] | 38 | class SK_API SkTextBlob final : public SkNVRefCnt<SkTextBlob> { |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 39 | public: |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 40 | |
| 41 | /** Returns conservative bounding box. Uses SkPaint associated with each glyph to |
| 42 | determine glyph bounds, and unions all bounds. Returned bounds may be |
| 43 | larger than the bounds of all glyphs in runs. |
| 44 | |
| 45 | @return conservative bounding box |
| 46 | */ |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 47 | const SkRect& bounds() const { return fBounds; } |
| 48 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 49 | /** Returns a non-zero value unique among all text blobs. |
| 50 | |
| 51 | @return identifier for SkTextBlob |
| 52 | */ |
joshualitt | 2af8583 | 2015-03-25 13:40:13 -0700 | [diff] [blame] | 53 | uint32_t uniqueID() const { return fUniqueID; } |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 54 | |
Mike Reed | ae0d860 | 2018-12-10 22:02:17 -0500 | [diff] [blame] | 55 | /** Returns the number of intervals that intersect bounds. |
| 56 | bounds describes a pair of lines parallel to the text advance. |
| 57 | The return count is zero or a multiple of two, and is at most twice the number of glyphs in |
| 58 | the the blob. |
| 59 | |
| 60 | Pass nullptr for intervals to determine the size of the interval array. |
| 61 | |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame^] | 62 | Runs within the blob that contain SkRSXforms are ignored when computing intercepts. |
| 63 | |
Mike Reed | ae0d860 | 2018-12-10 22:02:17 -0500 | [diff] [blame] | 64 | @param bounds lower and upper line parallel to the advance |
| 65 | @param intervals returned intersections; may be nullptr |
Cary Clark | 4f73883 | 2018-12-11 08:41:11 -0500 | [diff] [blame] | 66 | @param paint specifies stroking, SkPathEffect that affects the result; may be nullptr |
Mike Reed | ae0d860 | 2018-12-10 22:02:17 -0500 | [diff] [blame] | 67 | @return number of intersections; may be zero |
| 68 | */ |
| 69 | int getIntercepts(const SkScalar bounds[2], SkScalar intervals[], |
| 70 | const SkPaint* paint = nullptr) const; |
| 71 | |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 72 | /** Creates SkTextBlob with a single run. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 73 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 74 | font contains attributes used to define the run text. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 75 | |
| 76 | @param text character code points or glyphs drawn |
| 77 | @param byteLength byte length of text array |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 78 | @param font text size, typeface, text scale, and so on, used to draw |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 79 | @return SkTextBlob constructed from one run |
| 80 | */ |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 81 | static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font, |
Mike Reed | 97f3cc2 | 2018-12-03 09:45:17 -0500 | [diff] [blame] | 82 | SkTextEncoding encoding = kUTF8_SkTextEncoding); |
Herb Derby | 4b3a515 | 2018-07-17 16:10:30 -0400 | [diff] [blame] | 83 | |
Mike Reed | 97f3cc2 | 2018-12-03 09:45:17 -0500 | [diff] [blame] | 84 | /** Creates SkTextBlob with a single run. string meaning depends on SkTextEncoding; |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 85 | by default, string is encoded as UTF-8. |
| 86 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 87 | font contains attributes used to define the run text. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 88 | |
| 89 | @param string character code points or glyphs drawn |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 90 | @param font text size, typeface, text scale, and so on, used to draw |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 91 | @return SkTextBlob constructed from one run |
| 92 | */ |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 93 | static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font, |
Mike Reed | 97f3cc2 | 2018-12-03 09:45:17 -0500 | [diff] [blame] | 94 | SkTextEncoding encoding = kUTF8_SkTextEncoding) { |
Cary Clark | e12a090 | 2018-08-09 10:07:33 -0400 | [diff] [blame] | 95 | if (!string) { |
| 96 | return nullptr; |
| 97 | } |
Mike Reed | 3185f90 | 2018-10-26 16:33:00 -0400 | [diff] [blame] | 98 | return MakeFromText(string, strlen(string), font, encoding); |
Cary Clark | e12a090 | 2018-08-09 10:07:33 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Mike Reed | efb518d | 2018-12-06 13:30:23 -0500 | [diff] [blame] | 101 | /** Experimental. |
| 102 | Returns a textblob built from a single run of text with x-positions and a single y value. |
| 103 | This is equivalent to using SkTextBlobBuilder and calling allocRunPosH(). |
| 104 | Returns nullptr if byteLength is zero. |
| 105 | |
| 106 | @param text character code points or glyphs drawn (based on encoding) |
| 107 | @param byteLength byte length of text array |
| 108 | @param xpos array of x-positions, must contain values for all of the character points. |
| 109 | @param constY shared y-position for each character point, to be paired with each xpos. |
| 110 | @param font SkFont used for this run |
| 111 | @param encoding specifies the encoding of the text array. |
| 112 | @return new textblob or nullptr |
| 113 | */ |
| 114 | static sk_sp<SkTextBlob> MakeFromPosTextH(const void* text, size_t byteLength, |
| 115 | const SkScalar xpos[], SkScalar constY, const SkFont& font, |
| 116 | SkTextEncoding encoding = kUTF8_SkTextEncoding); |
| 117 | |
| 118 | /** Experimental. |
| 119 | Returns a textblob built from a single run of text with positions. |
| 120 | This is equivalent to using SkTextBlobBuilder and calling allocRunPos(). |
| 121 | Returns nullptr if byteLength is zero. |
| 122 | |
| 123 | @param text character code points or glyphs drawn (based on encoding) |
| 124 | @param byteLength byte length of text array |
| 125 | @param pos array of positions, must contain values for all of the character points. |
| 126 | @param font SkFont used for this run |
| 127 | @param encoding specifies the encoding of the text array. |
| 128 | @return new textblob or nullptr |
| 129 | */ |
| 130 | static sk_sp<SkTextBlob> MakeFromPosText(const void* text, size_t byteLength, |
| 131 | const SkPoint pos[], const SkFont& font, |
| 132 | SkTextEncoding encoding = kUTF8_SkTextEncoding); |
| 133 | |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame^] | 134 | // Experimental |
| 135 | static sk_sp<SkTextBlob> MakeFromRSXform(const void* text, size_t byteLength, |
| 136 | const SkRSXform xform[], const SkFont& font, |
| 137 | SkTextEncoding encoding = kUTF8_SkTextEncoding); |
| 138 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 139 | /** Writes data to allow later reconstruction of SkTextBlob. memory points to storage |
| 140 | to receive the encoded data, and memory_size describes the size of storage. |
| 141 | Returns bytes used if provided storage is large enough to hold all data; |
| 142 | otherwise, returns zero. |
| 143 | |
| 144 | procs.fTypefaceProc permits supplying a custom function to encode SkTypeface. |
| 145 | If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx |
| 146 | may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc |
| 147 | is called with a pointer to SkTypeface and user context. |
| 148 | |
Cary Clark | 8245649 | 2018-10-31 10:54:50 -0400 | [diff] [blame] | 149 | @param procs custom serial data encoders; may be nullptr |
| 150 | @param memory storage for data |
| 151 | @param memory_size size of storage |
| 152 | @return bytes written, or zero if required storage is larger than memory_size |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 153 | */ |
Khushal | 42f8bc4 | 2018-04-03 17:51:40 -0700 | [diff] [blame] | 154 | size_t serialize(const SkSerialProcs& procs, void* memory, size_t memory_size) const; |
| 155 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 156 | /** Returns storage containing SkData describing SkTextBlob, using optional custom |
| 157 | encoders. |
| 158 | |
| 159 | procs.fTypefaceProc permits supplying a custom function to encode SkTypeface. |
| 160 | If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx |
| 161 | may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc |
| 162 | is called with a pointer to SkTypeface and user context. |
| 163 | |
| 164 | @param procs custom serial data encoders; may be nullptr |
| 165 | @return storage containing serialized SkTextBlob |
| 166 | */ |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 167 | sk_sp<SkData> serialize(const SkSerialProcs& procs) const; |
Mike Reed | aaa3056 | 2017-07-21 11:53:23 -0400 | [diff] [blame] | 168 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 169 | /** Recreates SkTextBlob that was serialized into data. Returns constructed SkTextBlob |
| 170 | if successful; otherwise, returns nullptr. Fails if size is smaller than |
| 171 | required data length, or if data does not permit constructing valid SkTextBlob. |
| 172 | |
| 173 | procs.fTypefaceProc permits supplying a custom function to decode SkTypeface. |
| 174 | If procs.fTypefaceProc is nullptr, default decoding is used. procs.fTypefaceCtx |
| 175 | may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc |
| 176 | is called with a pointer to SkTypeface data, data byte length, and user context. |
| 177 | |
| 178 | @param data pointer for serial data |
| 179 | @param size size of data |
| 180 | @param procs custom serial data decoders; may be nullptr |
| 181 | @return SkTextBlob constructed from data in memory |
| 182 | */ |
Cary Clark | 785586a | 2018-07-19 10:07:01 -0400 | [diff] [blame] | 183 | static sk_sp<SkTextBlob> Deserialize(const void* data, size_t size, |
| 184 | const SkDeserialProcs& procs); |
Mike Reed | 8e74cbc | 2017-12-08 13:20:01 -0500 | [diff] [blame] | 185 | |
halcanary | 3377975 | 2015-10-27 14:01:05 -0700 | [diff] [blame] | 186 | private: |
Mike Klein | 408ef21 | 2018-10-30 15:23:00 +0000 | [diff] [blame] | 187 | friend class SkNVRefCnt<SkTextBlob>; |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 188 | class RunRecord; |
| 189 | |
Florin Malita | ab54e73 | 2018-07-27 09:47:15 -0400 | [diff] [blame] | 190 | enum GlyphPositioning : uint8_t; |
| 191 | |
Florin Malita | 3a9a7a3 | 2017-03-13 09:03:24 -0400 | [diff] [blame] | 192 | explicit SkTextBlob(const SkRect& bounds); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 193 | |
mtklein | b47cd4b | 2016-08-09 12:20:04 -0700 | [diff] [blame] | 194 | ~SkTextBlob(); |
bsalomon | 0728031 | 2014-11-20 08:02:46 -0800 | [diff] [blame] | 195 | |
| 196 | // Memory for objects of this class is created with sk_malloc rather than operator new and must |
| 197 | // be freed with sk_free. |
Yong-Hwan Baek | 688a8e5 | 2018-07-09 14:14:26 +0900 | [diff] [blame] | 198 | void operator delete(void* p); |
| 199 | void* operator new(size_t); |
| 200 | void* operator new(size_t, void* p); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 201 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 202 | static unsigned ScalarsPerGlyph(GlyphPositioning pos); |
| 203 | |
Florin Malita | 4a01ac9 | 2017-03-13 16:45:28 -0400 | [diff] [blame] | 204 | // Call when this blob is part of the key to a cache entry. This allows the cache |
| 205 | // to know automatically those entries can be purged when this SkTextBlob is deleted. |
Jim Van Verth | 474d687 | 2017-12-14 13:00:05 -0500 | [diff] [blame] | 206 | void notifyAddedToCache(uint32_t cacheID) const { |
| 207 | fCacheID.store(cacheID); |
Florin Malita | 4a01ac9 | 2017-03-13 16:45:28 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Herb Derby | 8a6348e | 2018-07-12 15:30:35 -0400 | [diff] [blame] | 210 | friend class SkGlyphRunList; |
Florin Malita | 4a01ac9 | 2017-03-13 16:45:28 -0400 | [diff] [blame] | 211 | friend class GrTextBlobCache; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 212 | friend class SkTextBlobBuilder; |
Cary Clark | 53c8769 | 2018-07-17 08:59:34 -0400 | [diff] [blame] | 213 | friend class SkTextBlobPriv; |
halcanary | 3377975 | 2015-10-27 14:01:05 -0700 | [diff] [blame] | 214 | friend class SkTextBlobRunIterator; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 215 | |
Mike Klein | 015c899 | 2018-08-09 12:23:19 -0400 | [diff] [blame] | 216 | const SkRect fBounds; |
| 217 | const uint32_t fUniqueID; |
| 218 | mutable std::atomic<uint32_t> fCacheID; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 219 | |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 220 | SkDEBUGCODE(size_t fStorageSize;) |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 221 | |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 222 | // The actual payload resides in externally-managed storage, following the object. |
| 223 | // (see the .cpp for more details) |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 224 | |
| 225 | typedef SkRefCnt INHERITED; |
| 226 | }; |
| 227 | |
| 228 | /** \class SkTextBlobBuilder |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 229 | Helper class for constructing SkTextBlob. |
| 230 | */ |
jbroman | 3053dfa | 2014-08-25 06:22:12 -0700 | [diff] [blame] | 231 | class SK_API SkTextBlobBuilder { |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 232 | public: |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 233 | |
| 234 | /** Constructs empty SkTextBlobBuilder. By default, SkTextBlobBuilder has no runs. |
| 235 | |
| 236 | @return empty SkTextBlobBuilder |
| 237 | */ |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 238 | SkTextBlobBuilder(); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 239 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 240 | /** Deletes data allocated internally by SkTextBlobBuilder. |
| 241 | */ |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 242 | ~SkTextBlobBuilder(); |
| 243 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 244 | /** Returns SkTextBlob built from runs of glyphs added by builder. Returned |
| 245 | SkTextBlob is immutable; it may be copied, but its contents may not be altered. |
| 246 | Returns nullptr if no runs of glyphs were added by builder. |
| 247 | |
| 248 | Resets SkTextBlobBuilder to its initial empty state, allowing it to be |
| 249 | reused to build a new set of runs. |
| 250 | |
| 251 | @return SkTextBlob or nullptr |
| 252 | */ |
reed | 2ab9057 | 2016-08-10 14:16:41 -0700 | [diff] [blame] | 253 | sk_sp<SkTextBlob> make(); |
| 254 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 255 | /** \struct SkTextBlobBuilder::RunBuffer |
| 256 | RunBuffer supplies storage for glyphs and positions within a run. |
| 257 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 258 | A run is a sequence of glyphs sharing font metrics and positioning. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 259 | Each run may position its glyphs in one of three ways: |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 260 | by specifying where the first glyph is drawn, and allowing font metrics to |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 261 | determine the advance to subsequent glyphs; by specifying a baseline, and |
| 262 | the position on that baseline for each glyph in run; or by providing SkPoint |
| 263 | array, one per glyph. |
| 264 | */ |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 265 | struct RunBuffer { |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 266 | SkGlyphID* glyphs; //!< storage for glyphs in run |
| 267 | SkScalar* pos; //!< storage for positions in run |
| 268 | char* utf8text; //!< reserved for future use |
| 269 | uint32_t* clusters; //!< reserved for future use |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 272 | /** Returns run with storage for glyphs. Caller must write count glyphs to |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 273 | RunBuffer::glyphs before next call to SkTextBlobBuilder. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 274 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 275 | RunBuffer::utf8text, and RunBuffer::clusters should be ignored. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 276 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 277 | Glyphs share metrics in font. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 278 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 279 | Glyphs are positioned on a baseline at (x, y), using font metrics to |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 280 | determine their relative placement. |
| 281 | |
| 282 | bounds defines an optional bounding box, used to suppress drawing when SkTextBlob |
| 283 | bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 284 | is computed from (x, y) and RunBuffer::glyphs metrics. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 285 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 286 | @param font SkFont used for this run |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 287 | @param count number of glyphs |
| 288 | @param x horizontal offset within the blob |
| 289 | @param y vertical offset within the blob |
| 290 | @param bounds optional run bounding box |
| 291 | @return writable glyph buffer |
| 292 | */ |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 293 | const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y, |
| 294 | const SkRect* bounds = nullptr); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 295 | |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 296 | /** Returns run with storage for glyphs and positions along baseline. Caller must |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 297 | write count glyphs to RunBuffer::glyphs, and count scalars to RunBuffer::pos; |
| 298 | before next call to SkTextBlobBuilder. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 299 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 300 | RunBuffer::utf8text, and RunBuffer::clusters should be ignored. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 301 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 302 | Glyphs share metrics in font. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 303 | |
| 304 | Glyphs are positioned on a baseline at y, using x-axis positions written by |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 305 | caller to RunBuffer::pos. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 306 | |
| 307 | bounds defines an optional bounding box, used to suppress drawing when SkTextBlob |
| 308 | bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 309 | is computed from y, RunBuffer::pos, and RunBuffer::glyphs metrics. |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 310 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 311 | @param font SkFont used for this run |
Cary Clark | af04551 | 2018-08-10 13:11:06 -0400 | [diff] [blame] | 312 | @param count number of glyphs |
| 313 | @param y vertical offset within the blob |
| 314 | @param bounds optional run bounding box |
| 315 | @return writable glyph buffer and x-axis position buffer |
| 316 | */ |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 317 | const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y, |
| 318 | const SkRect* bounds = nullptr); |
| 319 | |
| 320 | /** Returns run with storage for glyphs and SkPoint positions. Caller must |
| 321 | write count glyphs to RunBuffer::glyphs, and count SkPoint to RunBuffer::pos; |
| 322 | before next call to SkTextBlobBuilder. |
| 323 | |
| 324 | RunBuffer::utf8text, and RunBuffer::clusters should be ignored. |
| 325 | |
| 326 | Glyphs share metrics in font. |
| 327 | |
| 328 | Glyphs are positioned using SkPoint written by caller to RunBuffer::pos, using |
| 329 | two scalar values for each SkPoint. |
| 330 | |
| 331 | bounds defines an optional bounding box, used to suppress drawing when SkTextBlob |
| 332 | bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds |
| 333 | is computed from RunBuffer::pos, and RunBuffer::glyphs metrics. |
| 334 | |
| 335 | @param font SkFont used for this run |
| 336 | @param count number of glyphs |
| 337 | @param bounds optional run bounding box |
| 338 | @return writable glyph buffer and SkPoint buffer |
| 339 | */ |
| 340 | const RunBuffer& allocRunPos(const SkFont& font, int count, |
| 341 | const SkRect* bounds = nullptr); |
| 342 | |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame^] | 343 | // Experimental, RunBuffer.pos points to SkRSXforms |
| 344 | const RunBuffer& allocRunRSXform(const SkFont& font, int count); |
| 345 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 346 | private: |
Mike Reed | 6d59568 | 2018-12-05 17:28:14 -0500 | [diff] [blame] | 347 | const RunBuffer& allocRunText(const SkFont& font, |
Cary Clark | e12a090 | 2018-08-09 10:07:33 -0400 | [diff] [blame] | 348 | int count, |
| 349 | SkScalar x, |
| 350 | SkScalar y, |
| 351 | int textByteCount, |
| 352 | SkString lang, |
| 353 | const SkRect* bounds = nullptr); |
Mike Reed | 6d59568 | 2018-12-05 17:28:14 -0500 | [diff] [blame] | 354 | const RunBuffer& allocRunTextPosH(const SkFont& font, int count, SkScalar y, |
Cary Clark | e12a090 | 2018-08-09 10:07:33 -0400 | [diff] [blame] | 355 | int textByteCount, SkString lang, |
| 356 | const SkRect* bounds = nullptr); |
Mike Reed | 6d59568 | 2018-12-05 17:28:14 -0500 | [diff] [blame] | 357 | const RunBuffer& allocRunTextPos(const SkFont& font, int count, |
Cary Clark | e12a090 | 2018-08-09 10:07:33 -0400 | [diff] [blame] | 358 | int textByteCount, SkString lang, |
| 359 | const SkRect* bounds = nullptr); |
Mike Reed | 30cf62b | 2018-12-20 11:18:24 -0500 | [diff] [blame^] | 360 | const RunBuffer& allocRunRSXform(const SkFont& font, int count, |
| 361 | int textByteCount, SkString lang, |
| 362 | const SkRect* bounds = nullptr); |
| 363 | |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 364 | void reserve(size_t size); |
Mike Reed | b3f4aac | 2018-12-05 15:40:29 -0500 | [diff] [blame] | 365 | void allocInternal(const SkFont& font, SkTextBlob::GlyphPositioning positioning, |
halcanary | 4f0a23a | 2016-08-30 11:58:33 -0700 | [diff] [blame] | 366 | int count, int textBytes, SkPoint offset, const SkRect* bounds); |
Mike Reed | b3f4aac | 2018-12-05 15:40:29 -0500 | [diff] [blame] | 367 | bool mergeRun(const SkFont& font, SkTextBlob::GlyphPositioning positioning, |
Florin Malita | d923a71 | 2017-11-22 10:11:12 -0500 | [diff] [blame] | 368 | uint32_t count, SkPoint offset); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 369 | void updateDeferredBounds(); |
| 370 | |
fmalita | 3dc40ac | 2015-01-28 10:56:06 -0800 | [diff] [blame] | 371 | static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&); |
| 372 | static SkRect TightRunBounds(const SkTextBlob::RunRecord&); |
| 373 | |
Cary Clark | e12a090 | 2018-08-09 10:07:33 -0400 | [diff] [blame] | 374 | friend class SkTextBlobPriv; |
| 375 | friend class SkTextBlobBuilderPriv; |
| 376 | |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 377 | SkAutoTMalloc<uint8_t> fStorage; |
| 378 | size_t fStorageSize; |
| 379 | size_t fStorageUsed; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 380 | |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 381 | SkRect fBounds; |
| 382 | int fRunCount; |
| 383 | bool fDeferredBounds; |
| 384 | size_t fLastRun; // index into fStorage |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 385 | |
fmalita | 3c196de | 2014-09-20 05:40:22 -0700 | [diff] [blame] | 386 | RunBuffer fCurrentRunBuffer; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | #endif // SkTextBlob_DEFINED |