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

Clip the start position when performing SVG text queries

If a text query straddles multiple line boxes, only the first would be
considered, because |startPosition| would end up being negative.
Instead clip the character range to [0) (the following functions will
clip against the end position) and only reject ranges that are empty i.e.
that appear before the current fragment (logically.)

BUG=353462

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

git-svn-id: svn://svn.chromium.org/blink/trunk@169682 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6c5b3194
W3C نشاط
AB
This is a testharness.js-based test.
PASS SVGTextContentElement.getSubStringLength, BiDi.
PASS SVGTextContentElement.getSubStringLength, multiple text-chunks.
Harness: the test ran to completion.
<!DOCTYPE html>
<title>SVGTextContentElement.getSubStringLength</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id=log></div>
<div>
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<text x="10" y="20">W3C &#x0646;&#x0634;&#x0627;&#x0637;</text>
<text x="10 50" y="40">AB</text>
</svg>
</div>
<script>
test(function() {
var text = document.querySelector('text');
assert_equals(text.getNumberOfChars(), 8);
var lenFirst4 = text.getSubStringLength(0, 4);
var lenLast4 = text.getSubStringLength(4, 4);
var lenAll = text.getSubStringLength(0, 8);
assert_approx_equals(lenFirst4 + lenLast4, lenAll, 0.01, 'Sum of the parts equal the total.');
}, document.title+', BiDi.');
test(function() {
var text = document.querySelector('text + text');
assert_equals(text.getNumberOfChars(), 2);
var lenFirst = text.getSubStringLength(0, 1);
var lenLast = text.getSubStringLength(1, 1);
var lenAll = text.getSubStringLength(0, 2);
assert_approx_equals(lenFirst + lenLast, lenAll, 0.01, 'Sum of the parts equal the total.');
}, document.title+', multiple text-chunks.');
</script>
......@@ -141,7 +141,9 @@ bool SVGTextQuery::mapStartEndPositionsIntoFragmentCoordinates(Data* queryData,
startPosition -= queryData->processedCharacters;
endPosition -= queryData->processedCharacters;
if (startPosition >= endPosition || startPosition < 0 || endPosition < 0)
startPosition = max(0, startPosition);
if (startPosition >= endPosition)
return false;
modifyStartEndPositionsRespectingLigatures(queryData, startPosition, endPosition);
......
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