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