15#if !defined(SK_DISABLE_LEGACY_PARAGRAPH_UNICODE)
16#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
20#if defined(SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION)
24#if defined(SK_UNICODE_ICU4X_IMPLEMENTATION)
28#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
40#if !defined(SK_DISABLE_LEGACY_PARAGRAPH_UNICODE)
46#ifdef SK_UNICODE_ICU_IMPLEMENTATION
51#ifdef SK_UNICODE_ICU4X_IMPLEMENTATION
56#ifdef SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION
72 return std::make_unique<ParagraphBuilderImpl>(style, std::move(fontCollection),
get_unicode());
91 return std::make_unique<ParagraphBuilderImpl>(style, std::move(fontCollection),
99 , fFontCollection(
std::move(fontCollection))
100 , fParagraphStyle(style)
102#
if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
103 , fTextIsFinalized(
false)
104 , fUsingClientInfo(
false)
129 SkDEBUGF(
"SkParagraphBuilder.Pop() called too many times.\n");
148#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
156#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
163#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
170#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
177#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
180 SkASSERT(!fTextIsFinalized || lastOne);
194 pushStyle(topStyle.cloneForPlaceholder());
195 addText(std::u16string(1ull, 0xFFFC));
221#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
222 if (fTextIsFinalized) {
230#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
231 fTextIsFinalized =
true;
240 fUTF8IndexForUTF16Index.
clear();
241 fUTF16IndexForUTF8Index.
clear();
242#if !defined(SK_DISABLE_LEGACY_PARAGRAPH_UNICODE) && defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
243 if (fUsingClientInfo && !
fUnicode) {
246 std::move(fWordsUtf16),
247 std::move(fGraphemeBreaksUtf8),
248 std::move(fLineBreaksUtf8));
253 return std::make_unique<ParagraphImpl>(
266void ParagraphBuilderImpl::ensureUTF16Mapping() {
267 fillUTF16MappingOnce([&] {
270 [&](
size_t index) { fUTF8IndexForUTF16Index.
emplace_back(index); },
271 [&](
size_t index) { fUTF16IndexForUTF8Index.
emplace_back(index); });
275#if !defined(SK_DISABLE_LEGACY_CLIENT_UNICODE) && defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
276void ParagraphBuilderImpl::setWordsUtf8(std::vector<SkUnicode::Position> wordsUtf8) {
277 ensureUTF16Mapping();
278 std::vector<SkUnicode::Position> wordsUtf16;
280 wordsUtf16.emplace_back(fUTF16IndexForUTF8Index[indexUtf8]);
282 setWordsUtf16(wordsUtf16);
285void ParagraphBuilderImpl::setWordsUtf16(std::vector<SkUnicode::Position> wordsUtf16) {
286 fUsingClientInfo =
true;
287 fWordsUtf16 = std::move(wordsUtf16);
290void ParagraphBuilderImpl::setGraphemeBreaksUtf8(std::vector<SkUnicode::Position> graphemeBreaksUtf8) {
291 fUsingClientInfo =
true;
292 fGraphemeBreaksUtf8 = std::move(graphemeBreaksUtf8);
295void ParagraphBuilderImpl::setGraphemeBreaksUtf16(std::vector<SkUnicode::Position> graphemeBreaksUtf16) {
296 ensureUTF16Mapping();
297 std::vector<SkUnicode::Position> graphemeBreaksUtf8;
299 graphemeBreaksUtf8.emplace_back(fUTF8IndexForUTF16Index[indexUtf16]);
301 setGraphemeBreaksUtf8(graphemeBreaksUtf8);
304void ParagraphBuilderImpl::setLineBreaksUtf8(std::vector<SkUnicode::LineBreakBefore> lineBreaksUtf8) {
305 fUsingClientInfo =
true;
306 fLineBreaksUtf8 = std::move(lineBreaksUtf8);
309void ParagraphBuilderImpl::setLineBreaksUtf16(std::vector<SkUnicode::LineBreakBefore> lineBreaksUtf16) {
310 ensureUTF16Mapping();
311 std::vector<SkUnicode::LineBreakBefore> lineBreaksUtf8;
314 fUTF8IndexForUTF16Index[lineBreakUtf16.pos], lineBreakUtf16.breakType));
316 setLineBreaksUtf8(lineBreaksUtf8);
326 fUTF8IndexForUTF16Index.
clear();
327 fUTF16IndexForUTF8Index.
clear();
328#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
330 fGraphemeBreaksUtf8.clear();
331 fLineBreaksUtf8.clear();
332 fTextIsFinalized =
false;
338#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
#define SkASSERT_RELEASE(cond)
sk_sp< SkUnicode > get_unicode()
const char * data() const
void append(const char text[])
static SkString convertUtf16ToUtf8(const char16_t *utf16, int utf16Units)
static bool extractUtfConversionMapping(SkSpan< const char > utf8, Appender8 &&appender8, Appender16 &&appender16)
sk_sp< FontCollection > fFontCollection
void addPlaceholder(const PlaceholderStyle &placeholderStyle) override
~ParagraphBuilderImpl() override
skia_private::STArray< 4, Block, true > fStyledBlocks
sk_sp< SkUnicode > fUnicode
SkSpan< char > getText() override
skia_private::STArray< 4, Placeholder, true > fPlaceholders
static bool RequiresClientICU()
ParagraphStyle fParagraphStyle
ParagraphBuilderImpl(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
void addText(const std::u16string &text) override
const ParagraphStyle & getParagraphStyle() const override
TextStyle peekStyle() override
skia_private::STArray< 4, TextStyle, true > fTextStyles
const TextStyle & internalPeekStyle()
void pushStyle(const TextStyle &style) override
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
std::unique_ptr< Paragraph > Build() override
static std::unique_ptr< ParagraphBuilder > make(const ParagraphStyle &style, sk_sp< FontCollection > fontCollection, sk_sp< SkUnicode > unicode)
T & emplace_back(Args &&... args)
SKUNICODE_API sk_sp< SkUnicode > Make(SkSpan< char > text, std::vector< SkUnicode::Position > words, std::vector< SkUnicode::Position > graphemeBreaks, std::vector< SkUnicode::LineBreakBefore > lineBreaks)
SKUNICODE_API sk_sp< SkUnicode > Make()
SKUNICODE_API sk_sp< SkUnicode > Make()
SKUNICODE_API sk_sp< SkUnicode > Make()
const TextStyle & getTextStyle() const