Flutter Engine
txt Namespace Reference

Classes

class  AssetFontManager
 
class  DynamicFontManager
 
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  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 BM_StyledRunsGetRun (benchmark::State &state)
 
 BENCHMARK (BM_StyledRunsGetRun)
 
static void FontSkia_SetSkiaFont (sk_sp< SkTypeface > typeface, SkFont *skFont, const minikin::MinikinPaint &paint)
 
std::vector< std::string > GetDefaultFontFamilies ()
 
sk_sp< SkFontMgr > GetDefaultFontManager ()
 
 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, 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(LeftAlignParagraph))
 
 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(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)
 
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 56 of file paragraph_style.h.

Function Documentation

◆ BENCHMARK() [1/11]

txt::BENCHMARK ( BM_StyledRunsGetRun  )

◆ BENCHMARK() [2/11]

txt::BENCHMARK ( BM_ParagraphBuilderConstruction  )

◆ BENCHMARK() [3/11]

◆ BENCHMARK() [4/11]

txt::BENCHMARK ( BM_ParagraphBuilderPushStyle  )

◆ BENCHMARK() [5/11]

txt::BENCHMARK ( BM_ParagraphBuilderPushPop  )

◆ BENCHMARK() [6/11]

txt::BENCHMARK ( BM_ParagraphBuilderAddTextString  )

◆ BENCHMARK() [7/11]

txt::BENCHMARK ( BM_ParagraphBuilderAddTextChar  )

◆ BENCHMARK() [8/11]

◆ BENCHMARK() [9/11]

◆ BENCHMARK() [10/11]

◆ BENCHMARK() [11/11]

◆ 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(), and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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, and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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, 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:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
std::vector< std::string > font_families
Definition: text_style.h:49
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)

◆ 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(), 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(icu::Locale(), nullptr);
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:51
void resize(size_t size)
Definition: LineBreaker.h:102
uint16_t * buffer()
Definition: LineBreaker.h:109
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
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:49
void setLocale(const icu::Locale &locale, Hyphenator *hyphenator)

◆ BENCHMARK_DEFINE_F() [5/5]

txt::BENCHMARK_DEFINE_F ( ParagraphFixture  ,
SkTextBlobAlloc   
)

Definition at line 429 of file paragraph_benchmarks.cc.

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 }

◆ 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(), and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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(), and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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(), 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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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, and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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, and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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, and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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, and txt::ParagraphBuilderTxt::PushStyle().

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
TextDecorationStyle decoration_style
Definition: text_style.h:41
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ 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 }

◆ 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(), and GetTestFontCollection().

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

◆ 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(), and GetTestFontCollection().

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

◆ 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(), and GetTestFontCollection().

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

◆ 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(), and GetTestFontCollection().

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

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

◆ 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(), and txt::ParagraphBuilderTxt::PushStyle().

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

◆ 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

◆ 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

◆ 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(), and txt::ParagraphBuilderTxt::PushStyle().

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

◆ BM_StyledRunsGetRun()

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

Definition at line 26 of file styled_runs_benchmarks.cc.

References txt::StyledRuns::AddStyle(), BENCHMARK(), txt::StyledRuns::EndRunIfNeeded(), txt::StyledRuns::GetRun(), and txt::StyledRuns::StartRun().

26  {
27  StyledRuns runs;
28  TextStyle style;
29  runs.AddStyle(style);
30  runs.StartRun(0, 0);
31  runs.EndRunIfNeeded(11);
32  while (state.KeepRunning()) {
33  runs.GetRun(0);
34  }
35 }

◆ 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 4794 of file paragraph_unittests.cc.

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

Referenced by TEST_F().

4794  {
4795  std::vector<txt::Paragraph::TextBox> boxes =
4796  paragraph.GetRectsForRange(pos, pos + 1, Paragraph::RectHeightStyle::kMax,
4797  Paragraph::RectWidthStyle::kTight);
4798  return !boxes.empty() ? boxes.front().rect : SkRect::MakeEmpty();
4799 }
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 ( )

Definition at line 13 of file platform.cc.

Referenced by txt::FontCollection::SetupDefaultFontManager().

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 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

◆ 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/78]

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(), and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [2/78]

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(), and txt::ParagraphBuilderTxt::PushStyle().

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:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [3/78]

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(), and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [4/78]

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:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [5/78]

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(), and txt::ParagraphBuilderTxt::PushStyle().

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:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [6/78]

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(), and txt::ParagraphBuilderTxt::PushStyle().

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:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [7/78]

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(), 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [8/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [9/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [10/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [11/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [12/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [13/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [14/78]

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(), 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 accomodate 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [15/78]

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(), 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [16/78]

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(), 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [17/78]

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

Definition at line 1458 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(), 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:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [18/78]

txt::TEST_F ( ParagraphTest  ,
SimpleRedParagraph   
)

Definition at line 1585 of file paragraph_unittests.cc.

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

1585  {
1586  const char* text = "I am RED";
1587  auto icu_text = icu::UnicodeString::fromUTF8(text);
1588  std::u16string u16_text(icu_text.getBuffer(),
1589  icu_text.getBuffer() + icu_text.length());
1590 
1591  txt::ParagraphStyle paragraph_style;
1592  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1593 
1594  txt::TextStyle text_style;
1595  text_style.font_families = std::vector<std::string>(1, "Roboto");
1596  text_style.color = SK_ColorRED;
1597  builder.PushStyle(text_style);
1598 
1599  builder.AddText(u16_text);
1600 
1601  builder.Pop();
1602 
1603  auto paragraph = BuildParagraph(builder);
1604  paragraph->Layout(GetTestCanvasWidth());
1605 
1606  paragraph->Paint(GetCanvas(), 10.0, 15.0);
1607 
1608  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1609  for (size_t i = 0; i < u16_text.length(); i++) {
1610  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1611  }
1612  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1613  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
1614  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
1615  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
1616  ASSERT_TRUE(Snapshot());
1617 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [19/78]

txt::TEST_F ( ParagraphTest  ,
RainbowParagraph   
)

Definition at line 1619 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.

1619  {
1620  const char* text1 = "Red Roboto";
1621  auto icu_text1 = icu::UnicodeString::fromUTF8(text1);
1622  std::u16string u16_text1(icu_text1.getBuffer(),
1623  icu_text1.getBuffer() + icu_text1.length());
1624  const char* text2 = "big Greeen Default";
1625  auto icu_text2 = icu::UnicodeString::fromUTF8(text2);
1626  std::u16string u16_text2(icu_text2.getBuffer(),
1627  icu_text2.getBuffer() + icu_text2.length());
1628  const char* text3 = "Defcolor Homemade Apple";
1629  auto icu_text3 = icu::UnicodeString::fromUTF8(text3);
1630  std::u16string u16_text3(icu_text3.getBuffer(),
1631  icu_text3.getBuffer() + icu_text3.length());
1632  const char* text4 = "Small Blue Roboto";
1633  auto icu_text4 = icu::UnicodeString::fromUTF8(text4);
1634  std::u16string u16_text4(icu_text4.getBuffer(),
1635  icu_text4.getBuffer() + icu_text4.length());
1636  const char* text5 =
1637  "Continue Last Style With lots of words to check if it overlaps "
1638  "properly or not";
1639  auto icu_text5 = icu::UnicodeString::fromUTF8(text5);
1640  std::u16string u16_text5(icu_text5.getBuffer(),
1641  icu_text5.getBuffer() + icu_text5.length());
1642 
1643  txt::ParagraphStyle paragraph_style;
1644  paragraph_style.max_lines = 2;
1645  paragraph_style.text_align = TextAlign::left;
1646  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1647 
1648  txt::TextStyle text_style1;
1649  text_style1.font_families = std::vector<std::string>(1, "Roboto");
1650  text_style1.color = SK_ColorRED;
1651 
1652  builder.PushStyle(text_style1);
1653 
1654  builder.AddText(u16_text1);
1655 
1656  txt::TextStyle text_style2;
1657  text_style2.font_size = 50;
1658  text_style2.letter_spacing = 10;
1659  text_style2.word_spacing = 30;
1660  text_style2.font_weight = txt::FontWeight::w600;
1661  text_style2.color = SK_ColorGREEN;
1662  text_style2.font_families = std::vector<std::string>(1, "Roboto");
1663  text_style2.decoration = TextDecoration::kUnderline |
1666  text_style2.decoration_color = SK_ColorBLACK;
1667  builder.PushStyle(text_style2);
1668 
1669  builder.AddText(u16_text2);
1670 
1671  txt::TextStyle text_style3;
1672  text_style3.font_families = std::vector<std::string>(1, "Homemade Apple");
1673  builder.PushStyle(text_style3);
1674 
1675  builder.AddText(u16_text3);
1676 
1677  txt::TextStyle text_style4;
1678  text_style4.font_size = 14;
1679  text_style4.color = SK_ColorBLUE;
1680  text_style4.font_families = std::vector<std::string>(1, "Roboto");
1681  text_style4.decoration = TextDecoration::kUnderline |
1684  text_style4.decoration_color = SK_ColorBLACK;
1685  builder.PushStyle(text_style4);
1686 
1687  builder.AddText(u16_text4);
1688 
1689  // Extra text to see if it goes to default when there is more text chunks than
1690  // styles.
1691  builder.AddText(u16_text5);
1692 
1693  builder.Pop();
1694 
1695  auto paragraph = BuildParagraph(builder);
1696  paragraph->Layout(GetTestCanvasWidth());
1697  paragraph->Paint(GetCanvas(), 0, 0);
1698 
1699  u16_text1 += u16_text2 + u16_text3 + u16_text4;
1700  for (size_t i = 0; i < u16_text1.length(); i++) {
1701  ASSERT_EQ(paragraph->text_[i], u16_text1[i]);
1702  }
1703  ASSERT_TRUE(Snapshot());
1704  ASSERT_EQ(paragraph->runs_.runs_.size(), 4ull);
1705  ASSERT_EQ(paragraph->runs_.styles_.size(), 5ull);
1706  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style1));
1707  ASSERT_TRUE(paragraph->runs_.styles_[2].equals(text_style2));
1708  ASSERT_TRUE(paragraph->runs_.styles_[3].equals(text_style3));
1709  ASSERT_TRUE(paragraph->runs_.styles_[4].equals(text_style4));
1710  ASSERT_EQ(paragraph->records_[0].style().color, text_style1.color);
1711  ASSERT_EQ(paragraph->records_[1].style().color, text_style2.color);
1712  ASSERT_EQ(paragraph->records_[2].style().color, text_style3.color);
1713  ASSERT_EQ(paragraph->records_[3].style().color, text_style4.color);
1714 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
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() [20/78]

txt::TEST_F ( ParagraphTest  ,
DefaultStyleParagraph   
)

Definition at line 1717 of file paragraph_unittests.cc.

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

1717  {
1718  const char* text = "No TextStyle! Uh Oh!";
1719  auto icu_text = icu::UnicodeString::fromUTF8(text);
1720  std::u16string u16_text(icu_text.getBuffer(),
1721  icu_text.getBuffer() + icu_text.length());
1722 
1723  txt::ParagraphStyle paragraph_style;
1724  paragraph_style.font_family = "Roboto";
1725  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1726 
1727  builder.AddText(u16_text);
1728 
1729  builder.Pop();
1730 
1731  auto paragraph = BuildParagraph(builder);
1732  paragraph->Layout(GetTestCanvasWidth());
1733 
1734  paragraph->Paint(GetCanvas(), 10.0, 15.0);
1735 
1736  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1737  for (size_t i = 0; i < u16_text.length(); i++) {
1738  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1739  }
1740  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1741  ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull);
1742  ASSERT_TRUE(Snapshot());
1743 }
std::shared_ptr< FontCollection > GetTestFontCollection()
std::string font_family
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [21/78]

txt::TEST_F ( ParagraphTest  ,
BoldParagraph   
)

Definition at line 1745 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(), and w900.

1745  {
1746  const char* text = "This is Red max bold text!";
1747  auto icu_text = icu::UnicodeString::fromUTF8(text);
1748  std::u16string u16_text(icu_text.getBuffer(),
1749  icu_text.getBuffer() + icu_text.length());
1750 
1751  txt::ParagraphStyle paragraph_style;
1752  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1753 
1754  txt::TextStyle text_style;
1755  text_style.font_families = std::vector<std::string>(1, "Roboto");
1756  text_style.font_size = 60;
1757  text_style.letter_spacing = 0;
1758  text_style.font_weight = txt::FontWeight::w900;
1759  text_style.color = SK_ColorRED;
1760  builder.PushStyle(text_style);
1761 
1762  builder.AddText(u16_text);
1763 
1764  builder.Pop();
1765 
1766  auto paragraph = BuildParagraph(builder);
1767  paragraph->Layout(GetTestCanvasWidth());
1768 
1769  paragraph->Paint(GetCanvas(), 10.0, 60.0);
1770 
1771  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1772  for (size_t i = 0; i < u16_text.length(); i++) {
1773  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1774  }
1775  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1776  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
1777  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
1778  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
1779  ASSERT_TRUE(Snapshot());
1780 
1781  // width_ takes the full available space, but longest_line_ is only the width
1782  // of the text, which is less than one line.
1783  ASSERT_DOUBLE_EQ(paragraph->width_, GetTestCanvasWidth());
1784  ASSERT_TRUE(paragraph->longest_line_ < paragraph->width_);
1785  Paragraph::RectHeightStyle rect_height_style =
1786  Paragraph::RectHeightStyle::kMax;
1787  Paragraph::RectWidthStyle rect_width_style =
1788  Paragraph::RectWidthStyle::kTight;
1789  std::vector<txt::Paragraph::TextBox> boxes = paragraph->GetRectsForRange(
1790  0, strlen(text), rect_height_style, rect_width_style);
1791  ASSERT_DOUBLE_EQ(paragraph->longest_line_,
1792  boxes[boxes.size() - 1].rect.right() - boxes[0].rect.left());
1793 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
std::vector< std::string > font_families
Definition: text_style.h:49
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() [22/78]

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

Definition at line 1795 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(), and txt::TextStyle::word_spacing.

1795  {
1796  const char* text = "01234満毎冠行来昼本可\nabcd\n満毎冠行来昼本可";
1797  auto icu_text = icu::UnicodeString::fromUTF8(text);
1798  std::u16string u16_text(icu_text.getBuffer(),
1799  icu_text.getBuffer() + icu_text.length());
1800 
1801  txt::ParagraphStyle paragraph_style;
1802  paragraph_style.max_lines = 10;
1803  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1804 
1805  txt::TextStyle text_style;
1806  text_style.font_families = std::vector<std::string>(1, "Roboto");
1807  text_style.font_size = 20;
1808  text_style.letter_spacing = 0;
1809  text_style.word_spacing = 0;
1810  text_style.color = SK_ColorBLACK;
1811  text_style.height = 3.6345;
1812  text_style.has_height_override = true;
1813  builder.PushStyle(text_style);
1814 
1815  builder.AddText(u16_text);
1816 
1817  builder.Pop();
1818 
1819  auto paragraph = BuildParagraph(builder);
1820  paragraph->Layout(550);
1821 
1822  paragraph->Paint(GetCanvas(), 0, 0);
1823 
1824  SkPaint paint;
1825  paint.setStyle(SkPaint::kStroke_Style);
1826  paint.setAntiAlias(true);
1827  paint.setStrokeWidth(1);
1828 
1829  // Tests for GetRectsForRange()
1830  Paragraph::RectHeightStyle rect_height_style =
1831  Paragraph::RectHeightStyle::kIncludeLineSpacingMiddle;
1832  Paragraph::RectWidthStyle rect_width_style =
1833  Paragraph::RectWidthStyle::kTight;
1834  paint.setColor(SK_ColorRED);
1835  std::vector<txt::Paragraph::TextBox> boxes =
1836  paragraph->GetRectsForRange(0, 0, rect_height_style, rect_width_style);
1837  for (size_t i = 0; i < boxes.size(); ++i) {
1838  GetCanvas()->drawRect(boxes[i].rect, paint);
1839  }
1840  EXPECT_EQ(boxes.size(), 0ull);
1841 
1842  boxes =
1843  paragraph->GetRectsForRange(0, 40, rect_height_style, rect_width_style);
1844  for (size_t i = 0; i < boxes.size(); ++i) {
1845  GetCanvas()->drawRect(boxes[i].rect, paint);
1846  }
1847  EXPECT_EQ(boxes.size(), 3ull);
1848  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 0);
1849  EXPECT_NEAR(boxes[1].rect.top(), 92.805778503417969, 0.0001);
1850  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 43.851562);
1851  EXPECT_NEAR(boxes[1].rect.bottom(), 165.49578857421875, 0.0001);
1852 
1853  ASSERT_TRUE(Snapshot());
1854 }
bool has_height_override
Definition: text_style.h:54
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [23/78]

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

Definition at line 1856 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(), and txt::TextStyle::word_spacing.

1856  {
1857  const char* text =
1858  "This is a very long sentence to test if the text will properly wrap "
1859  "around and go to the next line. Sometimes, short sentence. Longer "
1860  "sentences are okay too because they are necessary. Very short. "
1861  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
1862  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
1863  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
1864  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
1865  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
1866  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
1867  "mollit anim id est laborum. "
1868  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
1869  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
1870  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
1871  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
1872  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
1873  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
1874  "mollit anim id est laborum.";
1875  auto icu_text = icu::UnicodeString::fromUTF8(text);
1876  std::u16string u16_text(icu_text.getBuffer(),
1877  icu_text.getBuffer() + icu_text.length());
1878 
1879  txt::ParagraphStyle paragraph_style;
1880  paragraph_style.max_lines = 14;
1881  paragraph_style.text_align = TextAlign::left;
1882  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1883 
1884  txt::TextStyle text_style;
1885  text_style.font_families = std::vector<std::string>(1, "Roboto");
1886  text_style.font_size = 26;
1887  text_style.letter_spacing = 1;
1888  text_style.word_spacing = 5;
1889  text_style.color = SK_ColorBLACK;
1890  text_style.height = 1;
1892  text_style.decoration_color = SK_ColorBLACK;
1893  builder.PushStyle(text_style);
1894 
1895  builder.AddText(u16_text);
1896 
1897  builder.Pop();
1898 
1899  auto paragraph = BuildParagraph(builder);
1900  paragraph->Layout(GetTestCanvasWidth() - 100);
1901 
1902  paragraph->Paint(GetCanvas(), 0, 0);
1903 
1904  ASSERT_TRUE(Snapshot());
1905 
1906  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
1907  for (size_t i = 0; i < u16_text.length(); i++) {
1908  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
1909  }
1910  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
1911  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
1912  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
1913  ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines);
1914  double expected_y = 24;
1915 
1916  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
1917  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
1918  expected_y += 30;
1919  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0);
1920 
1921  ASSERT_TRUE(paragraph->records_[1].style().equals(text_style));
1922  ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y);
1923  expected_y += 30;
1924  ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().x(), 0);
1925 
1926  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
1927  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
1928  expected_y += 30;
1929  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 0);
1930 
1931  ASSERT_TRUE(paragraph->records_[3].style().equals(text_style));
1932  ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y);
1933  expected_y += 30 * 10;
1934  ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().x(), 0);
1935 
1936  ASSERT_TRUE(paragraph->records_[13].style().equals(text_style));
1937  ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y);
1938  ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().x(), 0);
1939 
1940  ASSERT_EQ(paragraph_style.text_align,
1941  paragraph->GetParagraphStyle().text_align);
1942 
1943  // Tests for GetGlyphPositionAtCoordinate()
1944  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(0, 0).position, 0ull);
1945  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(1, 1).position, 0ull);
1946  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(1, 35).position, 68ull);
1947  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(1, 70).position, 134ull);
1948  ASSERT_EQ(paragraph->GetGlyphPositionAtCoordinate(2000, 35).position, 134ull);
1949 
1950  ASSERT_TRUE(Snapshot());
1951 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [24/78]

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

Definition at line 1953 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, and txt::TextStyle::word_spacing.

1953  {
1954  const char* text =
1955  "This is a very long sentence to test if the text will properly wrap "
1956  "around and go to the next line. Sometimes, short sentence. Longer "
1957  "sentences are okay too because they are necessary. Very short. "
1958  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
1959  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
1960  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
1961  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
1962  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
1963  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
1964  "mollit anim id est laborum. "
1965  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
1966  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
1967  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
1968  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
1969  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
1970  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
1971  "mollit anim id est laborum.";
1972  auto icu_text = icu::UnicodeString::fromUTF8(text);
1973  std::u16string u16_text(icu_text.getBuffer(),
1974  icu_text.getBuffer() + icu_text.length());
1975 
1976  txt::ParagraphStyle paragraph_style;
1977  paragraph_style.max_lines = 14;
1978  paragraph_style.text_align = TextAlign::right;
1979  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
1980 
1981  txt::TextStyle text_style;
1982  text_style.font_families = std::vector<std::string>(1, "Roboto");
1983  text_style.font_size = 26;
1984  text_style.letter_spacing = 1;
1985  text_style.word_spacing = 5;
1986  text_style.color = SK_ColorBLACK;
1987  text_style.height = 1;
1989  text_style.decoration_color = SK_ColorBLACK;
1990  builder.PushStyle(text_style);
1991 
1992  builder.AddText(u16_text);
1993 
1994  builder.Pop();
1995 
1996  auto paragraph = BuildParagraph(builder);
1997  int available_width = GetTestCanvasWidth() - 100;
1998  paragraph->Layout(available_width);
1999 
2000  paragraph->Paint(GetCanvas(), 0, 0);
2001 
2002  ASSERT_TRUE(Snapshot());
2003  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2004  for (size_t i = 0; i < u16_text.length(); i++) {
2005  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2006  }
2007  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2008  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2009  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2010  // Two records for each due to 'ghost' trailing whitespace run.
2011  ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines * 2);
2012  double expected_y = 24;
2013 
2014  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2015  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2016  expected_y += 30;
2017  ASSERT_NEAR(
2018  paragraph->records_[0].offset().x(),
2019  paragraph->width_ -
2020  paragraph->breaker_.getWidths()[paragraph->records_[0].line()],
2021  2.0);
2022 
2023  // width_ takes the full available space, while longest_line_ wraps the glyphs
2024  // as tightly as possible. Even though this text is more than one line long,
2025  // no line perfectly spans the width of the full line, so longest_line_ is
2026  // less than width_.
2027  ASSERT_DOUBLE_EQ(paragraph->width_, available_width);
2028  ASSERT_TRUE(paragraph->longest_line_ < available_width);
2029  ASSERT_DOUBLE_EQ(paragraph->longest_line_, 880.87109375);
2030 
2031  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2032  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2033  expected_y += 30;
2034  ASSERT_NEAR(
2035  paragraph->records_[2].offset().x(),
2036  paragraph->width_ -
2037  paragraph->breaker_.getWidths()[paragraph->records_[2].line()],
2038  2.0);
2039 
2040  ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
2041  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
2042  expected_y += 30;
2043  ASSERT_NEAR(
2044  paragraph->records_[4].offset().x(),
2045  paragraph->width_ -
2046  paragraph->breaker_.getWidths()[paragraph->records_[4].line()],
2047  2.0);
2048 
2049  ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
2050  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
2051  expected_y += 30 * 10;
2052  ASSERT_NEAR(
2053  paragraph->records_[6].offset().x(),
2054  paragraph->width_ -
2055  paragraph->breaker_.getWidths()[paragraph->records_[6].line()],
2056  2.0);
2057 
2058  ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
2059  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2060  ASSERT_NEAR(
2061  paragraph->records_[26].offset().x(),
2062  paragraph->width_ -
2063  paragraph->breaker_.getWidths()[paragraph->records_[26].line()],
2064  2.0);
2065 
2066  ASSERT_EQ(paragraph_style.text_align,
2067  paragraph->GetParagraphStyle().text_align);
2068 
2069  ASSERT_TRUE(Snapshot());
2070 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [25/78]

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

Definition at line 2072 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(), and txt::TextStyle::word_spacing.

2072  {
2073  const char* text =
2074  "This is a very long sentence to test if the text will properly wrap "
2075  "around and go to the next line. Sometimes, short sentence. Longer "
2076  "sentences are okay too because they are necessary. Very short. "
2077  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2078  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2079  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2080  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2081  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2082  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2083  "mollit anim id est laborum. "
2084  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2085  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2086  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2087  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2088  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2089  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2090  "mollit anim id est laborum.";
2091  auto icu_text = icu::UnicodeString::fromUTF8(text);
2092  std::u16string u16_text(icu_text.getBuffer(),
2093  icu_text.getBuffer() + icu_text.length());
2094 
2095  txt::ParagraphStyle paragraph_style;
2096  paragraph_style.max_lines = 14;
2097  paragraph_style.text_align = TextAlign::center;
2098  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2099 
2100  txt::TextStyle text_style;
2101  text_style.font_families = std::vector<std::string>(1, "Roboto");
2102  text_style.font_size = 26;
2103  text_style.letter_spacing = 1;
2104  text_style.word_spacing = 5;
2105  text_style.color = SK_ColorBLACK;
2106  text_style.height = 1;
2108  text_style.decoration_color = SK_ColorBLACK;
2109  builder.PushStyle(text_style);
2110 
2111  builder.AddText(u16_text);
2112 
2113  builder.Pop();
2114 
2115  auto paragraph = BuildParagraph(builder);
2116  paragraph->Layout(GetTestCanvasWidth() - 100);
2117 
2118  paragraph->Paint(GetCanvas(), 0, 0);
2119 
2120  ASSERT_TRUE(Snapshot());
2121  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2122  for (size_t i = 0; i < u16_text.length(); i++) {
2123  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2124  }
2125  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2126  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2127  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2128  // Two records for each due to 'ghost' trailing whitespace run.
2129  ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines * 2);
2130  double expected_y = 24;
2131 
2132  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2133  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2134  expected_y += 30;
2135  ASSERT_NEAR(paragraph->records_[0].offset().x(),
2136  (paragraph->width_ -
2137  paragraph->breaker_.getWidths()[paragraph->records_[0].line()]) /
2138  2,
2139  2.0);
2140 
2141  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2142  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2143  expected_y += 30;
2144  ASSERT_NEAR(paragraph->records_[2].offset().x(),
2145  (paragraph->width_ -
2146  paragraph->breaker_.getWidths()[paragraph->records_[2].line()]) /
2147  2,
2148  2.0);
2149 
2150  ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
2151  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
2152  expected_y += 30;
2153  ASSERT_NEAR(paragraph->records_[4].offset().x(),
2154  (paragraph->width_ -
2155  paragraph->breaker_.getWidths()[paragraph->records_[4].line()]) /
2156  2,
2157  2.0);
2158 
2159  ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
2160  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
2161  expected_y += 30 * 10;
2162  ASSERT_NEAR(paragraph->records_[6].offset().x(),
2163  (paragraph->width_ -
2164  paragraph->breaker_.getWidths()[paragraph->records_[6].line()]) /
2165  2,
2166  2.0);
2167 
2168  ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
2169  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2170  ASSERT_NEAR(
2171  paragraph->records_[26].offset().x(),
2172  (paragraph->width_ -
2173  paragraph->breaker_.getWidths()[paragraph->records_[26].line()]) /
2174  2,
2175  2.0);
2176 
2177  ASSERT_EQ(paragraph_style.text_align,
2178  paragraph->GetParagraphStyle().text_align);
2179 
2180  ASSERT_TRUE(Snapshot());
2181 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [26/78]

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

Definition at line 2183 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(), and txt::TextStyle::word_spacing.

2183  {
2184  const char* text =
2185  "This is a very long sentence to test if the text will properly wrap "
2186  "around and go to the next line. Sometimes, short sentence. Longer "
2187  "sentences are okay too because they are necessary. Very short. "
2188  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2189  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2190  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2191  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2192  "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
2193  "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
2194  "mollit anim id est laborum. "
2195  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
2196  "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
2197  "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
2198  "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
2199  "velit esse cillum dolore eu fugiat.";
2200  auto icu_text = icu::UnicodeString::fromUTF8(text);
2201  std::u16string u16_text(icu_text.getBuffer(),
2202  icu_text.getBuffer() + icu_text.length());
2203 
2204  txt::ParagraphStyle paragraph_style;
2205  paragraph_style.max_lines = 14;
2206  paragraph_style.text_align = TextAlign::justify;
2207  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2208 
2209  txt::TextStyle text_style;
2210  text_style.font_families = std::vector<std::string>(1, "Roboto");
2211  text_style.font_size = 26;
2212  text_style.letter_spacing = 0;
2213  text_style.word_spacing = 5;
2214  text_style.color = SK_ColorBLACK;
2215  text_style.height = 1;
2217  text_style.decoration_color = SK_ColorBLACK;
2218  builder.PushStyle(text_style);
2219 
2220  builder.AddText(u16_text);
2221 
2222  builder.Pop();
2223 
2224  auto paragraph = BuildParagraph(builder);
2225  paragraph->Layout(GetTestCanvasWidth() - 100);
2226 
2227  paragraph->Paint(GetCanvas(), 0, 0);
2228 
2229  ASSERT_TRUE(Snapshot());
2230  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2231  for (size_t i = 0; i < u16_text.length(); i++) {
2232  ASSERT_EQ(paragraph->text_[i], u16_text[i]);
2233  }
2234  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2235  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2236  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2237  ASSERT_EQ(paragraph->records_.size(), 27ull);
2238  double expected_y = 24;
2239 
2240  ASSERT_TRUE(paragraph->records_[0].style().equals(text_style));
2241  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y);
2242  expected_y += 30;
2243  ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0);
2244 
2245  ASSERT_TRUE(paragraph->records_[2].style().equals(text_style));
2246  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y);
2247  expected_y += 30;
2248  ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 0);
2249 
2250  ASSERT_TRUE(paragraph->records_[4].style().equals(text_style));
2251  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().y(), expected_y);
2252  expected_y += 30;
2253  ASSERT_DOUBLE_EQ(paragraph->records_[4].offset().x(), 0);
2254 
2255  ASSERT_TRUE(paragraph->records_[6].style().equals(text_style));
2256  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().y(), expected_y);
2257  expected_y += 30 * 10;
2258  ASSERT_DOUBLE_EQ(paragraph->records_[6].offset().x(), 0);
2259 
2260  ASSERT_TRUE(paragraph->records_[26].style().equals(text_style));
2261  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().y(), expected_y);
2262  ASSERT_DOUBLE_EQ(paragraph->records_[26].offset().x(), 0);
2263 
2264  ASSERT_EQ(paragraph_style.text_align,
2265  paragraph->GetParagraphStyle().text_align);
2266 
2267  ASSERT_TRUE(Snapshot());
2268 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [27/78]

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

Definition at line 2270 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(), and rtl.

2270  {
2271  const char* text =
2272  "אאא בּבּבּבּ אאאא בּבּ אאא בּבּבּ אאאאא בּבּבּבּ אאאא בּבּבּבּבּ "
2273  "אאאאא בּבּבּבּבּ אאאבּבּבּבּבּבּאאאאא בּבּבּבּבּבּאאאאאבּבּבּבּבּבּ אאאאא בּבּבּבּבּ "
2274  "אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ";
2275 
2276  auto icu_text = icu::UnicodeString::fromUTF8(text);
2277  std::u16string u16_text(icu_text.getBuffer(),
2278  icu_text.getBuffer() + icu_text.length());
2279 
2280  txt::ParagraphStyle paragraph_style;
2281  paragraph_style.max_lines = 14;
2282  paragraph_style.text_align = TextAlign::justify;
2283  paragraph_style.text_direction = TextDirection::rtl;
2284  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2285 
2286  txt::TextStyle text_style;
2287  text_style.font_families = std::vector<std::string>(1, "Ahem");
2288  text_style.font_size = 26;
2289  text_style.color = SK_ColorBLACK;
2290  text_style.height = 1;
2291  builder.PushStyle(text_style);
2292 
2293  builder.AddText(u16_text);
2294 
2295  builder.Pop();
2296 
2297  auto paragraph = BuildParagraph(builder);
2298  size_t paragraph_width = GetTestCanvasWidth() - 100;
2299  paragraph->Layout(paragraph_width);
2300 
2301  paragraph->Paint(GetCanvas(), 0, 0);
2302 
2303  auto glyph_line_width = [&paragraph](int index) {
2304  size_t second_to_last_position_index =
2305  paragraph->glyph_lines_[index].positions.size() - 1;
2306  return paragraph->glyph_lines_[index]
2307  .positions[second_to_last_position_index]
2308  .x_pos.end;
2309  };
2310 
2311  SkPaint paint;
2312  paint.setStyle(SkPaint::kStroke_Style);
2313  paint.setAntiAlias(true);
2314  paint.setStrokeWidth(1);
2315 
2316  // Tests for GetRectsForRange()
2317  Paragraph::RectHeightStyle rect_height_style =
2318  Paragraph::RectHeightStyle::kMax;
2319  Paragraph::RectWidthStyle rect_width_style =
2320  Paragraph::RectWidthStyle::kTight;
2321  paint.setColor(SK_ColorRED);
2322  std::vector<txt::Paragraph::TextBox> boxes =
2323  paragraph->GetRectsForRange(0, 100, rect_height_style, rect_width_style);
2324  for (size_t i = 0; i < boxes.size(); ++i) {
2325  GetCanvas()->drawRect(boxes[i].rect, paint);
2326  }
2327  ASSERT_EQ(boxes.size(), 5ull);
2328 
2329  paint.setColor(SK_ColorBLUE);
2330  boxes = paragraph->GetRectsForRange(240, 250, rect_height_style,
2331  rect_width_style);
2332  for (size_t i = 0; i < boxes.size(); ++i) {
2333  GetCanvas()->drawRect(boxes[i].rect, paint);
2334  }
2335  ASSERT_EQ(boxes.size(), 1ull);
2336  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 588);
2337  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 130);
2338  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 640);
2339  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 156);
2340  ASSERT_TRUE(Snapshot());
2341 
2342  // All lines should be justified to the width of the
2343  // paragraph.
2344  for (size_t i = 0; i < paragraph->glyph_lines_.size(); ++i) {
2345  ASSERT_EQ(glyph_line_width(i), paragraph_width);
2346  }
2347 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double font_size
Definition: text_style.h:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [28/78]

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

Definition at line 2349 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(), and rtl.

2349  {
2350  const char* text =
2351  "אאא בּבּבּבּ אאאא\nבּבּ אאא בּבּבּ אאאאא בּבּבּבּ אאאא בּבּבּבּבּ "
2352  "אאאאא בּבּבּבּבּ אאאבּבּבּבּבּבּאאאאא בּבּבּבּבּבּאאאאאבּבּבּבּבּבּ אאאאא בּבּבּבּבּ "
2353  "אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ אאאאא בּבּבּבּבּבּ";
2354 
2355  auto icu_text = icu::UnicodeString::fromUTF8(text);
2356  std::u16string u16_text(icu_text.getBuffer(),
2357  icu_text.getBuffer() + icu_text.length());
2358 
2359  txt::ParagraphStyle paragraph_style;
2360  paragraph_style.max_lines = 14;
2361  paragraph_style.text_align = TextAlign::justify;
2362  paragraph_style.text_direction = TextDirection::rtl;
2363  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2364 
2365  txt::TextStyle text_style;
2366  text_style.font_families = std::vector<std::string>(1, "Ahem");
2367  text_style.font_size = 26;
2368  text_style.color = SK_ColorBLACK;
2369  text_style.height = 1;
2370  builder.PushStyle(text_style);
2371 
2372  builder.AddText(u16_text);
2373 
2374  builder.Pop();
2375 
2376  auto paragraph = BuildParagraph(builder);
2377  size_t paragraph_width = GetTestCanvasWidth() - 100;
2378  paragraph->Layout(paragraph_width);
2379 
2380  paragraph->Paint(GetCanvas(), 0, 0);
2381 
2382  auto glyph_line_width = [&paragraph](int index) {
2383  size_t second_to_last_position_index =
2384  paragraph->glyph_lines_[index].positions.size() - 1;
2385  return paragraph->glyph_lines_[index]
2386  .positions[second_to_last_position_index]
2387  .x_pos.end;
2388  };
2389 
2390  SkPaint paint;
2391  paint.setStyle(SkPaint::kStroke_Style);
2392  paint.setAntiAlias(true);
2393  paint.setStrokeWidth(1);
2394 
2395  ASSERT_TRUE(Snapshot());
2396 
2397  // Tests for GetRectsForRange()
2398  Paragraph::RectHeightStyle rect_height_style =
2399  Paragraph::RectHeightStyle::kMax;
2400  Paragraph::RectWidthStyle rect_width_style =
2401  Paragraph::RectWidthStyle::kTight;
2402  paint.setColor(SK_ColorRED);
2403  std::vector<txt::Paragraph::TextBox> boxes =
2404  paragraph->GetRectsForRange(0, 30, rect_height_style, rect_width_style);
2405  for (size_t i = 0; i < boxes.size(); ++i) {
2406  GetCanvas()->drawRect(boxes[i].rect, paint);
2407  }
2408  ASSERT_EQ(boxes.size(), 2ull);
2409  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 562);
2410  EXPECT_FLOAT_EQ(boxes[0].rect.top(), -1.4305115e-06);
2411  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 900);
2412  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 26);
2413 
2414  paint.setColor(SK_ColorBLUE);
2415  boxes = paragraph->GetRectsForRange(240, 250, rect_height_style,
2416  rect_width_style);
2417  for (size_t i = 0; i < boxes.size(); ++i) {
2418  GetCanvas()->drawRect(boxes[i].rect, paint);
2419  }
2420  ASSERT_EQ(boxes.size(), 1ull);
2421  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 68);
2422  EXPECT_FLOAT_EQ(boxes[0].rect.top(), 130);
2423  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 120);
2424  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 156);
2425  ASSERT_TRUE(Snapshot());
2426 
2427  // All lines should be justified to the width of the
2428  // paragraph.
2429  for (size_t i = 0; i < paragraph->glyph_lines_.size(); ++i) {
2430  ASSERT_EQ(glyph_line_width(i), paragraph_width);
2431  }
2432 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double font_size
Definition: text_style.h:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [29/78]

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

Definition at line 2434 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(), and rtl.

2434  {
2435  const char* text = " leading space";
2436 
2437  auto icu_text = icu::UnicodeString::fromUTF8(text);
2438  std::u16string u16_text(icu_text.getBuffer(),
2439  icu_text.getBuffer() + icu_text.length());
2440 
2441  txt::ParagraphStyle paragraph_style;
2442  paragraph_style.max_lines = 14;
2443  paragraph_style.text_align = TextAlign::justify;
2444  paragraph_style.text_direction = TextDirection::rtl;
2445  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2446 
2447  txt::TextStyle text_style;
2448  text_style.font_families = std::vector<std::string>(1, "Ahem");
2449  text_style.font_size = 26;
2450  text_style.color = SK_ColorBLACK;
2451  text_style.height = 1;
2452  builder.PushStyle(text_style);
2453 
2454  builder.AddText(u16_text);
2455 
2456  builder.Pop();
2457 
2458  auto paragraph = BuildParagraph(builder);
2459  size_t paragraph_width = GetTestCanvasWidth() - 100;
2460  paragraph->Layout(paragraph_width);
2461 
2462  paragraph->Paint(GetCanvas(), 0, 0);
2463 
2464  SkPaint paint;
2465  paint.setStyle(SkPaint::kStroke_Style);
2466  paint.setAntiAlias(true);
2467  paint.setStrokeWidth(1);
2468 
2469  // Tests for GetRectsForRange()
2470  Paragraph::RectHeightStyle rect_height_style =
2471  Paragraph::RectHeightStyle::kMax;
2472  Paragraph::RectWidthStyle rect_width_style =
2473  Paragraph::RectWidthStyle::kTight;
2474  paint.setColor(SK_ColorRED);
2475  std::vector<txt::Paragraph::TextBox> boxes =
2476  paragraph->GetRectsForRange(0, 100, rect_height_style, rect_width_style);
2477  for (size_t i = 0; i < boxes.size(); ++i) {
2478  GetCanvas()->drawRect(boxes[i].rect, paint);
2479  }
2480  ASSERT_EQ(boxes.size(), 2ull);
2481 
2482  // This test should crash if behavior regresses.
2483 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double font_size
Definition: text_style.h:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [30/78]

txt::TEST_F ( ParagraphTest  ,
DecorationsParagraph   
)

Definition at line 2485 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::decoration_style, txt::TextStyle::decoration_thickness_multiplier, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), txt::TextStyle::height, kDashed, kDotted, kDouble, kLineThrough, kOverline, kSolid, kUnderline, kWavy, left, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), txt::ParagraphStyle::text_align, and txt::TextStyle::word_spacing.

2485  {
2486  txt::ParagraphStyle paragraph_style;
2487  paragraph_style.max_lines = 14;
2488  paragraph_style.text_align = TextAlign::left;
2489  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2490 
2491  txt::TextStyle text_style;
2492  text_style.font_families = std::vector<std::string>(1, "Roboto");
2493  text_style.font_size = 26;
2494  text_style.letter_spacing = 0;
2495  text_style.word_spacing = 5;
2496  text_style.color = SK_ColorBLACK;
2497  text_style.height = 2;
2498  text_style.decoration = TextDecoration::kUnderline |
2502  text_style.decoration_color = SK_ColorBLACK;
2503  text_style.decoration_thickness_multiplier = 2.0;
2504  builder.PushStyle(text_style);
2505  builder.AddText(u"This text should be");
2506 
2508  text_style.decoration_color = SK_ColorBLUE;
2509  text_style.decoration_thickness_multiplier = 1.0;
2510  builder.PushStyle(text_style);
2511  builder.AddText(u" decorated even when");
2512 
2514  text_style.decoration_color = SK_ColorBLACK;
2515  builder.PushStyle(text_style);
2516  builder.AddText(u" wrapped around to");
2517 
2519  text_style.decoration_color = SK_ColorBLACK;
2520  text_style.decoration_thickness_multiplier = 3.0;
2521  builder.PushStyle(text_style);
2522  builder.AddText(u" the next line.");
2523 
2525  text_style.decoration_color = SK_ColorRED;
2526  text_style.decoration_thickness_multiplier = 1.0;
2527  builder.PushStyle(text_style);
2528 
2529  builder.AddText(u" Otherwise, bad things happen.");
2530 
2531  builder.Pop();
2532 
2533  auto paragraph = BuildParagraph(builder);
2534  paragraph->Layout(GetTestCanvasWidth() - 100);
2535 
2536  paragraph->Paint(GetCanvas(), 0, 0);
2537 
2538  ASSERT_TRUE(Snapshot());
2539  ASSERT_EQ(paragraph->runs_.size(), 5ull);
2540  ASSERT_EQ(paragraph->records_.size(), 6ull);
2541 
2542  for (size_t i = 0; i < 6; ++i) {
2543  ASSERT_EQ(paragraph->records_[i].style().decoration,
2546  }
2547 
2548  ASSERT_EQ(paragraph->records_[0].style().decoration_style,
2550  ASSERT_EQ(paragraph->records_[1].style().decoration_style,
2552  ASSERT_EQ(paragraph->records_[2].style().decoration_style,
2554  ASSERT_EQ(paragraph->records_[3].style().decoration_style,
2556  ASSERT_EQ(paragraph->records_[4].style().decoration_style,
2558  ASSERT_EQ(paragraph->records_[5].style().decoration_style,
2560 
2561  ASSERT_EQ(paragraph->records_[0].style().decoration_color, SK_ColorBLACK);
2562  ASSERT_EQ(paragraph->records_[1].style().decoration_color, SK_ColorBLUE);
2563  ASSERT_EQ(paragraph->records_[2].style().decoration_color, SK_ColorBLACK);
2564  ASSERT_EQ(paragraph->records_[3].style().decoration_color, SK_ColorBLACK);
2565  ASSERT_EQ(paragraph->records_[4].style().decoration_color, SK_ColorBLACK);
2566  ASSERT_EQ(paragraph->records_[5].style().decoration_color, SK_ColorRED);
2567 
2568  ASSERT_EQ(paragraph->records_[0].style().decoration_thickness_multiplier,
2569  2.0);
2570  ASSERT_EQ(paragraph->records_[1].style().decoration_thickness_multiplier,
2571  1.0);
2572  ASSERT_EQ(paragraph->records_[2].style().decoration_thickness_multiplier,
2573  1.0);
2574  ASSERT_EQ(paragraph->records_[3].style().decoration_thickness_multiplier,
2575  3.0);
2576  ASSERT_EQ(paragraph->records_[4].style().decoration_thickness_multiplier,
2577  3.0);
2578  ASSERT_EQ(paragraph->records_[5].style().decoration_thickness_multiplier,
2579  1.0);
2580 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double decoration_thickness_multiplier
Definition: text_style.h:43
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
TextDecorationStyle decoration_style
Definition: text_style.h:41
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [31/78]

txt::TEST_F ( ParagraphTest  ,
WavyDecorationParagraph   
)

Definition at line 2582 of file paragraph_unittests.cc.

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

2582  {
2583  txt::ParagraphStyle paragraph_style;
2584  paragraph_style.max_lines = 14;
2585  paragraph_style.text_align = TextAlign::left;
2586  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2587 
2588  txt::TextStyle text_style;
2589  text_style.font_families = std::vector<std::string>(1, "Roboto");
2590  text_style.font_size = 26;
2591  text_style.letter_spacing = 0;
2592  text_style.word_spacing = 5;
2593  text_style.color = SK_ColorBLACK;
2594  text_style.height = 2;
2595  text_style.decoration = TextDecoration::kUnderline |
2598 
2600  text_style.decoration_color = SK_ColorRED;
2601  text_style.decoration_thickness_multiplier = 1.0;
2602  builder.PushStyle(text_style);
2603 
2604  builder.AddText(u" Otherwise, bad things happen.");
2605 
2606  builder.Pop();
2607 
2608  auto paragraph = BuildParagraph(builder);
2609  paragraph->Layout(GetTestCanvasWidth() - 100);
2610 
2611  paragraph->Paint(GetCanvas(), 0, 0);
2612 
2613  ASSERT_TRUE(Snapshot());
2614  ASSERT_EQ(paragraph->runs_.size(), 1ull);
2615  ASSERT_EQ(paragraph->records_.size(), 1ull);
2616 
2617  for (size_t i = 0; i < 1; ++i) {
2618  ASSERT_EQ(paragraph->records_[i].style().decoration,
2621  }
2622 
2623  ASSERT_EQ(paragraph->records_[0].style().decoration_style,
2625 
2626  ASSERT_EQ(paragraph->records_[0].style().decoration_color, SK_ColorRED);
2627 
2628  ASSERT_EQ(paragraph->records_[0].style().decoration_thickness_multiplier,
2629  1.0);
2630 
2631  SkPath path0;
2632  SkPath canonical_path0;
2633  paragraph->ComputeWavyDecoration(path0, 1, 1, 9.56, 1);
2634 
2635  canonical_path0.moveTo(1, 1);
2636  canonical_path0.rQuadTo(1, -1, 2, 0);
2637  canonical_path0.rQuadTo(1, 1, 2, 0);
2638  canonical_path0.rQuadTo(1, -1, 2, 0);
2639  canonical_path0.rQuadTo(1, 1, 2, 0);
2640  canonical_path0.rQuadTo(0.78, -0.78, 1.56, -0.3432);
2641 
2642  ASSERT_EQ(path0.countPoints(), canonical_path0.countPoints());
2643  for (int i = 0; i < canonical_path0.countPoints(); ++i) {
2644  ASSERT_EQ(path0.getPoint(i).x(), canonical_path0.getPoint(i).x());
2645  ASSERT_EQ(path0.getPoint(i).y(), canonical_path0.getPoint(i).y());
2646  }
2647 
2648  SkPath path1;
2649  SkPath canonical_path1;
2650  paragraph->ComputeWavyDecoration(path1, 1, 1, 8.35, 1);
2651 
2652  canonical_path1.moveTo(1, 1);
2653  canonical_path1.rQuadTo(1, -1, 2, 0);
2654  canonical_path1.rQuadTo(1, 1, 2, 0);
2655  canonical_path1.rQuadTo(1, -1, 2, 0);
2656  canonical_path1.rQuadTo(1, 1, 2, 0);
2657  canonical_path1.rQuadTo(0.175, -0.175, 0.35, -0.28875);
2658 
2659  ASSERT_EQ(path1.countPoints(), canonical_path1.countPoints());
2660  for (int i = 0; i < canonical_path1.countPoints(); ++i) {
2661  ASSERT_EQ(path1.getPoint(i).x(), canonical_path1.getPoint(i).x());
2662  ASSERT_EQ(path1.getPoint(i).y(), canonical_path1.getPoint(i).y());
2663  }
2664 
2665  SkPath path2;
2666  SkPath canonical_path2;
2667  paragraph->ComputeWavyDecoration(path2, 1, 1, 10.59, 1);
2668 
2669  canonical_path2.moveTo(1, 1);
2670  canonical_path2.rQuadTo(1, -1, 2, 0);
2671  canonical_path2.rQuadTo(1, 1, 2, 0);
2672  canonical_path2.rQuadTo(1, -1, 2, 0);
2673  canonical_path2.rQuadTo(1, 1, 2, 0);
2674  canonical_path2.rQuadTo(1, -1, 2, 0);
2675  canonical_path2.rQuadTo(0.295, 0.295, 0.59, 0.41595);
2676 
2677  ASSERT_EQ(path2.countPoints(), canonical_path2.countPoints());
2678  for (int i = 0; i < canonical_path2.countPoints(); ++i) {
2679  ASSERT_EQ(path2.getPoint(i).x(), canonical_path2.getPoint(i).x());
2680  ASSERT_EQ(path2.getPoint(i).y(), canonical_path2.getPoint(i).y());
2681  }
2682 
2683  SkPath path3;
2684  SkPath canonical_path3;
2685  paragraph->ComputeWavyDecoration(path3, 1, 1, 11.2, 1);
2686 
2687  canonical_path3.moveTo(1, 1);
2688  canonical_path3.rQuadTo(1, -1, 2, 0);
2689  canonical_path3.rQuadTo(1, 1, 2, 0);
2690  canonical_path3.rQuadTo(1, -1, 2, 0);
2691  canonical_path3.rQuadTo(1, 1, 2, 0);
2692  canonical_path3.rQuadTo(1, -1, 2, 0);
2693  canonical_path3.rQuadTo(0.6, 0.6, 1.2, 0.48);
2694 
2695  ASSERT_EQ(path3.countPoints(), canonical_path3.countPoints());
2696  for (int i = 0; i < canonical_path3.countPoints(); ++i) {
2697  ASSERT_EQ(path3.getPoint(i).x(), canonical_path3.getPoint(i).x());
2698  ASSERT_EQ(path3.getPoint(i).y(), canonical_path3.getPoint(i).y());
2699  }
2700 
2701  SkPath path4;
2702  SkPath canonical_path4;
2703  paragraph->ComputeWavyDecoration(path4, 1, 1, 12, 1);
2704 
2705  canonical_path4.moveTo(1, 1);
2706  canonical_path4.rQuadTo(1, -1, 2, 0);
2707  canonical_path4.rQuadTo(1, 1, 2, 0);
2708  canonical_path4.rQuadTo(1, -1, 2, 0);
2709  canonical_path4.rQuadTo(1, 1, 2, 0);
2710  canonical_path4.rQuadTo(1, -1, 2, 0);
2711  canonical_path4.rQuadTo(1, 1, 2, 0);
2712 
2713  ASSERT_EQ(path4.countPoints(), canonical_path4.countPoints());
2714  for (int i = 0; i < canonical_path4.countPoints(); ++i) {
2715  ASSERT_EQ(path4.getPoint(i).x(), canonical_path4.getPoint(i).x());
2716  ASSERT_EQ(path4.getPoint(i).y(), canonical_path4.getPoint(i).y());
2717  }
2718 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double decoration_thickness_multiplier
Definition: text_style.h:43
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
TextDecorationStyle decoration_style
Definition: text_style.h:41
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [32/78]

txt::TEST_F ( ParagraphTest  ,
ItalicsParagraph   
)

Definition at line 2720 of file paragraph_unittests.cc.

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

2720  {
2721  txt::ParagraphStyle paragraph_style;
2722  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2723 
2724  txt::TextStyle text_style;
2725  text_style.font_families = std::vector<std::string>(1, "Roboto");
2726  text_style.color = SK_ColorRED;
2727  text_style.font_size = 10;
2728  builder.PushStyle(text_style);
2729  builder.AddText(u"No italic ");
2730 
2731  text_style.font_style = txt::FontStyle::italic;
2732  builder.PushStyle(text_style);
2733  builder.AddText(u"Yes Italic ");
2734 
2735  builder.Pop();
2736  builder.AddText(u"No Italic again.");
2737 
2738  auto paragraph = BuildParagraph(builder);
2739  paragraph->Layout(GetTestCanvasWidth());
2740 
2741  paragraph->Paint(GetCanvas(), 0, 0);
2742 
2743  ASSERT_EQ(paragraph->runs_.runs_.size(), 3ull);
2744  ASSERT_EQ(paragraph->runs_.styles_.size(), 3ull);
2745  ASSERT_EQ(paragraph->records_[1].style().color, text_style.color);
2746  ASSERT_EQ(paragraph->records_[1].style().font_style, txt::FontStyle::italic);
2747  ASSERT_EQ(paragraph->records_[2].style().font_style, txt::FontStyle::normal);
2748  ASSERT_EQ(paragraph->records_[0].style().font_style, txt::FontStyle::normal);
2749  ASSERT_TRUE(Snapshot());
2750 }
std::shared_ptr< FontCollection > GetTestFontCollection()
FontStyle font_style
Definition: text_style.h:45
double font_size
Definition: text_style.h:50
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [33/78]

txt::TEST_F ( ParagraphTest  ,
ChineseParagraph   
)

Definition at line 2752 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::decoration_style, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), justify, kLineThrough, kOverline, kSolid, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), and txt::ParagraphBuilderTxt::PushStyle().

2752  {
2753  const char* text =
2754  "左線読設重説切後碁給能上目秘使約。満毎冠行来昼本可必図将発確年。今属場育"
2755  "図情闘陰野高備込制詩西校客。審対江置講今固残必託地集済決維駆年策。立得庭"
2756  "際輝求佐抗蒼提夜合逃表。注統天言件自謙雅載報紙喪。作画稿愛器灯女書利変探"
2757  "訃第金線朝開化建。子戦年帝励害表月幕株漠新期刊人秘。図的海力生禁挙保天戦"
2758  "聞条年所在口。";
2759  auto icu_text = icu::UnicodeString::fromUTF8(text);
2760  std::u16string u16_text(icu_text.getBuffer(),
2761  icu_text.getBuffer() + icu_text.length());
2762 
2763  txt::ParagraphStyle paragraph_style;
2764  paragraph_style.max_lines = 14;
2765  paragraph_style.text_align = TextAlign::justify;
2766  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2767 
2768  txt::TextStyle text_style;
2769  text_style.color = SK_ColorBLACK;
2770  text_style.font_size = 35;
2771  text_style.letter_spacing = 2;
2772  text_style.font_families = std::vector<std::string>(1, "Source Han Serif CN");
2773  text_style.decoration = TextDecoration::kUnderline |
2777  text_style.decoration_color = SK_ColorBLACK;
2778  builder.PushStyle(text_style);
2779 
2780  builder.AddText(u16_text);
2781 
2782  builder.Pop();
2783 
2784  auto paragraph = BuildParagraph(builder);
2785  paragraph->Layout(GetTestCanvasWidth() - 100);
2786 
2787  paragraph->Paint(GetCanvas(), 0, 0);
2788 
2789  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2790  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2791  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2792  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
2793  ASSERT_EQ(paragraph->records_.size(), 7ull);
2794 
2795  ASSERT_TRUE(Snapshot());
2796 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
SkColor decoration_color
Definition: text_style.h:40
TextDecorationStyle decoration_style
Definition: text_style.h:41
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [34/78]

txt::TEST_F ( ParagraphTest  ,
DISABLED_ArabicParagraph   
)

Definition at line 2799 of file paragraph_unittests.cc.

References txt::ParagraphBuilderTxt::AddText(), BuildParagraph(), txt::TextStyle::color, txt::TextStyle::decoration, txt::TextStyle::decoration_color, txt::TextStyle::decoration_style, txt::TextStyle::font_families, txt::TextStyle::font_size, GetTestFontCollection(), kLineThrough, kOverline, kSolid, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), right, and rtl.

2799  {
2800  const char* text =
2801  "من أسر وإعلان الخاصّة وهولندا،, عل قائمة الضغوط بالمطالبة تلك. الصفحة "
2802  "بمباركة التقليدية قام عن. تصفح";
2803  auto icu_text = icu::UnicodeString::fromUTF8(text);
2804  std::u16string u16_text(icu_text.getBuffer(),
2805  icu_text.getBuffer() + icu_text.length());
2806 
2807  txt::ParagraphStyle paragraph_style;
2808  paragraph_style.max_lines = 14;
2809  paragraph_style.text_align = TextAlign::right;
2810  paragraph_style.text_direction = TextDirection::rtl;
2811  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2812 
2813  txt::TextStyle text_style;
2814  text_style.color = SK_ColorBLACK;
2815  text_style.font_size = 35;
2816  text_style.letter_spacing = 2;
2817  text_style.font_families = std::vector<std::string>(1, "Katibeh");
2818  text_style.decoration = TextDecoration::kUnderline |
2822  text_style.decoration_color = SK_ColorBLACK;
2823  builder.PushStyle(text_style);
2824 
2825  builder.AddText(u16_text);
2826 
2827  builder.Pop();
2828 
2829  auto paragraph = BuildParagraph(builder);
2830  paragraph->Layout(GetTestCanvasWidth() - 100);
2831 
2832  paragraph->Paint(GetCanvas(), 0, 0);
2833 
2834  ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
2835 
2836  ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
2837  ASSERT_EQ(paragraph->runs_.styles_.size(), 2ull);
2838  ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style));
2839  ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
2840  ASSERT_EQ(paragraph->records_.size(), 2ull);
2841  ASSERT_EQ(paragraph->paragraph_style_.text_direction, TextDirection::rtl);
2842 
2843  for (size_t i = 0; i < u16_text.length(); i++) {
2844  ASSERT_EQ(paragraph->text_[i], u16_text[u16_text.length() - i]);
2845  }
2846 
2847  ASSERT_TRUE(Snapshot());
2848 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
SkColor decoration_color
Definition: text_style.h:40
TextDecorationStyle decoration_style
Definition: text_style.h:41
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [35/78]

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

Definition at line 2852 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, txt::Paragraph::kMax, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), right, rtl, and txt::TextStyle::word_spacing.

2852  {
2853  const char* text = "بمباركة التقليدية قام عن. تصفح يد ";
2854  auto icu_text = icu::UnicodeString::fromUTF8(text);
2855  std::u16string u16_text(icu_text.getBuffer(),
2856  icu_text.getBuffer() + icu_text.length());
2857 
2858  txt::ParagraphStyle paragraph_style;
2859  paragraph_style.max_lines = 14;
2860  paragraph_style.text_align = TextAlign::right;
2861  paragraph_style.text_direction = TextDirection::rtl;
2862  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2863 
2864  txt::TextStyle text_style;
2865  text_style.font_families = std::vector<std::string>(1, "Noto Naskh Arabic");
2866  text_style.font_size = 26;
2867  text_style.letter_spacing = 1;
2868  text_style.word_spacing = 5;
2869  text_style.color = SK_ColorBLACK;
2870  text_style.height = 1;
2872  text_style.decoration_color = SK_ColorBLACK;
2873  builder.PushStyle(text_style);
2874 
2875  builder.AddText(u16_text);
2876 
2877  builder.Pop();
2878 
2879  auto paragraph = BuildParagraph(builder);
2880  paragraph->Layout(GetTestCanvasWidth() - 100);
2881 
2882  paragraph->Paint(GetCanvas(), 0, 0);
2883 
2884  SkPaint paint;
2885  paint.setStyle(SkPaint::kStroke_Style);
2886  paint.setAntiAlias(true);
2887  paint.setStrokeWidth(1);
2888 
2889  // Tests for GetRectsForRange()
2890  Paragraph::RectHeightStyle rect_height_style =
2891  Paragraph::RectHeightStyle::kMax;
2892  Paragraph::RectWidthStyle rect_width_style =
2893  Paragraph::RectWidthStyle::kTight;
2894  paint.setColor(SK_ColorRED);
2895  std::vector<txt::Paragraph::TextBox> boxes =
2896  paragraph->GetRectsForRange(0, 100, rect_height_style, rect_width_style);
2897  for (size_t i = 0; i < boxes.size(); ++i) {
2898  GetCanvas()->drawRect(boxes[i].rect, paint);
2899  }
2900  EXPECT_EQ(boxes.size(), 2ull);
2901 
2902  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 556.48438);
2903  EXPECT_FLOAT_EQ(boxes[0].rect.top(), -0.26855469);
2904  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 900);
2905  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 44);
2906 
2907  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 510.03125);
2908  EXPECT_FLOAT_EQ(boxes[1].rect.top(), -0.26855469);
2909  EXPECT_FLOAT_EQ(boxes[1].rect.right(), 556.98438);
2910  EXPECT_FLOAT_EQ(boxes[1].rect.bottom(), 44);
2911 
2912  ASSERT_EQ(paragraph_style.text_align,
2913  paragraph->GetParagraphStyle().text_align);
2914 
2915  ASSERT_TRUE(Snapshot());
2916 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [36/78]

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

Definition at line 2920 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, txt::Paragraph::kMax, txt::Paragraph::kTight, kUnderline, left, txt::TextStyle::letter_spacing, ltr, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), and txt::TextStyle::word_spacing.

2920  {
2921  const char* text = "Helloبمباركة التقليدية قام عن. تصفح يد ";
2922  auto icu_text = icu::UnicodeString::fromUTF8(text);
2923  std::u16string u16_text(icu_text.getBuffer(),
2924  icu_text.getBuffer() + icu_text.length());
2925 
2926  txt::ParagraphStyle paragraph_style;
2927  paragraph_style.max_lines = 14;
2928  paragraph_style.text_align = TextAlign::left;
2929  paragraph_style.text_direction = TextDirection::ltr;
2930  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2931 
2932  txt::TextStyle text_style;
2933  text_style.font_families = std::vector<std::string>(1, "Noto Naskh Arabic");
2934  text_style.font_size = 26;
2935  text_style.letter_spacing = 1;
2936  text_style.word_spacing = 5;
2937  text_style.color = SK_ColorBLACK;
2938  text_style.height = 1;
2940  text_style.decoration_color = SK_ColorBLACK;
2941  builder.PushStyle(text_style);
2942 
2943  builder.AddText(u16_text);
2944 
2945  builder.Pop();
2946 
2947  auto paragraph = BuildParagraph(builder);
2948  paragraph->Layout(GetTestCanvasWidth() - 100);
2949 
2950  paragraph->Paint(GetCanvas(), 0, 0);
2951 
2952  SkPaint paint;
2953  paint.setStyle(SkPaint::kStroke_Style);
2954  paint.setAntiAlias(true);
2955  paint.setStrokeWidth(1);
2956 
2957  // Tests for GetRectsForRange()
2958  Paragraph::RectHeightStyle rect_height_style =
2959  Paragraph::RectHeightStyle::kMax;
2960  Paragraph::RectWidthStyle rect_width_style =
2961  Paragraph::RectWidthStyle::kTight;
2962  paint.setColor(SK_ColorRED);
2963  std::vector<txt::Paragraph::TextBox> boxes =
2964  paragraph->GetRectsForRange(36, 40, rect_height_style, rect_width_style);
2965  for (size_t i = 0; i < boxes.size(); ++i) {
2966  GetCanvas()->drawRect(boxes[i].rect, paint);
2967  }
2968  EXPECT_EQ(boxes.size(), 1ull);
2969 
2970  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 89.425781);
2971  EXPECT_FLOAT_EQ(boxes[0].rect.top(), -0.26855469);
2972  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 121.90625);
2973  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 44);
2974 
2975  ASSERT_EQ(paragraph_style.text_align,
2976  paragraph->GetParagraphStyle().text_align);
2977 
2978  ASSERT_TRUE(Snapshot());
2979 }
std::shared_ptr< FontCollection > GetTestFontCollection()
double height
Definition: text_style.h:53
double letter_spacing
Definition: text_style.h:51
double font_size
Definition: text_style.h:50
double word_spacing
Definition: text_style.h:52
SkColor decoration_color
Definition: text_style.h:40
std::vector< std::string > font_families
Definition: text_style.h:49
SkColor color
Definition: text_style.h:36
std::unique_ptr< ParagraphTxt > BuildParagraph(txt::ParagraphBuilderTxt &builder)

◆ TEST_F() [37/78]

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

Definition at line 2983 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, txt::Paragraph::kMax, txt::Paragraph::kTight, kUnderline, txt::TextStyle::letter_spacing, ltr, txt::ParagraphStyle::max_lines, txt::ParagraphBuilderTxt::Pop(), txt::ParagraphBuilderTxt::PushStyle(), right, and txt::TextStyle::word_spacing.

2983  {
2984  const char* text = "Helloبمباركة التقليدية قام عن. تصفح يد ";
2985  auto icu_text = icu::UnicodeString::fromUTF8(text);
2986  std::u16string u16_text(icu_text.getBuffer(),
2987  icu_text.getBuffer() + icu_text.length());
2988 
2989  txt::ParagraphStyle paragraph_style;
2990  paragraph_style.max_lines = 14;
2991  paragraph_style.text_align = TextAlign::right;
2992  paragraph_style.text_direction = TextDirection::ltr;
2993  txt::ParagraphBuilderTxt builder(paragraph_style, GetTestFontCollection());
2994 
2995  txt::TextStyle text_style;
2996  text_style.font_families = std::vector<std::string>(1, "Noto Naskh Arabic");
2997  text_style.font_size = 26;
2998  text_style.letter_spacing = 1;
2999  text_style.word_spacing = 5;
3000  text_style.color = SK_ColorBLACK;
3001  text_style.height = 1;
3003  text_style.decoration_color = SK_ColorBLACK;
3004  builder.PushStyle(text_style);
3005 
3006  builder.AddText(u16_text);
3007 
3008  builder.Pop();
3009 
3010  auto paragraph = BuildParagraph(builder);
3011  paragraph->Layout(GetTestCanvasWidth() - 100);
3012 
3013  paragraph->Paint(GetCanvas(), 0, 0);
3014 
3015  SkPaint paint;
3016  paint.setStyle(SkPaint::kStroke_Style);
3017  paint.setAntiAlias(true);
3018  paint.setStrokeWidth(1);
3019 
3020  // Tests for GetRectsForRange()
3021  Paragraph::RectHeightStyle rect_height_style =
3022  Paragraph::RectHeightStyle::kMax;
3023  Paragraph::RectWidthStyle rect_width_style =
3024  Paragraph::RectWidthStyle::kTight;
3025  paint.setColor(SK_ColorRED);
3026  std::vector<txt::Paragraph::TextBox> boxes =
3027  paragraph->GetRectsForRange(36, 40, rect_height_style, rect_width_style);
3028  for (size_t i = 0; i < boxes.size(); ++i) {
3029  GetCanvas()->drawRect(boxes[i].rect, paint);
3030  }
3031  EXPECT_EQ(boxes.size(), 2ull);
3032 
3033  EXPECT_FLOAT_EQ(boxes[0].rect.left(), 556.48438);
3034  EXPECT_FLOAT_EQ(boxes[0].rect.top(), -0.26855469);
3035  EXPECT_FLOAT_EQ(boxes[0].rect.right(), 577.72656);
3036  EXPECT_FLOAT_EQ(boxes[0].rect.bottom(), 44);
3037 
3038  EXPECT_FLOAT_EQ(boxes[1].rect.left(), 545.24609);
3039  EXPECT_FLOAT_EQ(boxes[1].rect.top(), -0.26855469);
3040  EXPECT_FLOAT_EQ(b