Commit f89f0432 authored by fs@opera.com's avatar fs@opera.com

Reset computed size of the <canvas> FontDescription when setting CRC2D.font

Avoid inheriting the zoom-factor when setting the CanvasRenderingContext2D
'font' property to the same font as is computed for the <canvas> element.
In this case the font descriptions would be considered the same, and hence
the font size computed using the effective zoom of the page would be used.

BUG=381989

Review URL: https://codereview.chromium.org/326893003

git-svn-id: svn://svn.chromium.org/blink/trunk@175950 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 479e48ea
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>
canvas {
font-family: sans-serif;
font-size: 100px;
zoom: 3;
}
</style>
<canvas width="100" height="100"></canvas>
<script>
test(function() {
var ctx = document.querySelector('canvas').getContext('2d');
// Set same font as will be computed on the canvas element.
ctx.font = "100px sans-serif";
assert_equals(ctx.font, "100px sans-serif");
}, "Zoom does not affect the font size.");
</script>
......@@ -1944,9 +1944,12 @@ void CanvasRenderingContext2D::setFont(const String& newFont)
// Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work
// relative to the canvas.
RefPtr<RenderStyle> newStyle = RenderStyle::create();
if (RenderStyle* computedStyle = canvas()->computedStyle())
newStyle->setFontDescription(computedStyle->fontDescription());
else {
if (RenderStyle* computedStyle = canvas()->computedStyle()) {
FontDescription elementFontDescription(computedStyle->fontDescription());
// Reset the computed size to avoid inheriting the zoom factor from the <canvas> element.
elementFontDescription.setComputedSize(elementFontDescription.specifiedSize());
newStyle->setFontDescription(elementFontDescription);
} else {
FontFamily fontFamily;
fontFamily.setFamily(defaultFontFamily);
......
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