Flutter Engine
 
Loading...
Searching...
No Matches
flutter::ParagraphBuilder Class Reference

#include <paragraph_builder.h>

Inheritance diagram for flutter::ParagraphBuilder:
flutter::RefCountedDartWrappable< ParagraphBuilder > fml::RefCountedThreadSafe< T > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase txt::ParagraphBuilderSkia

Public Member Functions

 ~ParagraphBuilder () override
 
void pushStyle (const tonic::Int32List &encoded, const std::vector< std::string > &fontFamilies, double fontSize, double letterSpacing, double wordSpacing, double height, double decorationThickness, const std::string &locale, Dart_Handle background_objects, Dart_Handle background_data, Dart_Handle foreground_objects, Dart_Handle foreground_data, Dart_Handle shadows_data, Dart_Handle font_features_data, Dart_Handle font_variations_data)
 
void pop ()
 
Dart_Handle addText (const std::u16string &text)
 
void addPlaceholder (double width, double height, unsigned alignment, double baseline_offset, unsigned baseline)
 
void build (Dart_Handle paragraph_handle)
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< ParagraphBuilder >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< T >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static void Create (Dart_Handle wrapper, Dart_Handle encoded_handle, Dart_Handle strutData, const std::string &fontFamily, const std::vector< std::string > &strutFontFamilies, double fontSize, double height, const std::u16string &ellipsis, const std::string &locale)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex ,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 20 of file paragraph_builder.h.

Constructor & Destructor Documentation

◆ ~ParagraphBuilder()

flutter::ParagraphBuilder::~ParagraphBuilder ( )
overridedefault

References build().

Member Function Documentation

◆ addPlaceholder()

void flutter::ParagraphBuilder::addPlaceholder ( double  width,
double  height,
unsigned  alignment,
double  baseline_offset,
unsigned  baseline 
)

Definition at line 515 of file paragraph_builder.cc.

519 {
520 txt::PlaceholderRun placeholder_run(
521 width, height, static_cast<txt::PlaceholderAlignment>(alignment),
522 static_cast<txt::TextBaseline>(baseline), baseline_offset);
523
524 m_paragraph_builder_->AddPlaceholder(placeholder_run);
525}
PlaceholderAlignment
Where to vertically align the placeholder relative to the surrounding text.
int32_t height
int32_t width

References height, and width.

◆ addText()

Dart_Handle flutter::ParagraphBuilder::addText ( const std::u16string &  text)

Definition at line 495 of file paragraph_builder.cc.

495 {
496 if (text.empty()) {
497 return Dart_Null();
498 }
499
500 // Use ICU to validate the UTF-16 input. Calling u_strToUTF8 with a null
501 // output buffer will return U_BUFFER_OVERFLOW_ERROR if the input is well
502 // formed.
503 const UChar* text_ptr = reinterpret_cast<const UChar*>(text.data());
504 UErrorCode error_code = U_ZERO_ERROR;
505 u_strToUTF8(nullptr, 0, nullptr, text_ptr, text.size(), &error_code);
506 if (error_code != U_BUFFER_OVERFLOW_ERROR) {
507 return tonic::ToDart("string is not well-formed UTF-16");
508 }
509
510 m_paragraph_builder_->AddText(text);
511
512 return Dart_Null();
513}
std::u16string text
Dart_Handle ToDart(const T &object)

References text, and tonic::ToDart().

◆ build()

void flutter::ParagraphBuilder::build ( Dart_Handle  paragraph_handle)

Definition at line 527 of file paragraph_builder.cc.

527 {
528 Paragraph::Create(paragraph_handle, m_paragraph_builder_->Build());
529 m_paragraph_builder_.reset();
531}
static void Create(Dart_Handle paragraph_handle, std::unique_ptr< txt::Paragraph > txt_paragraph)
Definition paragraph.h:20

References tonic::DartWrappable::ClearDartWrapper(), and flutter::Paragraph::Create().

Referenced by ~ParagraphBuilder().

◆ Create()

void flutter::ParagraphBuilder::Create ( Dart_Handle  wrapper,
Dart_Handle  encoded_handle,
Dart_Handle  strutData,
const std::string &  fontFamily,
const std::vector< std::string > &  strutFontFamilies,
double  fontSize,
double  height,
const std::u16string &  ellipsis,
const std::string &  locale 
)
static

Definition at line 148 of file paragraph_builder.cc.

156 {
158 auto res = fml::MakeRefCounted<ParagraphBuilder>(
159 encoded_handle, strutData, fontFamily, strutFontFamilies, fontSize,
160 height, ellipsis, locale);
161 res->AssociateWithDartWrapper(wrapper);
162}
static void ThrowIfUIOperationsProhibited()

References height, and flutter::UIDartState::ThrowIfUIOperationsProhibited().

◆ pop()

void flutter::ParagraphBuilder::pop ( )

Definition at line 491 of file paragraph_builder.cc.

491 {
492 m_paragraph_builder_->Pop();
493}

◆ pushStyle()

void flutter::ParagraphBuilder::pushStyle ( const tonic::Int32List &  encoded,
const std::vector< std::string > &  fontFamilies,
double  fontSize,
double  letterSpacing,
double  wordSpacing,
double  height,
double  decorationThickness,
const std::string &  locale,
Dart_Handle  background_objects,
Dart_Handle  background_data,
Dart_Handle  foreground_objects,
Dart_Handle  foreground_data,
Dart_Handle  shadows_data,
Dart_Handle  font_features_data,
Dart_Handle  font_variations_data 
)

Definition at line 363 of file paragraph_builder.cc.

377 {
378 FML_DCHECK(encoded.num_elements() == 9);
379
380 int32_t mask = encoded[0];
381
382 // Set to use the properties of the previous style if the property is not
383 // explicitly given.
384 txt::TextStyle style = m_paragraph_builder_->PeekStyle();
385
386 style.half_leading = mask & kTSLeadingDistributionMask;
387 // Only change the style property from the previous value if a new explicitly
388 // set value is available
389 if (mask & kTSColorMask) {
390 style.color = encoded[kTSColorIndex];
391 }
392
393 if (mask & kTSTextDecorationMask) {
394 style.decoration =
395 static_cast<txt::TextDecoration>(encoded[kTSTextDecorationIndex]);
396 }
397
398 if (mask & kTSTextDecorationColorMask) {
399 style.decoration_color = encoded[kTSTextDecorationColorIndex];
400 }
401
402 if (mask & kTSTextDecorationStyleMask) {
403 style.decoration_style = static_cast<txt::TextDecorationStyle>(
404 encoded[kTSTextDecorationStyleIndex]);
405 }
406
407 if (mask & kTSTextDecorationThicknessMask) {
408 style.decoration_thickness_multiplier = decorationThickness;
409 }
410
411 if (mask & kTSTextBaselineMask) {
412 // TODO(abarth): Implement TextBaseline. The CSS version of this
413 // property wasn't wired up either.
414 }
415
416 if (mask & (kTSFontWeightMask | kTSFontStyleMask | kTSFontSizeMask |
417 kTSLetterSpacingMask | kTSWordSpacingMask)) {
418 if (mask & kTSFontWeightMask) {
419 style.font_weight = encoded[kTSFontWeightIndex];
420 }
421
422 if (mask & kTSFontStyleMask) {
423 style.font_style =
424 static_cast<txt::FontStyle>(encoded[kTSFontStyleIndex]);
425 }
426
427 if (mask & kTSFontSizeMask) {
428 style.font_size = fontSize;
429 }
430
431 if (mask & kTSLetterSpacingMask) {
432 style.letter_spacing = letterSpacing;
433 }
434
435 if (mask & kTSWordSpacingMask) {
436 style.word_spacing = wordSpacing;
437 }
438 }
439
440 if (mask & kTSHeightMask) {
441 style.height = height;
442 style.has_height_override = style.height != kTextHeightNone;
443 }
444
445 if (mask & kTSLocaleMask) {
446 style.locale = locale;
447 }
448
449 if (mask & kTSBackgroundMask) {
450 Paint background(background_objects, background_data);
451 if (background.isNotNull()) {
452 DlPaint dl_paint;
453 background.paint(dl_paint, DisplayListOpFlags::kDrawParagraphFlags,
455 style.background = dl_paint;
456 }
457 }
458
459 if (mask & kTSForegroundMask) {
460 Paint foreground(foreground_objects, foreground_data);
461 if (foreground.isNotNull()) {
462 DlPaint dl_paint;
463 foreground.paint(dl_paint, DisplayListOpFlags::kDrawParagraphFlags,
465 style.foreground = dl_paint;
466 }
467 }
468
469 if (mask & kTSTextShadowsMask) {
470 decodeTextShadows(shadows_data, style.text_shadows);
471 }
472
473 if (mask & kTSFontFamilyMask) {
474 // The child style's font families override the parent's font families.
475 // If the child's fonts are not available, then the font collection will
476 // use the system fallback fonts (not the parent's fonts).
477 style.font_families = fontFamilies;
478 }
479
480 if (mask & kTSFontFeaturesMask) {
481 decodeFontFeatures(font_features_data, style.font_features);
482 }
483
484 if (mask & kTSFontVariationsMask) {
485 decodeFontVariations(font_variations_data, style.font_variations);
486 }
487
488 m_paragraph_builder_->PushStyle(style);
489}
static constexpr DisplayListAttributeFlags kDrawParagraphFlags
std::vector< std::string > font_families
Definition text_style.h:40
std::optional< flutter::DlPaint > foreground
Definition text_style.h:48
TextDecorationStyle decoration_style
Definition text_style.h:31
FontStyle font_style
Definition text_style.h:35
SkColor decoration_color
Definition text_style.h:30
double word_spacing
Definition text_style.h:43
FontFeatures font_features
Definition text_style.h:52
FontVariations font_variations
Definition text_style.h:53
bool has_height_override
Definition text_style.h:45
std::vector< TextShadow > text_shadows
Definition text_style.h:51
double font_size
Definition text_style.h:41
std::string locale
Definition text_style.h:46
SkColor color
Definition text_style.h:26
double decoration_thickness_multiplier
Definition text_style.h:33
std::optional< flutter::DlPaint > background
Definition text_style.h:47
double letter_spacing
Definition text_style.h:42
#define FML_DCHECK(condition)
Definition logging.h:122
void decodeFontVariations(Dart_Handle font_variations_data, txt::FontVariations &font_variations)
void decodeTextShadows(Dart_Handle shadows_data, std::vector< txt::TextShadow > &decoded_shadows)
void decodeFontFeatures(Dart_Handle font_features_data, txt::FontFeatures &font_features)
flutter::DlPaint DlPaint
FontStyle
Definition font_style.h:10
TextDecorationStyle

References txt::TextStyle::background, txt::TextStyle::color, flutter::decodeFontFeatures(), flutter::decodeFontVariations(), flutter::decodeTextShadows(), txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::decoration_style, txt::TextStyle::decoration_thickness_multiplier, FML_DCHECK, txt::TextStyle::font_families, txt::TextStyle::font_features, txt::TextStyle::font_size, txt::TextStyle::font_style, txt::TextStyle::font_variations, txt::TextStyle::font_weight, txt::TextStyle::foreground, txt::TextStyle::half_leading, txt::TextStyle::has_height_override, height, txt::TextStyle::height, flutter::kDecal, flutter::DisplayListOpFlags::kDrawParagraphFlags, txt::TextStyle::letter_spacing, txt::TextStyle::locale, txt::TextStyle::text_shadows, and txt::TextStyle::word_spacing.


The documentation for this class was generated from the following files: