Prelim ideographic baseline and MinIntrinsicWeight, Arabic test, prepare

for RTL language support implementation.

Change-Id: I99a6af74aa3607ff9b58ba98426ad3026f02b816
This commit is contained in:
Gary Qian
2017-07-06 14:23:59 -07:00
parent 4ed0e488da
commit 7e01820ef8
5 changed files with 65 additions and 7 deletions

View File

@@ -328,7 +328,8 @@ void Paragraph::Layout(double width, bool force) {
alphabetic_baseline_ = metrics.fCapHeight * run.style.height;
// TODO(garyq): Properly implement ideographic_baseline_.
ideographic_baseline_ =
(metrics.fDescent + metrics.fCapHeight) * run.style.height;
(metrics.fUnderlinePosition + metrics.fCapHeight) *
run.style.height;
}
}
if (max_descent < metrics.fDescent * run.style.height)
@@ -412,7 +413,7 @@ double Paragraph::GetAlphabeticBaseline() const {
}
double Paragraph::GetIdeographicBaseline() const {
// TODO(garyq): Implement.
// TODO(garyq): Currently fCapHeight + fUnderlinePosition. Verify this.
return ideographic_baseline_;
}
@@ -421,8 +422,8 @@ double Paragraph::GetMaxIntrinsicWidth() const {
}
double Paragraph::GetMinIntrinsicWidth() const {
// TODO(garyq): Implement.
return min_intrinsic_width_;
// TODO(garyq): This is a lower bound. Actual value may be slightly higher.
return max_intrinsic_width_ / paragraph_style_.max_lines;
}
double Paragraph::GetHeight() const {
@@ -531,8 +532,8 @@ void Paragraph::PaintDecorations(SkCanvas* canvas,
// Overline
if (style.decoration & 0x2) {
if (style.decoration_style != TextDecorationStyle::kWavy)
canvas->drawLine(x, y + metrics.fAscent + y_offset, x + width,
y + metrics.fAscent + y_offset, paint);
canvas->drawLine(x, y + metrics.fAscent - y_offset, x + width,
y + metrics.fAscent - y_offset, paint);
else
PaintWavyDecoration(canvas, wave_coords, paint, x, y, metrics.fAscent,
width);

View File

@@ -73,6 +73,7 @@ class Paragraph {
FRIEND_TEST(RenderTest, DecorationsParagraph);
FRIEND_TEST(RenderTest, ItalicsParagraph);
FRIEND_TEST(RenderTest, ChineseParagraph);
FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph);
std::vector<uint16_t> text_;
StyledRuns runs_;

View File

@@ -34,7 +34,10 @@ class ParagraphStyle {
double font_size = 14;
size_t max_lines = 1;
double line_height = 1.0;
std::string ellipsis;
std::string ellipsis = "...";
// TODO(garyq): Implement right to left.
// Right to left (Arabic, Hebrew, etc).
bool rtl = false;
};
} // namespace txt

View File

@@ -67,6 +67,7 @@ class StyledRuns {
FRIEND_TEST(RenderTest, DecorationsParagraph);
FRIEND_TEST(RenderTest, ItalicsParagraph);
FRIEND_TEST(RenderTest, ChineseParagraph);
FRIEND_TEST(RenderTest, DISABLED_ArabicParagraph);
struct IndexedRun {
size_t style_index = 0;

View File

@@ -763,6 +763,7 @@ TEST_F(RenderTest, ChineseParagraph) {
txt::ParagraphStyle paragraph_style;
paragraph_style.max_lines = 14;
paragraph_style.text_align = TextAlign::right;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
@@ -794,4 +795,55 @@ TEST_F(RenderTest, ChineseParagraph) {
ASSERT_TRUE(Snapshot());
}
// TODO(garyq): Support RTL languages.
TEST_F(RenderTest, DISABLED_ArabicParagraph) {
const char* text =
"من أسر وإعلان الخاصّة وهولندا،, عل قائمة الضغوط بالمطالبة تلك. الصفحة "
"بمباركة التقليدية قام عن. تصفح";
auto icu_text = icu::UnicodeString::fromUTF8(text);
std::u16string u16_text(icu_text.getBuffer(),
icu_text.getBuffer() + icu_text.length());
txt::ParagraphStyle paragraph_style;
paragraph_style.max_lines = 14;
paragraph_style.text_align = TextAlign::right;
paragraph_style.rtl = true;
auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir());
txt::ParagraphBuilder builder(paragraph_style, &font_collection);
txt::TextStyle text_style;
text_style.color = SK_ColorBLACK;
text_style.font_size = 35;
text_style.letter_spacing = 2;
text_style.font_family = "Katibeh";
text_style.decoration = txt::TextDecoration(0x1 | 0x2 | 0x4);
text_style.decoration_style = txt::TextDecorationStyle::kSolid;
text_style.decoration_color = SK_ColorBLACK;
builder.PushStyle(text_style);
builder.AddText(u16_text);
builder.Pop();
auto paragraph = builder.Build();
paragraph->Layout(GetTestCanvasWidth() - 100);
paragraph->Paint(GetCanvas(), 0, 0);
ASSERT_EQ(paragraph->text_.size(), std::string{text}.length());
ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull);
ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull);
ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style));
ASSERT_EQ(paragraph->records_[0].style().color, text_style.color);
ASSERT_EQ(paragraph->records_.size(), 2ull);
ASSERT_EQ(paragraph->paragraph_style_.rtl, true);
for (size_t i = 0; i < u16_text.length(); i++) {
ASSERT_EQ(paragraph->text_[i], u16_text[u16_text.length() - i]);
}
ASSERT_TRUE(Snapshot());
}
} // namespace txt