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,
  kWrapperInfoIndex,
  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 495 of file paragraph_builder.cc.

499  {
500  txt::PlaceholderRun placeholder_run(
501  width, height, static_cast<txt::PlaceholderAlignment>(alignment),
502  static_cast<txt::TextBaseline>(baseline), baseline_offset);
503 
504  m_paragraphBuilder->AddPlaceholder(placeholder_run);
505 
506  return Dart_Null();
507 }
int32_t height
int32_t width

◆ addText()

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

Definition at line 475 of file paragraph_builder.cc.

References tonic::ToDart().

475  {
476  if (text.empty()) {
477  return Dart_Null();
478  }
479 
480  // Use ICU to validate the UTF-16 input. Calling u_strToUTF8 with a null
481  // output buffer will return U_BUFFER_OVERFLOW_ERROR if the input is well
482  // formed.
483  const UChar* text_ptr = reinterpret_cast<const UChar*>(text.data());
484  UErrorCode error_code = U_ZERO_ERROR;
485  u_strToUTF8(nullptr, 0, nullptr, text_ptr, text.size(), &error_code);
486  if (error_code != U_BUFFER_OVERFLOW_ERROR) {
487  return tonic::ToDart("string is not well-formed UTF-16");
488  }
489 
490  m_paragraphBuilder->AddText(text);
491 
492  return Dart_Null();
493 }
Dart_Handle ToDart(const T &object)

◆ build()

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

Definition at line 509 of file paragraph_builder.cc.

References flutter::Paragraph::Create().

509  {
510  Paragraph::Create(paragraph_handle, m_paragraphBuilder->Build());
511 }
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 156 of file paragraph_builder.cc.

References height.

Referenced by flutter::ParagraphBuilder_constructor().

164  {
165  return fml::MakeRefCounted<ParagraphBuilder>(encoded, strutData, fontFamily,
166  strutFontFamilies, fontSize,
167  height, ellipsis, locale);
168 }
int32_t height

◆ pop()

void flutter::ParagraphBuilder::pop ( )

Definition at line 471 of file paragraph_builder.cc.

471  {
472  m_paragraphBuilder->Pop();
473 }

◆ 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 353 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::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.

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

◆ RegisterNatives()

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

Definition at line 150 of file paragraph_builder.cc.

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

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

150  {
151  natives->Register(
152  {{"ParagraphBuilder_constructor", ParagraphBuilder_constructor, 9, true},
154 }
#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: