Flutter Engine
txt Namespace Reference

Classes

class  AssetFontManager
 
class  DynamicFontManager
 
class  FakeProvider
 
class  FontAssetProvider
 
class  FontCollection
 
class  FontCollectionTest
 
class  FontFeatures
 
class  FontSkia
 
class  LineMetrics
 
class  PaintRecord
 
class  Paragraph
 
class  ParagraphBuilder
 
class  ParagraphBuilderSkia
 
class  ParagraphBuilderTxt
 
class  ParagraphFixture
 
class  ParagraphSkia
 
class  ParagraphStyle
 
class  ParagraphTxt
 
class  PlaceholderRun
 
class  PlatformFuchsiaTest
 
class  RenderTest
 
class  RunMetrics
 
class  StyledRuns
 
class  TestFontManager
 
class  TextShadow
 
class  TextStyle
 
class  TxtFallbackFontProvider
 
class  TypefaceFontAssetProvider
 
class  TypefaceFontStyleSet
 

Typedefs

using GlyphID = uint32_t
 
using ParagraphTest = RenderTest
 

Enumerations

enum  FontStyle {
  FontStyle::normal,
  FontStyle::italic
}
 
enum  FontWeight {
  FontWeight::w100,
  FontWeight::w200,
  FontWeight::w300,
  FontWeight::w400,
  FontWeight::w500,
  FontWeight::w600,
  FontWeight::w700,
  FontWeight::w800,
  FontWeight::w900
}
 
enum  TextAlign {
  TextAlign::left,
  TextAlign::right,
  TextAlign::center,
  TextAlign::justify,
  TextAlign::start,
  TextAlign::end
}
 
enum  TextDirection {
  TextDirection::rtl,
  TextDirection::ltr
}
 
enum  TextHeightBehavior {
  kAll = 0x0,
  kDisableFirstAscent = 0x1,
  kDisableLastDescent = 0x2,
  kDisableAll = 0x1 | 0x2
}
 
enum  PlaceholderAlignment {
  PlaceholderAlignment::kBaseline,
  PlaceholderAlignment::kAboveBaseline,
  PlaceholderAlignment::kBelowBaseline,
  PlaceholderAlignment::kTop,
  PlaceholderAlignment::kBottom,
  PlaceholderAlignment::kMiddle
}
 Where to vertically align the placeholder relative to the surrounding text. More...
 
enum  TextBaseline {
  kAlphabetic,
  kIdeographic
}
 
enum  TextDecoration {
  kNone = 0x0,
  kUnderline = 0x1,
  kOverline = 0x2,
  kLineThrough = 0x4
}
 
enum  TextDecorationStyle {
  kSolid,
  kDouble,
  kDotted,
  kDashed,
  kWavy
}
 

Functions

static void BM_PaintRecordInit (benchmark::State &state)
 
 BENCHMARK (BM_PaintRecordInit)
 
 BENCHMARK_F (ParagraphFixture, ShortLayout)(benchmark
 
 BENCHMARK_F (ParagraphFixture, LongLayout)(benchmark
 
 BENCHMARK_F (ParagraphFixture, JustifyLayout)(benchmark
 
 BENCHMARK_F (ParagraphFixture, ManyStylesLayout)(benchmark
 
 BENCHMARK_DEFINE_F (ParagraphFixture, TextBigO)(benchmark
 
 RangeMultiplier (4) -> Range(1<< 6, 1<< 14) ->Complexity(benchmark::oN)
 
 BENCHMARK_DEFINE_F (ParagraphFixture, StylesBigO)(benchmark
 
 BENCHMARK_F (ParagraphFixture, PaintSimple)(benchmark
 
 BENCHMARK_F (ParagraphFixture, PaintLarge)(benchmark
 
 BENCHMARK_F (ParagraphFixture, PaintDecoration)(benchmark
 
 BENCHMARK_DEFINE_F (ParagraphFixture, MinikinDoLayout)(benchmark
 
 BENCHMARK_DEFINE_F (ParagraphFixture, AddStyleRun)(benchmark
 
 BENCHMARK_DEFINE_F (ParagraphFixture, SkTextBlobAlloc)(benchmark
 
static void BM_ParagraphBuilderConstruction (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderConstruction)
 
static void BM_ParagraphBuilderPushStyle (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderPushStyle)
 
static void BM_ParagraphBuilderPushPop (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderPushPop)
 
static void BM_ParagraphBuilderAddTextString (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderAddTextString)
 
static void BM_ParagraphBuilderAddTextChar (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderAddTextChar)
 
static void BM_ParagraphBuilderAddTextU16stringShort (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderAddTextU16stringShort)
 
static void BM_ParagraphBuilderAddTextU16stringLong (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderAddTextU16stringLong)
 
static void BM_ParagraphBuilderShortParagraphConstruct (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderShortParagraphConstruct)
 
static void BM_ParagraphBuilderLongParagraphConstruct (benchmark::State &state)
 
 BENCHMARK (BM_ParagraphBuilderLongParagraphConstruct)
 
static void FontSkia_SetSkiaFont (sk_sp< SkTypeface > typeface, SkFont *skFont, const minikin::MinikinPaint &paint)
 
std::vector< std::string > GetDefaultFontFamilies ()
 
sk_sp< SkFontMgr > GetDefaultFontManager (uint32_t font_initialization_data)
 
 TEST (FontCollectionTest, CheckSkTypefacesSorting)
 
 TEST_F (ParagraphTest, SimpleParagraph)
 
 TEST_F (ParagraphTest, SimpleParagraphSmall)
 
 TEST_F (ParagraphTest, GetGlyphPositionAtCoordinateSegfault)
 
 TEST_F (ParagraphTest, GetGlyphPositionAtCoordinateMultiRun)
 
 TEST_F (ParagraphTest, LineMetricsParagraph1)
 
 TEST_F (ParagraphTest, DISABLE_ON_MAC(LineMetricsParagraph2))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderBaselineParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderAboveBaselineParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderBelowBaselineParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderBottomParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderTopParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderMiddleParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_MAC(DISABLE_ON_WINDOWS(InlinePlaceholderIdeographicBaselineParagraph)))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderBreakParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderGetRectsParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderLongestLine))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(InlinePlaceholderIntrinsicWidth))
 
 TEST_F (ParagraphTest, SimpleRedParagraph)
 
 TEST_F (ParagraphTest, RainbowParagraph)
 
 TEST_F (ParagraphTest, DefaultStyleParagraph)
 
 TEST_F (ParagraphTest, BoldParagraph)
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(HeightOverrideParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(HeightOverrideHalfLeadingTextStyle))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(MixedTextHeightBehaviorSameLine))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(MixedTextHeightBehaviorSameLineWithZeroHeight))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(HeightOverrideHalfLeadingStrut))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(ZeroHeightHalfLeadingStrutForceHeight))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(LeftAlignParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(LeftAlignRTLParagraphHitTest))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(RightAlignParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(CenterAlignParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(JustifyAlignParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(JustifyRTL))
 
 TEST_F (ParagraphTest, LINUX_ONLY(JustifyRTLNewLine))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(JustifyPlaceholder))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(LeadingSpaceRTL))
 
 TEST_F (ParagraphTest, DecorationsParagraph)
 
 TEST_F (ParagraphTest, WavyDecorationParagraph)
 
 TEST_F (ParagraphTest, ItalicsParagraph)
 
 TEST_F (ParagraphTest, ChineseParagraph)
 
 TEST_F (ParagraphTest, DISABLED_ArabicParagraph)
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(ArabicRectsParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(ArabicRectsLTRLeftAlignParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(ArabicRectsLTRRightAlignParagraph))
 
 TEST_F (ParagraphTest, GetGlyphPositionAtCoordinateParagraph)
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeParagraph))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeTight))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeIncludeLineSpacingMiddle))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeIncludeLineSpacingTop))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeIncludeLineSpacingBottom))
 
 TEST_F (ParagraphTest, GetRectsForRangeIncludeCombiningCharacter)
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeCenterParagraph))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineLeftAlign))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineRightAlign))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeCenterParagraphNewlineCentered))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineRTLLeftAlign))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeParagraphNewlineRTLRightAlign))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeCenterParagraphNewlineRTLCentered))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeCenterMultiLineParagraph))
 
 TEST_F (ParagraphTest, LINUX_ONLY(GetRectsForRangeStrut))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(GetRectsForRangeStrutFallback))
 
SkRect GetCoordinatesForGlyphPosition (txt::Paragraph &paragraph, size_t pos)
 
 TEST_F (ParagraphTest, GetWordBoundaryParagraph)
 
 TEST_F (ParagraphTest, SpacingParagraph)
 
 TEST_F (ParagraphTest, LongWordParagraph)
 
 TEST_F (ParagraphTest, LINUX_ONLY(KernScaleParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(NewlineParagraph))
 
 TEST_F (ParagraphTest, LINUX_ONLY(EmojiParagraph))
 
 TEST_F (ParagraphTest, LINUX_ONLY(EmojiMultiLineRectsParagraph))
 
 TEST_F (ParagraphTest, LINUX_ONLY(LigatureCharacters))
 
 TEST_F (ParagraphTest, HyphenBreakParagraph)
 
 TEST_F (ParagraphTest, RepeatLayoutParagraph)
 
 TEST_F (ParagraphTest, Ellipsize)
 
 TEST_F (ParagraphTest, UnderlineShiftParagraph)
 
 TEST_F (ParagraphTest, SimpleShadow)
 
 TEST_F (ParagraphTest, ComplexShadow)
 
 TEST_F (ParagraphTest, DISABLE_ON_MAC(BaselineParagraph))
 
 TEST_F (ParagraphTest, FontFallbackParagraph)
 
 TEST_F (ParagraphTest, LINUX_ONLY(StrutParagraph1))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(StrutParagraph2))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(StrutParagraph3))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(StrutForceParagraph))
 
 TEST_F (ParagraphTest, DISABLE_ON_WINDOWS(StrutDefaultParagraph))
 
 TEST_F (ParagraphTest, FontFeaturesParagraph)
 
 TEST_F (ParagraphTest, KhmerLineBreaker)
 
 TEST_F (ParagraphTest, TextHeightBehaviorRectsParagraph)
 
 TEST_F (ParagraphTest, MixedTextHeightBehaviorRectsParagraph)
 
 TEST_F (PlatformFuchsiaTest, GetDefaultFontManager)
 
 TEST_F (PlatformFuchsiaTest, GetDefaultFontManagerFail)
 
const std::string & GetFontDir ()
 
void SetFontDir (const std::string &dir)
 
const fml::CommandLineGetCommandLineForProcess ()
 
void SetCommandLine (fml::CommandLine cmd)
 
void RegisterFontsFromPath (TypefaceFontAssetProvider &font_provider, std::string directory_path)
 
std::shared_ptr< FontCollectionGetTestFontCollection ()
 
std::unique_ptr< ParagraphTxtBuildParagraph (txt::ParagraphBuilderTxt &builder)
 

Variables

static const float kDoubleDecorationSpacing = 3.0f
 
const int objReplacementChar = 0xFFFC
 
const int replacementChar = 0xFFFD
 
static std::string gFontDir
 
static fml::CommandLine gCommandLine
 

Typedef Documentation

◆ GlyphID

using txt::GlyphID = typedef uint32_t

Definition at line 44 of file paragraph_txt.h.

◆ ParagraphTest

using txt::ParagraphTest = typedef RenderTest

Definition at line 37 of file paragraph_unittests.cc.

Enumeration Type Documentation

◆ FontStyle

enum txt::FontStyle
strong
Enumerator
normal 
italic 

Definition at line 22 of file font_style.h.

◆ FontWeight

enum txt::FontWeight
strong
Enumerator
w100 
w200 
w300 
w400 
w500 
w600 
w700 
w800 
w900 

Definition at line 22 of file font_weight.h.

22  {
23  w100, // Thin
24  w200, // Extra-Light
25  w300, // Light
26  w400, // Normal/Regular
27  w500, // Medium
28  w600, // Semi-bold
29  w700, // Bold
30  w800, // Extra-Bold
31  w900, // Black
32 };

◆ PlaceholderAlignment

Where to vertically align the placeholder relative to the surrounding text.

Enumerator
kBaseline 

Match the baseline of the placeholder with the baseline.

kAboveBaseline 

Align the bottom edge of the placeholder with the baseline such that the placeholder sits on top of the baseline.

kBelowBaseline 

Align the top edge of the placeholder with the baseline specified in such that the placeholder hangs below the baseline.

kTop 

Align the top edge of the placeholder with the top edge of the font. When the placeholder is very tall, the extra space will hang from the top and extend through the bottom of the line.

kBottom 

Align the bottom edge of the placeholder with the top edge of the font. When the placeholder is very tall, the extra space will rise from the bottom and extend through the top of the line.

kMiddle 

Align the middle of the placeholder with the middle of the text. When the placeholder is very tall, the extra space will grow equally from the top and bottom of the line.

Definition at line 25 of file placeholder_run.h.

25  {
26  /// Match the baseline of the placeholder with the baseline.
27  kBaseline,
28 
29  /// Align the bottom edge of the placeholder with the baseline such that the
30  /// placeholder sits on top of the baseline.
32 
33  /// Align the top edge of the placeholder with the baseline specified in
34  /// such that the placeholder hangs below the baseline.
36 
37  /// Align the top edge of the placeholder with the top edge of the font.
38  /// When the placeholder is very tall, the extra space will hang from
39  /// the top and extend through the bottom of the line.
40  kTop,
41 
42  /// Align the bottom edge of the placeholder with the top edge of the font.
43  /// When the placeholder is very tall, the extra space will rise from
44  /// the bottom and extend through the top of the line.
45  kBottom,
46 
47  /// Align the middle of the placeholder with the middle of the text. When the
48  /// placeholder is very tall, the extra space will grow equally from
49  /// the top and bottom of the line.
50  kMiddle,
51 };
Match the baseline of the placeholder with the baseline.

◆ TextAlign

enum txt::TextAlign
strong
Enumerator
left 
right 
center 
justify 
start 
end 

Definition at line 30 of file paragraph_style.h.

◆ TextBaseline

Enumerator
kAlphabetic 
kIdeographic 

Definition at line 22 of file text_baseline.h.

◆ TextDecoration

Enumerator
kNone 
kUnderline 
kOverline 
kLineThrough 

Definition at line 24 of file text_decoration.h.

24  {
25  kNone = 0x0,
26  kUnderline = 0x1,
27  kOverline = 0x2,
28  kLineThrough = 0x4,
29 };

◆ TextDecorationStyle

Enumerator
kSolid 
kDouble 
kDotted 
kDashed 
kWavy 

Definition at line 31 of file text_decoration.h.

◆ TextDirection

enum txt::TextDirection
strong
Enumerator
rtl 
ltr 

Definition at line 39 of file paragraph_style.h.

◆ TextHeightBehavior

Enumerator
kAll 
kDisableFirstAscent 
kDisableLastDescent 
kDisableAll 

Definition at line 58 of file paragraph_style.h.

Function Documentation

◆ BENCHMARK() [1/10]

txt::BENCHMARK ( BM_ParagraphBuilderConstruction  )

◆ BENCHMARK() [2/10]

◆ BENCHMARK() [3/10]

txt::BENCHMARK ( BM_ParagraphBuilderPushStyle  )

◆ BENCHMARK() [4/10]

txt::BENCHMARK ( BM_ParagraphBuilderPushPop  )

◆ BENCHMARK() [5/10]

txt::BENCHMARK ( BM_ParagraphBuilderAddTextString  )

◆ BENCHMARK() [6/10]

txt::BENCHMARK ( BM_ParagraphBuilderAddTextChar  )

◆ BENCHMARK() [7/10]

◆ BENCHMARK() [8/10]

◆ BENCHMARK() [9/10]

◆ BENCHMARK() [10/10]

◆ BENCHMARK_DEFINE_F() [1/5]

txt::BENCHMARK_DEFINE_F ( ParagraphFixture  ,
TextBigO   
)

Definition at line 187 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphStyle::font_family, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), state, and text.

187  {
188  std::vector<uint16_t> text;
189  for (uint16_t i = 0; i < state.range(0); ++i) {
190  text.push_back(i % 5 == 0 ? ' ' : i);
191  }
192  std::u16string u16_text(text.data(), text.data() + text.size());
193 
194  txt::ParagraphStyle paragraph_style;
195  paragraph_style.font_family = "Roboto";
196 
197  txt::TextStyle text_style;
198  text_style.font_families = std::vector<std::string>(1, "Roboto");
199  text_style.color = SK_ColorBLACK;
200 
201  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
202 
203  builder.PushStyle(text_style);
204  builder.AddText(u16_text);
205  builder.Pop();
206  auto paragraph = BuildParagraph(builder);
207  while (state.KeepRunning()) {
208  paragraph->SetDirty();
209  paragraph->Layout(300);
210  }
211  state.SetComplexityN(state.range(0));
212 }
std::string font_family
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_DEFINE_F() [2/5]

txt::BENCHMARK_DEFINE_F ( ParagraphFixture  ,
StylesBigO   
)

Definition at line 218 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphBuilderTxt::PushStyle(), state, and text.

218  {
219  const char* text = "vry shrt ";
220  auto icu_text = icu::UnicodeString::fromUTF8(text);
221  std::u16string u16_text(icu_text.getBuffer(),
222  icu_text.getBuffer() + icu_text.length());
223 
224  txt::ParagraphStyle paragraph_style;
225 
226  txt::TextStyle text_style;
227  text_style.font_families = std::vector<std::string>(1, "Roboto");
228  text_style.color = SK_ColorBLACK;
229 
230  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
231 
232  for (int i = 0; i < state.range(0); ++i) {
233  builder.PushStyle(text_style);
234  builder.AddText(u16_text);
235  }
236  auto paragraph = BuildParagraph(builder);
237  while (state.KeepRunning()) {
238  paragraph->SetDirty();
239  paragraph->Layout(300);
240  }
241  state.SetComplexityN(state.range(0));
242 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_DEFINE_F() [3/5]

txt::BENCHMARK_DEFINE_F ( ParagraphFixture  ,
MinikinDoLayout   
)

Definition at line 362 of file paragraph_benchmarks.cc.

References minikin::Layout::doLayout(), txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::TextStyle::font_size, txt::TextStyle::letter_spacing, state, text, and txt::TextStyle::word_spacing.

362  {
363  std::vector<uint16_t> text;
364  for (uint16_t i = 0; i < 16000 * 2; ++i) {
365  text.push_back(i % 5 == 0 ? ' ' : i);
366  }
367  minikin::FontStyle font;
368  txt::TextStyle text_style;
369  text_style.font_families = std::vector<std::string>(1, "Roboto");
370  minikin::MinikinPaint paint;
371 
372  font = minikin::FontStyle(4, false);
373  paint.size = text_style.font_size;
374  paint.letterSpacing = text_style.letter_spacing;
375  paint.wordSpacing = text_style.word_spacing;
376 
377  auto collection = font_collection_->GetMinikinFontCollectionForFamilies(
378  text_style.font_families, "en-US");
379 
380  while (state.KeepRunning()) {
381  minikin::Layout layout;
382  layout.doLayout(text.data(), 0, state.range(0), state.range(0), 0, font,
383  paint, collection);
384  }
385  state.SetComplexityN(state.range(0));
386 }
FontStyle
Definition: font_style.h:22
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
std::vector< std::string > font_families
Definition: text_style.h:50
void doLayout(const uint16_t *buf, size_t start, size_t count, size_t bufSize, bool isRtl, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr< FontCollection > &collection)
std::u16string text
AtkStateType state

◆ BENCHMARK_DEFINE_F() [4/5]

txt::BENCHMARK_DEFINE_F ( ParagraphFixture  ,
AddStyleRun   
)

Definition at line 392 of file paragraph_benchmarks.cc.

References minikin::LineBreaker::addStyleRun(), minikin::LineBreaker::buffer(), txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::TextStyle::font_size, txt::TextStyle::letter_spacing, minikin::LineBreaker::resize(), minikin::LineBreaker::setLocale(), minikin::LineBreaker::setText(), state, text, and txt::TextStyle::word_spacing.

392  {
393  std::vector<uint16_t> text;
394  for (uint16_t i = 0; i < 16000 * 2; ++i) {
395  text.push_back(i % 5 == 0 ? ' ' : i);
396  }
397  minikin::FontStyle font;
398  txt::TextStyle text_style;
399  text_style.font_families = std::vector<std::string>(1, "Roboto");
400  minikin::MinikinPaint paint;
401 
402  font = minikin::FontStyle(4, false);
403  paint.size = text_style.font_size;
404  paint.letterSpacing = text_style.letter_spacing;
405  paint.wordSpacing = text_style.word_spacing;
406 
407  minikin::LineBreaker breaker;
408  breaker.setLocale();
409  breaker.resize(text.size());
410  memcpy(breaker.buffer(), text.data(), text.size() * sizeof(text[0]));
411  breaker.setText();
412 
413  while (state.KeepRunning()) {
414  for (int i = 0; i < 20; ++i) {
415  breaker.addStyleRun(&paint,
416  font_collection_->GetMinikinFontCollectionForFamilies(
417  std::vector<std::string>(1, "Roboto"), "en-US"),
418  font, state.range(0) / 20 * i,
419  state.range(0) / 20 * (i + 1), false);
420  }
421  }
422  state.SetComplexityN(state.range(0));
423 }
FontStyle
Definition: font_style.h:22
double letter_spacing
Definition: text_style.h:52
void resize(size_t size)
Definition: LineBreaker.h:105
uint16_t * buffer()
Definition: LineBreaker.h:112
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
float addStyleRun(MinikinPaint *paint, const std::shared_ptr< FontCollection > &typeface, FontStyle style, size_t start, size_t end, bool isRtl)
std::vector< std::string > font_families
Definition: text_style.h:50
std::u16string text
AtkStateType state

◆ BENCHMARK_DEFINE_F() [5/5]

txt::BENCHMARK_DEFINE_F ( ParagraphFixture  ,
SkTextBlobAlloc   
)

Definition at line 429 of file paragraph_benchmarks.cc.

References state.

429  {
430  SkFont font;
431  font.setEdging(SkFont::Edging::kAntiAlias);
432  font.setSize(14);
433  font.setEmbolden(false);
434 
435  while (state.KeepRunning()) {
436  SkTextBlobBuilder builder;
437  builder.allocRunPos(font, state.range(0));
438  }
439  state.SetComplexityN(state.range(0));
440 }
AtkStateType state

◆ BENCHMARK_F() [1/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
ShortLayout   
)

Definition at line 58 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), state, and text.

Referenced by flutter::testing::DartNativeBenchmarks::TearDown().

58  {
59  const char* text = "Hello World";
60  auto icu_text = icu::UnicodeString::fromUTF8(text);
61  std::u16string u16_text(icu_text.getBuffer(),
62  icu_text.getBuffer() + icu_text.length());
63 
64  txt::ParagraphStyle paragraph_style;
65 
66  txt::TextStyle text_style;
67  text_style.font_families = std::vector<std::string>(1, "Roboto");
68  text_style.color = SK_ColorBLACK;
69  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
70 
71  builder.PushStyle(text_style);
72  builder.AddText(u16_text);
73  builder.Pop();
74  auto paragraph = BuildParagraph(builder);
75  while (state.KeepRunning()) {
76  paragraph->SetDirty();
77  paragraph->Layout(300);
78  }
79 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_F() [2/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
LongLayout   
)

Definition at line 81 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), state, and text.

81  {
82  const char* text =
83  "This is a very long sentence to test if the text will properly wrap "
84  "around and go to the next line. Sometimes, short sentence. Longer "
85  "sentences are okay too because they are necessary. Very short. "
86  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
87  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
88  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
89  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
90  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
91  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
92  "mollit anim id est laborum. "
93  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
94  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
95  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
96  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
97  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
98  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
99  "mollit anim id est laborum.";
100  auto icu_text = icu::UnicodeString::fromUTF8(text);
101  std::u16string u16_text(icu_text.getBuffer(),
102  icu_text.getBuffer() + icu_text.length());
103 
104  txt::ParagraphStyle paragraph_style;
105 
106  txt::TextStyle text_style;
107  text_style.font_families = std::vector<std::string>(1, "Roboto");
108  text_style.color = SK_ColorBLACK;
109 
110  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
111 
112  builder.PushStyle(text_style);
113  builder.AddText(u16_text);
114  builder.Pop();
115  auto paragraph = BuildParagraph(builder);
116  while (state.KeepRunning()) {
117  paragraph->SetDirty();
118  paragraph->Layout(300);
119  }
120 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_F() [3/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
JustifyLayout   
)

Definition at line 122 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, justify, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), state, text, and txt::ParagraphStyle::text_align.

122  {
123  const char* text =
124  "This is a very long sentence to test if the text will properly wrap "
125  "around and go to the next line. Sometimes, short sentence. Longer "
126  "sentences are okay too because they are necessary. Very short. "
127  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
128  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
129  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
130  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
131  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
132  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
133  "mollit anim id est laborum. "
134  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
135  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
136  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
137  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
138  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
139  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
140  "mollit anim id est laborum.";
141  auto icu_text = icu::UnicodeString::fromUTF8(text);
142  std::u16string u16_text(icu_text.getBuffer(),
143  icu_text.getBuffer() + icu_text.length());
144 
145  txt::ParagraphStyle paragraph_style;
146  paragraph_style.text_align = TextAlign::justify;
147 
148  txt::TextStyle text_style;
149  text_style.font_families = std::vector<std::string>(1, "Roboto");
150  text_style.color = SK_ColorBLACK;
151 
152  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
153 
154  builder.PushStyle(text_style);
155  builder.AddText(u16_text);
156  builder.Pop();
157  auto paragraph = BuildParagraph(builder);
158  while (state.KeepRunning()) {
159  paragraph->SetDirty();
160  paragraph->Layout(300);
161  }
162 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_F() [4/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
ManyStylesLayout   
)

Definition at line 164 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphBuilderTxt::PushStyle(), state, and text.

164  {
165  const char* text = "-";
166  auto icu_text = icu::UnicodeString::fromUTF8(text);
167  std::u16string u16_text(icu_text.getBuffer(),
168  icu_text.getBuffer() + icu_text.length());
169 
170  txt::ParagraphStyle paragraph_style;
171 
172  txt::TextStyle text_style;
173  text_style.font_families = std::vector<std::string>(1, "Roboto");
174  text_style.color = SK_ColorBLACK;
175  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
176  for (int i = 0; i < 1000; ++i) {
177  builder.PushStyle(text_style);
178  builder.AddText(u16_text);
179  }
180  auto paragraph = BuildParagraph(builder);
181  while (state.KeepRunning()) {
182  paragraph->SetDirty();
183  paragraph->Layout(300);
184  }
185 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_F() [5/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
PaintSimple   
)

Definition at line 248 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::ParagraphFixture::canvas_, txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphBuilderTxt::PushStyle(), state, and text.

248  {
249  const char* text = "Hello world! This is a simple sentence to test drawing.";
250  auto icu_text = icu::UnicodeString::fromUTF8(text);
251  std::u16string u16_text(icu_text.getBuffer(),
252  icu_text.getBuffer() + icu_text.length());
253 
254  txt::ParagraphStyle paragraph_style;
255 
256  txt::TextStyle text_style;
257  text_style.font_families = std::vector<std::string>(1, "Roboto");
258  text_style.color = SK_ColorBLACK;
259  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
260  builder.PushStyle(text_style);
261  builder.AddText(u16_text);
262  auto paragraph = BuildParagraph(builder);
263  paragraph->Layout(300);
264 
265  int offset = 0;
266  while (state.KeepRunning()) {
267  paragraph->Paint(canvas_.get(), offset % 700, 10);
268  offset++;
269  }
270 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_F() [6/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
PaintLarge   
)

Definition at line 272 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::ParagraphFixture::canvas_, txt::TextStyle::color, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, txt::ParagraphBuilderTxt::PushStyle(), state, and text.

272  {
273  const char* text =
274  "Hello world! This is a simple sentence to test drawing. Hello world! "
275  "This is a simple sentence to test drawing. Hello world! This is a "
276  "simple sentence to test drawing.Hello world! This is a simple sentence "
277  "to test drawing. Hello world! "
278  "This is a simple sentence to test drawing. Hello world! This is a "
279  "simple sentence to test drawing.Hello world! This is a simple sentence "
280  "to test drawing. Hello world! "
281  "This is a simple sentence to test drawing. Hello world! This is a "
282  "simple sentence to test drawing.Hello world! This is a simple sentence "
283  "to test drawing. Hello world! "
284  "This is a simple sentence to test drawing. Hello world! This is a "
285  "simple sentence to test drawing.Hello world! This is a simple sentence "
286  "to test drawing. Hello world! "
287  "This is a simple sentence to test drawing. Hello world! This is a "
288  "simple sentence to test drawing.Hello world! This is a simple sentence "
289  "to test drawing. Hello world! "
290  "This is a simple sentence to test drawing. Hello world! This is a "
291  "simple sentence to test drawing.";
292  auto icu_text = icu::UnicodeString::fromUTF8(text);
293  std::u16string u16_text(icu_text.getBuffer(),
294  icu_text.getBuffer() + icu_text.length());
295 
296  txt::ParagraphStyle paragraph_style;
297 
298  txt::TextStyle text_style;
299  text_style.font_families = std::vector<std::string>(1, "Roboto");
300  text_style.color = SK_ColorBLACK;
301  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
302  builder.PushStyle(text_style);
303  builder.AddText(u16_text);
304  auto paragraph = BuildParagraph(builder);
305  paragraph->Layout(300);
306 
307  int offset = 0;
308  while (state.KeepRunning()) {
309  paragraph->Paint(canvas_.get(), offset % 700, 10);
310  offset++;
311  }
312 }
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BENCHMARK_F() [7/7]

txt::BENCHMARK_F ( ParagraphFixture  ,
PaintDecoration   
)

Definition at line 314 of file paragraph_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::ParagraphFixture::canvas_, txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_style, txt::ParagraphFixture::font_collection_, txt::TextStyle::font_families, kDotted, kLineThrough, kOverline, kSolid, kUnderline, kWavy, txt::ParagraphBuilderTxt::PushStyle(), state, and text.

314  {
315  const char* text =
316  "Hello world! This is a simple sentence to test drawing. Hello world! "
317  "This is a simple sentence to test drawing.";
318  auto icu_text = icu::UnicodeString::fromUTF8(text);
319  std::u16string u16_text(icu_text.getBuffer(),
320  icu_text.getBuffer() + icu_text.length());
321 
322  txt::ParagraphStyle paragraph_style;
323 
324  txt::TextStyle text_style;
325  text_style.font_families = std::vector<std::string>(1, "Roboto");
330  text_style.color = SK_ColorBLACK;
331 
332  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection_);
333 
334  builder.PushStyle(text_style);
335  builder.AddText(u16_text);
336 
338  builder.PushStyle(text_style);
339  builder.AddText(u16_text);
340 
342  builder.PushStyle(text_style);
343  builder.AddText(u16_text);
344 
345  auto paragraph = BuildParagraph(builder);
346  paragraph->Layout(300);
347 
348  int offset = 0;
349  while (state.KeepRunning()) {
350  paragraph->Paint(canvas_.get(), offset % 700, 10);
351  offset++;
352  }
353 }
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
TextDecorationStyle
Definition: ax_enums.h:995
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text
AtkStateType state

◆ BM_PaintRecordInit()

static void txt::BM_PaintRecordInit ( benchmark::State &  state)
static

Definition at line 26 of file paint_record_benchmarks.cc.

References BENCHMARK(), and txt::TextStyle::font_families.

26  {
27  TextStyle style;
28  style.font_families = std::vector<std::string>(1, "Roboto");
29 
30  SkFont font;
31  font.setEdging(SkFont::Edging::kAntiAlias);
32  font.setSize(14);
33  font.setEmbolden(false);
34 
35  SkTextBlobBuilder builder;
36  builder.allocRunPos(font, 100);
37  auto text_blob = builder.make();
38 
39  while (state.KeepRunning()) {
40  PaintRecord PaintRecord(style, text_blob, SkFontMetrics(), 0, 0, 0, false);
41  }
42 }
AtkStateType state

◆ BM_ParagraphBuilderAddTextChar()

static void txt::BM_ParagraphBuilderAddTextChar ( benchmark::State &  state)
static

Definition at line 79 of file paragraph_builder_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BENCHMARK(), GetTestFontCollection(), and text.

79  {
80  std::u16string text = u"Hello World";
81 
82  txt::ParagraphStyle paragraph_style;
83  auto font_collection = GetTestFontCollection();
84  while (state.KeepRunning()) {
85  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
86  builder.AddText(text);
87  }
88 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::u16string text
AtkStateType state

◆ BM_ParagraphBuilderAddTextString()

static void txt::BM_ParagraphBuilderAddTextString ( benchmark::State &  state)
static

Definition at line 65 of file paragraph_builder_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BENCHMARK(), GetTestFontCollection(), and text.

65  {
66  std::u16string text = u"Hello World";
67 
68  auto font_collection = GetTestFontCollection();
69 
70  txt::ParagraphStyle paragraph_style;
71 
72  while (state.KeepRunning()) {
73  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
74  builder.AddText(text);
75  }
76 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::u16string text
AtkStateType state

◆ BM_ParagraphBuilderAddTextU16stringLong()

static void txt::BM_ParagraphBuilderAddTextU16stringLong ( benchmark::State &  state)
static

Definition at line 106 of file paragraph_builder_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BENCHMARK(), GetTestFontCollection(), and text.

106  {
107  const char* text =
108  "This is a very long sentence to test if the text will properly wrap "
109  "around and go to the next line. Sometimes, short sentence. Longer "
110  "sentences are okay too because they are necessary. Very short. "
111  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
112  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
113  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
114  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
115  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
116  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
117  "mollit anim id est laborum. "
118  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
119  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
120  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
121  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
122  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
123  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
124  "mollit anim id est laborum.";
125  auto icu_text = icu::UnicodeString::fromUTF8(text);
126  std::u16string u16_text(icu_text.getBuffer(),
127  icu_text.getBuffer() + icu_text.length());
128 
129  auto font_collection = GetTestFontCollection();
130 
131  txt::ParagraphStyle paragraph_style;
132 
133  while (state.KeepRunning()) {
134  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
135  builder.AddText(u16_text);
136  }
137 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::u16string text
AtkStateType state

◆ BM_ParagraphBuilderAddTextU16stringShort()

static void txt::BM_ParagraphBuilderAddTextU16stringShort ( benchmark::State &  state)
static

Definition at line 91 of file paragraph_builder_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BENCHMARK(), GetTestFontCollection(), and text.

91  {
92  const char* text = "H";
93  auto icu_text = icu::UnicodeString::fromUTF8(text);
94  std::u16string u16_text(icu_text.getBuffer(),
95  icu_text.getBuffer() + icu_text.length());
96 
97  txt::ParagraphStyle paragraph_style;
98  auto font_collection = GetTestFontCollection();
99  while (state.KeepRunning()) {
100  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
101  builder.AddText(u16_text);
102  }
103 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::u16string text
AtkStateType state

◆ BM_ParagraphBuilderConstruction()

static void txt::BM_ParagraphBuilderConstruction ( benchmark::State &  state)
static

Definition at line 30 of file paragraph_builder_benchmarks.cc.

References BENCHMARK(), and GetTestFontCollection().

30  {
31  txt::ParagraphStyle paragraph_style;
32  auto font_collection = GetTestFontCollection();
33  while (state.KeepRunning()) {
34  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
35  }
36 }
std::shared_ptr< FontCollection > GetTestFontCollection()
AtkStateType state

◆ BM_ParagraphBuilderLongParagraphConstruct()

static void txt::BM_ParagraphBuilderLongParagraphConstruct ( benchmark::State &  state)
static

Definition at line 162 of file paragraph_builder_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BENCHMARK(), txt::ParagraphBuilderTxt::Build(), txt::TextStyle::color, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

162  {
163  const char* text =
164  "This is a very long sentence to test if the text will properly wrap "
165  "around and go to the next line. Sometimes, short sentence. Longer "
166  "sentences are okay too because they are necessary. Very short. "
167  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
168  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
169  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
170  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
171  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
172  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
173  "mollit anim id est laborum. "
174  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
175  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
176  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
177  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
178  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
179  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
180  "mollit anim id est laborum.";
181  auto icu_text = icu::UnicodeString::fromUTF8(text);
182  std::u16string u16_text(icu_text.getBuffer(),
183  icu_text.getBuffer() + icu_text.length());
184 
185  txt::ParagraphStyle paragraph_style;
186 
187  txt::TextStyle text_style;
188  text_style.color = SK_ColorBLACK;
189  auto font_collection = GetTestFontCollection();
190  while (state.KeepRunning()) {
191  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
192  builder.PushStyle(text_style);
193  builder.AddText(u16_text);
194  builder.Pop();
195  auto paragraph = builder.Build();
196  }
197 }
std::shared_ptr< FontCollection > GetTestFontCollection()
SkColor color
Definition: text_style.h:36
std::u16string text
AtkStateType state

◆ BM_ParagraphBuilderPushPop()

static void txt::BM_ParagraphBuilderPushPop ( benchmark::State &  state)
static

Definition at line 52 of file paragraph_builder_benchmarks.cc.

References BENCHMARK(), txt::TextStyle::color, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), and txt::ParagraphBuilderTxt::PushStyle().

52  {
53  txt::ParagraphStyle paragraph_style;
54  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
55 
56  txt::TextStyle text_style;
57  text_style.color = SK_ColorBLACK;
58  while (state.KeepRunning()) {
59  builder.PushStyle(text_style);
60  builder.Pop();
61  }
62 }
std::shared_ptr< FontCollection > GetTestFontCollection()
SkColor color
Definition: text_style.h:36
AtkStateType state

◆ BM_ParagraphBuilderPushStyle()

static void txt::BM_ParagraphBuilderPushStyle ( benchmark::State &  state)
static

Definition at line 39 of file paragraph_builder_benchmarks.cc.

References BENCHMARK(), txt::TextStyle::color, GetTestFontCollection(), and txt::ParagraphBuilderTxt::PushStyle().

39  {
40  txt::ParagraphStyle paragraph_style;
41 
42  txt::TextStyle text_style;
43  text_style.color = SK_ColorBLACK;
44  auto font_collection = GetTestFontCollection();
45  while (state.KeepRunning()) {
46  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
47  builder.PushStyle(text_style);
48  }
49 }
std::shared_ptr< FontCollection > GetTestFontCollection()
SkColor color
Definition: text_style.h:36
AtkStateType state

◆ BM_ParagraphBuilderShortParagraphConstruct()

static void txt::BM_ParagraphBuilderShortParagraphConstruct ( benchmark::State &  state)
static

Definition at line 140 of file paragraph_builder_benchmarks.cc.

References txt::ParagraphBuilderTxt::AddText(), BENCHMARK(), txt::ParagraphBuilderTxt::Build(), txt::TextStyle::color, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

141  {
142  const char* text = "Hello World";
143  auto icu_text = icu::UnicodeString::fromUTF8(text);
144  std::u16string u16_text(icu_text.getBuffer(),
145  icu_text.getBuffer() + icu_text.length());
146 
147  txt::ParagraphStyle paragraph_style;
148 
149  txt::TextStyle text_style;
150  text_style.color = SK_ColorBLACK;
151  auto font_collection = GetTestFontCollection();
152  while (state.KeepRunning()) {
153  txt::ParagraphBuilderTxt builder(paragraph_style, font_collection);
154  builder.PushStyle(text_style);
155  builder.AddText(u16_text);
156  builder.Pop();
157  auto paragraph = builder.Build();
158  }
159 }
std::shared_ptr< FontCollection > GetTestFontCollection()
SkColor color
Definition: text_style.h:36
std::u16string text
AtkStateType state

◆ BuildParagraph()

std::unique_ptr< ParagraphTxt > txt::BuildParagraph ( txt::ParagraphBuilderTxt builder)

Definition at line 124 of file txt_test_utils.cc.

References txt::ParagraphBuilderTxt::Build().

Referenced by BENCHMARK_DEFINE_F(), BENCHMARK_F(), and TEST_F().

125  {
126  return std::unique_ptr<txt::ParagraphTxt>(
127  static_cast<txt::ParagraphTxt*>(builder.Build().release()));
128 }
virtual std::unique_ptr< Paragraph > Build() override

◆ FontSkia_SetSkiaFont()

static void txt::FontSkia_SetSkiaFont ( sk_sp< SkTypeface >  typeface,
SkFont *  skFont,
const minikin::MinikinPaint paint 
)
static

Definition at line 52 of file font_skia.cc.

References minikin::LinearTextFlag, minikin::MinikinPaint::paintFlags, and minikin::MinikinPaint::size.

Referenced by txt::FontSkia::GetBounds(), and txt::FontSkia::GetHorizontalAdvance().

54  {
55  skFont->setTypeface(std::move(typeface));
56  skFont->setLinearMetrics((paint.paintFlags & minikin::LinearTextFlag) != 0);
57  // TODO: set more paint parameters from Minikin
58  skFont->setSize(paint.size);
59 }

◆ GetCommandLineForProcess()

const fml::CommandLine & txt::GetCommandLineForProcess ( )

Definition at line 44 of file txt_test_utils.cc.

References gCommandLine.

44  {
45  return gCommandLine;
46 }
static fml::CommandLine gCommandLine

◆ GetCoordinatesForGlyphPosition()

SkRect txt::GetCoordinatesForGlyphPosition ( txt::Paragraph paragraph,
size_t  pos 
)

Definition at line 5312 of file paragraph_unittests.cc.

References txt::Paragraph::GetRectsForRange(), txt::Paragraph::kMax, and txt::Paragraph::kTight.

Referenced by TEST_F().

5312  {
5313  std::vector<txt::Paragraph::TextBox> boxes =
5314  paragraph.GetRectsForRange(pos, pos + 1, Paragraph::RectHeightStyle::kMax,
5315  Paragraph::RectWidthStyle::kTight);
5316  return !boxes.empty() ? boxes.front().rect : SkRect::MakeEmpty();
5317 }
virtual std::vector< TextBox > GetRectsForRange(size_t start, size_t end, RectHeightStyle rect_height_style, RectWidthStyle rect_width_style)=0

◆ GetDefaultFontFamilies()

std::vector< std::string > txt::GetDefaultFontFamilies ( )

Definition at line 9 of file platform.cc.

Referenced by txt::FontCollection::ClearFontFamilyCache(), and txt::FontCollection::GetMinikinFontCollectionForFamilies().

9  {
10  return {"Arial"};
11 }

◆ GetDefaultFontManager()

sk_sp< SkFontMgr > txt::GetDefaultFontManager ( uint32_t  font_initialization_data)

Definition at line 13 of file platform.cc.

Referenced by txt::FontCollection::SetupDefaultFontManager(), and TEST_F().

13  {
14  return SkFontMgr::RefDefault();
15 }

◆ GetFontDir()

const std::string & txt::GetFontDir ( )

Definition at line 36 of file txt_test_utils.cc.

References gFontDir.

Referenced by BENCHMARK_DEFINE_F(), GetTestFontCollection(), main(), SkParagraphFixture::SetUp(), and TEST().

36  {
37  return gFontDir;
38 }
static std::string gFontDir

◆ GetTestFontCollection()

std::shared_ptr< FontCollection > txt::GetTestFontCollection ( )

Definition at line 109 of file txt_test_utils.cc.

References GetFontDir(), and RegisterFontsFromPath().

Referenced by BM_ParagraphBuilderAddTextChar(), BM_ParagraphBuilderAddTextString(), BM_ParagraphBuilderAddTextU16stringLong(), BM_ParagraphBuilderAddTextU16stringShort(), BM_ParagraphBuilderConstruction(), BM_ParagraphBuilderLongParagraphConstruct(), BM_ParagraphBuilderPushPop(), BM_ParagraphBuilderPushStyle(), BM_ParagraphBuilderShortParagraphConstruct(), txt::ParagraphFixture::SetUp(), and TEST_F().

109  {
110  std::unique_ptr<TypefaceFontAssetProvider> font_provider =
111  std::make_unique<TypefaceFontAssetProvider>();
112  RegisterFontsFromPath(*font_provider, GetFontDir());
113 
114  std::shared_ptr<FontCollection> collection =
115  std::make_shared<FontCollection>();
116  collection->SetAssetFontManager(
117  sk_make_sp<AssetFontManager>(std::move(font_provider)));
118 
119  return collection;
120 }
void RegisterFontsFromPath(TypefaceFontAssetProvider &font_provider, std::string directory_path)
const std::string & GetFontDir()

◆ RangeMultiplier()

txt::RangeMultiplier ( ) -> Range(1<< 6, 1<< 14) ->Complexity(benchmark::oN)

◆ RegisterFontsFromPath()

void txt::RegisterFontsFromPath ( TypefaceFontAssetProvider font_provider,
std::string  directory_path 
)

Definition at line 52 of file txt_test_utils.cc.

References INVALID_HANDLE_VALUE, flutter::path, and txt::TypefaceFontAssetProvider::RegisterTypeface().

Referenced by GetTestFontCollection().

53  {
54 #if defined(_WIN32)
55  std::string path = directory_path + "\\*";
56  WIN32_FIND_DATAA ffd;
57  HANDLE directory = FindFirstFileA(path.c_str(), &ffd);
58  if (directory == INVALID_HANDLE_VALUE) {
59  return;
60  }
61 
62  do {
63  if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
64  continue;
65  }
66 
67  std::string file_name(ffd.cFileName);
68 
69  std::stringstream file_path;
70  file_path << directory_path << "/" << file_name;
71 
72  font_provider.RegisterTypeface(
73  SkTypeface::MakeFromFile(file_path.str().c_str()));
74  } while (FindNextFileA(directory, &ffd) != 0);
75 
76  // TODO(bkonyi): check for error here?
77  FindClose(directory);
78 #else
79  auto directory_closer = [](DIR* directory) {
80  if (directory != nullptr) {
81  ::closedir(directory);
82  }
83  };
84 
85  std::unique_ptr<DIR, decltype(directory_closer)> directory(
86  ::opendir(directory_path.c_str()), directory_closer);
87 
88  if (directory == nullptr) {
89  return;
90  }
91 
92  for (struct dirent* entry = ::readdir(directory.get()); entry != nullptr;
93  entry = ::readdir(directory.get())) {
94  if (entry->d_type != DT_REG) {
95  continue;
96  }
97 
98  std::string file_name(entry->d_name);
99 
100  std::stringstream file_path;
101  file_path << directory_path << "/" << file_name;
102 
103  font_provider.RegisterTypeface(
104  SkTypeface::MakeFromFile(file_path.str().c_str()));
105  }
106 #endif
107 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
#define INVALID_HANDLE_VALUE
void * HANDLE
Definition: windows_types.h:36

◆ SetCommandLine()

void txt::SetCommandLine ( fml::CommandLine  cmd)

Definition at line 48 of file txt_test_utils.cc.

Referenced by main().

48  {
49  gCommandLine = std::move(cmd);
50 }
static fml::CommandLine gCommandLine

◆ SetFontDir()

void txt::SetFontDir ( const std::string &  dir)

Definition at line 40 of file txt_test_utils.cc.

Referenced by main().

40  {
41  gFontDir = dir;
42 }
static std::string gFontDir

◆ TEST()

txt::TEST ( FontCollectionTest  ,
CheckSkTypefacesSorting   
)

Definition at line 68 of file font_collection_unittests.cc.

References GetFontDir(), and width.

68  {
69  // We have to make a real SkTypeface here. Not all the structs from the
70  // SkTypeface headers are fully declared to be able to gmock.
71  // SkCustomTypefaceBuilder is the simplest way to get a simple SkTypeface.
72  SkCustomTypefaceBuilder typefaceBuilder1;
73  typefaceBuilder1.setFontStyle(SkFontStyle(SkFontStyle::kThin_Weight,
74  SkFontStyle::kExpanded_Width,
75  SkFontStyle::kItalic_Slant));
76  // For the purpose of this test, we need to fill this to make the SkTypeface
77  // build but it doesn't matter. We only care about the SkFontStyle.
78  PopulateUserTypefaceBoilerplate(&typefaceBuilder1);
79  sk_sp<SkTypeface> typeface1{typefaceBuilder1.detach()};
80 
81  SkCustomTypefaceBuilder typefaceBuilder2;
82  typefaceBuilder2.setFontStyle(SkFontStyle(SkFontStyle::kLight_Weight,
83  SkFontStyle::kNormal_Width,
84  SkFontStyle::kUpright_Slant));
85  PopulateUserTypefaceBoilerplate(&typefaceBuilder2);
86  sk_sp<SkTypeface> typeface2{typefaceBuilder2.detach()};
87 
88  SkCustomTypefaceBuilder typefaceBuilder3;
89  typefaceBuilder3.setFontStyle(SkFontStyle(SkFontStyle::kNormal_Weight,
90  SkFontStyle::kNormal_Width,
91  SkFontStyle::kUpright_Slant));
92  PopulateUserTypefaceBoilerplate(&typefaceBuilder3);
93  sk_sp<SkTypeface> typeface3{typefaceBuilder3.detach()};
94 
95  SkCustomTypefaceBuilder typefaceBuilder4;
96  typefaceBuilder4.setFontStyle(SkFontStyle(SkFontStyle::kThin_Weight,
97  SkFontStyle::kCondensed_Width,
98  SkFontStyle::kUpright_Slant));
99  PopulateUserTypefaceBoilerplate(&typefaceBuilder4);
100  sk_sp<SkTypeface> typeface4{typefaceBuilder4.detach()};
101 
102  std::vector<sk_sp<SkTypeface>> candidateTypefaces = {typeface1, typeface2,
103  typeface3, typeface4};
104 
105  // This sorts the vector in-place.
106  txt::FontCollection::SortSkTypefaces(candidateTypefaces);
107 
108  // The second one is first because it's both the most normal width font
109  // with the lightest weight.
110  ASSERT_EQ(candidateTypefaces[0].get(), typeface2.get());
111  // Then the most normal width font with normal weight.
112  ASSERT_EQ(candidateTypefaces[1].get(), typeface3.get());
113  // Then a less normal (condensed) width font.
114  ASSERT_EQ(candidateTypefaces[2].get(), typeface4.get());
115  // All things equal, 4 came before 1 because we arbitrarily chose to make the
116  // narrower font come first.
117  ASSERT_EQ(candidateTypefaces[3].get(), typeface1.get());
118 
119  // Double check.
120  ASSERT_EQ(candidateTypefaces[0]->fontStyle().weight(),
121  SkFontStyle::kLight_Weight);
122  ASSERT_EQ(candidateTypefaces[0]->fontStyle().width(),
123  SkFontStyle::kNormal_Width);
124 
125  ASSERT_EQ(candidateTypefaces[1]->fontStyle().weight(),
126  SkFontStyle::kNormal_Weight);
127  ASSERT_EQ(candidateTypefaces[1]->fontStyle().width(),
128  SkFontStyle::kNormal_Width);
129 
130  ASSERT_EQ(candidateTypefaces[2]->fontStyle().weight(),
131  SkFontStyle::kThin_Weight);
132  ASSERT_EQ(candidateTypefaces[2]->fontStyle().width(),
133  SkFontStyle::kCondensed_Width);
134 
135  ASSERT_EQ(candidateTypefaces[3]->fontStyle().weight(),
136  SkFontStyle::kThin_Weight);
137  ASSERT_EQ(candidateTypefaces[3]->fontStyle().width(),
138  SkFontStyle::kExpanded_Width);
139 }
int32_t width

◆ TEST_F() [1/89]

txt::TEST_F ( ParagraphTest  ,
SimpleParagraph   
)

Definition at line 39 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

Referenced by TEST_F().

39  {
40  const char* text = "Hello World Text Dialog";
41  auto icu_text = icu::UnicodeString::fromUTF8(text);
42  std::u16string u16_text(icu_text.getBuffer(),
43  icu_text.getBuffer() + icu_text.length());
44 
45  txt::ParagraphStyle paragraph_style;
46  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
47 
48  txt::TextStyle text_style;
49  // We must supply a font here, as the default is Arial, and we do not
50  // include Arial in our test fonts as it is proprietary. We want it to
51  // be Arial default though as it is one of the most common fonts on host
52  // platforms. On real devices/apps, Arial should be able to be resolved.
53  text_style.font_families = std::vector<std::string>(1, "Roboto");
54  text_style.color = SK_ColorBLACK;
55  builder.PushStyle(text_style);
56  builder.AddText(u16_text);
57 
58  builder.Pop();
59 
60  auto paragraph = BuildParagraph(builder);
61  paragraph->Layout(GetTestCanvasWidth());
62 
63  paragraph->Paint(GetCanvas(), 10.0, 15.0);
64 
65  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
66  for (size_t i = 0; i < u16_text.length(); i++) {
67  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
68  }
69  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
70  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
71  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
72  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
73  ASSERT_TRUE(Snapshot());
74 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [2/89]

txt::TEST_F ( PlatformFuchsiaTest  ,
GetDefaultFontManager   
)

Definition at line 51 of file platform_fuchsia_unittests.cc.

References txt::PlatformFuchsiaTest::fake_provider(), GetDefaultFontManager(), and txt::PlatformFuchsiaTest::GetProvider().

51  {
52  zx_handle_t handle = GetProvider().TakeChannel().release();
53  auto font_manager = GetDefaultFontManager(handle);
54 
55  // Nonnull font initialization data should not create SkFontMgr::RefDefault().
56  EXPECT_NE(font_manager, SkFontMgr::RefDefault());
57 
58  // Check to see that our font provider was called.
59  EXPECT_FALSE(fake_provider().WasInvoked());
60  font_manager->matchFamily("Invalid font.");
61  EXPECT_TRUE(fake_provider().WasInvoked());
62 }
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition: platform.cc:13

◆ TEST_F() [3/89]

txt::TEST_F ( PlatformFuchsiaTest  ,
GetDefaultFontManagerFail   
)

Definition at line 64 of file platform_fuchsia_unittests.cc.

References GetDefaultFontManager().

64  {
65  // Null font initialization data should create SkFontMgr::RefDefault().
66  EXPECT_EQ(GetDefaultFontManager(0), SkFontMgr::RefDefault());
67 }
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition: platform.cc:13

◆ TEST_F() [4/89]

txt::TEST_F ( ParagraphTest  ,
SimpleParagraphSmall   
)

Definition at line 76 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

76  {
77  const char* text =
78  "Hello World Text Dialog. This is a very small text in order to check "
79  "for constant advance additions that are only visible when the advance "
80  "of the glyphs are small.";
81  auto icu_text = icu::UnicodeString::fromUTF8(text);
82  std::u16string u16_text(icu_text.getBuffer(),
83  icu_text.getBuffer() + icu_text.length());
84 
85  txt::ParagraphStyle paragraph_style;
86  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
87 
88  txt::TextStyle text_style;
89  text_style.font_size = 6;
90  // We must supply a font here, as the default is Arial, and we do not
91  // include Arial in our test fonts as it is proprietary. We want it to
92  // be Arial default though as it is one of the most common fonts on host
93  // platforms. On real devices/apps, Arial should be able to be resolved.
94  text_style.font_families = std::vector<std::string>(1, "Roboto");
95  text_style.color = SK_ColorBLACK;
96  builder.PushStyle(text_style);
97  builder.AddText(u16_text);
98 
99  builder.Pop();
100 
101  auto paragraph = BuildParagraph(builder);
102  paragraph->Layout(GetTestCanvasWidth());
103 
104  paragraph->Paint(GetCanvas(), 10.0, 15.0);
105 
106  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
107  for (size_t i = 0; i < u16_text.length(); i++) {
108  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
109  }
110  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
111  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
112  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
113  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
114  ASSERT_TRUE(Snapshot());
115 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double font_size
Definition: text_style.h:51
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [5/89]

txt::TEST_F ( ParagraphTest  ,
GetGlyphPositionAtCoordinateSegfault   
)

Definition at line 121 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

121  {
122  const char* text = "Hello World\nText Dialog";
123  auto icu_text = icu::UnicodeString::fromUTF8(text);
124  std::u16string u16_text(icu_text.getBuffer(),
125  icu_text.getBuffer() + icu_text.length());
126 
127  txt::ParagraphStyle paragraph_style;
128  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
129 
130  txt::TextStyle text_style;
131  // We must supply a font here, as the default is Arial, and we do not
132  // include Arial in our test fonts as it is proprietary. We want it to
133  // be Arial default though as it is one of the most common fonts on host
134  // platforms. On real devices/apps, Arial should be able to be resolved.
135  text_style.font_families = std::vector<std::string>(1, "Roboto");
136  text_style.color = SK_ColorBLACK;
137  builder.PushStyle(text_style);
138  builder.AddText(u16_text);
139 
140  builder.Pop();
141 
142  auto paragraph = BuildParagraph(builder);
143  paragraph->Layout(GetTestCanvasWidth());
144 
145  paragraph->Paint(GetCanvas(), 10.0, 15.0);
146 
147  ASSERT_EQ(paragraph->final_line_count_, paragraph->line_metrics_.size());
148  ASSERT_EQ(paragraph->final_line_count_, 2ull);
149  ASSERT_EQ(paragraph->GetLineCount(), 2ull);
150 
151  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(0.2, 0.2).position, 0ull);
152  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(20.2, 0.2).position, 3ull);
153  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(0.2, 20.2).position, 12ull);
154 
155  // We artificially reproduce the conditions that cause segfaults in very
156  // specific circumstances in the wild. By adding this empty un-laid-out
157  // LineMetrics at the end, we force the case where final_line_count_
158  // represents the true number of lines whereas line_metrics_ has one
159  // extra empty one.
160  paragraph->line_metrics_.emplace_back(23, 24, 24, 24, true);
161 
162  ASSERT_EQ(paragraph->final_line_count_, paragraph->line_metrics_.size() - 1);
163  ASSERT_EQ(paragraph->final_line_count_, 2ull);
164  ASSERT_EQ(paragraph->GetLineCount(), 2ull);
165 
166  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(0.2, 20.2).position, 12ull);
167  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(0.2, 0.2).position, 0ull);
168  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(20.2, 0.2).position, 3ull);
169 
170  paragraph->line_metrics_.emplace_back(24, 25, 25, 25, true);
171 
172  ASSERT_EQ(paragraph->final_line_count_, paragraph->line_metrics_.size() - 2);
173  ASSERT_EQ(paragraph->final_line_count_, 2ull);
174  ASSERT_EQ(paragraph->GetLineCount(), 2ull);
175 
176  ASSERT_TRUE(Snapshot());
177 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [6/89]

txt::TEST_F ( ParagraphTest  ,
GetGlyphPositionAtCoordinateMultiRun   
)

Definition at line 181 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), and txt::ParagraphBuilderTxt::PushStyle().

181  {
182  txt::ParagraphStyle paragraph_style;
183  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
184 
185  txt::TextStyle text_style;
186  text_style.font_families = std::vector<std::string>(1, "Ahem");
187  text_style.color = SK_ColorBLACK;
188  text_style.font_size = 10;
189  builder.PushStyle(text_style);
190  builder.AddText(u"A");
191  text_style.font_size = 20;
192  builder.PushStyle(text_style);
193  builder.AddText(u"B");
194  text_style.font_size = 30;
195  builder.PushStyle(text_style);
196  builder.AddText(u"C");
197 
198  auto paragraph = BuildParagraph(builder);
199  paragraph->Layout(GetTestCanvasWidth());
200 
201  paragraph->Paint(GetCanvas(), 10.0, 15.0);
202 
203  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(2.0, 5.0).position, 0ull);
204  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(12.0, 5.0).position, 1ull);
205  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(32.0, 5.0).position, 2ull);
206 
207  ASSERT_TRUE(Snapshot());
208 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double font_size
Definition: text_style.h:51
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [7/89]

txt::TEST_F ( ParagraphTest  ,
LineMetricsParagraph1   
)

Definition at line 210 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

210  {
211  const char* text = "Hello! What is going on?\nSecond line \nthirdline";
212  auto icu_text = icu::UnicodeString::fromUTF8(text);
213  std::u16string u16_text(icu_text.getBuffer(),
214  icu_text.getBuffer() + icu_text.length());
215 
216  txt::ParagraphStyle paragraph_style;
217  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
218 
219  txt::TextStyle text_style;
220  // We must supply a font here, as the default is Arial, and we do not
221  // include Arial in our test fonts as it is proprietary. We want it to
222  // be Arial default though as it is one of the most common fonts on host
223  // platforms. On real devices/apps, Arial should be able to be resolved.
224  text_style.font_families = std::vector<std::string>(1, "Roboto");
225  text_style.color = SK_ColorBLACK;
226  builder.PushStyle(text_style);
227  builder.AddText(u16_text);
228 
229  builder.Pop();
230 
231  auto paragraph = BuildParagraph(builder);
232  paragraph->Layout(GetTestCanvasWidth());
233 
234  paragraph->Paint(GetCanvas(), 0, 0);
235 
236  ASSERT_TRUE(Snapshot());
237 
238  ASSERT_EQ(paragraph->GetLineMetrics().size(), 3ull);
239  ASSERT_EQ(paragraph->GetLineMetrics()[0].start_index, 0ull);
240  ASSERT_EQ(paragraph->GetLineMetrics()[0].end_index, 24ull);
241  ASSERT_EQ(paragraph->GetLineMetrics()[0].end_including_newline, 25ull);
242  ASSERT_EQ(paragraph->GetLineMetrics()[0].end_excluding_whitespace, 24ull);
243  ASSERT_EQ(paragraph->GetLineMetrics()[0].hard_break, true);
244  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].ascent, 12.988281);
245  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].descent, 3.4179688);
246  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].width, 149.72266);
247  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].left, 0.0);
248  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].baseline, 12.582031);
249  ASSERT_EQ(paragraph->GetLineMetrics()[0].line_number, 0ull);
250  ASSERT_EQ(paragraph->GetLineMetrics()[0].run_metrics.size(), 1ull);
251  ASSERT_EQ(
252  paragraph->GetLineMetrics()[0]
253  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
254  ->second.text_style->color,
255  SK_ColorBLACK);
256  ASSERT_EQ(
257  paragraph->GetLineMetrics()[0]
258  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
259  ->second.text_style->font_families,
260  std::vector<std::string>(1, "Roboto"));
261  ASSERT_FLOAT_EQ(
262  paragraph->GetLineMetrics()[0]
263  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
264  ->second.font_metrics.fAscent,
265  -12.988281);
266  ASSERT_FLOAT_EQ(
267  paragraph->GetLineMetrics()[0]
268  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
269  ->second.font_metrics.fDescent,
270  3.4179688);
271  ASSERT_FLOAT_EQ(
272  paragraph->GetLineMetrics()[0]
273  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
274  ->second.font_metrics.fXHeight,
275  7.3964844);
276  ASSERT_FLOAT_EQ(
277  paragraph->GetLineMetrics()[0]
278  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
279  ->second.font_metrics.fLeading,
280  0);
281  ASSERT_FLOAT_EQ(
282  paragraph->GetLineMetrics()[0]
283  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
284  ->second.font_metrics.fTop,
285  -14.786133);
286  ASSERT_FLOAT_EQ(
287  paragraph->GetLineMetrics()[0]
288  .run_metrics.lower_bound(paragraph->GetLineMetrics()[0].start_index)
289  ->second.font_metrics.fUnderlinePosition,
290  1.0253906);
291 
292  ASSERT_EQ(paragraph->GetLineMetrics()[1].start_index, 25ull);
293  ASSERT_EQ(paragraph->GetLineMetrics()[1].end_index, 37ull);
294  ASSERT_EQ(paragraph->GetLineMetrics()[1].end_including_newline, 38ull);
295  ASSERT_EQ(paragraph->GetLineMetrics()[1].end_excluding_whitespace, 36ull);
296  ASSERT_EQ(paragraph->GetLineMetrics()[1].hard_break, true);
297  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].ascent, 12.988281);
298  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].descent, 3.4179688);
299  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].width, 72.0625);
300  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].left, 0.0);
301  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].baseline, 28.582031);
302  ASSERT_EQ(paragraph->GetLineMetrics()[1].line_number, 1ull);
303  ASSERT_EQ(paragraph->GetLineMetrics()[1].run_metrics.size(), 1ull);
304  ASSERT_EQ(
305  paragraph->GetLineMetrics()[1]
306  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
307  ->second.text_style->color,
308  SK_ColorBLACK);
309  ASSERT_EQ(
310  paragraph->GetLineMetrics()[1]
311  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
312  ->second.text_style->font_families,
313  std::vector<std::string>(1, "Roboto"));
314  ASSERT_FLOAT_EQ(
315  paragraph->GetLineMetrics()[1]
316  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
317  ->second.font_metrics.fAscent,
318  -12.988281);
319  ASSERT_FLOAT_EQ(
320  paragraph->GetLineMetrics()[1]
321  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
322  ->second.font_metrics.fDescent,
323  3.4179688);
324  ASSERT_FLOAT_EQ(
325  paragraph->GetLineMetrics()[1]
326  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
327  ->second.font_metrics.fXHeight,
328  7.3964844);
329  ASSERT_FLOAT_EQ(
330  paragraph->GetLineMetrics()[1]
331  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
332  ->second.font_metrics.fLeading,
333  0);
334  ASSERT_FLOAT_EQ(
335  paragraph->GetLineMetrics()[1]
336  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
337  ->second.font_metrics.fTop,
338  -14.786133);
339  ASSERT_FLOAT_EQ(
340  paragraph->GetLineMetrics()[1]
341  .run_metrics.lower_bound(paragraph->GetLineMetrics()[1].start_index)
342  ->second.font_metrics.fUnderlinePosition,
343  1.0253906);
344 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [8/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_MAC(LineMetricsParagraph2)   
)

Definition at line 346 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

346  {
347  const char* text = "test string alphabetic";
348  auto icu_text = icu::UnicodeString::fromUTF8(text);
349  std::u16string alphabetic(icu_text.getBuffer(),
350  icu_text.getBuffer() + icu_text.length());
351 
352  const char* text2 = "测试中文日本語한국어";
353  auto icu_text2 = icu::UnicodeString::fromUTF8(text2);
354  std::u16string cjk(icu_text2.getBuffer(),
355  icu_text2.getBuffer() + icu_text2.length());
356 
357  txt::ParagraphStyle paragraph_style;
358  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
359 
360  txt::TextStyle text_style;
361  text_style.font_families = std::vector<std::string>(1, "Roboto");
362  text_style.font_families.push_back("Noto Sans CJK JP");
363  text_style.font_size = 27;
364  text_style.color = SK_ColorBLACK;
365  builder.PushStyle(text_style);
366  builder.AddText(alphabetic);
367 
368  text_style.font_size = 24;
369  builder.PushStyle(text_style);
370  builder.AddText(cjk);
371 
372  builder.Pop();
373 
374  auto paragraph = BuildParagraph(builder);
375  paragraph->Layout(350);
376 
377  paragraph->Paint(GetCanvas(), 0, 0);
378 
379  ASSERT_TRUE(Snapshot());
380 
381  ASSERT_EQ(paragraph->GetLineMetrics().size(), 2ull);
382  ASSERT_EQ(paragraph->GetLineMetrics()[0].start_index, 0ull);
383  ASSERT_EQ(paragraph->GetLineMetrics()[0].end_index, 26ull);
384  ASSERT_EQ(paragraph->GetLineMetrics()[0].end_including_newline, 26ull);
385  ASSERT_EQ(paragraph->GetLineMetrics()[0].end_excluding_whitespace, 26ull);
386  ASSERT_EQ(paragraph->GetLineMetrics()[0].hard_break, false);
387  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].ascent, 27.84);
388  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].descent, 7.6799998);
389  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].width, 348.61328);
390  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].left, 0.0);
391  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0].baseline, 28.32);
392  ASSERT_EQ(paragraph->GetLineMetrics()[0].line_number, 0ull);
393  ASSERT_EQ(paragraph->GetLineMetrics()[0].run_metrics.size(), 2ull);
394  // First run
395  ASSERT_EQ(paragraph->GetLineMetrics()[0]
396  .run_metrics.lower_bound(2)
397  ->second.text_style->font_size,
398  27);
399  ASSERT_EQ(paragraph->GetLineMetrics()[0]
400  .run_metrics.lower_bound(2)
401  ->second.text_style->font_families,
402  text_style.font_families);
403  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
404  .run_metrics.lower_bound(2)
405  ->second.font_metrics.fAscent,
406  -25.048828);
407  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
408  .run_metrics.lower_bound(2)
409  ->second.font_metrics.fDescent,
410  6.5917969);
411 
412  ASSERT_EQ(paragraph->GetLineMetrics()[0]
413  .run_metrics.lower_bound(21)
414  ->second.text_style->font_size,
415  27);
416  ASSERT_EQ(paragraph->GetLineMetrics()[0]
417  .run_metrics.lower_bound(21)
418  ->second.text_style->font_families,
419  text_style.font_families);
420  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
421  .run_metrics.lower_bound(21)
422  ->second.font_metrics.fAscent,
423  -25.048828);
424  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
425  .run_metrics.lower_bound(21)
426  ->second.font_metrics.fDescent,
427  6.5917969);
428 
429  // Second run
430  ASSERT_EQ(paragraph->GetLineMetrics()[0]
431  .run_metrics.lower_bound(22)
432  ->second.text_style->font_size,
433  24);
434  ASSERT_EQ(paragraph->GetLineMetrics()[0]
435  .run_metrics.lower_bound(22)
436  ->second.text_style->font_families,
437  text_style.font_families);
438  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
439  .run_metrics.lower_bound(22)
440  ->second.font_metrics.fAscent,
441  -27.84);
442  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
443  .run_metrics.lower_bound(22)
444  ->second.font_metrics.fDescent,
445  7.6799998);
446 
447  ASSERT_EQ(paragraph->GetLineMetrics()[0]
448  .run_metrics.lower_bound(24)
449  ->second.text_style->font_size,
450  24);
451  ASSERT_EQ(paragraph->GetLineMetrics()[0]
452  .run_metrics.lower_bound(24)
453  ->second.text_style->font_families,
454  text_style.font_families);
455  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
456  .run_metrics.lower_bound(24)
457  ->second.font_metrics.fAscent,
458  -27.84);
459  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[0]
460  .run_metrics.lower_bound(24)
461  ->second.font_metrics.fDescent,
462  7.6799998);
463 
464  ASSERT_EQ(paragraph->GetLineMetrics()[1].start_index, 26ull);
465  ASSERT_EQ(paragraph->GetLineMetrics()[1].end_index, 32ull);
466  ASSERT_EQ(paragraph->GetLineMetrics()[1].end_including_newline, 32ull);
467  ASSERT_EQ(paragraph->GetLineMetrics()[1].end_excluding_whitespace, 32ull);
468  ASSERT_EQ(paragraph->GetLineMetrics()[1].hard_break, true);
469  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].ascent, 27.84);
470  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].descent, 7.6799998);
471  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].width, 138.23438);
472  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].left, 0.0);
473  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1].baseline, 64.32);
474  ASSERT_EQ(paragraph->GetLineMetrics()[1].line_number, 1ull);
475  ASSERT_EQ(paragraph->GetLineMetrics()[1].run_metrics.size(), 1ull);
476  // Indexing below the line will just resolve to the first run in the line.
477  ASSERT_EQ(paragraph->GetLineMetrics()[1]
478  .run_metrics.lower_bound(3)
479  ->second.text_style->font_size,
480  24);
481  ASSERT_EQ(paragraph->GetLineMetrics()[1]
482  .run_metrics.lower_bound(3)
483  ->second.text_style->font_families,
484  text_style.font_families);
485  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1]
486  .run_metrics.lower_bound(3)
487  ->second.font_metrics.fAscent,
488  -27.84);
489  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1]
490  .run_metrics.lower_bound(3)
491  ->second.font_metrics.fDescent,
492  7.6799998);
493 
494  // Indexing within the line
495  ASSERT_EQ(paragraph->GetLineMetrics()[1]
496  .run_metrics.lower_bound(31)
497  ->second.text_style->font_size,
498  24);
499  ASSERT_EQ(paragraph->GetLineMetrics()[1]
500  .run_metrics.lower_bound(31)
501  ->second.text_style->font_families,
502  text_style.font_families);
503  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1]
504  .run_metrics.lower_bound(31)
505  ->second.font_metrics.fAscent,
506  -27.84);
507  ASSERT_FLOAT_EQ(paragraph->GetLineMetrics()[1]
508  .run_metrics.lower_bound(31)
509  ->second.font_metrics.fDescent,
510  7.6799998);
511 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double font_size
Definition: text_style.h:51
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [9/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderParagraph)   
)

Definition at line 513 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBaseline, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

513  {
514  const char* text = "012 34";
515  auto icu_text = icu::UnicodeString::fromUTF8(text);
516  std::u16string u16_text(icu_text.getBuffer(),
517  icu_text.getBuffer() + icu_text.length());
518 
519  txt::ParagraphStyle paragraph_style;
520  paragraph_style.max_lines = 14;
521  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
522 
523  txt::TextStyle text_style;
524  text_style.font_families = std::vector<std::string>(1, "Roboto");
525  text_style.font_size = 26;
526  text_style.letter_spacing = 1;
527  text_style.word_spacing = 5;
528  text_style.color = SK_ColorBLACK;
529  text_style.height = 1;
531  text_style.decoration_color = SK_ColorBLACK;
532  builder.PushStyle(text_style);
533 
534  builder.AddText(u16_text);
535 
536  txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
538  builder.AddPlaceholder(placeholder_run);
539 
540  builder.AddText(u16_text);
541 
542  builder.AddPlaceholder(placeholder_run);
543  txt::PlaceholderRun placeholder_run2(5, 50, PlaceholderAlignment::kBaseline,
545  builder.AddPlaceholder(placeholder_run2);
546  builder.AddPlaceholder(placeholder_run);
547  builder.AddPlaceholder(placeholder_run2);
548  builder.AddText(u16_text);
549  builder.AddPlaceholder(placeholder_run2);
550 
551  builder.AddText(u16_text);
552  builder.AddText(u16_text);
553  builder.AddPlaceholder(placeholder_run2);
554  builder.AddPlaceholder(placeholder_run2);
555  builder.AddPlaceholder(placeholder_run2);
556  builder.AddPlaceholder(placeholder_run2);
557  builder.AddPlaceholder(placeholder_run2);
558  builder.AddPlaceholder(placeholder_run);
559  builder.AddText(u16_text);
560  builder.AddText(u16_text);
561  builder.AddText(u16_text);
562  builder.AddText(u16_text);
563  builder.AddText(u16_text);
564  builder.AddPlaceholder(placeholder_run2);
565  builder.AddPlaceholder(placeholder_run);
566  builder.AddText(u16_text);
567  builder.AddText(u16_text);
568 
569  builder.Pop();
570 
571  auto paragraph = BuildParagraph(builder);
572  paragraph->Layout(GetTestCanvasWidth());
573 
574  paragraph->Paint(GetCanvas(), 0, 0);
575 
576  SkPaint paint;
577  paint.setStyle(SkPaint::kStroke_Style);
578  paint.setAntiAlias(true);
579  paint.setStrokeWidth(1);
580 
581  Paragraph::RectHeightStyle rect_height_style =
582  Paragraph::RectHeightStyle::kTight;
583  Paragraph::RectWidthStyle rect_width_style =
584  Paragraph::RectWidthStyle::kTight;
585  paint.setColor(SK_ColorRED);
586  std::vector<txt::Paragraph::TextBox> boxes =
587  paragraph->GetRectsForRange(0, 3, rect_height_style, rect_width_style);
588  for (size_t i = 0; i < boxes.size(); ++i) {
589  GetCanvas()->drawRect(boxes[i].rect, paint);
590  }
591  // ASSERT_TRUE(Snapshot());
592  EXPECT_EQ(boxes.size(), 1ull);
593 
594  paint.setColor(SK_ColorGREEN);
595  boxes =
596  paragraph->GetRectsForRange(0, 1, rect_height_style, rect_width_style);
597  for (size_t i = 0; i < boxes.size(); ++i) {
598  GetCanvas()->drawRect(boxes[i].rect, paint);
599  }
600  EXPECT_EQ(boxes.size(), 1ull);
601 
602  paint.setColor(SK_ColorRED);
603  boxes = paragraph->GetRectsForPlaceholders();
604  for (size_t i = 0; i < boxes.size(); ++i) {
605  GetCanvas()->drawRect(boxes[i].rect, paint);
606  }
607 
608  paint.setColor(SK_ColorBLUE);
609  boxes =
610  paragraph->GetRectsForRange(4, 17, rect_height_style, rect_width_style);
611  for (size_t i = 0; i < boxes.size(); ++i) {
612  GetCanvas()->drawRect(boxes[i].rect, paint);
613  }
614  EXPECT_EQ(boxes.size(), 7ull);
615  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 90.945312);
616  EXPECT_FLOAT_EQ(boxes[1].rect.top(), 50);
617  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 140.94531);
618  EXPECT_FLOAT_EQ(boxes[1].rect.bottom(), 100);
619 
620  EXPECT_FLOAT_EQ(boxes[3].rect.left(), 231.39062);
621  EXPECT_FLOAT_EQ(boxes[3].rect.top(), 50);
622  EXPECT_FLOAT_EQ(boxes[3].rect.right(), 231.39062 + 50);
623  EXPECT_FLOAT_EQ(boxes[3].rect.bottom(), 100);
624 
625  EXPECT_FLOAT_EQ(boxes[4].rect.left(), 281.39062);
626  EXPECT_FLOAT_EQ(boxes[4].rect.top(), 0);
627  EXPECT_FLOAT_EQ(boxes[4].rect.right(), 281.39062 + 5);
628  EXPECT_FLOAT_EQ(boxes[4].rect.bottom(), 50);
629 
630  EXPECT_FLOAT_EQ(boxes[6].rect.left(), 336.39062);
631  EXPECT_FLOAT_EQ(boxes[6].rect.top(), 0);
632  EXPECT_FLOAT_EQ(boxes[6].rect.right(), 336.39062 + 5);
633  EXPECT_FLOAT_EQ(boxes[6].rect.bottom(), 50);
634 
635  ASSERT_TRUE(Snapshot());
636 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [10/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderBaselineParagraph)   
)

Definition at line 638 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBaseline, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

638  {
639  const char* text = "012 34";
640  auto icu_text = icu::UnicodeString::fromUTF8(text);
641  std::u16string u16_text(icu_text.getBuffer(),
642  icu_text.getBuffer() + icu_text.length());
643 
644  txt::ParagraphStyle paragraph_style;
645  paragraph_style.max_lines = 14;
646  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
647 
648  txt::TextStyle text_style;
649  text_style.font_families = std::vector<std::string>(1, "Roboto");
650  text_style.font_size = 26;
651  text_style.letter_spacing = 1;
652  text_style.word_spacing = 5;
653  text_style.color = SK_ColorBLACK;
654  text_style.height = 1;
656  text_style.decoration_color = SK_ColorBLACK;
657  builder.PushStyle(text_style);
658 
659  builder.AddText(u16_text);
660 
661  txt::PlaceholderRun placeholder_run(55, 50, PlaceholderAlignment::kBaseline,
662  TextBaseline::kAlphabetic, 38.34734);
663  builder.AddPlaceholder(placeholder_run);
664 
665  builder.AddText(u16_text);
666 
667  builder.Pop();
668 
669  auto paragraph = BuildParagraph(builder);
670  paragraph->Layout(GetTestCanvasWidth());
671 
672  paragraph->Paint(GetCanvas(), 0, 0);
673 
674  SkPaint paint;
675  paint.setStyle(SkPaint::kStroke_Style);
676  paint.setAntiAlias(true);
677  paint.setStrokeWidth(1);
678 
679  Paragraph::RectHeightStyle rect_height_style =
680  Paragraph::RectHeightStyle::kTight;
681  Paragraph::RectWidthStyle rect_width_style =
682  Paragraph::RectWidthStyle::kTight;
683  paint.setColor(SK_ColorRED);
684  std::vector<txt::Paragraph::TextBox> boxes =
685  paragraph->GetRectsForPlaceholders();
686  for (size_t i = 0; i < boxes.size(); ++i) {
687  GetCanvas()->drawRect(boxes[i].rect, paint);
688  }
689  EXPECT_EQ(boxes.size(), 1ull);
690  // Verify the box is in the right place
691  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
692  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
693  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 145.94531);
694  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
695 
696  paint.setColor(SK_ColorBLUE);
697  boxes =
698  paragraph->GetRectsForRange(5, 6, rect_height_style, rect_width_style);
699  for (size_t i = 0; i < boxes.size(); ++i) {
700  GetCanvas()->drawRect(boxes[i].rect, paint);
701  }
702  EXPECT_EQ(boxes.size(), 1ull);
703  // Verify the other text didn't just shift to accommodate it.
704  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 75.34375);
705  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 14.226246);
706  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 90.945312);
707  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 44.694996);
708 
709  ASSERT_TRUE(Snapshot());
710 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [11/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderAboveBaselineParagraph)   
)

Definition at line 712 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAboveBaseline, kAlphabetic, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

713  {
714  const char* text = "012 34";
715  auto icu_text = icu::UnicodeString::fromUTF8(text);
716  std::u16string u16_text(icu_text.getBuffer(),
717  icu_text.getBuffer() + icu_text.length());
718 
719  txt::ParagraphStyle paragraph_style;
720  paragraph_style.max_lines = 14;
721  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
722 
723  txt::TextStyle text_style;
724  text_style.font_families = std::vector<std::string>(1, "Roboto");
725  text_style.font_size = 26;
726  text_style.letter_spacing = 1;
727  text_style.word_spacing = 5;
728  text_style.color = SK_ColorBLACK;
729  text_style.height = 1;
731  text_style.decoration_color = SK_ColorBLACK;
732  builder.PushStyle(text_style);
733 
734  builder.AddText(u16_text);
735 
736  txt::PlaceholderRun placeholder_run(55, 50,
737  PlaceholderAlignment::kAboveBaseline,
738  TextBaseline::kAlphabetic, 903129.129308);
739  builder.AddPlaceholder(placeholder_run);
740 
741  builder.AddText(u16_text);
742 
743  builder.Pop();
744 
745  auto paragraph = BuildParagraph(builder);
746  paragraph->Layout(GetTestCanvasWidth());
747 
748  paragraph->Paint(GetCanvas(), 0, 0);
749 
750  SkPaint paint;
751  paint.setStyle(SkPaint::kStroke_Style);
752  paint.setAntiAlias(true);
753  paint.setStrokeWidth(1);
754 
755  Paragraph::RectHeightStyle rect_height_style =
756  Paragraph::RectHeightStyle::kTight;
757  Paragraph::RectWidthStyle rect_width_style =
758  Paragraph::RectWidthStyle::kTight;
759  paint.setColor(SK_ColorRED);
760  std::vector<txt::Paragraph::TextBox> boxes =
761  paragraph->GetRectsForPlaceholders();
762  for (size_t i = 0; i < boxes.size(); ++i) {
763  GetCanvas()->drawRect(boxes[i].rect, paint);
764  }
765  EXPECT_EQ(boxes.size(), 1ull);
766  // Verify the box is in the right place
767  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
768  EXPECT_FLOAT_EQ(boxes[0].rect.top(), -0.34765625);
769  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 145.94531);
770  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 49.652344);
771 
772  paint.setColor(SK_ColorBLUE);
773  boxes =
774  paragraph->GetRectsForRange(5, 6, rect_height_style, rect_width_style);
775  for (size_t i = 0; i < boxes.size(); ++i) {
776  GetCanvas()->drawRect(boxes[i].rect, paint);
777  }
778  EXPECT_EQ(boxes.size(), 1ull);
779  // Verify the other text didn't just shift to accommodate it.
780  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 75.34375);
781  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 25.53125);
782  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 90.945312);
783  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 56);
784 
785  ASSERT_TRUE(Snapshot());
786 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [12/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderBelowBaselineParagraph)   
)

Definition at line 788 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBelowBaseline, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

789  {
790  const char* text = "012 34";
791  auto icu_text = icu::UnicodeString::fromUTF8(text);
792  std::u16string u16_text(icu_text.getBuffer(),
793  icu_text.getBuffer() + icu_text.length());
794 
795  txt::ParagraphStyle paragraph_style;
796  paragraph_style.max_lines = 14;
797  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
798 
799  txt::TextStyle text_style;
800  text_style.font_families = std::vector<std::string>(1, "Roboto");
801  text_style.font_size = 26;
802  text_style.letter_spacing = 1;
803  text_style.word_spacing = 5;
804  text_style.color = SK_ColorBLACK;
805  text_style.height = 1;
807  text_style.decoration_color = SK_ColorBLACK;
808  builder.PushStyle(text_style);
809 
810  builder.AddText(u16_text);
811 
812  txt::PlaceholderRun placeholder_run(55, 50,
813  PlaceholderAlignment::kBelowBaseline,
814  TextBaseline::kAlphabetic, 903129.129308);
815  builder.AddPlaceholder(placeholder_run);
816 
817  builder.AddText(u16_text);
818 
819  builder.Pop();
820 
821  auto paragraph = BuildParagraph(builder);
822  paragraph->Layout(GetTestCanvasWidth());
823 
824  paragraph->Paint(GetCanvas(), 0, 0);
825 
826  SkPaint paint;
827  paint.setStyle(SkPaint::kStroke_Style);
828  paint.setAntiAlias(true);
829  paint.setStrokeWidth(1);
830 
831  Paragraph::RectHeightStyle rect_height_style =
832  Paragraph::RectHeightStyle::kTight;
833  Paragraph::RectWidthStyle rect_width_style =
834  Paragraph::RectWidthStyle::kTight;
835  paint.setColor(SK_ColorRED);
836  std::vector<txt::Paragraph::TextBox> boxes =
837  paragraph->GetRectsForPlaceholders();
838  for (size_t i = 0; i < boxes.size(); ++i) {
839  GetCanvas()->drawRect(boxes[i].rect, paint);
840  }
841  EXPECT_EQ(boxes.size(), 1ull);
842  // Verify the box is in the right place
843  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
844  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 24);
845  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 145.94531);
846  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 74);
847 
848  paint.setColor(SK_ColorBLUE);
849  boxes =
850  paragraph->GetRectsForRange(5, 6, rect_height_style, rect_width_style);
851  for (size_t i = 0; i < boxes.size(); ++i) {
852  GetCanvas()->drawRect(boxes[i].rect, paint);
853  }
854  EXPECT_EQ(boxes.size(), 1ull);
855  // Verify the other text didn't just shift to accommodate it.
856  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 75.34375);
857  EXPECT_FLOAT_EQ(boxes[0].rect.top(), -0.12109375);
858  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 90.945312);
859  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 30.347656);
860 
861  ASSERT_TRUE(Snapshot());
862 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [13/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderBottomParagraph)   
)

Definition at line 864 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBottom, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

864  {
865  const char* text = "012 34";
866  auto icu_text = icu::UnicodeString::fromUTF8(text);
867  std::u16string u16_text(icu_text.getBuffer(),
868  icu_text.getBuffer() + icu_text.length());
869 
870  txt::ParagraphStyle paragraph_style;
871  paragraph_style.max_lines = 14;
872  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
873 
874  txt::TextStyle text_style;
875  text_style.font_families = std::vector<std::string>(1, "Roboto");
876  text_style.font_size = 26;
877  text_style.letter_spacing = 1;
878  text_style.word_spacing = 5;
879  text_style.color = SK_ColorBLACK;
880  text_style.height = 1;
882  text_style.decoration_color = SK_ColorBLACK;
883  builder.PushStyle(text_style);
884 
885  builder.AddText(u16_text);
886 
887  txt::PlaceholderRun placeholder_run(55, 50, PlaceholderAlignment::kBottom,
889  builder.AddPlaceholder(placeholder_run);
890 
891  builder.AddText(u16_text);
892 
893  builder.Pop();
894 
895  auto paragraph = BuildParagraph(builder);
896  paragraph->Layout(GetTestCanvasWidth());
897 
898  paragraph->Paint(GetCanvas(), 0, 0);
899 
900  SkPaint paint;
901  paint.setStyle(SkPaint::kStroke_Style);
902  paint.setAntiAlias(true);
903  paint.setStrokeWidth(1);
904 
905  Paragraph::RectHeightStyle rect_height_style =
906  Paragraph::RectHeightStyle::kTight;
907  Paragraph::RectWidthStyle rect_width_style =
908  Paragraph::RectWidthStyle::kTight;
909  paint.setColor(SK_ColorRED);
910  std::vector<txt::Paragraph::TextBox> boxes =
911  paragraph->GetRectsForPlaceholders();
912  for (size_t i = 0; i < boxes.size(); ++i) {
913  GetCanvas()->drawRect(boxes[i].rect, paint);
914  }
915  EXPECT_EQ(boxes.size(), 1ull);
916  // Verify the box is in the right place
917  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
918  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
919  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 145.94531);
920  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
921 
922  paint.setColor(SK_ColorBLUE);
923  boxes =
924  paragraph->GetRectsForRange(0, 1, rect_height_style, rect_width_style);
925  for (size_t i = 0; i < boxes.size(); ++i) {
926  GetCanvas()->drawRect(boxes[i].rect, paint);
927  }
928  EXPECT_EQ(boxes.size(), 1ull);
929  // Verify the other text didn't just shift to accommodate it.
930  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 0.5);
931  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 19.53125);
932  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 16.101562);
933  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
934 
935  ASSERT_TRUE(Snapshot());
936 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [14/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderTopParagraph)   
)

Definition at line 938 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, txt::Paragraph::kTight, kTop, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

938  {
939  const char* text = "012 34";
940  auto icu_text = icu::UnicodeString::fromUTF8(text);
941  std::u16string u16_text(icu_text.getBuffer(),
942  icu_text.getBuffer() + icu_text.length());
943 
944  txt::ParagraphStyle paragraph_style;
945  paragraph_style.max_lines = 14;
946  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
947 
948  txt::TextStyle text_style;
949  text_style.font_families = std::vector<std::string>(1, "Roboto");
950  text_style.font_size = 26;
951  text_style.letter_spacing = 1;
952  text_style.word_spacing = 5;
953  text_style.color = SK_ColorBLACK;
954  text_style.height = 1;
956  text_style.decoration_color = SK_ColorBLACK;
957  builder.PushStyle(text_style);
958 
959  builder.AddText(u16_text);
960 
961  txt::PlaceholderRun placeholder_run(55, 50, PlaceholderAlignment::kTop,
963  builder.AddPlaceholder(placeholder_run);
964 
965  builder.AddText(u16_text);
966 
967  builder.Pop();
968 
969  auto paragraph = BuildParagraph(builder);
970  paragraph->Layout(GetTestCanvasWidth());
971 
972  paragraph->Paint(GetCanvas(), 0, 0);
973 
974  SkPaint paint;
975  paint.setStyle(SkPaint::kStroke_Style);
976  paint.setAntiAlias(true);
977  paint.setStrokeWidth(1);
978 
979  Paragraph::RectHeightStyle rect_height_style =
980  Paragraph::RectHeightStyle::kTight;
981  Paragraph::RectWidthStyle rect_width_style =
982  Paragraph::RectWidthStyle::kTight;
983  paint.setColor(SK_ColorRED);
984  std::vector<txt::Paragraph::TextBox> boxes =
985  paragraph->GetRectsForPlaceholders();
986  for (size_t i = 0; i < boxes.size(); ++i) {
987  GetCanvas()->drawRect(boxes[i].rect, paint);
988  }
989  EXPECT_EQ(boxes.size(), 1ull);
990  // Verify the box is in the right place
991  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
992  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
993  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 145.94531);
994  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
995 
996  paint.setColor(SK_ColorBLUE);
997  boxes =
998  paragraph->GetRectsForRange(0, 1, rect_height_style, rect_width_style);
999  for (size_t i = 0; i < boxes.size(); ++i) {
1000  GetCanvas()->drawRect(boxes[i].rect, paint);
1001  }
1002  EXPECT_EQ(boxes.size(), 1ull);
1003  // Verify the other text didn't just shift to accommodate it.
1004  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 0.5);
1005  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
1006  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 16.101562);
1007  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 30.46875);
1008 
1009  ASSERT_TRUE(Snapshot());
1010 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [15/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderMiddleParagraph)   
)

Definition at line 1012 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kMiddle, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1012  {
1013  const char* text = "012 34";
1014  auto icu_text = icu::UnicodeString::fromUTF8(text);
1015  std::u16string u16_text(icu_text.getBuffer(),
1016  icu_text.getBuffer() + icu_text.length());
1017 
1018  txt::ParagraphStyle paragraph_style;
1019  paragraph_style.max_lines = 14;
1020  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1021 
1022  txt::TextStyle text_style;
1023  text_style.font_families = std::vector<std::string>(1, "Roboto");
1024  text_style.font_size = 26;
1025  text_style.letter_spacing = 1;
1026  text_style.word_spacing = 5;
1027  text_style.color = SK_ColorBLACK;
1028  text_style.height = 1;
1030  text_style.decoration_color = SK_ColorBLACK;
1031  builder.PushStyle(text_style);
1032 
1033  builder.AddText(u16_text);
1034 
1035  txt::PlaceholderRun placeholder_run(55, 50, PlaceholderAlignment::kMiddle,
1037  builder.AddPlaceholder(placeholder_run);
1038 
1039  builder.AddText(u16_text);
1040 
1041  builder.Pop();
1042 
1043  auto paragraph = BuildParagraph(builder);
1044  paragraph->Layout(GetTestCanvasWidth());
1045 
1046  paragraph->Paint(GetCanvas(), 0, 0);
1047 
1048  SkPaint paint;
1049  paint.setStyle(SkPaint::kStroke_Style);
1050  paint.setAntiAlias(true);
1051  paint.setStrokeWidth(1);
1052 
1053  Paragraph::RectHeightStyle rect_height_style =
1054  Paragraph::RectHeightStyle::kTight;
1055  Paragraph::RectWidthStyle rect_width_style =
1056  Paragraph::RectWidthStyle::kTight;
1057  paint.setColor(SK_ColorRED);
1058  std::vector<txt::Paragraph::TextBox> boxes =
1059  paragraph->GetRectsForPlaceholders();
1060  for (size_t i = 0; i < boxes.size(); ++i) {
1061  GetCanvas()->drawRect(boxes[i].rect, paint);
1062  }
1063  EXPECT_EQ(boxes.size(), 1ull);
1064  // Verify the box is in the right place
1065  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
1066  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
1067  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 145.94531);
1068  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
1069 
1070  paint.setColor(SK_ColorBLUE);
1071  boxes =
1072  paragraph->GetRectsForRange(5, 6, rect_height_style, rect_width_style);
1073  for (size_t i = 0; i < boxes.size(); ++i) {
1074  GetCanvas()->drawRect(boxes[i].rect, paint);
1075  }
1076  EXPECT_EQ(boxes.size(), 1ull);
1077  // Verify the other text didn't just shift to accommodate it.
1078  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 75.34375);
1079  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 9.765625);
1080  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 90.945312);
1081  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 40.234375);
1082 
1083  ASSERT_TRUE(Snapshot());
1084 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [16/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_MAC( DISABLE_ON_WINDOWS(InlinePlaceholderIdeographicBaselineParagraph))   
)

Definition at line 1086 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kBaseline, kIdeographic, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1088  {
1089  const char* text = "給能上目秘使";
1090  auto icu_text = icu::UnicodeString::fromUTF8(text);
1091  std::u16string u16_text(icu_text.getBuffer(),
1092  icu_text.getBuffer() + icu_text.length());
1093 
1094  txt::ParagraphStyle paragraph_style;
1095  paragraph_style.max_lines = 14;
1096  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1097 
1098  txt::TextStyle text_style;
1099  text_style.font_families = std::vector<std::string>(1, "Source Han Serif CN");
1100  text_style.font_size = 26;
1101  text_style.letter_spacing = 1;
1102  text_style.word_spacing = 5;
1103  text_style.color = SK_ColorBLACK;
1104  text_style.height = 1;
1106  text_style.decoration_color = SK_ColorBLACK;
1107  builder.PushStyle(text_style);
1108 
1109  builder.AddText(u16_text);
1110 
1111  txt::PlaceholderRun placeholder_run(55, 50, PlaceholderAlignment::kBaseline,
1112  TextBaseline::kIdeographic, 38.34734);
1113  builder.AddPlaceholder(placeholder_run);
1114 
1115  builder.AddText(u16_text);
1116 
1117  builder.Pop();
1118 
1119  auto paragraph = BuildParagraph(builder);
1120  paragraph->Layout(GetTestCanvasWidth());
1121 
1122  paragraph->Paint(GetCanvas(), 0, 0);
1123 
1124  SkPaint paint;
1125  paint.setStyle(SkPaint::kStroke_Style);
1126  paint.setAntiAlias(true);
1127  paint.setStrokeWidth(1);
1128 
1129  Paragraph::RectHeightStyle rect_height_style =
1130  Paragraph::RectHeightStyle::kTight;
1131  Paragraph::RectWidthStyle rect_width_style =
1132  Paragraph::RectWidthStyle::kTight;
1133  paint.setColor(SK_ColorRED);
1134  std::vector<txt::Paragraph::TextBox> boxes =
1135  paragraph->GetRectsForPlaceholders();
1136  for (size_t i = 0; i < boxes.size(); ++i) {
1137  GetCanvas()->drawRect(boxes[i].rect, paint);
1138  }
1139  EXPECT_EQ(boxes.size(), 1ull);
1140  // Verify the box is in the right place
1141  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 162.5);
1142  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
1143  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 217.5);
1144  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
1145 
1146  paint.setColor(SK_ColorBLUE);
1147  boxes =
1148  paragraph->GetRectsForRange(5, 6, rect_height_style, rect_width_style);
1149  for (size_t i = 0; i < boxes.size(); ++i) {
1150  GetCanvas()->drawRect(boxes[i].rect, paint);
1151  }
1152  EXPECT_EQ(boxes.size(), 1ull);
1153  // Verify the other text didn't just shift to accommodate it.
1154  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 135.5);
1155  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 4.7033391);
1156  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 162.5);
1157  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 42.065342);
1158 
1159  ASSERT_TRUE(Snapshot());
1160 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [17/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderBreakParagraph)   
)

Definition at line 1162 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBaseline, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1162  {
1163  const char* text = "012 34";
1164  auto icu_text = icu::UnicodeString::fromUTF8(text);
1165  std::u16string u16_text(icu_text.getBuffer(),
1166  icu_text.getBuffer() + icu_text.length());
1167 
1168  txt::ParagraphStyle paragraph_style;
1169  paragraph_style.max_lines = 14;
1170  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1171 
1172  txt::TextStyle text_style;
1173  text_style.font_families = std::vector<std::string>(1, "Roboto");
1174  text_style.font_size = 26;
1175  text_style.letter_spacing = 1;
1176  text_style.word_spacing = 5;
1177  text_style.color = SK_ColorBLACK;
1178  text_style.height = 1;
1180  text_style.decoration_color = SK_ColorBLACK;
1181  builder.PushStyle(text_style);
1182 
1183  builder.AddText(u16_text);
1184 
1185  txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
1187  txt::PlaceholderRun placeholder_run2(25, 25, PlaceholderAlignment::kBaseline,
1189  builder.AddPlaceholder(placeholder_run);
1190  builder.AddPlaceholder(placeholder_run);
1191  builder.AddPlaceholder(placeholder_run);
1192  builder.AddPlaceholder(placeholder_run2);
1193  builder.AddPlaceholder(placeholder_run);
1194  builder.AddText(u16_text);
1195  builder.AddPlaceholder(placeholder_run);
1196  builder.AddPlaceholder(placeholder_run);
1197  builder.AddPlaceholder(placeholder_run);
1198  builder.AddPlaceholder(placeholder_run);
1199  builder.AddPlaceholder(placeholder_run2);
1200  builder.AddPlaceholder(placeholder_run);
1201  builder.AddPlaceholder(placeholder_run);
1202  builder.AddPlaceholder(placeholder_run);
1203  builder.AddPlaceholder(placeholder_run);
1204  builder.AddPlaceholder(placeholder_run);
1205  builder.AddPlaceholder(placeholder_run);
1206  builder.AddPlaceholder(placeholder_run2);
1207  builder.AddPlaceholder(placeholder_run);
1208  builder.AddPlaceholder(placeholder_run);
1209  builder.AddPlaceholder(placeholder_run);
1210  builder.AddPlaceholder(placeholder_run);
1211  builder.AddPlaceholder(placeholder_run);
1212  builder.AddPlaceholder(placeholder_run);
1213  builder.AddPlaceholder(placeholder_run);
1214  builder.AddPlaceholder(placeholder_run2);
1215  builder.AddPlaceholder(placeholder_run);
1216 
1217  builder.AddText(u16_text);
1218 
1219  builder.AddPlaceholder(placeholder_run);
1220  builder.AddPlaceholder(placeholder_run2);
1221 
1222  builder.AddText(u16_text);
1223  builder.AddText(u16_text);
1224  builder.AddText(u16_text);
1225  builder.AddText(u16_text);
1226  builder.AddPlaceholder(placeholder_run2);
1227  builder.AddPlaceholder(placeholder_run);
1228  builder.AddText(u16_text);
1229  builder.AddPlaceholder(placeholder_run2);
1230  builder.AddText(u16_text);
1231  builder.AddText(u16_text);
1232  builder.AddText(u16_text);
1233  builder.AddText(u16_text);
1234  builder.AddText(u16_text);
1235  builder.AddText(u16_text);
1236  builder.AddText(u16_text);
1237  builder.AddText(u16_text);
1238  builder.AddText(u16_text);
1239  builder.AddText(u16_text);
1240  builder.AddText(u16_text);
1241  builder.AddText(u16_text);
1242  builder.AddText(u16_text);
1243  builder.AddText(u16_text);
1244  builder.AddText(u16_text);
1245  builder.AddText(u16_text);
1246  builder.AddText(u16_text);
1247  builder.AddText(u16_text);
1248  builder.AddText(u16_text);
1249 
1250  builder.Pop();
1251 
1252  auto paragraph = BuildParagraph(builder);
1253  paragraph->Layout(GetTestCanvasWidth() - 100);
1254 
1255  paragraph->Paint(GetCanvas(), 0, 0);
1256 
1257  SkPaint paint;
1258  paint.setStyle(SkPaint::kStroke_Style);
1259  paint.setAntiAlias(true);
1260  paint.setStrokeWidth(1);
1261 
1262  Paragraph::RectHeightStyle rect_height_style =
1263  Paragraph::RectHeightStyle::kTight;
1264  Paragraph::RectWidthStyle rect_width_style =
1265  Paragraph::RectWidthStyle::kTight;
1266  paint.setColor(SK_ColorRED);
1267  std::vector<txt::Paragraph::TextBox> boxes =
1268  paragraph->GetRectsForRange(0, 3, rect_height_style, rect_width_style);
1269  for (size_t i = 0; i < boxes.size(); ++i) {
1270  GetCanvas()->drawRect(boxes[i].rect, paint);
1271  }
1272  EXPECT_EQ(boxes.size(), 1ull);
1273 
1274  paint.setColor(SK_ColorGREEN);
1275  boxes = paragraph->GetRectsForRange(175, 176, rect_height_style,
1276  rect_width_style);
1277  for (size_t i = 0; i < boxes.size(); ++i) {
1278  GetCanvas()->drawRect(boxes[i].rect, paint);
1279  }
1280  EXPECT_EQ(boxes.size(), 1ull);
1281  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 31.703125);
1282  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 218.53125);
1283  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 47.304688);
1284  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 249);
1285 
1286  paint.setColor(SK_ColorRED);
1287  boxes = paragraph->GetRectsForPlaceholders();
1288  for (size_t i = 0; i < boxes.size(); ++i) {
1289  GetCanvas()->drawRect(boxes[i].rect, paint);
1290  }
1291 
1292  paint.setColor(SK_ColorBLUE);
1293  boxes =
1294  paragraph->GetRectsForRange(4, 45, rect_height_style, rect_width_style);
1295  for (size_t i = 0; i < boxes.size(); ++i) {
1296  GetCanvas()->drawRect(boxes[i].rect, paint);
1297  }
1298  EXPECT_EQ(boxes.size(), 30ull);
1299  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 59.742188);
1300  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 26.378906);
1301  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 90.945312);
1302  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 56.847656);
1303 
1304  EXPECT_FLOAT_EQ(boxes[11].rect.left(), 606.39062);
1305  EXPECT_FLOAT_EQ(boxes[11].rect.top(), 38);
1306  EXPECT_FLOAT_EQ(boxes[11].rect.right(), 631.39062);
1307  EXPECT_FLOAT_EQ(boxes[11].rect.bottom(), 63);
1308 
1309  EXPECT_FLOAT_EQ(boxes[17].rect.left(), 0.5);
1310  EXPECT_FLOAT_EQ(boxes[17].rect.top(), 63.5);
1311  EXPECT_FLOAT_EQ(boxes[17].rect.right(), 50.5);
1312  EXPECT_FLOAT_EQ(boxes[17].rect.bottom(), 113.5);
1313 
1314  ASSERT_TRUE(Snapshot());
1315 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [18/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderGetRectsParagraph)   
)

Definition at line 1317 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBaseline, txt::Paragraph::kMax, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1317  {
1318  const char* text = "012 34";
1319  auto icu_text = icu::UnicodeString::fromUTF8(text);
1320  std::u16string u16_text(icu_text.getBuffer(),
1321  icu_text.getBuffer() + icu_text.length());
1322 
1323  txt::ParagraphStyle paragraph_style;
1324  paragraph_style.max_lines = 14;
1325  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1326 
1327  txt::TextStyle text_style;
1328  text_style.font_families = std::vector<std::string>(1, "Roboto");
1329  text_style.font_size = 26;
1330  text_style.letter_spacing = 1;
1331  text_style.word_spacing = 5;
1332  text_style.color = SK_ColorBLACK;
1333  text_style.height = 1;
1335  text_style.decoration_color = SK_ColorBLACK;
1336  builder.PushStyle(text_style);
1337 
1338  builder.AddText(u16_text);
1339 
1340  txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
1342  txt::PlaceholderRun placeholder_run2(5, 20, PlaceholderAlignment::kBaseline,
1344  builder.AddPlaceholder(placeholder_run);
1345  builder.AddPlaceholder(placeholder_run);
1346  builder.AddPlaceholder(placeholder_run);
1347  builder.AddPlaceholder(placeholder_run);
1348  builder.AddPlaceholder(placeholder_run);
1349  builder.AddPlaceholder(placeholder_run);
1350  builder.AddPlaceholder(placeholder_run);
1351  builder.AddPlaceholder(placeholder_run);
1352  builder.AddPlaceholder(placeholder_run2);
1353  builder.AddPlaceholder(placeholder_run);
1354  builder.AddPlaceholder(placeholder_run);
1355  builder.AddPlaceholder(placeholder_run);
1356  builder.AddPlaceholder(placeholder_run);
1357  builder.AddPlaceholder(placeholder_run);
1358  builder.AddPlaceholder(placeholder_run2);
1359  builder.AddPlaceholder(placeholder_run);
1360  builder.AddPlaceholder(placeholder_run);
1361  builder.AddPlaceholder(placeholder_run);
1362  builder.AddPlaceholder(placeholder_run);
1363  builder.AddPlaceholder(placeholder_run);
1364  builder.AddPlaceholder(placeholder_run);
1365  builder.AddPlaceholder(placeholder_run);
1366  builder.AddPlaceholder(placeholder_run);
1367 
1368  builder.AddText(u16_text);
1369 
1370  builder.AddPlaceholder(placeholder_run);
1371  builder.AddPlaceholder(placeholder_run2);
1372  builder.AddPlaceholder(placeholder_run2);
1373  builder.AddPlaceholder(placeholder_run);
1374  builder.AddPlaceholder(placeholder_run2);
1375  builder.AddPlaceholder(placeholder_run2);
1376 
1377  builder.AddText(u16_text);
1378  builder.AddText(u16_text);
1379  builder.AddText(u16_text);
1380  builder.AddText(u16_text);
1381  builder.AddText(u16_text);
1382  builder.AddText(u16_text);
1383  builder.AddText(u16_text);
1384  builder.AddText(u16_text);
1385  builder.AddText(u16_text);
1386  builder.AddText(u16_text);
1387  builder.AddText(u16_text);
1388  builder.AddPlaceholder(placeholder_run2);
1389  builder.AddPlaceholder(placeholder_run);
1390  builder.AddPlaceholder(placeholder_run2);
1391  builder.AddPlaceholder(placeholder_run);
1392  builder.AddPlaceholder(placeholder_run2);
1393  builder.AddText(u16_text);
1394 
1395  builder.Pop();
1396 
1397  auto paragraph = BuildParagraph(builder);
1398  paragraph->Layout(GetTestCanvasWidth());
1399 
1400  paragraph->Paint(GetCanvas(), 0, 0);
1401 
1402  SkPaint paint;
1403  paint.setStyle(SkPaint::kStroke_Style);
1404  paint.setAntiAlias(true);
1405  paint.setStrokeWidth(1);
1406  paint.setColor(SK_ColorRED);
1407  std::vector<txt::Paragraph::TextBox> boxes =
1408  paragraph->GetRectsForPlaceholders();
1409  for (size_t i = 0; i < boxes.size(); ++i) {
1410  GetCanvas()->drawRect(boxes[i].rect, paint);
1411  }
1412  EXPECT_EQ(boxes.size(), 34ull);
1413  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 90.945312);
1414  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 0);
1415  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 140.94531);
1416  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 50);
1417 
1418  EXPECT_FLOAT_EQ(boxes[16].rect.left(), 800.94531);
1419  EXPECT_FLOAT_EQ(boxes[16].rect.top(), 0);
1420  EXPECT_FLOAT_EQ(boxes[16].rect.right(), 850.94531);
1421  EXPECT_FLOAT_EQ(boxes[16].rect.bottom(), 50);
1422 
1423  EXPECT_FLOAT_EQ(boxes[33].rect.left(), 503.48438);
1424  EXPECT_FLOAT_EQ(boxes[33].rect.top(), 160);
1425  EXPECT_FLOAT_EQ(boxes[33].rect.right(), 508.48438);
1426  EXPECT_FLOAT_EQ(boxes[33].rect.bottom(), 180);
1427 
1428  Paragraph::RectHeightStyle rect_height_style =
1429  Paragraph::RectHeightStyle::kMax;
1430  Paragraph::RectWidthStyle rect_width_style =
1431  Paragraph::RectWidthStyle::kTight;
1432  paint.setColor(SK_ColorBLUE);
1433  boxes =
1434  paragraph->GetRectsForRange(30, 50, rect_height_style, rect_width_style);
1435  for (size_t i = 0; i < boxes.size(); ++i) {
1436  GetCanvas()->drawRect(boxes[i].rect, paint);
1437  }
1438  EXPECT_EQ(boxes.size(), 8ull);
1439  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 216.10156);
1440  // Top should be taller than "tight"
1441  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 60);
1442  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 290.94531);
1443  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 120);
1444 
1445  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 290.94531);
1446  EXPECT_FLOAT_EQ(boxes[1].rect.top(), 60);
1447  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 340.94531);
1448  EXPECT_FLOAT_EQ(boxes[1].rect.bottom(), 120);
1449 
1450  EXPECT_FLOAT_EQ(boxes[2].rect.left(), 340.94531);
1451  EXPECT_FLOAT_EQ(boxes[2].rect.top(), 60);
1452  EXPECT_FLOAT_EQ(boxes[2].rect.right(), 345.94531);
1453  EXPECT_FLOAT_EQ(boxes[2].rect.bottom(), 120);
1454 
1455  ASSERT_TRUE(Snapshot());
1456 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [19/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderLongestLine)   
)

Definition at line 1458 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBaseline, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and txt::TextStyle::word_spacing.

1458  {
1459  txt::ParagraphStyle paragraph_style;
1460  paragraph_style.max_lines = 1;
1461  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1462 
1463  txt::TextStyle text_style;
1464  text_style.font_families = std::vector<std::string>(1, "Roboto");
1465  text_style.font_size = 26;
1466  text_style.letter_spacing = 1;
1467  text_style.word_spacing = 5;
1468  text_style.color = SK_ColorBLACK;
1469  text_style.height = 1;
1471  text_style.decoration_color = SK_ColorBLACK;
1472  builder.PushStyle(text_style);
1473 
1474  txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
1476  builder.AddPlaceholder(placeholder_run);
1477  builder.Pop();
1478 
1479  auto paragraph = BuildParagraph(builder);
1480  paragraph->Layout(GetTestCanvasWidth());
1481 
1482  ASSERT_DOUBLE_EQ(paragraph->width_, GetTestCanvasWidth());
1483  ASSERT_TRUE(paragraph->longest_line_ < GetTestCanvasWidth());
1484  ASSERT_TRUE(paragraph->longest_line_ >= 50);
1485 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [20/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(InlinePlaceholderIntrinsicWidth)   
)

Definition at line 1487 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddPlaceholder(), txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, DISABLE_ON_WINDOWS, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kAlphabetic, kBaseline, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), TEST_F(), text, and txt::TextStyle::word_spacing.

1487  {
1488  const char* text = "A ";
1489  auto icu_text = icu::UnicodeString::fromUTF8(text);
1490  std::u16string u16_text(icu_text.getBuffer(),
1491  icu_text.getBuffer() + icu_text.length());
1492 
1493  txt::PlaceholderRun placeholder_run(50, 50, PlaceholderAlignment::kBaseline,
1495 
1496  txt::ParagraphStyle paragraph_style;
1497  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1498 
1499  txt::TextStyle text_style;
1500  text_style.font_families = std::vector<std::string>(1, "Roboto");
1501  text_style.font_size = 20;
1502  text_style.decoration_color = SK_ColorBLACK;
1503  builder.PushStyle(text_style);
1504 
1505  builder.AddText(u16_text);
1506  builder.AddPlaceholder(placeholder_run);
1507 
1508  builder.Pop();
1509 
1510  auto paragraph = BuildParagraph(builder);
1511  paragraph->Layout(GetTestCanvasWidth());
1512 
1513  ASSERT_DOUBLE_EQ(paragraph->GetMinIntrinsicWidth(), 50);
1514  ASSERT_DOUBLE_EQ(paragraph->GetMaxIntrinsicWidth(), 68);
1515 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double font_size
Definition: text_style.h:51
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [21/89]

txt::TEST_F ( ParagraphTest  ,
SimpleRedParagraph   
)

Definition at line 1615 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and text.

1615  {
1616  const char* text = "I am RED";
1617  auto icu_text = icu::UnicodeString::fromUTF8(text);
1618  std::u16string u16_text(icu_text.getBuffer(),
1619  icu_text.getBuffer() + icu_text.length());
1620 
1621  txt::ParagraphStyle paragraph_style;
1622  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1623 
1624  txt::TextStyle text_style;
1625  text_style.font_families = std::vector<std::string>(1, "Roboto");
1626  text_style.color = SK_ColorRED;
1627  builder.PushStyle(text_style);
1628 
1629  builder.AddText(u16_text);
1630 
1631  builder.Pop();
1632 
1633  auto paragraph = BuildParagraph(builder);
1634  paragraph->Layout(GetTestCanvasWidth());
1635 
1636  paragraph->Paint(GetCanvas(), 10.0, 15.0);
1637 
1638  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1639  for (size_t i = 0; i < u16_text.length(); i++) {
1640  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1641  }
1642  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1643  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
1644  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
1645  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
1646  ASSERT_TRUE(Snapshot());
1647 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [22/89]

txt::TEST_F ( ParagraphTest  ,
RainbowParagraph   
)

Definition at line 1649 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, txt::TextStyle::font_weight, GetTestFontCollection(), kLineThrough, kOverline, kUnderline, left, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), w600, and txt::TextStyle::word_spacing.

1649  {
1650  const char* text1 = "Red Roboto";
1651  auto icu_text1 = icu::UnicodeString::fromUTF8(text1);
1652  std::u16string u16_text1(icu_text1.getBuffer(),
1653  icu_text1.getBuffer() + icu_text1.length());
1654  const char* text2 = "big Greeen Default";
1655  auto icu_text2 = icu::UnicodeString::fromUTF8(text2);
1656  std::u16string u16_text2(icu_text2.getBuffer(),
1657  icu_text2.getBuffer() + icu_text2.length());
1658  const char* text3 = "Defcolor Homemade Apple";
1659  auto icu_text3 = icu::UnicodeString::fromUTF8(text3);
1660  std::u16string u16_text3(icu_text3.getBuffer(),
1661  icu_text3.getBuffer() + icu_text3.length());
1662  const char* text4 = "Small Blue Roboto";
1663  auto icu_text4 = icu::UnicodeString::fromUTF8(text4);
1664  std::u16string u16_text4(icu_text4.getBuffer(),
1665  icu_text4.getBuffer() + icu_text4.length());
1666  const char* text5 =
1667  "Continue Last Style With lots of words to check if it overlaps "
1668  "properly or not";
1669  auto icu_text5 = icu::UnicodeString::fromUTF8(text5);
1670  std::u16string u16_text5(icu_text5.getBuffer(),
1671  icu_text5.getBuffer() + icu_text5.length());
1672 
1673  txt::ParagraphStyle paragraph_style;
1674  paragraph_style.max_lines = 2;
1675  paragraph_style.text_align = TextAlign::left;
1676  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1677 
1678  txt::TextStyle text_style1;
1679  text_style1.font_families = std::vector<std::string>(1, "Roboto");
1680  text_style1.color = SK_ColorRED;
1681 
1682  builder.PushStyle(text_style1);
1683 
1684  builder.AddText(u16_text1);
1685 
1686  txt::TextStyle text_style2;
1687  text_style2.font_size = 50;
1688  text_style2.letter_spacing = 10;
1689  text_style2.word_spacing = 30;
1690  text_style2.font_weight = txt::FontWeight::w600;
1691  text_style2.color = SK_ColorGREEN;
1692  text_style2.font_families = std::vector<std::string>(1, "Roboto");
1693  text_style2.decoration = TextDecoration::kUnderline |
1696  text_style2.decoration_color = SK_ColorBLACK;
1697  builder.PushStyle(text_style2);
1698 
1699  builder.AddText(u16_text2);
1700 
1701  txt::TextStyle text_style3;
1702  text_style3.font_families = std::vector<std::string>(1, "Homemade Apple");
1703  builder.PushStyle(text_style3);
1704 
1705  builder.AddText(u16_text3);
1706 
1707  txt::TextStyle text_style4;
1708  text_style4.font_size = 14;
1709  text_style4.color = SK_ColorBLUE;
1710  text_style4.font_families = std::vector<std::string>(1, "Roboto");
1711  text_style4.decoration = TextDecoration::kUnderline |
1714  text_style4.decoration_color = SK_ColorBLACK;
1715  builder.PushStyle(text_style4);
1716 
1717  builder.AddText(u16_text4);
1718 
1719  // Extra text to see if it goes to default when there is more text chunks than
1720  // styles.
1721  builder.AddText(u16_text5);
1722 
1723  builder.Pop();
1724 
1725  auto paragraph = BuildParagraph(builder);
1726  paragraph->Layout(GetTestCanvasWidth());
1727  paragraph->Paint(GetCanvas(), 0, 0);
1728 
1729  u16_text1 += u16_text2 + u16_text3 + u16_text4;
1730  for (size_t i = 0; i < u16_text1.length(); i++) {
1731  ASSERT_EQ(paragraph->text_[i], u16_text1[i]);
1732  }
1733  ASSERT_TRUE(Snapshot());
1734  ASSERT_EQ(paragraph->runs_.runs_.size(), 4ull);
1735  ASSERT_EQ(paragraph->runs_.styles_.size(), 5ull);
1736  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style1));
1737  ASSERT_TRUE(paragraph->runs_.styles_[2].equals(text_style2));
1738  ASSERT_TRUE(paragraph->runs_.styles_[3].equals(text_style3));
1739  ASSERT_TRUE(paragraph->runs_.styles_[4].equals(text_style4));
1740  ASSERT_EQ(paragraph->records_[0].style().color, text_style1.color);
1741  ASSERT_EQ(paragraph->records_[1].style().color, text_style2.color);
1742  ASSERT_EQ(paragraph->records_[2].style().color, text_style3.color);
1743  ASSERT_EQ(paragraph->records_[3].style().color, text_style4.color);
1744 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
FontWeight font_weight
Definition: text_style.h:44
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [23/89]

txt::TEST_F ( ParagraphTest  ,
DefaultStyleParagraph   
)

Definition at line 1747 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::ParagraphStyle::font_family, GetTestFontCollection(), txt::ParagraphBuilderTxt::Pop(), and text.

1747  {
1748  const char* text = "No TextStyle! Uh Oh!";
1749  auto icu_text = icu::UnicodeString::fromUTF8(text);
1750  std::u16string u16_text(icu_text.getBuffer(),
1751  icu_text.getBuffer() + icu_text.length());
1752 
1753  txt::ParagraphStyle paragraph_style;
1754  paragraph_style.font_family = "Roboto";
1755  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1756 
1757  builder.AddText(u16_text);
1758 
1759  builder.Pop();
1760 
1761  auto paragraph = BuildParagraph(builder);
1762  paragraph->Layout(GetTestCanvasWidth());
1763 
1764  paragraph->Paint(GetCanvas(), 10.0, 15.0);
1765 
1766  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1767  for (size_t i = 0; i < u16_text.length(); i++) {
1768  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1769  }
1770  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1771  ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull);
1772  ASSERT_TRUE(Snapshot());
1773 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::string font_family
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [24/89]

txt::TEST_F ( ParagraphTest  ,
BoldParagraph   
)

Definition at line 1775 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, txt::TextStyle::font_weight, GetTestFontCollection(), txt::Paragraph::kMax, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and w900.

1775  {
1776  const char* text = "This is Red max bold text!";
1777  auto icu_text = icu::UnicodeString::fromUTF8(text);
1778  std::u16string u16_text(icu_text.getBuffer(),
1779  icu_text.getBuffer() + icu_text.length());
1780 
1781  txt::ParagraphStyle paragraph_style;
1782  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1783 
1784  txt::TextStyle text_style;
1785  text_style.font_families = std::vector<std::string>(1, "Roboto");
1786  text_style.font_size = 60;
1787  text_style.letter_spacing = 0;
1788  text_style.font_weight = txt::FontWeight::w900;
1789  text_style.color = SK_ColorRED;
1790  builder.PushStyle(text_style);
1791 
1792  builder.AddText(u16_text);
1793 
1794  builder.Pop();
1795 
1796  auto paragraph = BuildParagraph(builder);
1797  paragraph->Layout(GetTestCanvasWidth());
1798 
1799  paragraph->Paint(GetCanvas(), 10.0, 60.0);
1800 
1801  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1802  for (size_t i = 0; i < u16_text.length(); i++) {
1803  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1804  }
1805  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1806  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
1807  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
1808  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
1809  ASSERT_TRUE(Snapshot());
1810 
1811  // width_ takes the full available space, but longest_line_ is only the width
1812  // of the text, which is less than one line.
1813  ASSERT_DOUBLE_EQ(paragraph->width_, GetTestCanvasWidth());
1814  ASSERT_TRUE(paragraph->longest_line_ < paragraph->width_);
1815  Paragraph::RectHeightStyle rect_height_style =
1816  Paragraph::RectHeightStyle::kMax;
1817  Paragraph::RectWidthStyle rect_width_style =
1818  Paragraph::RectWidthStyle::kTight;
1819  std::vector<txt::Paragraph::TextBox> boxes = paragraph->GetRectsForRange(
1820  0, strlen(text), rect_height_style, rect_width_style);
1821  ASSERT_DOUBLE_EQ(paragraph->longest_line_,
1822  boxes[boxes.size() - 1].rect.right() - boxes[0].rect.left());
1823 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
FontWeight font_weight
Definition: text_style.h:44
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [25/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(HeightOverrideParagraph)   
)

Definition at line 1825 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::has_height_override, txt::TextStyle::height, txt::Paragraph::kIncludeLineSpacingMiddle, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1825  {
1826  const char* text = "01234満毎冠行来昼本可\nabcd\n満毎冠行来昼本可";
1827  auto icu_text = icu::UnicodeString::fromUTF8(text);
1828  std::u16string u16_text(icu_text.getBuffer(),
1829  icu_text.getBuffer() + icu_text.length());
1830 
1831  txt::ParagraphStyle paragraph_style;
1832  paragraph_style.max_lines = 10;
1833  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1834 
1835  txt::TextStyle text_style;
1836  text_style.font_families = std::vector<std::string>(1, "Roboto");
1837  text_style.font_size = 20;
1838  text_style.letter_spacing = 0;
1839  text_style.word_spacing = 0;
1840  text_style.color = SK_ColorBLACK;
1841  text_style.height = 3.6345;
1842  text_style.has_height_override = true;
1843  builder.PushStyle(text_style);
1844 
1845  builder.AddText(u16_text);
1846 
1847  builder.Pop();
1848 
1849  auto paragraph = BuildParagraph(builder);
1850  paragraph->Layout(550);
1851 
1852  paragraph->Paint(GetCanvas(), 0, 0);
1853 
1854  SkPaint paint;
1855  paint.setStyle(SkPaint::kStroke_Style);
1856  paint.setAntiAlias(true);
1857  paint.setStrokeWidth(1);
1858 
1859  // Tests for GetRectsForRange()
1860  Paragraph::RectHeightStyle rect_height_style =
1861  Paragraph::RectHeightStyle::kIncludeLineSpacingMiddle;
1862  Paragraph::RectWidthStyle rect_width_style =
1863  Paragraph::RectWidthStyle::kTight;
1864  paint.setColor(SK_ColorRED);
1865  std::vector<txt::Paragraph::TextBox> boxes =
1866  paragraph->GetRectsForRange(0, 0, rect_height_style, rect_width_style);
1867  for (size_t i = 0; i < boxes.size(); ++i) {
1868  GetCanvas()->drawRect(boxes[i].rect, paint);
1869  }
1870  EXPECT_EQ(boxes.size(), 0ull);
1871 
1872  boxes =
1873  paragraph->GetRectsForRange(0, 40, rect_height_style, rect_width_style);
1874  for (size_t i = 0; i < boxes.size(); ++i) {
1875  GetCanvas()->drawRect(boxes[i].rect, paint);
1876  }
1877  EXPECT_EQ(boxes.size(), 3ull);
1878  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 0);
1879  EXPECT_NEAR(boxes[1].rect.top(), 92.805778503417969, 0.0001);
1880  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 43.851562);
1881  EXPECT_NEAR(boxes[1].rect.bottom(), 165.49578857421875, 0.0001);
1882 
1883  ASSERT_TRUE(Snapshot());
1884 }
bool has_height_override
Definition: text_style.h:55
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [26/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(HeightOverrideHalfLeadingTextStyle)   
)

Definition at line 1886 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::half_leading, txt::TextStyle::has_height_override, txt::TextStyle::height, kAll, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1886  {
1887  // All 3 lines will have the same typeface.
1888  const char* text = "01234満毎冠行来昼本可\nabcd\n満毎冠行来昼本可";
1889  auto icu_text = icu::UnicodeString::fromUTF8(text);
1890  std::u16string u16_text(icu_text.getBuffer(),
1891  icu_text.getBuffer() + icu_text.length());
1892 
1893  txt::ParagraphStyle paragraph_style;
1894  paragraph_style.max_lines = 10;
1895  paragraph_style.text_height_behavior = TextHeightBehavior::kAll;
1896  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1897 
1898  txt::TextStyle text_style;
1899  text_style.font_families = std::vector<std::string>(1, "Roboto");
1900  text_style.font_size = 20;
1901  text_style.letter_spacing = 0;
1902  text_style.word_spacing = 0;
1903  text_style.color = SK_ColorBLACK;
1904  text_style.height = 3.6345;
1905  text_style.has_height_override = true;
1906  // Override paragraph_style.text_height_behavior:
1907  text_style.half_leading = true;
1908  builder.PushStyle(text_style);
1909 
1910  builder.AddText(u16_text);
1911 
1912  builder.Pop();
1913 
1914  auto paragraph = BuildParagraph(builder);
1915  paragraph->Layout(550);
1916 
1917  paragraph->Paint(GetCanvas(), 0, 0);
1918 
1919  SkPaint paint;
1920  paint.setStyle(SkPaint::kStroke_Style);
1921  paint.setAntiAlias(true);
1922  paint.setStrokeWidth(1);
1923 
1924  // Tests for GetRectsForRange()
1925  Paragraph::RectHeightStyle rect_height_style =
1926  Paragraph::RectHeightStyle::kTight;
1927  Paragraph::RectHeightStyle rect_height_style_max =
1928  Paragraph::RectHeightStyle::kMax;
1929  Paragraph::RectWidthStyle rect_width_style =
1930  Paragraph::RectWidthStyle::kTight;
1931  paint.setColor(SK_ColorRED);
1932 
1933  std::vector<txt::Paragraph::TextBox> boxes =
1934  paragraph->GetRectsForRange(0, 40, rect_height_style, rect_width_style);
1935  for (size_t i = 0; i < boxes.size(); ++i) {
1936  GetCanvas()->drawRect(boxes[i].rect, paint);
1937  }
1938 
1939  std::vector<txt::Paragraph::TextBox> line_boxes = paragraph->GetRectsForRange(
1940  0, 40, rect_height_style_max, rect_width_style);
1941  EXPECT_EQ(boxes.size(), 3ull);
1942  EXPECT_EQ(line_boxes.size(), 3ull);
1943 
1944  const double line_spacing1 = boxes[1].rect.top() - boxes[0].rect.bottom();
1945  const double line_spacing2 = boxes[2].rect.top() - boxes[1].rect.bottom();
1946 
1947  EXPECT_EQ(line_spacing1, line_spacing2);
1948 
1949  // half leading.
1950  EXPECT_EQ(line_boxes[0].rect.top() - boxes[0].rect.top(),
1951  boxes[0].rect.bottom() - line_boxes[0].rect.bottom());
1952  EXPECT_EQ(line_boxes[1].rect.top() - boxes[1].rect.top(),
1953  boxes[1].rect.bottom() - line_boxes[1].rect.bottom());
1954  EXPECT_EQ(line_boxes[2].rect.top() - boxes[2].rect.top(),
1955  boxes[2].rect.bottom() - line_boxes[2].rect.bottom());
1956  // With half-leadding, the x coordinates should remain the same.
1957  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 0);
1958  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 43.851562);
1959 
1960  ASSERT_TRUE(Snapshot());
1961 }
bool has_height_override
Definition: text_style.h:55
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
bool half_leading
Definition: text_style.h:47
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [27/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(MixedTextHeightBehaviorSameLine)   
)

Definition at line 1963 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::half_leading, txt::TextStyle::has_height_override, txt::TextStyle::height, kAll, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

1963  {
1964  // Both runs will still have the same typeface, but with different text height
1965  // behaviors.
1966  const char* text = "01234満毎冠行来昼本可abcd";
1967  auto icu_text = icu::UnicodeString::fromUTF8(text);
1968  std::u16string u16_text(icu_text.getBuffer(),
1969  icu_text.getBuffer() + icu_text.length());
1970 
1971  std::u16string u16_text2(icu_text.getBuffer(),
1972  icu_text.getBuffer() + icu_text.length());
1973 
1974  txt::ParagraphStyle paragraph_style;
1975  paragraph_style.max_lines = 10;
1976  paragraph_style.text_height_behavior = TextHeightBehavior::kAll;
1977  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1978 
1979  txt::TextStyle text_style;
1980  text_style.font_families = std::vector<std::string>(1, "Roboto");
1981  text_style.font_size = 20;
1982  text_style.letter_spacing = 0;
1983  text_style.word_spacing = 0;
1984  text_style.color = SK_ColorBLACK;
1985  text_style.height = 3.6345;
1986  text_style.has_height_override = true;
1987  // First run, with half-leading.
1988  text_style.half_leading = true;
1989  builder.PushStyle(text_style);
1990  builder.AddText(u16_text);
1991 
1992  // Second run with AD-scaling.
1993  text_style.half_leading = false;
1994 
1995  builder.PushStyle(text_style);
1996  builder.AddText(u16_text2);
1997  builder.Pop();
1998 
1999  auto paragraph = BuildParagraph(builder);
2000  paragraph->Layout(550);
2001 
2002  paragraph->Paint(GetCanvas(), 0, 0);
2003 
2004  SkPaint paint;
2005  paint.setStyle(SkPaint::kStroke_Style);
2006  paint.setAntiAlias(true);
2007  paint.setStrokeWidth(1);
2008  // Tests for GetRectsForRange()
2009  Paragraph::RectHeightStyle rect_height_style =
2010  Paragraph::RectHeightStyle::kTight;
2011  Paragraph::RectHeightStyle rect_height_style_max =
2012  Paragraph::RectHeightStyle::kMax;
2013  Paragraph::RectWidthStyle rect_width_style =
2014  Paragraph::RectWidthStyle::kTight;
2015  paint.setColor(SK_ColorRED);
2016 
2017  std::vector<txt::Paragraph::TextBox> boxes = paragraph->GetRectsForRange(
2018  0, icu_text.length(), rect_height_style, rect_width_style);
2019  for (size_t i = 0; i < boxes.size(); ++i) {
2020  GetCanvas()->drawRect(boxes[i].rect, paint);
2021  }
2022 
2023  std::vector<txt::Paragraph::TextBox> line_boxes = paragraph->GetRectsForRange(
2024  0, icu_text.length(), rect_height_style_max, rect_width_style);
2025  // The runs has the same typeface so they should be grouped together.
2026  EXPECT_EQ(boxes.size(), 1ull);
2027  EXPECT_EQ(line_boxes.size(), 1ull);
2028 
2029  const double glyphHeight = boxes[0].rect.height();
2030  const double metricsAscent = 18.5546875;
2031  const double metricsDescent = 4.8828125;
2032  EXPECT_DOUBLE_EQ(glyphHeight, metricsAscent + metricsDescent);
2033 
2034  const double line_height = 3.6345 * 20;
2035  const double leading = line_height - glyphHeight;
2036 
2037  // Overall descent is from half-leading and overall ascent is from AD-scaling.
2038  EXPECT_NEAR(boxes[0].rect.top() - line_boxes[0].rect.top(),
2039  leading * metricsAscent / (metricsAscent + metricsDescent),
2040  0.001);
2041 
2042  EXPECT_NEAR(line_boxes[0].rect.bottom() - boxes[0].rect.bottom(),
2043  leading * 0.5, 0.001);
2044 }
bool has_height_override
Definition: text_style.h:55
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
bool half_leading
Definition: text_style.h:47
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [28/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(MixedTextHeightBehaviorSameLineWithZeroHeight)   
)

Definition at line 2046 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::half_leading, txt::TextStyle::has_height_override, txt::TextStyle::height, kAll, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

2047  {
2048  // Both runs will still have the same typeface, but with different text height
2049  // behaviors.
2050  const char* text = "01234満毎冠行来昼本可abcd";
2051  auto icu_text = icu::UnicodeString::fromUTF8(text);
2052  std::u16string u16_text(icu_text.getBuffer(),
2053  icu_text.getBuffer() + icu_text.length());
2054 
2055  txt::ParagraphStyle paragraph_style;
2056  paragraph_style.max_lines = 10;
2057  paragraph_style.text_height_behavior = TextHeightBehavior::kAll;
2058  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2059 
2060  txt::TextStyle text_style;
2061  text_style.font_families = std::vector<std::string>(1, "Roboto");
2062  text_style.font_size = 20;
2063  text_style.letter_spacing = 0;
2064  text_style.word_spacing = 0;
2065  text_style.color = SK_ColorBLACK;
2066  // Set height to 0
2067  text_style.height = 0;
2068  text_style.has_height_override = true;
2069  // First run, with half-leading.
2070  text_style.half_leading = true;
2071  builder.PushStyle(text_style);
2072  builder.AddText(u16_text);
2073 
2074  // Second run with AD-scaling.
2075  text_style.half_leading = false;
2076 
2077  builder.PushStyle(text_style);
2078  builder.AddText(u16_text);
2079  builder.Pop();
2080 
2081  auto paragraph = BuildParagraph(builder);
2082  paragraph->Layout(550);
2083 
2084  paragraph->Paint(GetCanvas(), 0, 0);
2085 
2086  SkPaint paint;
2087  paint.setStyle(SkPaint::kStroke_Style);
2088  paint.setAntiAlias(true);
2089  paint.setStrokeWidth(1);
2090  // Tests for GetRectsForRange()
2091  Paragraph::RectHeightStyle rect_height_style =
2092  Paragraph::RectHeightStyle::kTight;
2093  Paragraph::RectHeightStyle rect_height_style_max =
2094  Paragraph::RectHeightStyle::kMax;
2095  Paragraph::RectWidthStyle rect_width_style =
2096  Paragraph::RectWidthStyle::kTight;
2097  paint.setColor(SK_ColorRED);
2098 
2099  std::vector<txt::Paragraph::TextBox> boxes = paragraph->GetRectsForRange(
2100  0, icu_text.length(), rect_height_style, rect_width_style);
2101  for (size_t i = 0; i < boxes.size(); ++i) {
2102  GetCanvas()->drawRect(boxes[i].rect, paint);
2103  }
2104 
2105  std::vector<txt::Paragraph::TextBox> line_boxes = paragraph->GetRectsForRange(
2106  0, icu_text.length(), rect_height_style_max, rect_width_style);
2107  // The runs has the same typeface so they should be grouped together.
2108  EXPECT_EQ(boxes.size(), 1ull);
2109  EXPECT_EQ(line_boxes.size(), 1ull);
2110 
2111  const double glyphHeight = boxes[0].rect.height();
2112  const double metricsAscent = 18.5546875;
2113  const double metricsDescent = 4.8828125;
2114  EXPECT_DOUBLE_EQ(glyphHeight, metricsAscent + metricsDescent);
2115 
2116  // line_height for both styled runs is 0, but the overall line height is not
2117  // 0.
2118  EXPECT_DOUBLE_EQ(line_boxes[0].rect.height(),
2119  metricsAscent - (metricsAscent + metricsDescent) / 2);
2120  EXPECT_LT(boxes[0].rect.top(), 0.0);
2121  EXPECT_GT(boxes[0].rect.bottom(), 0.0);
2122 }
bool has_height_override
Definition: text_style.h:55
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
bool half_leading
Definition: text_style.h:47
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [29/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(HeightOverrideHalfLeadingStrut)   
)

Definition at line 2124 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::half_leading, txt::TextStyle::has_height_override, txt::TextStyle::height, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

2124  {
2125  // All 3 lines will have the same typeface.
2126  const char* text = "01234満毎冠行来昼本可\nabcd\n満毎冠行来昼本可";
2127  auto icu_text = icu::UnicodeString::fromUTF8(text);
2128  std::u16string u16_text(icu_text.getBuffer(),
2129  icu_text.getBuffer() + icu_text.length());
2130 
2131  txt::ParagraphStyle paragraph_style;
2132  paragraph_style.max_lines = 10;
2133  paragraph_style.strut_enabled = true;
2134  paragraph_style.strut_has_height_override = true;
2135  paragraph_style.strut_height = 3.6345;
2136  paragraph_style.strut_font_size = 20;
2137  paragraph_style.strut_font_families.push_back("Roboto");
2138  paragraph_style.strut_half_leading = true;
2139  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2140 
2141  txt::TextStyle text_style;
2142  text_style.font_families = std::vector<std::string>(1, "Roboto");
2143  text_style.font_size = 20;
2144  text_style.letter_spacing = 0;
2145  text_style.word_spacing = 0;
2146  text_style.color = SK_ColorBLACK;
2147  text_style.height = 3.6345;
2148  text_style.has_height_override = true;
2149  text_style.half_leading = true;
2150  builder.PushStyle(text_style);
2151 
2152  builder.AddText(u16_text);
2153 
2154  builder.Pop();
2155 
2156  auto paragraph = BuildParagraph(builder);
2157  paragraph->Layout(550);
2158 
2159  paragraph->Paint(GetCanvas(), 0, 0);
2160 
2161  SkPaint paint;
2162  paint.setStyle(SkPaint::kStroke_Style);
2163  paint.setAntiAlias(true);
2164  paint.setStrokeWidth(1);
2165 
2166  // Tests for GetRectsForRange()
2167  Paragraph::RectHeightStyle rect_height_style =
2168  Paragraph::RectHeightStyle::kTight;
2169  Paragraph::RectHeightStyle rect_height_style_max =
2170  Paragraph::RectHeightStyle::kMax;
2171  Paragraph::RectWidthStyle rect_width_style =
2172  Paragraph::RectWidthStyle::kTight;
2173  paint.setColor(SK_ColorRED);
2174 
2175  std::vector<txt::Paragraph::TextBox> boxes =
2176  paragraph->GetRectsForRange(0, 40, rect_height_style, rect_width_style);
2177  for (size_t i = 0; i < boxes.size(); ++i) {
2178  GetCanvas()->drawRect(boxes[i].rect, paint);
2179  }
2180 
2181  std::vector<txt::Paragraph::TextBox> line_boxes = paragraph->GetRectsForRange(
2182  0, 40, rect_height_style_max, rect_width_style);
2183  EXPECT_EQ(boxes.size(), 3ull);
2184  EXPECT_EQ(line_boxes.size(), 3ull);
2185 
2186  const double line_spacing1 = boxes[1].rect.top() - boxes[0].rect.bottom();
2187  const double line_spacing2 = boxes[2].rect.top() - boxes[1].rect.bottom();
2188 
2189  EXPECT_EQ(line_spacing1, line_spacing2);
2190 
2191  // Strut half leading.
2192  EXPECT_EQ(line_boxes[0].rect.top() - boxes[0].rect.top(),
2193  boxes[0].rect.bottom() - line_boxes[0].rect.bottom());
2194  EXPECT_EQ(line_boxes[1].rect.top() - boxes[1].rect.top(),
2195  boxes[1].rect.bottom() - line_boxes[1].rect.bottom());
2196  EXPECT_EQ(line_boxes[2].rect.top() - boxes[2].rect.top(),
2197  boxes[2].rect.bottom() - line_boxes[2].rect.bottom());
2198 
2199  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 0);
2200  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 43.851562);
2201 
2202  ASSERT_TRUE(Snapshot());
2203 }
bool has_height_override
Definition: text_style.h:55
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
bool half_leading
Definition: text_style.h:47
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [30/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(ZeroHeightHalfLeadingStrutForceHeight)   
)

Definition at line 2205 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::half_leading, txt::TextStyle::has_height_override, txt::TextStyle::height, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

2206  {
2207  // All 3 lines will have the same typeface.
2208  const char* text = "01234満毎冠行来昼本可abcdn満毎冠行来昼本可";
2209  auto icu_text = icu::UnicodeString::fromUTF8(text);
2210  std::u16string u16_text(icu_text.getBuffer(),
2211  icu_text.getBuffer() + icu_text.length());
2212 
2213  txt::ParagraphStyle paragraph_style;
2214  paragraph_style.max_lines = 10;
2215  paragraph_style.strut_enabled = true;
2216  paragraph_style.strut_has_height_override = true;
2217  paragraph_style.strut_height = 0;
2218  // Force strut height.
2219  paragraph_style.force_strut_height = true;
2220  paragraph_style.strut_font_size = 20;
2221  paragraph_style.strut_font_families.push_back("Roboto");
2222  paragraph_style.strut_half_leading = true;
2223  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2224 
2225  txt::TextStyle text_style;
2226  text_style.font_families = std::vector<std::string>(1, "Roboto");
2227  text_style.font_size = 20;
2228  text_style.letter_spacing = 0;
2229  text_style.word_spacing = 0;
2230  text_style.color = SK_ColorBLACK;
2231  text_style.height = 0;
2232  text_style.has_height_override = true;
2233 
2234  // First run, with half-leading.
2235  text_style.half_leading = true;
2236  builder.PushStyle(text_style);
2237  builder.AddText(u16_text);
2238 
2239  // Second run with AD-scaling.
2240  text_style.half_leading = false;
2241 
2242  builder.PushStyle(text_style);
2243  builder.AddText(u16_text);
2244  builder.Pop();
2245 
2246  auto paragraph = BuildParagraph(builder);
2247  paragraph->Layout(550);
2248 
2249  paragraph->Paint(GetCanvas(), 0, 0);
2250 
2251  SkPaint paint;
2252  paint.setStyle(SkPaint::kStroke_Style);
2253  paint.setAntiAlias(true);
2254  paint.setStrokeWidth(1);
2255 
2256  // Tests for GetRectsForRange()
2257  Paragraph::RectHeightStyle rect_height_style =
2258  Paragraph::RectHeightStyle::kTight;
2259  Paragraph::RectHeightStyle rect_height_style_max =
2260  Paragraph::RectHeightStyle::kMax;
2261  Paragraph::RectWidthStyle rect_width_style =
2262  Paragraph::RectWidthStyle::kTight;
2263  paint.setColor(SK_ColorRED);
2264 
2265  std::vector<txt::Paragraph::TextBox> boxes = paragraph->GetRectsForRange(
2266  0, icu_text.length(), rect_height_style, rect_width_style);
2267  for (size_t i = 0; i < boxes.size(); ++i) {
2268  GetCanvas()->drawRect(boxes[i].rect, paint);
2269  }
2270 
2271  std::vector<txt::Paragraph::TextBox> line_boxes = paragraph->GetRectsForRange(
2272  0, icu_text.length(), rect_height_style_max, rect_width_style);
2273  // The runs has the same typeface so they should be grouped together.
2274  EXPECT_EQ(boxes.size(), 1ull);
2275  EXPECT_EQ(line_boxes.size(), 1ull);
2276 
2277  const double glyphHeight = boxes[0].rect.height();
2278  const double metricsAscent = 18.5546875;
2279  const double metricsDescent = 4.8828125;
2280  EXPECT_DOUBLE_EQ(glyphHeight, metricsAscent + metricsDescent);
2281 
2282  EXPECT_DOUBLE_EQ(line_boxes[0].rect.height(), 0.0);
2283 
2284  ASSERT_TRUE(Snapshot());
2285 }
bool has_height_override
Definition: text_style.h:55
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
bool half_leading
Definition: text_style.h:47
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [31/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(LeftAlignParagraph)   
)

Definition at line 2287 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kUnderline, left, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

2287  {
2288  const char* text =
2289  "This is a very long sentence to test if the text will properly wrap "
2290  "around and go to the next line. Sometimes, short sentence. Longer "
2291  "sentences are okay too because they are necessary. Very short. "
2292  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2293  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2294  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2295  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2296  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2297  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2298  "mollit anim id est laborum. "
2299  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2300  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2301  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2302  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2303  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2304  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2305  "mollit anim id est laborum.";
2306  auto icu_text = icu::UnicodeString::fromUTF8(text);
2307  std::u16string u16_text(icu_text.getBuffer(),
2308  icu_text.getBuffer() + icu_text.length());
2309 
2310  txt::ParagraphStyle paragraph_style;
2311  paragraph_style.max_lines = 14;
2312  paragraph_style.text_align = TextAlign::left;
2313  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2314 
2315  txt::TextStyle text_style;
2316  text_style.font_families = std::vector<std::string>(1, "Roboto");
2317  text_style.font_size = 26;
2318  text_style.letter_spacing = 1;
2319  text_style.word_spacing = 5;
2320  text_style.color = SK_ColorBLACK;
2321  text_style.height = 1;
2323  text_style.decoration_color = SK_ColorBLACK;
2324  builder.PushStyle(text_style);
2325 
2326  builder.AddText(u16_text);
2327 
2328  builder.Pop();
2329 
2330  auto paragraph = BuildParagraph(builder);
2331  paragraph->Layout(GetTestCanvasWidth() - 100);
2332 
2333  paragraph->Paint(GetCanvas(), 0, 0);
2334 
2335  ASSERT_TRUE(Snapshot());
2336 
2337  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2338  for (size_t i = 0; i < u16_text.length(); i++) {
2339  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2340  }
2341  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2342  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2343  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2344  ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines);
2345  double expected_y = 24;
2346 
2347  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2348  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2349  expected_y += 30;
2350  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0);
2351 
2352  ASSERT_TRUE(paragraph->records_[1].style().equals(text_style));
2353  ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y);
2354  expected_y += 30;
2355  ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().x(), 0);
2356 
2357  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2358  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2359  expected_y += 30;
2360  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 0);
2361 
2362  ASSERT_TRUE(paragraph->records_[3].style().equals(text_style));
2363  ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y);
2364  expected_y += 30 * 10;
2365  ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().x(), 0);
2366 
2367  ASSERT_TRUE(paragraph->records_[13].style().equals(text_style));
2368  ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y);
2369  ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().x(), 0);
2370 
2371  ASSERT_EQ(paragraph_style.text_align,
2372  paragraph->GetParagraphStyle().text_align);
2373 
2374  // Tests for GetGlyphPositionAtCoordinate()
2375  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(0, 0).position, 0ull);
2376  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(1, 1).position, 0ull);
2377  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(1, 35).position, 68ull);
2378  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(1, 70).position, 134ull);
2379  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(2000, 35).position, 134ull);
2380 
2381  ASSERT_TRUE(Snapshot());
2382 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [32/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(LeftAlignRTLParagraphHitTest)   
)

Definition at line 2384 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kUnderline, left, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), rtl, text, and txt::TextStyle::word_spacing.

2384  {
2385  // Regression test for https://github.com/flutter/flutter/issues/54969.
2386  const char* text = "بمباركة التقليدية قام عن. تصفح";
2387  auto icu_text = icu::UnicodeString::fromUTF8(text);
2388  std::u16string u16_text(icu_text.getBuffer(),
2389  icu_text.getBuffer() + icu_text.length());
2390 
2391  txt::ParagraphStyle paragraph_style;
2392  paragraph_style.max_lines = 1;
2393  paragraph_style.text_align = TextAlign::left;
2394  paragraph_style.text_direction = TextDirection::rtl;
2395  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2396 
2397  txt::TextStyle text_style;
2398  text_style.font_families = std::vector<std::string>(1, "Roboto");
2399  text_style.font_size = 26;
2400  text_style.letter_spacing = 1;
2401  text_style.word_spacing = 5;
2402  text_style.color = SK_ColorBLACK;
2403  text_style.height = 1;
2405  text_style.decoration_color = SK_ColorBLACK;
2406  builder.PushStyle(text_style);
2407 
2408  builder.AddText(u16_text);
2409 
2410  builder.Pop();
2411 
2412  auto paragraph = BuildParagraph(builder);
2413  paragraph->Layout(GetTestCanvasWidth());
2414 
2415  paragraph->Paint(GetCanvas(), 0, 0);
2416 
2417  ASSERT_TRUE(Snapshot());
2418 
2419  // Tests for GetGlyphPositionAtCoordinate()
2420  ASSERT_EQ(
2421  paragraph->GetGlyphPositionAtCoordinate(GetTestCanvasWidth() - 0.5, 0.5)
2422  .position,
2423  0ull);
2424 
2425  ASSERT_TRUE(Snapshot());
2426 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [33/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(RightAlignParagraph)   
)

Definition at line 2428 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), right, text, and txt::TextStyle::word_spacing.

2428  {
2429  const char* text =
2430  "This is a very long sentence to test if the text will properly wrap "
2431  "around and go to the next line. Sometimes, short sentence. Longer "
2432  "sentences are okay too because they are necessary. Very short. "
2433  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2434  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2435  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2436  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2437  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2438  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2439  "mollit anim id est laborum. "
2440  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2441  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2442  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2443  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2444  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2445  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2446  "mollit anim id est laborum.";
2447  auto icu_text = icu::UnicodeString::fromUTF8(text);
2448  std::u16string u16_text(icu_text.getBuffer(),
2449  icu_text.getBuffer() + icu_text.length());
2450 
2451  txt::ParagraphStyle paragraph_style;
2452  paragraph_style.max_lines = 14;
2453  paragraph_style.text_align = TextAlign::right;
2454  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2455 
2456  txt::TextStyle text_style;
2457  text_style.font_families = std::vector<std::string>(1, "Roboto");
2458  text_style.font_size = 26;
2459  text_style.letter_spacing = 1;
2460  text_style.word_spacing = 5;
2461  text_style.color = SK_ColorBLACK;
2462  text_style.height = 1;
2464  text_style.decoration_color = SK_ColorBLACK;
2465  builder.PushStyle(text_style);
2466 
2467  builder.AddText(u16_text);
2468 
2469  builder.Pop();
2470 
2471  auto paragraph = BuildParagraph(builder);
2472  int available_width = GetTestCanvasWidth() - 100;
2473  paragraph->Layout(available_width);
2474 
2475  paragraph->Paint(GetCanvas(), 0, 0);
2476 
2477  ASSERT_TRUE(Snapshot());
2478  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2479  for (size_t i = 0; i < u16_text.length(); i++) {
2480  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2481  }
2482  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2483  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2484  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2485  // Two records for each due to 'ghost' trailing whitespace run.
2486  ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines * 2);
2487  double expected_y = 24;
2488 
2489  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2490  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2491  expected_y += 30;
2492  ASSERT_NEAR(paragraph->records_[0].offset().x(),
2493  paragraph->width_ -
2494  paragraph->line_widths_[paragraph->records_[0].line()],
2495  2.0);
2496 
2497  // width_ takes the full available space, while longest_line_ wraps the glyphs
2498  // as tightly as possible. Even though this text is more than one line long,
2499  // no line perfectly spans the width of the full line, so longest_line_ is
2500  // less than width_.
2501  ASSERT_DOUBLE_EQ(paragraph->width_, available_width);
2502  ASSERT_TRUE(paragraph->longest_line_ < available_width);
2503  ASSERT_DOUBLE_EQ(paragraph->longest_line_, 880.87109375);
2504 
2505  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2506  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2507  expected_y += 30;
2508  ASSERT_NEAR(paragraph->records_[2].offset().x(),
2509  paragraph->width_ -
2510  paragraph->line_widths_[paragraph->records_[2].line()],
2511  2.0);
2512 
2513  ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
2514  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
2515  expected_y += 30;
2516  ASSERT_NEAR(paragraph->records_[4].offset().x(),
2517  paragraph->width_ -
2518  paragraph->line_widths_[paragraph->records_[4].line()],
2519  2.0);
2520 
2521  ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
2522  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
2523  expected_y += 30 * 10;
2524  ASSERT_NEAR(paragraph->records_[6].offset().x(),
2525  paragraph->width_ -
2526  paragraph->line_widths_[paragraph->records_[6].line()],
2527  2.0);
2528 
2529  ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
2530  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2531  ASSERT_NEAR(paragraph->records_[26].offset().x(),
2532  paragraph->width_ -
2533  paragraph->line_widths_[paragraph->records_[26].line()],
2534  2.0);
2535 
2536  ASSERT_EQ(paragraph_style.text_align,
2537  paragraph->GetParagraphStyle().text_align);
2538 
2539  ASSERT_TRUE(Snapshot());
2540 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [34/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(CenterAlignParagraph)   
)

Definition at line 2542 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), center, txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

2542  {
2543  const char* text =
2544  "This is a very long sentence to test if the text will properly wrap "
2545  "around and go to the next line. Sometimes, short sentence. Longer "
2546  "sentences are okay too because they are necessary. Very short. "
2547  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2548  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2549  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2550  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2551  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2552  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2553  "mollit anim id est laborum. "
2554  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2555  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2556  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2557  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2558  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2559  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2560  "mollit anim id est laborum.";
2561  auto icu_text = icu::UnicodeString::fromUTF8(text);
2562  std::u16string u16_text(icu_text.getBuffer(),
2563  icu_text.getBuffer() + icu_text.length());
2564 
2565  txt::ParagraphStyle paragraph_style;
2566  paragraph_style.max_lines = 14;
2567  paragraph_style.text_align = TextAlign::center;
2568  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2569 
2570  txt::TextStyle text_style;
2571  text_style.font_families = std::vector<std::string>(1, "Roboto");
2572  text_style.font_size = 26;
2573  text_style.letter_spacing = 1;
2574  text_style.word_spacing = 5;
2575  text_style.color = SK_ColorBLACK;
2576  text_style.height = 1;
2578  text_style.decoration_color = SK_ColorBLACK;
2579  builder.PushStyle(text_style);
2580 
2581  builder.AddText(u16_text);
2582 
2583  builder.Pop();
2584 
2585  auto paragraph = BuildParagraph(builder);
2586  paragraph->Layout(GetTestCanvasWidth() - 100);
2587 
2588  paragraph->Paint(GetCanvas(), 0, 0);
2589 
2590  ASSERT_TRUE(Snapshot());
2591  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2592  for (size_t i = 0; i < u16_text.length(); i++) {
2593  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2594  }
2595  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2596  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2597  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2598  // Two records for each due to 'ghost' trailing whitespace run.
2599  ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines * 2);
2600  double expected_y = 24;
2601 
2602  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2603  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2604  expected_y += 30;
2605  ASSERT_NEAR(paragraph->records_[0].offset().x(),
2606  (paragraph->width_ -
2607  paragraph->line_widths_[paragraph->records_[0].line()]) /
2608  2,
2609  2.0);
2610 
2611  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2612  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2613  expected_y += 30;
2614  ASSERT_NEAR(paragraph->records_[2].offset().x(),
2615  (paragraph->width_ -
2616  paragraph->line_widths_[paragraph->records_[2].line()]) /
2617  2,
2618  2.0);
2619 
2620  ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
2621  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
2622  expected_y += 30;
2623  ASSERT_NEAR(paragraph->records_[4].offset().x(),
2624  (paragraph->width_ -
2625  paragraph->line_widths_[paragraph->records_[4].line()]) /
2626  2,
2627  2.0);
2628 
2629  ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
2630  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
2631  expected_y += 30 * 10;
2632  ASSERT_NEAR(paragraph->records_[6].offset().x(),
2633  (paragraph->width_ -
2634  paragraph->line_widths_[paragraph->records_[6].line()]) /
2635  2,
2636  2.0);
2637 
2638  ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
2639  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2640  ASSERT_NEAR(paragraph->records_[26].offset().x(),
2641  (paragraph->width_ -
2642  paragraph->line_widths_[paragraph->records_[26].line()]) /
2643  2,
2644  2.0);
2645 
2646  ASSERT_EQ(paragraph_style.text_align,
2647  paragraph->GetParagraphStyle().text_align);
2648 
2649  ASSERT_TRUE(Snapshot());
2650 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [35/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(JustifyAlignParagraph)   
)

Definition at line 2652 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, justify, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), text, and txt::TextStyle::word_spacing.

2652  {
2653  const char* text =
2654  "This is a very long sentence to test if the text will properly wrap "
2655  "around and go to the next line. Sometimes, short sentence. Longer "
2656  "sentences are okay too because they are necessary. Very short. "
2657  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2658  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2659  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2660  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2661  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2662  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2663  "mollit anim id est laborum. "
2664  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2665  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2666  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2667  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2668  "velit esse cillum dolore eu fugiat.";
2669  auto icu_text = icu::UnicodeString::fromUTF8(text);
2670  std::u16string u16_text(icu_text.getBuffer(),
2671  icu_text.getBuffer() + icu_text.length());
2672 
2673  txt::ParagraphStyle paragraph_style;
2674  paragraph_style.max_lines = 14;
2675  paragraph_style.text_align = TextAlign::justify;
2676  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2677 
2678  txt::TextStyle text_style;
2679  text_style.font_families = std::vector<std::string>(1, "Roboto");
2680  text_style.font_size = 26;
2681  text_style.letter_spacing = 0;
2682  text_style.word_spacing = 5;
2683  text_style.color = SK_ColorBLACK;
2684  text_style.height = 1;
2686  text_style.decoration_color = SK_ColorBLACK;
2687  builder.PushStyle(text_style);
2688 
2689  builder.AddText(u16_text);
2690 
2691  builder.Pop();
2692 
2693  auto paragraph = BuildParagraph(builder);
2694  paragraph->Layout(GetTestCanvasWidth() - 100);
2695 
2696  paragraph->Paint(GetCanvas(), 0, 0);
2697 
2698  ASSERT_TRUE(Snapshot());
2699  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2700  for (size_t i = 0; i < u16_text.length(); i++) {
2701  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2702  }
2703  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2704  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2705  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2706  ASSERT_EQ(paragraph->records_.size(), 27ull);
2707  double expected_y = 24;
2708 
2709  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2710  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2711  expected_y += 30;
2712  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0);
2713 
2714  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2715  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2716  expected_y += 30;
2717  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 0);
2718 
2719  ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
2720  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
2721  expected_y += 30;
2722  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().x(), 0);
2723 
2724  ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
2725  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
2726  expected_y += 30 * 10;
2727  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().x(), 0);
2728 
2729  ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
2730  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2731  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().x(), 0);
2732 
2733  ASSERT_EQ(paragraph_style.text_align,
2734  paragraph->GetParagraphStyle().text_align);
2735 
2736  ASSERT_TRUE(Snapshot());
2737 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double letter_spacing
Definition: text_style.h:52
double font_size
Definition: text_style.h:51
double word_spacing
Definition: text_style.h:53
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [36/89]

txt::TEST_F ( ParagraphTest  ,
DISABLE_ON_WINDOWS(JustifyRTL)   
)

Definition at line 2739 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, justify, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), rtl, and text.

2739  {
2740  const char* text =
2741  "אאא בּבּבּבּ אאאא בּבּ אאא בּבּבּ אאאאא בּבּבּבּ אאאא בּבּבּבּבּ "
2742  "אאאאא בּבּבּבּבּ אאאבּבּבּבּבּבּאאאאא בּבּבּבּבּבּאאאאאבּבּבּבּבּבּ אאאאא בּבּבּבּבּ "
2743  "אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ";
2744 
2745  auto icu_text = icu::UnicodeString::fromUTF8(text);
2746  std::u16string u16_text(icu_text.getBuffer(),
2747  icu_text.getBuffer() + icu_text.length());
2748 
2749  txt::ParagraphStyle paragraph_style;
2750  paragraph_style.max_lines = 14;
2751  paragraph_style.text_align = TextAlign::justify;
2752  paragraph_style.text_direction = TextDirection::rtl;
2753  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2754 
2755  txt::TextStyle text_style;
2756  text_style.font_families = std::vector<std::string>(1, "Ahem");
2757  text_style.font_size = 26;
2758  text_style.color = SK_ColorBLACK;
2759  text_style.height = 1;
2760  builder.PushStyle(text_style);
2761 
2762  builder.AddText(u16_text);
2763 
2764  builder.Pop();
2765 
2766  auto paragraph = BuildParagraph(builder);
2767  size_t paragraph_width = GetTestCanvasWidth() - 100;
2768  paragraph->Layout(paragraph_width);
2769 
2770  paragraph->Paint(GetCanvas(), 0, 0);
2771 
2772  auto glyph_line_width = [&paragraph](int index) {
2773  size_t second_to_last_position_index =
2774  paragraph->glyph_lines_[index].positions.size() - 1;
2775  return paragraph->glyph_lines_[index]
2776  .positions[second_to_last_position_index]
2777  .x_pos.end;
2778  };
2779 
2780  SkPaint paint;
2781  paint.setStyle(SkPaint::kStroke_Style);
2782  paint.setAntiAlias(true);
2783  paint.setStrokeWidth(1);
2784 
2785  // Tests for GetRectsForRange()
2786  Paragraph::RectHeightStyle rect_height_style =
2787  Paragraph::RectHeightStyle::kMax;
2788  Paragraph::RectWidthStyle rect_width_style =
2789  Paragraph::RectWidthStyle::kTight;
2790  paint.setColor(SK_ColorRED);
2791  std::vector<txt::Paragraph::TextBox> boxes =
2792  paragraph->GetRectsForRange(0, 100, rect_height_style, rect_width_style);
2793  for (size_t i = 0; i < boxes.size(); ++i) {
2794  GetCanvas()->drawRect(boxes[i].rect, paint);
2795  }
2796  ASSERT_EQ(boxes.size(), 5ull);
2797 
2798  paint.setColor(SK_ColorBLUE);
2799  boxes = paragraph->GetRectsForRange(240, 250, rect_height_style,
2800  rect_width_style);
2801  for (size_t i = 0; i < boxes.size(); ++i) {
2802  GetCanvas()->drawRect(boxes[i].rect, paint);
2803  }
2804  ASSERT_EQ(boxes.size(), 1ull);
2805  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 588);
2806  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 130);
2807  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 640);
2808  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 156);
2809  ASSERT_TRUE(Snapshot());
2810 
2811  // All lines should be justified to the width of the
2812  // paragraph.
2813  for (size_t i = 0; i < paragraph->glyph_lines_.size(); ++i) {
2814  ASSERT_EQ(glyph_line_width(i), paragraph_width);
2815  }
2816 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:54
double font_size
Definition: text_style.h:51
std::vector< std::string > font_families
Definition: text_style.h:50
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)
std::u16string text

◆ TEST_F() [37/89]

txt::TEST_F ( ParagraphTest  ,
LINUX_ONLY(JustifyRTLNewLine)   
)

Definition at line 2818 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, justify, txt::Paragraph::kMax, txt::Paragraph::kTight, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), rtl, and text.

2818  {
2819  const char* text =
2820  "אאא בּבּבּבּ אאאא\nבּבּ אאא בּבּבּ אאאאא בּבּבּבּ אאאא בּבּבּבּבּ "
2821  "אאאאא בּבּבּבּבּ אאאבּבּבּבּבּבּאאאאא בּבּבּבּבּבּאאאאאבּבּבּבּבּבּ אאאאא בּבּבּבּבּ "
2822  "אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ";
2823 
2824  auto icu_text = icu::UnicodeString::fromUTF8(text);
2825  std::u16string u16_text(icu_text.getBuffer(),
2826  icu_text.getBuffer() + icu_text.length());
2827 
2828  txt::ParagraphStyle paragraph_style;
2829  paragraph_style.max_lines = 14;
2830  paragraph_style.text_align = TextAlign::justify;
2831  paragraph_style.text_direction = TextDirection::rtl;
2832  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2833 
2834  txt::TextStyle text_style;
2835  text_style.font_families = std::vector<std::string>(1, "Ahem");
2836  text_style.font_size = 26;
2837  text_style.color = SK_ColorBLACK;
2838  text_style.height = 1;
2839  builder.PushStyle(text_style);
2840 
2841  builder.AddText(u16_text);
2842 
2843  builder.Pop();
2844 
2845  auto paragraph = BuildParagraph(builder);
2846  size_t paragraph_width = GetTestCanvasWidth() - 100;
2847  paragraph->Layout(paragraph_width);
2848 
2849  paragraph->Paint(GetCanvas(), 0, 0);
2850 
2851  auto glyph_line_width = [&paragraph](int index) {
2852  size_t second_to_last_position_index =
2853  paragraph->glyph_lines_[index].positions.size() - 1;
2854  return paragraph->glyph_lines_[index]
2855  .positions[second_to_last_position_index]
2856  .x_pos.end;
2857  };
2858 
2859