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