зеркало из https://github.com/mozilla/gecko-dev.git
Bug 463934 - text bounds do not account for position properly
Landing this to see if it fixes bug 465222 - tsvg regression November 3 2008 r=roc, sr=roc, a1.9.1=beltzner
This commit is contained in:
Родитель
06c7b6ae8f
Коммит
598a7a8191
|
@ -47,6 +47,8 @@ include $(topsrcdir)/config/rules.mk
|
||||||
_TEST_FILES = \
|
_TEST_FILES = \
|
||||||
test_bbox.xhtml \
|
test_bbox.xhtml \
|
||||||
bbox-helper.svg \
|
bbox-helper.svg \
|
||||||
|
bounds-helper.svg \
|
||||||
|
test_bounds.html \
|
||||||
test_dataTypes.html \
|
test_dataTypes.html \
|
||||||
dataTypes-helper.svg \
|
dataTypes-helper.svg \
|
||||||
test_getSubStringLength.xhtml \
|
test_getSubStringLength.xhtml \
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="750"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
|
||||||
|
<style type="text/css">
|
||||||
|
text { font: 20px monospace; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<g id="g">
|
||||||
|
<text id="text1" x="25" y="25">abc</text>
|
||||||
|
<rect id="rect1" x="50" y="50" width="50" height="50" fill="green"/>
|
||||||
|
<rect id="rect1a" x="50" y="50" width="50" height="50" fill="none" stroke-width="2" stroke="yellow"/>
|
||||||
|
<text id="text2" x="125" y="25">abc</text>
|
||||||
|
<g transform="rotate(45 175 75)">
|
||||||
|
<rect id="rect2" x="150" y="50" width="50" height="50" fill="yellow"/>
|
||||||
|
<rect id="rect2a" x="150" y="50" width="50" height="50" fill="none" stroke-width="2" stroke="blue"/>
|
||||||
|
<text id="text3" x="150" y="50" text-anchor="middle">abc</text>
|
||||||
|
</g>
|
||||||
|
<g transform="scale(2)">
|
||||||
|
<rect id="rect3" x="25" y="80" width="50" height="50" fill="green"/>
|
||||||
|
<rect id="rect3a" x="25" y="80" width="50" height="50" fill="none" stroke-width="2" stroke="blue"/>
|
||||||
|
</g>
|
||||||
|
<g transform="scale(2) rotate(45 175 75)">
|
||||||
|
<rect id="rect4" x="150" y="50" width="50" height="50" fill="yellow"/>
|
||||||
|
<rect id="rect4a" x="150" y="50" width="50" height="50" fill="none" stroke-width="2" stroke="blue"/>
|
||||||
|
<text id="text4" x="125" y="125">abc</text>
|
||||||
|
</g>
|
||||||
|
<text id="text1a" x="85" y="25" stroke="black" stroke-width="1">M</text>
|
||||||
|
<text id="text2a" x="185" y="25" stroke="black" stroke-width="10">M</text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
После Ширина: | Высота: | Размер: 1.4 KiB |
|
@ -0,0 +1,126 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=463934
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 463934</title>
|
||||||
|
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=463934">Mozilla Bug 463934</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none"></div>
|
||||||
|
|
||||||
|
<iframe id="svg" src="bounds-helper.svg"></iframe>
|
||||||
|
|
||||||
|
<pre id="test">
|
||||||
|
<script class="testbody" type="application/javascript">
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
function runTest()
|
||||||
|
{
|
||||||
|
function isRounded(a, b, message) {
|
||||||
|
is (Math.round(a), Math.round(b), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var doc = $("svg").contentWindow.document;
|
||||||
|
|
||||||
|
var text1 = doc.getElementById("text1");
|
||||||
|
|
||||||
|
var len = text1.getComputedTextLength();
|
||||||
|
|
||||||
|
var text1Bounds = text1.getBoundingClientRect();
|
||||||
|
var text2Bounds = doc.getElementById("text2").getBoundingClientRect();
|
||||||
|
var text3Bounds = doc.getElementById("text3").getBoundingClientRect();
|
||||||
|
var text4Bounds = doc.getElementById("text4").getBoundingClientRect();
|
||||||
|
|
||||||
|
var sin45 = Math.sin(Math.PI / 4);
|
||||||
|
|
||||||
|
isRounded(text1Bounds.left, 25, "text1.getBoundingClientRect().left");
|
||||||
|
isRounded(text1Bounds.width, len, "text1.getBoundingClientRect().width");
|
||||||
|
|
||||||
|
isRounded(text2Bounds.left, text1Bounds.left + 100, "text2.getBoundingClientRect().left");
|
||||||
|
isRounded(text2Bounds.top, text1Bounds.top, "text2.getBoundingClientRect().top");
|
||||||
|
isRounded(text2Bounds.width, text1Bounds.width, "text2.getBoundingClientRect().width");
|
||||||
|
isRounded(text2Bounds.height, text1Bounds.height, "text2.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(text3Bounds.width, (text1Bounds.width + text1Bounds.height) * sin45 + .5, "text3.getBoundingClientRect().width");
|
||||||
|
isRounded(text3Bounds.height, (text1Bounds.height + text1Bounds.width) * sin45 + .5, "text3.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(text4Bounds.width, 2 * (text1Bounds.width + text1Bounds.height) * sin45, "text4.getBoundingClientRect().width");
|
||||||
|
isRounded(text4Bounds.height, 2 * ((text1Bounds.height + text1Bounds.width) * sin45 - .5), "text4.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
var rect1Bounds = doc.getElementById("rect1").getBoundingClientRect();
|
||||||
|
var rect2Bounds = doc.getElementById("rect2").getBoundingClientRect();
|
||||||
|
var rect3Bounds = doc.getElementById("rect3").getBoundingClientRect();
|
||||||
|
var rect4Bounds = doc.getElementById("rect4").getBoundingClientRect();
|
||||||
|
|
||||||
|
isRounded(rect1Bounds.left, 50, "rect1.getBoundingClientRect().left");
|
||||||
|
isRounded(rect1Bounds.top, 50, "rect1.getBoundingClientRect().top");
|
||||||
|
isRounded(rect1Bounds.width, 50, "rect1.getBoundingClientRect().width");
|
||||||
|
isRounded(rect1Bounds.height, 50, "rect1.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(rect2Bounds.left, 175 - 50 * sin45 - .5, "rect2.getBoundingClientRect().left");
|
||||||
|
isRounded(rect2Bounds.top, 75 - 50 * sin45 - .5, "rect2.getBoundingClientRect().top");
|
||||||
|
isRounded(rect2Bounds.width, (50 * sin45 + .5) * 2, "rect2.getBoundingClientRect().width");
|
||||||
|
isRounded(rect2Bounds.height, (50 * sin45 + .5) * 2, "rect2.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(rect3Bounds.left, 50, "rect3.getBoundingClientRect().left");
|
||||||
|
isRounded(rect3Bounds.top, 160, "rect3.getBoundingClientRect().top");
|
||||||
|
isRounded(rect3Bounds.width, 100, "rect3.getBoundingClientRect().width");
|
||||||
|
isRounded(rect3Bounds.height, 100, "rect3.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(rect4Bounds.left, 350 - 100 * sin45 - .5, "rect4.getBoundingClientRect().left");
|
||||||
|
isRounded(rect4Bounds.top, 150 - 100 * sin45 - .5, "rect4.getBoundingClientRect().top");
|
||||||
|
isRounded(rect4Bounds.width, (100 * sin45 + .5) * 2, "rect4.getBoundingClientRect().width");
|
||||||
|
isRounded(rect4Bounds.height, (100 * sin45 + .5) * 2, "rect4.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
var rect1aBounds = doc.getElementById("rect1a").getBoundingClientRect();
|
||||||
|
var rect2aBounds = doc.getElementById("rect2a").getBoundingClientRect();
|
||||||
|
var rect3aBounds = doc.getElementById("rect3a").getBoundingClientRect();
|
||||||
|
var rect4aBounds = doc.getElementById("rect4a").getBoundingClientRect();
|
||||||
|
|
||||||
|
isRounded(rect1aBounds.left, 49, "rect1a.getBoundingClientRect().left");
|
||||||
|
isRounded(rect1aBounds.top, 49, "rect1a.getBoundingClientRect().top");
|
||||||
|
isRounded(rect1aBounds.width, 52, "rect1a.getBoundingClientRect().width");
|
||||||
|
isRounded(rect1aBounds.height, 52, "rect1a.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(rect2aBounds.left, 175 - 52 * sin45 - .5, "rect2a.getBoundingClientRect().left");
|
||||||
|
isRounded(rect2aBounds.top, 75 - 52 * sin45 - .5, "rect2a.getBoundingClientRect().top");
|
||||||
|
isRounded(rect2aBounds.width, 52 * sin45 * 2, "rect2a.getBoundingClientRect().width");
|
||||||
|
isRounded(rect2aBounds.height, 52 * sin45 * 2, "rect2a.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(rect3aBounds.left, 48, "rect3a.getBoundingClientRect().left");
|
||||||
|
isRounded(rect3aBounds.top, 158, "rect3a.getBoundingClientRect().top");
|
||||||
|
isRounded(rect3aBounds.width, 104, "rect3a.getBoundingClientRect().width");
|
||||||
|
isRounded(rect3aBounds.height, 104, "rect3a.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
isRounded(rect4aBounds.left, 350 - 104 * sin45 - .5, "rect4a.getBoundingClientRect().left");
|
||||||
|
isRounded(rect4aBounds.top, 150 - 104 * sin45 - .5, "rect4a.getBoundingClientRect().top");
|
||||||
|
isRounded(rect4aBounds.width, (104 * sin45 + .5) * 2, "rect4a.getBoundingClientRect().width");
|
||||||
|
isRounded(rect4aBounds.height, (104 * sin45 + .5) * 2, "rect4a.getBoundingClientRect().height");
|
||||||
|
|
||||||
|
var text1a = doc.getElementById("text1a");
|
||||||
|
|
||||||
|
var text1aBounds = text1a.getBoundingClientRect();
|
||||||
|
var text2aBounds = doc.getElementById("text2a").getBoundingClientRect();
|
||||||
|
|
||||||
|
var len = text1a.getComputedTextLength();
|
||||||
|
|
||||||
|
isRounded(text1aBounds.left, 85 - 1, "text1a.getBoundingClientRect().width");
|
||||||
|
isRounded(text1aBounds.width, len + 1, "text1a.getBoundingClientRect().width");
|
||||||
|
|
||||||
|
isRounded(text2aBounds.left, text1aBounds.left + 100 - 4, "text2a.getBoundingClientRect().left");
|
||||||
|
isRounded(text2aBounds.width, text1aBounds.width + 9, "text2a.getBoundingClientRect().width");
|
||||||
|
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", runTest, false);
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -428,19 +428,25 @@ nsSVGGlyphFrame::UpdateCoveredRegion()
|
||||||
mRect.Empty();
|
mRect.Empty();
|
||||||
|
|
||||||
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
||||||
|
SetMatrixPropagation(PR_FALSE);
|
||||||
CharacterIterator iter(this, PR_TRUE);
|
CharacterIterator iter(this, PR_TRUE);
|
||||||
|
|
||||||
gfxRect extent;
|
gfxRect extent;
|
||||||
|
|
||||||
if (SetupCairoStrokeGeometry(tmpCtx)) {
|
if (SetupCairoStrokeGeometry(tmpCtx)) {
|
||||||
|
gfxFloat strokeWidth = tmpCtx->CurrentLineWidth();
|
||||||
AddCharactersToPath(&iter, tmpCtx);
|
AddCharactersToPath(&iter, tmpCtx);
|
||||||
|
tmpCtx->SetLineWidth(strokeWidth);
|
||||||
|
tmpCtx->IdentityMatrix();
|
||||||
extent = tmpCtx->GetUserStrokeExtent();
|
extent = tmpCtx->GetUserStrokeExtent();
|
||||||
} else if (GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None) {
|
} else if (GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None) {
|
||||||
AddBoundingBoxesToPath(&iter, tmpCtx);
|
AddBoundingBoxesToPath(&iter, tmpCtx);
|
||||||
|
tmpCtx->IdentityMatrix();
|
||||||
extent = tmpCtx->GetUserPathExtent();
|
extent = tmpCtx->GetUserPathExtent();
|
||||||
} else {
|
} else {
|
||||||
extent = gfxRect(0, 0, 0, 0);
|
extent = gfxRect(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
SetMatrixPropagation(PR_TRUE);
|
||||||
|
|
||||||
if (!extent.IsEmpty()) {
|
if (!extent.IsEmpty()) {
|
||||||
gfxMatrix matrix;
|
gfxMatrix matrix;
|
||||||
|
@ -1173,6 +1179,11 @@ nsSVGGlyphFrame::ContainsPoint(const nsPoint &aPoint)
|
||||||
PRBool
|
PRBool
|
||||||
nsSVGGlyphFrame::GetGlobalTransform(gfxMatrix *aMatrix)
|
nsSVGGlyphFrame::GetGlobalTransform(gfxMatrix *aMatrix)
|
||||||
{
|
{
|
||||||
|
if (!GetMatrixPropagation()) {
|
||||||
|
aMatrix->Reset();
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMSVGMatrix> ctm;
|
nsCOMPtr<nsIDOMSVGMatrix> ctm;
|
||||||
GetCanvasTM(getter_AddRefs(ctm));
|
GetCanvasTM(getter_AddRefs(ctm));
|
||||||
if (!ctm)
|
if (!ctm)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче