mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 718266 - Simplify dasharray code. r=jwatt
This commit is contained in:
parent
23660a956c
commit
85497421d0
@ -100,22 +100,14 @@ nsSVGGeometryFrame::GetStrokeWidth()
|
||||
GetStyleSVG()->mStrokeWidth);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount)
|
||||
bool
|
||||
nsSVGGeometryFrame::GetStrokeDashData(FallibleTArray<gfxFloat>& dashes,
|
||||
gfxFloat *dashOffset)
|
||||
{
|
||||
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
||||
(mContent->IsNodeOfType(nsINode::eTEXT) ?
|
||||
mContent->GetParent() : mContent);
|
||||
*aDashes = nsnull;
|
||||
*aCount = 0;
|
||||
|
||||
PRUint32 count = GetStyleSVG()->mStrokeDasharrayLength;
|
||||
gfxFloat *dashes = nsnull;
|
||||
|
||||
if (count) {
|
||||
const nsStyleCoord *dasharray = GetStyleSVG()->mStrokeDasharray;
|
||||
nsPresContext *presContext = PresContext();
|
||||
gfxFloat totalLength = 0.0f;
|
||||
if (!count || !dashes.SetLength(count)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
gfxFloat pathScale = 1.0;
|
||||
|
||||
@ -123,50 +115,34 @@ nsSVGGeometryFrame::GetStrokeDashArray(gfxFloat **aDashes, PRUint32 *aCount)
|
||||
pathScale = static_cast<nsSVGPathElement*>(mContent)->
|
||||
GetPathLengthScale(nsSVGPathElement::eForStroking);
|
||||
if (pathScale <= 0) {
|
||||
return NS_OK;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
dashes = new gfxFloat[count];
|
||||
if (dashes) {
|
||||
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
||||
(mContent->IsNodeOfType(nsINode::eTEXT) ?
|
||||
mContent->GetParent() : mContent);
|
||||
|
||||
const nsStyleCoord *dasharray = GetStyleSVG()->mStrokeDasharray;
|
||||
nsPresContext *presContext = PresContext();
|
||||
gfxFloat totalLength = 0.0;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
dashes[i] =
|
||||
nsSVGUtils::CoordToFloat(presContext,
|
||||
ctx,
|
||||
dasharray[i]) * pathScale;
|
||||
if (dashes[i] < 0.0f) {
|
||||
delete [] dashes;
|
||||
return NS_OK;
|
||||
if (dashes[i] < 0.0) {
|
||||
return false;
|
||||
}
|
||||
totalLength += dashes[i];
|
||||
}
|
||||
} else {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (totalLength == 0.0f) {
|
||||
delete [] dashes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
*aDashes = dashes;
|
||||
*aCount = count;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
float
|
||||
nsSVGGeometryFrame::GetStrokeDashoffset()
|
||||
{
|
||||
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
||||
(mContent->IsNodeOfType(nsINode::eTEXT) ?
|
||||
mContent->GetParent() : mContent);
|
||||
|
||||
return
|
||||
nsSVGUtils::CoordToFloat(PresContext(),
|
||||
*dashOffset = nsSVGUtils::CoordToFloat(presContext,
|
||||
ctx,
|
||||
GetStyleSVG()->mStrokeDashoffset);
|
||||
|
||||
return (totalLength > 0.0);
|
||||
}
|
||||
|
||||
PRUint16
|
||||
@ -304,12 +280,10 @@ nsSVGGeometryFrame::SetupCairoStrokeHitGeometry(gfxContext *aContext)
|
||||
{
|
||||
SetupCairoStrokeGeometry(aContext);
|
||||
|
||||
gfxFloat *dashArray;
|
||||
PRUint32 count;
|
||||
GetStrokeDashArray(&dashArray, &count);
|
||||
if (count > 0) {
|
||||
aContext->SetDash(dashArray, count, GetStrokeDashoffset());
|
||||
delete [] dashArray;
|
||||
AutoFallibleTArray<gfxFloat, 10> dashes;
|
||||
gfxFloat dashOffset;
|
||||
if (GetStrokeDashData(dashes, &dashOffset)) {
|
||||
aContext->SetDash(dashes.Elements(), dashes.Length(), dashOffset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,8 +116,7 @@ protected:
|
||||
virtual PRUint16 GetHitTestFlags();
|
||||
|
||||
private:
|
||||
nsresult GetStrokeDashArray(double **arr, PRUint32 *count);
|
||||
float GetStrokeDashoffset();
|
||||
bool GetStrokeDashData(FallibleTArray<gfxFloat>& dashes, gfxFloat *dashOffset);
|
||||
|
||||
/**
|
||||
* Returns the given 'fill-opacity' or 'stroke-opacity' value multiplied by
|
||||
|
Loading…
Reference in New Issue
Block a user