Skip to content

Commit 1146888

Browse files
tkent-googlepull[bot]
authored andcommitted
sideways: Support SVG
In , a text in sideways-lr works like a text in horizontal-tb. Bug: 40501131 Change-Id: I17340abd83cbe375d7cc8d1a6a37521d7bfc8157 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5992678 Commit-Queue: Koji Ishii Reviewed-by: Koji Ishii Auto-Submit: Kent Tamura Cr-Commit-Position: refs/heads/main@{#1378784}
1 parent 04ffdd1 commit 1146888

File tree

17 files changed

+83
-16
lines changed

17 files changed

+83
-16
lines changed

third_party/blink/renderer/core/layout/inline/fragment_item.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,22 @@ AffineTransform FragmentItem::BuildSvgTransformForTextPath(
709709
// PositionOnPath()|.
710710
float x = svg_data.rect.x();
711711
float y = svg_data.rect.y();
712-
if (IsHorizontal()) {
713-
y += font_data->GetFontMetrics().FixedAscent(font_baseline);
714-
transform.Translate(-svg_data.rect.width() / 2, svg_data.baseline_shift);
715-
} else {
716-
x += font_data->GetFontMetrics().FixedDescent(font_baseline);
717-
transform.Translate(svg_data.baseline_shift, -svg_data.rect.height() / 2);
712+
switch (GetWritingMode()) {
713+
case WritingMode::kHorizontalTb:
714+
y += font_data->GetFontMetrics().FixedAscent(font_baseline);
715+
transform.Translate(-svg_data.rect.width() / 2, svg_data.baseline_shift);
716+
break;
717+
case WritingMode::kVerticalLr:
718+
case WritingMode::kVerticalRl:
719+
case WritingMode::kSidewaysRl:
720+
x += font_data->GetFontMetrics().FixedDescent(font_baseline);
721+
transform.Translate(svg_data.baseline_shift, -svg_data.rect.height() / 2);
722+
break;
723+
case WritingMode::kSidewaysLr:
724+
x += font_data->GetFontMetrics().FixedAscent(font_baseline);
725+
y = svg_data.rect.bottom();
726+
transform.Translate(-svg_data.baseline_shift, svg_data.rect.height() / 2);
727+
break;
718728
}
719729
transform.PreConcat(length_adjust);
720730
transform.SetE(transform.E() + x);

third_party/blink/renderer/core/layout/svg/svg_text_layout_algorithm.cc

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,11 @@ void SvgTextLayoutAlgorithm::PositionOnPath(
667667
// mid is x + advance / 2 + offset
668668
// -> false
669669
// mid is y + advance / 2 + offset
670+
const float char_offset = IsHorizontal() ? *info.x
671+
: IsVerticalDownward() ? *info.y
672+
: -*info.y;
670673
const float mid =
671-
((horizontal_ ? *info.x : *info.y) + info.inline_size / 2) /
672-
scaling_factor +
673-
offset;
674+
(char_offset + info.inline_size / 2) / scaling_factor + offset;
674675

675676
// 5.1.2.3. Let length be the length of path.
676677
// 5.1.2.9. If path is a closed subpath depending on the values of
@@ -698,26 +699,34 @@ void SvgTextLayoutAlgorithm::PositionOnPath(
698699
info.hidden = true;
699700
}
700701
point_tangent.tangent_in_degrees += info.rotate.value_or(0.0f);
701-
if (!horizontal_) {
702+
if (IsVerticalDownward()) {
702703
point_tangent.tangent_in_degrees -= 90;
704+
} else if (IsVerticalUpward()) {
705+
point_tangent.tangent_in_degrees += 90;
703706
}
704707
info.rotate = point_tangent.tangent_in_degrees;
705708
if (*info.rotate == 0.0f) {
706-
if (horizontal_) {
709+
if (IsHorizontal()) {
707710
info.x = point_tangent.point.x() * scaling_factor -
708711
info.inline_size / 2;
709712
info.y = point_tangent.point.y() * scaling_factor + *info.y;
710-
} else {
713+
} else if (IsVerticalDownward()) {
711714
info.x = point_tangent.point.x() * scaling_factor + *info.x;
712715
info.y = point_tangent.point.y() * scaling_factor -
713716
info.inline_size / 2;
717+
} else {
718+
info.x = point_tangent.point.x() * scaling_factor + *info.x;
719+
info.y = point_tangent.point.y() * scaling_factor +
720+
info.inline_size / 2;
714721
}
715722
} else {
716723
// Unlike the specification, we just set result[index].x/y to the
717724
// point along the path. The character is moved by an
718725
// AffineTransform produced from baseline_shift and inline_size/2.
719726
// See |FragmentItem::BuildSVGTransformForTextPath()|.
720-
info.baseline_shift = horizontal_ ? *info.y : *info.x;
727+
info.baseline_shift = IsHorizontal() ? *info.y
728+
: IsVerticalDownward() ? *info.x
729+
: -*info.x;
721730
info.x = point_tangent.point.x() * scaling_factor;
722731
info.y = point_tangent.point.y() * scaling_factor;
723732
}
@@ -769,12 +778,15 @@ void SvgTextLayoutAlgorithm::PositionOnPath(
769778
reverse_result_range,
770779
[](const auto& info) { return !info.hidden && !info.middle; });
771780
if (iter != reverse_result_range.end()) {
772-
if (horizontal_) {
781+
if (IsHorizontal()) {
773782
path_end_x = *iter->x + iter->inline_size;
774783
path_end_y = *iter->y;
775-
} else {
784+
} else if (IsVerticalDownward()) {
776785
path_end_x = *iter->x;
777786
path_end_y = *iter->y + iter->inline_size;
787+
} else {
788+
path_end_x = *iter->x;
789+
path_end_y = *iter->y - iter->inline_size;
778790
}
779791
} else {
780792
path_end_x = 0.0f;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
This is a testharness.js-based test.
22
[FAIL] - sideways-lr
3-
assert_equals: expected 225 but got 0
3+
assert_equals: F expected 225 but got 45
44
Harness: the test ran to completion.
55

Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

third_party/blink/web_tests/svg/text/sideways-lr-basic.svg

Lines changed: 15 additions & 0 deletions
Loading

third_party/blink/web_tests/svg/text/sideways-rl-basic-expected.svg

Lines changed: 15 additions & 0 deletions
Loading

third_party/blink/web_tests/svg/text/sideways-rl-basic.svg

Lines changed: 15 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)