Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::ParagraphBuilder Class Reference

#include <paragraph_builder.h>

Inheritance diagram for flutter::ParagraphBuilder:
flutter::RefCountedDartWrappable< ParagraphBuilder > fml::RefCountedThreadSafe< ParagraphBuilder > 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< ParagraphBuilder >
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
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () 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< ParagraphBuilder >
 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

Member Function Documentation

◆ addPlaceholder()

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

Definition at line 521 of file paragraph_builder.cc.

525 {
526 txt::PlaceholderRun placeholder_run(
527 width, height, static_cast<txt::PlaceholderAlignment>(alignment),
528 static_cast<txt::TextBaseline>(baseline), baseline_offset);
529
530 m_paragraph_builder_->AddPlaceholder(placeholder_run);
531}
PlaceholderAlignment
Where to vertically align the placeholder relative to the surrounding text.
TextBaseline
Definition: text_baseline.h:22
int32_t height
int32_t width

◆ addText()

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

Definition at line 501 of file paragraph_builder.cc.

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

◆ build()

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

Definition at line 533 of file paragraph_builder.cc.

533 {
534 Paragraph::Create(paragraph_handle, m_paragraph_builder_->Build());
535 m_paragraph_builder_.reset();
537}
static void Create(Dart_Handle paragraph_handle, std::unique_ptr< txt::Paragraph > txt_paragraph)
Definition: paragraph.h:20

◆ 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()

◆ pop()

void flutter::ParagraphBuilder::pop ( )

Definition at line 497 of file paragraph_builder.cc.

497 {
498 m_paragraph_builder_->Pop();
499}

◆ 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 370 of file paragraph_builder.cc.

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

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