2014-08-21 15:53:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkTextBlob_DEFINED
|
|
|
|
#define SkTextBlob_DEFINED
|
|
|
|
|
2016-02-17 21:13:44 +00:00
|
|
|
#include "../private/SkTemplates.h"
|
2018-10-26 20:33:00 +00:00
|
|
|
#include "SkFont.h"
|
2014-08-21 15:53:26 +00:00
|
|
|
#include "SkPaint.h"
|
2016-08-30 18:58:33 +00:00
|
|
|
#include "SkString.h"
|
2014-08-21 15:53:26 +00:00
|
|
|
#include "SkRefCnt.h"
|
2018-09-19 14:28:59 +00:00
|
|
|
|
2018-08-09 16:23:19 +00:00
|
|
|
#include <atomic>
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2018-12-20 16:18:24 +00:00
|
|
|
struct SkRSXform;
|
2017-12-08 18:20:01 +00:00
|
|
|
struct SkSerialProcs;
|
|
|
|
struct SkDeserialProcs;
|
|
|
|
|
2014-08-21 15:53:26 +00:00
|
|
|
/** \class SkTextBlob
|
2018-08-10 17:11:06 +00:00
|
|
|
SkTextBlob combines multiple text runs into an immutable container. Each text
|
|
|
|
run consists of glyphs, SkPaint, and position. Only parts of SkPaint related to
|
|
|
|
fonts and text rendering are used by run.
|
2014-08-21 15:53:26 +00:00
|
|
|
*/
|
2018-10-30 15:23:00 +00:00
|
|
|
class SK_API SkTextBlob final : public SkNVRefCnt<SkTextBlob> {
|
2014-08-21 15:53:26 +00:00
|
|
|
public:
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Returns conservative bounding box. Uses SkPaint associated with each glyph to
|
|
|
|
determine glyph bounds, and unions all bounds. Returned bounds may be
|
|
|
|
larger than the bounds of all glyphs in runs.
|
|
|
|
|
|
|
|
@return conservative bounding box
|
|
|
|
*/
|
2014-08-21 15:53:26 +00:00
|
|
|
const SkRect& bounds() const { return fBounds; }
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns a non-zero value unique among all text blobs.
|
|
|
|
|
|
|
|
@return identifier for SkTextBlob
|
|
|
|
*/
|
2015-03-25 20:40:13 +00:00
|
|
|
uint32_t uniqueID() const { return fUniqueID; }
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2018-12-11 03:02:17 +00:00
|
|
|
/** Returns the number of intervals that intersect bounds.
|
|
|
|
bounds describes a pair of lines parallel to the text advance.
|
|
|
|
The return count is zero or a multiple of two, and is at most twice the number of glyphs in
|
|
|
|
the the blob.
|
|
|
|
|
|
|
|
Pass nullptr for intervals to determine the size of the interval array.
|
|
|
|
|
2018-12-20 22:06:34 +00:00
|
|
|
Runs within the blob that contain SkRSXform are ignored when computing intercepts.
|
2018-12-20 16:18:24 +00:00
|
|
|
|
2018-12-11 03:02:17 +00:00
|
|
|
@param bounds lower and upper line parallel to the advance
|
|
|
|
@param intervals returned intersections; may be nullptr
|
2018-12-11 13:41:11 +00:00
|
|
|
@param paint specifies stroking, SkPathEffect that affects the result; may be nullptr
|
2018-12-11 03:02:17 +00:00
|
|
|
@return number of intersections; may be zero
|
|
|
|
*/
|
|
|
|
int getIntercepts(const SkScalar bounds[2], SkScalar intervals[],
|
|
|
|
const SkPaint* paint = nullptr) const;
|
|
|
|
|
2018-10-26 20:33:00 +00:00
|
|
|
/** Creates SkTextBlob with a single run.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
font contains attributes used to define the run text.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2019-01-14 18:38:43 +00:00
|
|
|
When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or
|
|
|
|
SkTextEncoding::kUTF32, this function uses the default
|
|
|
|
character-to-glyph mapping from the SkTypeface in font. It does not
|
|
|
|
perform typeface fallback for characters not found in the SkTypeface.
|
|
|
|
It does not perform kerning or other complex shaping; glyphs are
|
|
|
|
positioned based on their default advances.
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
@param text character code points or glyphs drawn
|
|
|
|
@param byteLength byte length of text array
|
2019-01-14 18:38:43 +00:00
|
|
|
@param font text size, typeface, text scale, and so on, used to draw
|
|
|
|
@param encoding text encoding used in the text array
|
2018-08-10 17:11:06 +00:00
|
|
|
@return SkTextBlob constructed from one run
|
|
|
|
*/
|
2018-10-26 20:33:00 +00:00
|
|
|
static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font,
|
2019-01-14 18:38:43 +00:00
|
|
|
SkTextEncoding encoding = kUTF8_SkTextEncoding);
|
2018-07-17 20:10:30 +00:00
|
|
|
|
2018-12-03 14:45:17 +00:00
|
|
|
/** Creates SkTextBlob with a single run. string meaning depends on SkTextEncoding;
|
2018-08-10 17:11:06 +00:00
|
|
|
by default, string is encoded as UTF-8.
|
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
font contains attributes used to define the run text.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2019-01-14 18:38:43 +00:00
|
|
|
When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or
|
|
|
|
SkTextEncoding::kUTF32, this function uses the default
|
|
|
|
character-to-glyph mapping from the SkTypeface in font. It does not
|
|
|
|
perform typeface fallback for characters not found in the SkTypeface.
|
|
|
|
It does not perform kerning or other complex shaping; glyphs are
|
|
|
|
positioned based on their default advances.
|
|
|
|
|
|
|
|
@param string character code points or glyphs drawn
|
|
|
|
@param font text size, typeface, text scale, and so on, used to draw
|
|
|
|
@param encoding text encoding used in the text array
|
|
|
|
@return SkTextBlob constructed from one run
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-10-26 20:33:00 +00:00
|
|
|
static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font,
|
2019-01-14 18:38:43 +00:00
|
|
|
SkTextEncoding encoding = kUTF8_SkTextEncoding) {
|
2018-08-09 14:07:33 +00:00
|
|
|
if (!string) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-10-26 20:33:00 +00:00
|
|
|
return MakeFromText(string, strlen(string), font, encoding);
|
2018-08-09 14:07:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 18:30:23 +00:00
|
|
|
/** Experimental.
|
|
|
|
Returns a textblob built from a single run of text with x-positions and a single y value.
|
|
|
|
This is equivalent to using SkTextBlobBuilder and calling allocRunPosH().
|
|
|
|
Returns nullptr if byteLength is zero.
|
|
|
|
|
|
|
|
@param text character code points or glyphs drawn (based on encoding)
|
|
|
|
@param byteLength byte length of text array
|
|
|
|
@param xpos array of x-positions, must contain values for all of the character points.
|
|
|
|
@param constY shared y-position for each character point, to be paired with each xpos.
|
|
|
|
@param font SkFont used for this run
|
|
|
|
@param encoding specifies the encoding of the text array.
|
|
|
|
@return new textblob or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkTextBlob> MakeFromPosTextH(const void* text, size_t byteLength,
|
|
|
|
const SkScalar xpos[], SkScalar constY, const SkFont& font,
|
|
|
|
SkTextEncoding encoding = kUTF8_SkTextEncoding);
|
|
|
|
|
|
|
|
/** Experimental.
|
|
|
|
Returns a textblob built from a single run of text with positions.
|
|
|
|
This is equivalent to using SkTextBlobBuilder and calling allocRunPos().
|
|
|
|
Returns nullptr if byteLength is zero.
|
|
|
|
|
|
|
|
@param text character code points or glyphs drawn (based on encoding)
|
|
|
|
@param byteLength byte length of text array
|
|
|
|
@param pos array of positions, must contain values for all of the character points.
|
|
|
|
@param font SkFont used for this run
|
|
|
|
@param encoding specifies the encoding of the text array.
|
|
|
|
@return new textblob or nullptr
|
|
|
|
*/
|
|
|
|
static sk_sp<SkTextBlob> MakeFromPosText(const void* text, size_t byteLength,
|
|
|
|
const SkPoint pos[], const SkFont& font,
|
|
|
|
SkTextEncoding encoding = kUTF8_SkTextEncoding);
|
|
|
|
|
2018-12-20 16:18:24 +00:00
|
|
|
// Experimental
|
|
|
|
static sk_sp<SkTextBlob> MakeFromRSXform(const void* text, size_t byteLength,
|
|
|
|
const SkRSXform xform[], const SkFont& font,
|
|
|
|
SkTextEncoding encoding = kUTF8_SkTextEncoding);
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Writes data to allow later reconstruction of SkTextBlob. memory points to storage
|
|
|
|
to receive the encoded data, and memory_size describes the size of storage.
|
|
|
|
Returns bytes used if provided storage is large enough to hold all data;
|
|
|
|
otherwise, returns zero.
|
|
|
|
|
|
|
|
procs.fTypefaceProc permits supplying a custom function to encode SkTypeface.
|
|
|
|
If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx
|
|
|
|
may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc
|
|
|
|
is called with a pointer to SkTypeface and user context.
|
|
|
|
|
2018-10-31 14:54:50 +00:00
|
|
|
@param procs custom serial data encoders; may be nullptr
|
|
|
|
@param memory storage for data
|
|
|
|
@param memory_size size of storage
|
|
|
|
@return bytes written, or zero if required storage is larger than memory_size
|
2018-08-10 17:11:06 +00:00
|
|
|
*/
|
2018-04-04 00:51:40 +00:00
|
|
|
size_t serialize(const SkSerialProcs& procs, void* memory, size_t memory_size) const;
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns storage containing SkData describing SkTextBlob, using optional custom
|
|
|
|
encoders.
|
|
|
|
|
|
|
|
procs.fTypefaceProc permits supplying a custom function to encode SkTypeface.
|
|
|
|
If procs.fTypefaceProc is nullptr, default encoding is used. procs.fTypefaceCtx
|
|
|
|
may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc
|
|
|
|
is called with a pointer to SkTypeface and user context.
|
|
|
|
|
|
|
|
@param procs custom serial data encoders; may be nullptr
|
|
|
|
@return storage containing serialized SkTextBlob
|
|
|
|
*/
|
2018-07-19 14:07:01 +00:00
|
|
|
sk_sp<SkData> serialize(const SkSerialProcs& procs) const;
|
2017-07-21 15:53:23 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Recreates SkTextBlob that was serialized into data. Returns constructed SkTextBlob
|
|
|
|
if successful; otherwise, returns nullptr. Fails if size is smaller than
|
|
|
|
required data length, or if data does not permit constructing valid SkTextBlob.
|
|
|
|
|
|
|
|
procs.fTypefaceProc permits supplying a custom function to decode SkTypeface.
|
|
|
|
If procs.fTypefaceProc is nullptr, default decoding is used. procs.fTypefaceCtx
|
|
|
|
may be used to provide user context to procs.fTypefaceProc; procs.fTypefaceProc
|
|
|
|
is called with a pointer to SkTypeface data, data byte length, and user context.
|
|
|
|
|
|
|
|
@param data pointer for serial data
|
|
|
|
@param size size of data
|
|
|
|
@param procs custom serial data decoders; may be nullptr
|
|
|
|
@return SkTextBlob constructed from data in memory
|
|
|
|
*/
|
2018-07-19 14:07:01 +00:00
|
|
|
static sk_sp<SkTextBlob> Deserialize(const void* data, size_t size,
|
|
|
|
const SkDeserialProcs& procs);
|
2017-12-08 18:20:01 +00:00
|
|
|
|
2015-10-27 21:01:05 +00:00
|
|
|
private:
|
2018-10-30 15:23:00 +00:00
|
|
|
friend class SkNVRefCnt<SkTextBlob>;
|
2014-09-20 12:40:22 +00:00
|
|
|
class RunRecord;
|
|
|
|
|
2018-07-27 13:47:15 +00:00
|
|
|
enum GlyphPositioning : uint8_t;
|
|
|
|
|
2017-03-13 13:03:24 +00:00
|
|
|
explicit SkTextBlob(const SkRect& bounds);
|
2014-09-20 12:40:22 +00:00
|
|
|
|
2016-08-09 19:20:04 +00:00
|
|
|
~SkTextBlob();
|
2014-11-20 16:02:46 +00:00
|
|
|
|
|
|
|
// Memory for objects of this class is created with sk_malloc rather than operator new and must
|
|
|
|
// be freed with sk_free.
|
2018-07-09 05:14:26 +00:00
|
|
|
void operator delete(void* p);
|
|
|
|
void* operator new(size_t);
|
|
|
|
void* operator new(size_t, void* p);
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2014-08-26 14:56:44 +00:00
|
|
|
static unsigned ScalarsPerGlyph(GlyphPositioning pos);
|
|
|
|
|
2017-03-13 20:45:28 +00:00
|
|
|
// Call when this blob is part of the key to a cache entry. This allows the cache
|
|
|
|
// to know automatically those entries can be purged when this SkTextBlob is deleted.
|
2017-12-14 18:00:05 +00:00
|
|
|
void notifyAddedToCache(uint32_t cacheID) const {
|
|
|
|
fCacheID.store(cacheID);
|
2017-03-13 20:45:28 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 19:30:35 +00:00
|
|
|
friend class SkGlyphRunList;
|
2017-03-13 20:45:28 +00:00
|
|
|
friend class GrTextBlobCache;
|
2014-08-21 15:53:26 +00:00
|
|
|
friend class SkTextBlobBuilder;
|
2018-07-17 12:59:34 +00:00
|
|
|
friend class SkTextBlobPriv;
|
2015-10-27 21:01:05 +00:00
|
|
|
friend class SkTextBlobRunIterator;
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2018-08-09 16:23:19 +00:00
|
|
|
const SkRect fBounds;
|
|
|
|
const uint32_t fUniqueID;
|
|
|
|
mutable std::atomic<uint32_t> fCacheID;
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2014-09-20 12:40:22 +00:00
|
|
|
SkDEBUGCODE(size_t fStorageSize;)
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2014-09-20 12:40:22 +00:00
|
|
|
// The actual payload resides in externally-managed storage, following the object.
|
|
|
|
// (see the .cpp for more details)
|
2014-08-21 15:53:26 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \class SkTextBlobBuilder
|
2018-08-10 17:11:06 +00:00
|
|
|
Helper class for constructing SkTextBlob.
|
|
|
|
*/
|
2014-08-25 13:22:12 +00:00
|
|
|
class SK_API SkTextBlobBuilder {
|
2014-08-21 15:53:26 +00:00
|
|
|
public:
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
/** Constructs empty SkTextBlobBuilder. By default, SkTextBlobBuilder has no runs.
|
|
|
|
|
|
|
|
@return empty SkTextBlobBuilder
|
|
|
|
*/
|
2014-09-20 12:40:22 +00:00
|
|
|
SkTextBlobBuilder();
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Deletes data allocated internally by SkTextBlobBuilder.
|
|
|
|
*/
|
2014-08-21 15:53:26 +00:00
|
|
|
~SkTextBlobBuilder();
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns SkTextBlob built from runs of glyphs added by builder. Returned
|
|
|
|
SkTextBlob is immutable; it may be copied, but its contents may not be altered.
|
|
|
|
Returns nullptr if no runs of glyphs were added by builder.
|
|
|
|
|
|
|
|
Resets SkTextBlobBuilder to its initial empty state, allowing it to be
|
|
|
|
reused to build a new set of runs.
|
|
|
|
|
|
|
|
@return SkTextBlob or nullptr
|
|
|
|
*/
|
2016-08-10 21:16:41 +00:00
|
|
|
sk_sp<SkTextBlob> make();
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** \struct SkTextBlobBuilder::RunBuffer
|
|
|
|
RunBuffer supplies storage for glyphs and positions within a run.
|
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
A run is a sequence of glyphs sharing font metrics and positioning.
|
2018-08-10 17:11:06 +00:00
|
|
|
Each run may position its glyphs in one of three ways:
|
2018-11-07 19:59:03 +00:00
|
|
|
by specifying where the first glyph is drawn, and allowing font metrics to
|
2018-08-10 17:11:06 +00:00
|
|
|
determine the advance to subsequent glyphs; by specifying a baseline, and
|
|
|
|
the position on that baseline for each glyph in run; or by providing SkPoint
|
|
|
|
array, one per glyph.
|
|
|
|
*/
|
2014-08-21 15:53:26 +00:00
|
|
|
struct RunBuffer {
|
2018-08-10 17:11:06 +00:00
|
|
|
SkGlyphID* glyphs; //!< storage for glyphs in run
|
|
|
|
SkScalar* pos; //!< storage for positions in run
|
|
|
|
char* utf8text; //!< reserved for future use
|
|
|
|
uint32_t* clusters; //!< reserved for future use
|
2019-01-01 20:40:28 +00:00
|
|
|
|
2019-01-02 18:22:58 +00:00
|
|
|
// experimental
|
2019-01-01 20:40:28 +00:00
|
|
|
SkPoint* points() const { return reinterpret_cast<SkPoint*>(pos); }
|
2019-01-02 18:22:58 +00:00
|
|
|
// experimental
|
2019-01-01 20:40:28 +00:00
|
|
|
SkRSXform* xforms() const { return reinterpret_cast<SkRSXform*>(pos); }
|
2014-08-21 15:53:26 +00:00
|
|
|
};
|
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns run with storage for glyphs. Caller must write count glyphs to
|
2018-11-07 19:59:03 +00:00
|
|
|
RunBuffer::glyphs before next call to SkTextBlobBuilder.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
RunBuffer::utf8text, and RunBuffer::clusters should be ignored.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
Glyphs share metrics in font.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
Glyphs are positioned on a baseline at (x, y), using font metrics to
|
2018-08-10 17:11:06 +00:00
|
|
|
determine their relative placement.
|
|
|
|
|
|
|
|
bounds defines an optional bounding box, used to suppress drawing when SkTextBlob
|
|
|
|
bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds
|
2018-11-07 19:59:03 +00:00
|
|
|
is computed from (x, y) and RunBuffer::glyphs metrics.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
@param font SkFont used for this run
|
2018-08-10 17:11:06 +00:00
|
|
|
@param count number of glyphs
|
|
|
|
@param x horizontal offset within the blob
|
|
|
|
@param y vertical offset within the blob
|
|
|
|
@param bounds optional run bounding box
|
|
|
|
@return writable glyph buffer
|
|
|
|
*/
|
2018-11-07 19:59:03 +00:00
|
|
|
const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
|
|
|
|
const SkRect* bounds = nullptr);
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns run with storage for glyphs and positions along baseline. Caller must
|
2018-11-07 19:59:03 +00:00
|
|
|
write count glyphs to RunBuffer::glyphs, and count scalars to RunBuffer::pos;
|
|
|
|
before next call to SkTextBlobBuilder.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
RunBuffer::utf8text, and RunBuffer::clusters should be ignored.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
Glyphs share metrics in font.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
Glyphs are positioned on a baseline at y, using x-axis positions written by
|
2018-11-07 19:59:03 +00:00
|
|
|
caller to RunBuffer::pos.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
|
|
|
bounds defines an optional bounding box, used to suppress drawing when SkTextBlob
|
|
|
|
bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds
|
2018-11-07 19:59:03 +00:00
|
|
|
is computed from y, RunBuffer::pos, and RunBuffer::glyphs metrics.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
@param font SkFont used for this run
|
2018-08-10 17:11:06 +00:00
|
|
|
@param count number of glyphs
|
|
|
|
@param y vertical offset within the blob
|
|
|
|
@param bounds optional run bounding box
|
|
|
|
@return writable glyph buffer and x-axis position buffer
|
|
|
|
*/
|
2018-11-07 19:59:03 +00:00
|
|
|
const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y,
|
|
|
|
const SkRect* bounds = nullptr);
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2018-08-10 17:11:06 +00:00
|
|
|
/** Returns run with storage for glyphs and SkPoint positions. Caller must
|
2018-11-07 19:59:03 +00:00
|
|
|
write count glyphs to RunBuffer::glyphs, and count SkPoint to RunBuffer::pos;
|
|
|
|
before next call to SkTextBlobBuilder.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
RunBuffer::utf8text, and RunBuffer::clusters should be ignored.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
Glyphs share metrics in font.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
Glyphs are positioned using SkPoint written by caller to RunBuffer::pos, using
|
2018-08-10 17:11:06 +00:00
|
|
|
two scalar values for each SkPoint.
|
|
|
|
|
|
|
|
bounds defines an optional bounding box, used to suppress drawing when SkTextBlob
|
|
|
|
bounds does not intersect SkSurface bounds. If bounds is nullptr, SkTextBlob bounds
|
2018-11-07 19:59:03 +00:00
|
|
|
is computed from RunBuffer::pos, and RunBuffer::glyphs metrics.
|
2018-08-10 17:11:06 +00:00
|
|
|
|
2018-11-07 19:59:03 +00:00
|
|
|
@param font SkFont used for this run
|
2018-08-10 17:11:06 +00:00
|
|
|
@param count number of glyphs
|
|
|
|
@param bounds optional run bounding box
|
|
|
|
@return writable glyph buffer and SkPoint buffer
|
|
|
|
*/
|
2018-11-07 19:59:03 +00:00
|
|
|
const RunBuffer& allocRunPos(const SkFont& font, int count,
|
|
|
|
const SkRect* bounds = nullptr);
|
|
|
|
|
2018-12-20 22:06:34 +00:00
|
|
|
// Experimental, RunBuffer.pos points to SkRSXform array
|
2018-12-20 16:18:24 +00:00
|
|
|
const RunBuffer& allocRunRSXform(const SkFont& font, int count);
|
|
|
|
|
2014-08-21 15:53:26 +00:00
|
|
|
private:
|
2018-12-05 22:28:14 +00:00
|
|
|
const RunBuffer& allocRunText(const SkFont& font,
|
2018-08-09 14:07:33 +00:00
|
|
|
int count,
|
|
|
|
SkScalar x,
|
|
|
|
SkScalar y,
|
|
|
|
int textByteCount,
|
|
|
|
SkString lang,
|
|
|
|
const SkRect* bounds = nullptr);
|
2018-12-05 22:28:14 +00:00
|
|
|
const RunBuffer& allocRunTextPosH(const SkFont& font, int count, SkScalar y,
|
2018-08-09 14:07:33 +00:00
|
|
|
int textByteCount, SkString lang,
|
|
|
|
const SkRect* bounds = nullptr);
|
2018-12-05 22:28:14 +00:00
|
|
|
const RunBuffer& allocRunTextPos(const SkFont& font, int count,
|
2018-08-09 14:07:33 +00:00
|
|
|
int textByteCount, SkString lang,
|
|
|
|
const SkRect* bounds = nullptr);
|
2018-12-20 16:18:24 +00:00
|
|
|
const RunBuffer& allocRunRSXform(const SkFont& font, int count,
|
|
|
|
int textByteCount, SkString lang,
|
|
|
|
const SkRect* bounds = nullptr);
|
|
|
|
|
2014-09-20 12:40:22 +00:00
|
|
|
void reserve(size_t size);
|
2018-12-05 20:40:29 +00:00
|
|
|
void allocInternal(const SkFont& font, SkTextBlob::GlyphPositioning positioning,
|
2016-08-30 18:58:33 +00:00
|
|
|
int count, int textBytes, SkPoint offset, const SkRect* bounds);
|
2018-12-05 20:40:29 +00:00
|
|
|
bool mergeRun(const SkFont& font, SkTextBlob::GlyphPositioning positioning,
|
2017-11-22 15:11:12 +00:00
|
|
|
uint32_t count, SkPoint offset);
|
2014-08-21 15:53:26 +00:00
|
|
|
void updateDeferredBounds();
|
|
|
|
|
2015-01-28 18:56:06 +00:00
|
|
|
static SkRect ConservativeRunBounds(const SkTextBlob::RunRecord&);
|
|
|
|
static SkRect TightRunBounds(const SkTextBlob::RunRecord&);
|
|
|
|
|
2018-08-09 14:07:33 +00:00
|
|
|
friend class SkTextBlobPriv;
|
|
|
|
friend class SkTextBlobBuilderPriv;
|
|
|
|
|
2014-09-20 12:40:22 +00:00
|
|
|
SkAutoTMalloc<uint8_t> fStorage;
|
|
|
|
size_t fStorageSize;
|
|
|
|
size_t fStorageUsed;
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2014-09-20 12:40:22 +00:00
|
|
|
SkRect fBounds;
|
|
|
|
int fRunCount;
|
|
|
|
bool fDeferredBounds;
|
|
|
|
size_t fLastRun; // index into fStorage
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2014-09-20 12:40:22 +00:00
|
|
|
RunBuffer fCurrentRunBuffer;
|
2014-08-21 15:53:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkTextBlob_DEFINED
|