Flutter Engine
flutter::ParagraphBuilder Class Reference

#include <paragraph_builder.h>

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

Public Member Functions

 ~ParagraphBuilder () override
 
void pushStyle (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)
 
void pop ()
 
Dart_Handle addText (const std::u16string &text)
 
Dart_Handle 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 size_t GetAllocationSize () const
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static fml::RefPtr< ParagraphBuildercreate (tonic::Int32List &encoded, 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 void RegisterNatives (tonic::DartLibraryNatives *natives)
 

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 24 of file paragraph_builder.h.

Constructor & Destructor Documentation

◆ ~ParagraphBuilder()

flutter::ParagraphBuilder::~ParagraphBuilder ( )
overridedefault

Referenced by flutter::decodeStrut().

Member Function Documentation

◆ addPlaceholder()

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

Definition at line 511 of file paragraph_builder.cc.

515  {
516  txt::PlaceholderRun placeholder_run(
517  width, height, static_cast<txt::PlaceholderAlignment>(alignment),
518  static_cast<txt::TextBaseline>(baseline), baseline_offset);
519 
520  m_paragraphBuilder->AddPlaceholder(placeholder_run);
521 
522  return Dart_Null();
523 }
int32_t width
int32_t height

◆ addText()

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

Definition at line 491 of file paragraph_builder.cc.

References tonic::ToDart().

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

◆ build()

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

Definition at line 525 of file paragraph_builder.cc.

References flutter::Paragraph::Create().

525  {
526  Paragraph::Create(paragraph_handle, m_paragraphBuilder->Build());
527 }
static void Create(Dart_Handle paragraph_handle, std::unique_ptr< txt::Paragraph > txt_paragraph)
Definition: paragraph.h:26

◆ create()

fml::RefPtr< ParagraphBuilder > flutter::ParagraphBuilder::create ( tonic::Int32List &  encoded,
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 160 of file paragraph_builder.cc.

References height.

Referenced by flutter::ParagraphBuilder_constructor().

168  {
169  return fml::MakeRefCounted<ParagraphBuilder>(encoded, strutData, fontFamily,
170  strutFontFamilies, fontSize,
171  height, ellipsis, locale);
172 }
int32_t height

◆ pop()

void flutter::ParagraphBuilder::pop ( )

Definition at line 487 of file paragraph_builder.cc.

487  {
488  m_paragraphBuilder->Pop();
489 }

◆ pushStyle()

void flutter::ParagraphBuilder::pushStyle ( 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 
)

Definition at line 368 of file paragraph_builder.cc.

References txt::TextStyle::background, txt::TextStyle::color, flutter::decodeFontFeatures(), 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_weight, txt::TextStyle::foreground, txt::TextStyle::half_leading, txt::TextStyle::has_background, txt::TextStyle::has_foreground, txt::TextStyle::has_height_override, height, txt::TextStyle::height, txt::TextStyle::letter_spacing, txt::TextStyle::locale, flutter::Paint::paint(), txt::TextStyle::text_shadows, and txt::TextStyle::word_spacing.

381  {
382  FML_DCHECK(encoded.num_elements() == 9);
383 
384  int32_t mask = encoded[0];
385 
386  // Set to use the properties of the previous style if the property is not
387  // explicitly given.
388  txt::TextStyle style = m_paragraphBuilder->PeekStyle();
389 
390  style.half_leading = mask & tsLeadingDistributionMask;
391  // Only change the style property from the previous value if a new explicitly
392  // set value is available
393  if (mask & tsColorMask) {
394  style.color = encoded[tsColorIndex];
395  }
396 
397  if (mask & tsTextDecorationMask) {
398  style.decoration =
399  static_cast<txt::TextDecoration>(encoded[tsTextDecorationIndex]);
400  }
401 
402  if (mask & tsTextDecorationColorMask) {
403  style.decoration_color = encoded[tsTextDecorationColorIndex];
404  }
405 
406  if (mask & tsTextDecorationStyleMask) {
407  style.decoration_style = static_cast<txt::TextDecorationStyle>(
408  encoded[tsTextDecorationStyleIndex]);
409  }
410 
411  if (mask & tsTextDecorationThicknessMask) {
412  style.decoration_thickness_multiplier = decorationThickness;
413  }
414 
415  if (mask & tsTextBaselineMask) {
416  // TODO(abarth): Implement TextBaseline. The CSS version of this
417  // property wasn't wired up either.
418  }
419 
420  if (mask & (tsFontWeightMask | tsFontStyleMask | tsFontSizeMask |
421  tsLetterSpacingMask | tsWordSpacingMask)) {
422  if (mask & tsFontWeightMask) {
423  style.font_weight =
424  static_cast<txt::FontWeight>(encoded[tsFontWeightIndex]);
425  }
426 
427  if (mask & tsFontStyleMask) {
428  style.font_style = static_cast<txt::FontStyle>(encoded[tsFontStyleIndex]);
429  }
430 
431  if (mask & tsFontSizeMask) {
432  style.font_size = fontSize;
433  }
434 
435  if (mask & tsLetterSpacingMask) {
436  style.letter_spacing = letterSpacing;
437  }
438 
439  if (mask & tsWordSpacingMask) {
440  style.word_spacing = wordSpacing;
441  }
442  }
443 
444  if (mask & tsHeightMask) {
445  style.height = height;
446  style.has_height_override = true;
447  }
448 
449  if (mask & tsLocaleMask) {
450  style.locale = locale;
451  }
452 
453  if (mask & tsBackgroundMask) {
454  Paint background(background_objects, background_data);
455  if (background.paint()) {
456  style.has_background = true;
457  style.background = *background.paint();
458  }
459  }
460 
461  if (mask & tsForegroundMask) {
462  Paint foreground(foreground_objects, foreground_data);
463  if (foreground.paint()) {
464  style.has_foreground = true;
465  style.foreground = *foreground.paint();
466  }
467  }
468 
469  if (mask & tsTextShadowsMask) {
470  decodeTextShadows(shadows_data, style.text_shadows);
471  }
472 
473  if (mask & tsFontFamilyMask) {
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 & tsFontFeaturesMask) {
481  decodeFontFeatures(font_features_data, style.font_features);
482  }
483 
484  m_paragraphBuilder->PushStyle(style);
485 }
bool has_background
Definition: text_style.h:57
FontStyle
Definition: font_style.h:22
std::vector< TextShadow > text_shadows
Definition: text_style.h:63
TextDecorationStyle
#define FML_DCHECK(condition)
Definition: logging.h:86
bool has_height_override
Definition: text_style.h:55
double height
Definition: text_style.h:54
double decoration_thickness_multiplier
Definition: text_style.h:43
FontStyle font_style
Definition: text_style.h:45
FontWeight
Definition: font_weight.h:22
double letter_spacing
Definition: text_style.h:52
std::string locale
Definition: text_style.h:56
double font_size
Definition: text_style.h:51
void decodeTextShadows(Dart_Handle shadows_data, std::vector< txt::TextShadow > &decoded_shadows)
FontFeatures font_features
Definition: text_style.h:64
double word_spacing
Definition: text_style.h:53
bool half_leading
Definition: text_style.h:47
SkColor decoration_color
Definition: text_style.h:40
TextDecorationStyle decoration_style
Definition: text_style.h:41
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
bool has_foreground
Definition: text_style.h:59
SkPaint foreground
Definition: text_style.h:60
int32_t height
void decodeFontFeatures(Dart_Handle font_features_data, txt::FontFeatures &font_features)
FontWeight font_weight
Definition: text_style.h:44
SkPaint background
Definition: text_style.h:58
TextDecoration

◆ RegisterNatives()

void flutter::ParagraphBuilder::RegisterNatives ( tonic::DartLibraryNatives natives)
static

Definition at line 154 of file paragraph_builder.cc.

References DART_REGISTER_NATIVE, FOR_EACH_BINDING, and flutter::ParagraphBuilder_constructor().

Referenced by flutter::DartUI::InitForGlobal().

154  {
155  natives->Register(
156  {{"ParagraphBuilder_constructor", ParagraphBuilder_constructor, 9, true},
158 }
#define FOR_EACH_BINDING(V)
void Register(std::initializer_list< Entry > entries)
#define DART_REGISTER_NATIVE(CLASS, METHOD)
static void ParagraphBuilder_constructor(Dart_NativeArguments args)

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