forked from mirrors/gecko-dev
Bug 1916111 - zoom polygons and polylines r=emilio, a=RyanVM
Differential Revision: https://phabricator.services.mozilla.com/D221079
This commit is contained in:
parent
5e26dbfdc7
commit
2cbd7c00c5
5 changed files with 33 additions and 11 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "SVGPolyElement.h"
|
||||
#include "DOMSVGPointList.h"
|
||||
#include "mozilla/dom/SVGAnimatedLength.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "SVGContentUtils.h"
|
||||
|
||||
|
|
@ -48,13 +49,15 @@ void SVGPolyElement::GetMarkPoints(nsTArray<SVGMark>* aMarks) {
|
|||
|
||||
if (!points.Length()) return;
|
||||
|
||||
float px = points[0].mX, py = points[0].mY, prevAngle = 0.0;
|
||||
float zoom = UserSpaceMetrics::GetZoom(this);
|
||||
|
||||
float px = points[0].mX * zoom, py = points[0].mY * zoom, prevAngle = 0.0;
|
||||
|
||||
aMarks->AppendElement(SVGMark(px, py, 0, SVGMark::eStart));
|
||||
|
||||
for (uint32_t i = 1; i < points.Length(); ++i) {
|
||||
float x = points[i].mX;
|
||||
float y = points[i].mY;
|
||||
float x = points[i].mX * zoom;
|
||||
float y = points[i].mY * zoom;
|
||||
float angle = std::atan2(y - py, x - px);
|
||||
|
||||
// Vertex marker.
|
||||
|
|
@ -93,18 +96,20 @@ bool SVGPolyElement::GetGeometryBounds(Rect* aBounds,
|
|||
return false;
|
||||
}
|
||||
|
||||
float zoom = UserSpaceMetrics::GetZoom(this);
|
||||
|
||||
if (aToBoundsSpace.IsRectilinear()) {
|
||||
// We can avoid transforming each point and just transform the result.
|
||||
// Important for large point lists.
|
||||
Rect bounds(points[0], Size());
|
||||
Rect bounds(points[0] * zoom, Size());
|
||||
for (uint32_t i = 1; i < points.Length(); ++i) {
|
||||
bounds.ExpandToEnclose(points[i]);
|
||||
bounds.ExpandToEnclose(points[i] * zoom);
|
||||
}
|
||||
*aBounds = aToBoundsSpace.TransformBounds(bounds);
|
||||
} else {
|
||||
*aBounds = Rect(aToBoundsSpace.TransformPoint(points[0]), Size());
|
||||
*aBounds = Rect(aToBoundsSpace.TransformPoint(points[0] * zoom), Size());
|
||||
for (uint32_t i = 1; i < points.Length(); ++i) {
|
||||
aBounds->ExpandToEnclose(aToBoundsSpace.TransformPoint(points[i]));
|
||||
aBounds->ExpandToEnclose(aToBoundsSpace.TransformPoint(points[i] * zoom));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "mozilla/dom/SVGPolygonElement.h"
|
||||
#include "mozilla/dom/SVGPolygonElementBinding.h"
|
||||
#include "mozilla/dom/SVGAnimatedLength.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "SVGContentUtils.h"
|
||||
|
||||
|
|
@ -64,9 +65,11 @@ already_AddRefed<Path> SVGPolygonElement::BuildPath(PathBuilder* aBuilder) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
aBuilder->MoveTo(points[0]);
|
||||
float zoom = UserSpaceMetrics::GetZoom(this);
|
||||
|
||||
aBuilder->MoveTo(points[0] * zoom);
|
||||
for (uint32_t i = 1; i < points.Length(); ++i) {
|
||||
aBuilder->LineTo(points[i]);
|
||||
aBuilder->LineTo(points[i] * zoom);
|
||||
}
|
||||
|
||||
aBuilder->Close();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "mozilla/dom/SVGPolylineElement.h"
|
||||
#include "mozilla/dom/SVGPolylineElementBinding.h"
|
||||
#include "mozilla/dom/SVGAnimatedLength.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
|
@ -41,9 +42,11 @@ already_AddRefed<Path> SVGPolylineElement::BuildPath(PathBuilder* aBuilder) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
aBuilder->MoveTo(points[0]);
|
||||
float zoom = UserSpaceMetrics::GetZoom(this);
|
||||
|
||||
aBuilder->MoveTo(points[0] * zoom);
|
||||
for (uint32_t i = 1; i < points.Length(); ++i) {
|
||||
aBuilder->LineTo(points[i]);
|
||||
aBuilder->LineTo(points[i] * zoom);
|
||||
}
|
||||
|
||||
return aBuilder->Finish();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
stroke-width: 40px;
|
||||
stroke: lime;
|
||||
}
|
||||
polygon, polyline {
|
||||
fill: lime;
|
||||
}
|
||||
svg {
|
||||
background-color: red;
|
||||
}
|
||||
|
|
@ -23,5 +26,7 @@
|
|||
<line y1=80 y2=80 x1=0 x2=20rem />
|
||||
<line y1=120 y2=120 x1=0 x2=50% />
|
||||
<line y1=160 y2=160 x1=0 x2=4vw />
|
||||
<polygon points="0,200 200,200 200,240 0,240"/>
|
||||
<polyline points="0,240 200,240 200,280 0,280"/>
|
||||
</svg>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<link rel="author" href="https://mozilla.org" title="Mozilla">
|
||||
<link rel="help" href="https://drafts.csswg.org/css-viewport/#zoom-property">
|
||||
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1899695">
|
||||
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1916111">
|
||||
<link rel="match" href="svg-ref.html">
|
||||
<style>
|
||||
:root {
|
||||
|
|
@ -21,6 +22,9 @@
|
|||
stroke-width: 10px;
|
||||
stroke: lime;
|
||||
}
|
||||
polygon, polyline {
|
||||
fill: lime;
|
||||
}
|
||||
svg {
|
||||
background-color: red;
|
||||
}
|
||||
|
|
@ -34,6 +38,8 @@
|
|||
<line y1=20 y2=20 x1=0 x2=5rem />
|
||||
<line y1=30 y2=30 x1=0 x2=50% />
|
||||
<line y1=40 y2=40 x1=0 x2=1vw />
|
||||
<polygon points="0,50 50,50 50,60 0,60"/>
|
||||
<polyline points="0,60 50,60 50,70 0,70"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue