Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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< 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

Member Function Documentation

◆ addPlaceholder()

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

Definition at line 519 of file paragraph_builder.cc.

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

◆ addText()

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

Definition at line 499 of file paragraph_builder.cc.

499 {
500 if (text.empty()) {
501 return Dart_Null();
502 }
503
504 // Use ICU to validate the UTF-16 input. Calling u_strToUTF8 with a null
505 // output buffer will return U_BUFFER_OVERFLOW_ERROR if the input is well
506 // formed.
507 const UChar* text_ptr = reinterpret_cast<const UChar*>(text.data());
508 UErrorCode error_code = U_ZERO_ERROR;
509 u_strToUTF8(nullptr, 0, nullptr, text_ptr, text.size(), &error_code);
510 if (error_code != U_BUFFER_OVERFLOW_ERROR) {
511 return tonic::ToDart("string is not well-formed UTF-16");
512 }
513
514 m_paragraph_builder_->AddText(text);
515
516 return Dart_Null();
517}
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 531 of file paragraph_builder.cc.

531 {
532 Paragraph::Create(paragraph_handle, m_paragraph_builder_->Build());
533 m_paragraph_builder_.reset();
535}
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 146 of file paragraph_builder.cc.

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

◆ pop()

void flutter::ParagraphBuilder::pop ( )

Definition at line 495 of file paragraph_builder.cc.

495 {
496 m_paragraph_builder_->Pop();
497}

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

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

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