Commit a037c0d9 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Fix font-orientation segmentation

When there are no script segments (i.e., all the text is in
single script) and in vertical flow, we create a single
segment and split it at the font-orientation boundaries.

This patch fixes to create the single segment from the first
text item, not from the first item. If it is created from the
first item and the first item is not a text item, we may give
incorrect script and/or font-orientation to HarfBuzz.

Bug: 10061548
Change-Id: I5ea87920f8cbc76cdc13fe25611f7a7a34284813
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847697Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703803}
parent f8f2f729
...@@ -953,22 +953,26 @@ void NGInlineNode::SegmentFontOrientation(NGInlineNodeData* data) { ...@@ -953,22 +953,26 @@ void NGInlineNode::SegmentFontOrientation(NGInlineNodeData* data) {
// If we don't have |NGInlineItemSegments| yet, create a segment for the // If we don't have |NGInlineItemSegments| yet, create a segment for the
// entire content. // entire content.
const unsigned capacity = items.size() + text_content.length() / 10; const unsigned capacity = items.size() + text_content.length() / 10;
if (!data->segments) { NGInlineItemSegments* segments = data->segments.get();
data->segments = std::make_unique<NGInlineItemSegments>(); if (segments) {
data->segments->ReserveCapacity(capacity);
data->segments->Append(text_content.length(), items.front());
} else {
DCHECK(!data->segments->IsEmpty()); DCHECK(!data->segments->IsEmpty());
data->segments->ReserveCapacity(capacity); data->segments->ReserveCapacity(capacity);
DCHECK_EQ(text_content.length(), data->segments->EndOffset());
} }
DCHECK_EQ(text_content.length(), data->segments->EndOffset());
unsigned segment_index = 0; unsigned segment_index = 0;
for (const NGInlineItem& item : items) { for (const NGInlineItem& item : items) {
if (item.Type() == NGInlineItem::kText && item.Length() && if (item.Type() == NGInlineItem::kText && item.Length() &&
item.Style()->GetFont().GetFontDescription().Orientation() == item.Style()->GetFont().GetFontDescription().Orientation() ==
FontOrientation::kVerticalMixed) { FontOrientation::kVerticalMixed) {
segment_index = data->segments->AppendMixedFontOrientation( if (!segments) {
data->segments = std::make_unique<NGInlineItemSegments>();
segments = data->segments.get();
segments->ReserveCapacity(capacity);
segments->Append(text_content.length(), item);
DCHECK_EQ(text_content.length(), data->segments->EndOffset());
}
segment_index = segments->AppendMixedFontOrientation(
text_content, item.StartOffset(), item.EndOffset(), segment_index); text_content, item.StartOffset(), item.EndOffset(), segment_index);
} }
} }
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Test: Test Mongolian in a span renders the same as without the span</title>
<link rel="match" href="reference/mongolian-span-001-ref.html">
<link rel="help" href="https://drafts.csswg.org/css-writing-modes-3/#block-flow">
<link rel="author" href="mailto:kojii@chromium.org">
<style>
html {
writing-mode: vertical-lr;
font-size: 50px;
}
</style>
<body>
<div>ᠶᠠᠫᠣᠨ</div>
<div><span>ᠶᠠᠫᠣᠨ</span></div>
</body>
<!DOCTYPE html>
<meta charset="utf-8">
<style>
html {
writing-mode: vertical-lr;
font-size: 50px;
}
</style>
<body>
<div>ᠶᠠᠫᠣᠨ</div>
<div>ᠶᠠᠫᠣᠨ</div>
</body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment