Commit f7fde4b9 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

vector icon: Switch ordering of transforms in rtl paint vector icon.

Vector icons with FLIPS_IN_RTL get shown. Right now there are only the
submenu arrow and the tablet mode back button which uses this command.
This also only happens when using the 2x icon. The current
transforms applied on rtl 2x icons are:
  - scale down by factor of 2
  - scale by -1
  - translate by the canvas size
This results in the icon being translated out of its bounds and not
being shown. This cl does the scaling down after the translation.

Test: gfx_unittests VectorIconTest.FlipsInRtl
Bug: 769366, 768059
Change-Id: I67e748ea23c9020f13a693546db2fade07e05ae6
Reviewed-on: https://chromium-review.googlesource.com/687826Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504776}
parent 01507a2a
...@@ -433,13 +433,13 @@ void PaintPath(Canvas* canvas, ...@@ -433,13 +433,13 @@ void PaintPath(Canvas* canvas,
previous_command_type = command_type; previous_command_type = command_type;
} }
ScopedRTLFlipCanvas scoped_rtl_flip_canvas(canvas, canvas_size, flips_in_rtl);
if (dip_size != canvas_size) { if (dip_size != canvas_size) {
SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(canvas_size); SkScalar scale = SkIntToScalar(dip_size) / SkIntToScalar(canvas_size);
canvas->sk_canvas()->scale(scale, scale); canvas->sk_canvas()->scale(scale, scale);
} }
ScopedRTLFlipCanvas scoped_rtl_flip_canvas(canvas, canvas_size, flips_in_rtl);
if (!clip_rect.isEmpty()) if (!clip_rect.isEmpty())
canvas->sk_canvas()->clipRect(clip_rect); canvas->sk_canvas()->clipRect(clip_rect);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <vector> #include <vector>
#include "base/i18n/rtl.h"
#include "cc/paint/paint_record.h" #include "cc/paint/paint_record.h"
#include "cc/paint/paint_recorder.h" #include "cc/paint/paint_recorder.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
...@@ -65,6 +66,47 @@ TEST(VectorIconTest, RelativeMoveToAfterClose) { ...@@ -65,6 +66,47 @@ TEST(VectorIconTest, RelativeMoveToAfterClose) {
EXPECT_EQ(SkIntToScalar(77), last_point.y()); EXPECT_EQ(SkIntToScalar(77), last_point.y());
} }
TEST(VectorIconTest, FlipsInRtl) {
// Set the locale to a rtl language otherwise FLIPS_IN_RTL will do nothing.
base::i18n::SetICUDefaultLocale("he");
ASSERT_TRUE(base::i18n::IsRTL());
const int canvas_size = 20;
const SkColor color = SK_ColorWHITE;
Canvas canvas(gfx::Size(canvas_size, canvas_size), 1.0f, true);
// Create a 20x20 square icon which has FLIPS_IN_RTL, and CANVAS_DIMENSIONS
// are twice as large as |canvas|.
const PathElement elements[] = {
CANVAS_DIMENSIONS, 2 * canvas_size,
FLIPS_IN_RTL,
MOVE_TO, 10, 10,
R_H_LINE_TO, 20,
R_V_LINE_TO, 20,
R_H_LINE_TO, -20,
CLOSE,
END,
};
const VectorIcon icon = {elements, nullptr};
PaintVectorIcon(&canvas, icon, canvas_size, color);
// Count the number of pixels in the canvas.
auto bitmap = canvas.GetBitmap();
int colored_pixel_count = 0;
for (int i = 0; i < bitmap.width(); ++i) {
for (int j = 0; j < bitmap.height(); ++j) {
if (bitmap.getColor(i, j) == color)
colored_pixel_count++;
}
}
// Verify that the amount of colored pixels on the canvas bitmap should be a
// quarter of the original icon, since each side should be scaled down by a
// factor of two.
EXPECT_EQ(100, colored_pixel_count);
}
} // namespace } // namespace
} // namespace gfx } // namespace gfx
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