Implement new TextMetrics, returned by canvas measureText()
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jul 2017 23:53:26 +0000 (23:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jul 2017 23:53:26 +0000 (23:53 +0000)
commit8360bd4a1ff7f47473bb84f4eca6692c3b1164fb
treecb09e425e6502610fb477fb945fef852c0b53720
parent3105ae7e3b6f03c49fdee163dd852e7da0aa1821
Implement new TextMetrics, returned by canvas measureText()
https://bugs.webkit.org/show_bug.cgi?id=82798
Source/WebCore:

<rdar://problem/11159332>

Patch by Arnaud Renevier  <a.renevier@sisa.samsung.com> and Fujii Hironori <Hironori.Fujii@sony.com> on 2017-07-26
Reviewed by Dean Jackson.

The specification: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-measuretext

Add new attributes to TextMetrics.

Add a new method textOffset() of CanvasRenderingContext2D by
extracting from drawTextInternal() to use the same horizontal and
vertical offsets of a text in both drawTextInternal() and
measureText().

Test: fast/canvas/canvas-measureText-2.html

* html/TextMetrics.h:
(WebCore::TextMetrics::actualBoundingBoxLeft):
(WebCore::TextMetrics::setActualBoundingBoxLeft):
(WebCore::TextMetrics::actualBoundingBoxRight):
(WebCore::TextMetrics::setActualBoundingBoxRight):
(WebCore::TextMetrics::fontBoundingBoxAscent):
(WebCore::TextMetrics::setFontBoundingBoxAscent):
(WebCore::TextMetrics::fontBoundingBoxDescent):
(WebCore::TextMetrics::setFontBoundingBoxDescent):
(WebCore::TextMetrics::actualBoundingBoxAscent):
(WebCore::TextMetrics::setActualBoundingBoxAscent):
(WebCore::TextMetrics::actualBoundingBoxDescent):
(WebCore::TextMetrics::setActualBoundingBoxDescent):
(WebCore::TextMetrics::emHeightAscent):
(WebCore::TextMetrics::setEmHeightAscent):
(WebCore::TextMetrics::emHeightDescent):
(WebCore::TextMetrics::setEmHeightDescent):
(WebCore::TextMetrics::hangingBaseline):
(WebCore::TextMetrics::setHangingBaseline):
(WebCore::TextMetrics::alphabeticBaseline):
(WebCore::TextMetrics::setAlphabeticBaseline):
(WebCore::TextMetrics::ideographicBaseline):
(WebCore::TextMetrics::setIdeographicBaseline):
Added getters and setters.
(WebCore::TextMetrics::TextMetrics): Deleted.
* html/TextMetrics.idl: Added new attributes.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::FontProxy::fontMetrics):
Changed the return value type to a const reference of FontMetrics
not to copy it.
(WebCore::CanvasRenderingContext2D::FontProxy::width):
Added the second arguemnt of GlyphOverflow type.
(WebCore::CanvasRenderingContext2D::measureText): Calculate and
set the new attributes of TextMetrics.
(WebCore::CanvasRenderingContext2D::textOffset): Extracted from drawTextInternal.
(WebCore::CanvasRenderingContext2D::drawTextInternal): Removed the
offset calculation code and call textOffset.
* html/canvas/CanvasRenderingContext2D.h: Added the method
declaration of textOffset. Change types of fontMetrics and width
methods.
* platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
(WebCore::FontCascade::floatWidthForComplexText): Added a dummy
implementation of calculating GlyphOverflow.

LayoutTests:

Patch by Arnaud Renevier  <a.renevier@sisa.samsung.com> and Fujii Hironori <Hironori.Fujii@sony.com> on 2017-07-26
Reviewed by Dean Jackson.

Create a test that checks that:
     - ascent + descent is greater than zero
     - actualBoundingBoxLeft + actualBoundingBoxRight is somewhere
       quite close to width
     - when baseline is top, emHeightAscent is 0 (respectively
       bottom/emHeightDescent)
     - when baseline is hanging, hangingBaseline in 0 (respectively
       alphabetic and ideographic)
     - order of different vertical measures (for example,
       emHeightAscent is always higher that alphabeticBaseline)

* fast/canvas/canvas-measureText-2-expected.txt: Added.
* fast/canvas/canvas-measureText-2.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219970 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-measureText-2-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-measureText-2.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/TextMetrics.h
Source/WebCore/html/TextMetrics.idl
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.h
Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp