OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 } | 276 } |
277 | 277 |
278 unsigned position; | 278 unsigned position; |
279 FloatPoint startPosition; | 279 FloatPoint startPosition; |
280 }; | 280 }; |
281 | 281 |
282 static FloatPoint calculateGlyphPositionWithoutTransform(const SVGTextQuery::Dat a* queryData, const SVGTextFragment& fragment, int offsetInFragment) | 282 static FloatPoint calculateGlyphPositionWithoutTransform(const SVGTextQuery::Dat a* queryData, const SVGTextFragment& fragment, int offsetInFragment) |
283 { | 283 { |
284 float glyphOffsetInDirection = 0; | 284 float glyphOffsetInDirection = 0; |
285 if (offsetInFragment) { | 285 if (offsetInFragment) { |
286 SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData ->textLayoutObject, fragment.characterOffset, offsetInFragment, queryData->textL ayoutObject->styleRef().direction()); | 286 SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData ->textLayoutObject, fragment.characterOffset, offsetInFragment, queryData->textB ox->direction()); |
287 if (queryData->isVerticalText) | 287 if (queryData->isVerticalText) |
288 glyphOffsetInDirection = metrics.height(); | 288 glyphOffsetInDirection = metrics.height(); |
289 else | 289 else |
290 glyphOffsetInDirection = metrics.width(); | 290 glyphOffsetInDirection = metrics.width(); |
291 } | 291 } |
292 | 292 |
293 if (!queryData->textBox->isLeftToRightDirection()) { | |
294 float fragmentExtent = queryData->isVerticalText ? fragment.height : fra gment.width; | |
295 glyphOffsetInDirection = fragmentExtent - glyphOffsetInDirection; | |
296 } | |
297 | |
293 FloatPoint glyphPosition(fragment.x, fragment.y); | 298 FloatPoint glyphPosition(fragment.x, fragment.y); |
294 if (queryData->isVerticalText) | 299 if (queryData->isVerticalText) |
295 glyphPosition.move(0, glyphOffsetInDirection); | 300 glyphPosition.move(0, glyphOffsetInDirection); |
296 else | 301 else |
297 glyphPosition.move(glyphOffsetInDirection, 0); | 302 glyphPosition.move(glyphOffsetInDirection, 0); |
298 | 303 |
299 return glyphPosition; | 304 return glyphPosition; |
300 } | 305 } |
301 | 306 |
302 static FloatPoint calculateGlyphPosition(const SVGTextQuery::Data* queryData, co nst SVGTextFragment& fragment, int offsetInFragment) | 307 static FloatPoint calculateGlyphPosition(const SVGTextQuery::Data* queryData, co nst SVGTextFragment& fragment, int offsetInFragment) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 422 |
418 static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent) | 423 static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent) |
419 { | 424 { |
420 float scalingFactor = queryData->textLayoutObject->scalingFactor(); | 425 float scalingFactor = queryData->textLayoutObject->scalingFactor(); |
421 ASSERT(scalingFactor); | 426 ASSERT(scalingFactor); |
422 | 427 |
423 FloatPoint glyphPosition = calculateGlyphPositionWithoutTransform(queryData, fragment, startPosition); | 428 FloatPoint glyphPosition = calculateGlyphPositionWithoutTransform(queryData, fragment, startPosition); |
424 glyphPosition.move(0, -queryData->textLayoutObject->scaledFont().fontMetrics ().floatAscent() / scalingFactor); | 429 glyphPosition.move(0, -queryData->textLayoutObject->scaledFont().fontMetrics ().floatAscent() / scalingFactor); |
425 extent.setLocation(glyphPosition); | 430 extent.setLocation(glyphPosition); |
426 | 431 |
427 SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->te xtLayoutObject, fragment.characterOffset + startPosition, 1, queryData->textLayo utObject->styleRef().direction()); | 432 // Use the SVGTextMetrics computed by SVGTextMetricsBuilder (which spends |
428 extent.setSize(FloatSize(metrics.width(), metrics.height())); | 433 // time attempting to compute more correct glyph bounds already, handling |
434 // cursive scripts to some degree.) | |
435 Vector<SVGTextMetrics>& textMetricsValues = queryData->textLayoutObject->lay outAttributes()->textMetricsValues(); | |
436 const SVGTextMetrics& metrics = textMetricsValues[fragment.characterOffset + startPosition]; | |
fs
2015/03/30 12:01:19
This was missing a piece... =/ - Uploaded it as ht
| |
437 | |
438 // TODO(fs): Negative glyph extents seems kind of weird to have, but | |
439 // presently it can occur in some cases (like Arabic.) | |
440 FloatSize glyphSize(std::max<float>(metrics.width(), 0), std::max<float>(met rics.height(), 0)); | |
441 extent.setSize(glyphSize); | |
442 | |
443 // If RTL, adjust the starting point to align with the LHS of the glyph boun ding box. | |
444 if (!queryData->textBox->isLeftToRightDirection()) { | |
445 if (queryData->isVerticalText) | |
446 extent.move(0, -glyphSize.height()); | |
447 else | |
448 extent.move(-glyphSize.width(), 0); | |
449 } | |
429 | 450 |
430 AffineTransform fragmentTransform; | 451 AffineTransform fragmentTransform; |
431 fragment.buildFragmentTransform(fragmentTransform, SVGTextFragment::Transfor mIgnoringTextLength); | 452 fragment.buildFragmentTransform(fragmentTransform, SVGTextFragment::Transfor mIgnoringTextLength); |
432 | 453 |
433 extent = fragmentTransform.mapRect(extent); | 454 extent = fragmentTransform.mapRect(extent); |
434 } | 455 } |
435 | 456 |
436 static inline FloatRect calculateFragmentBoundaries(const LayoutSVGInlineText& t extLayoutObject, const SVGTextFragment& fragment) | 457 static inline FloatRect calculateFragmentBoundaries(const LayoutSVGInlineText& t extLayoutObject, const SVGTextFragment& fragment) |
437 { | 458 { |
438 float scalingFactor = textLayoutObject.scalingFactor(); | 459 float scalingFactor = textLayoutObject.scalingFactor(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const | 529 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const |
509 { | 530 { |
510 CharacterNumberAtPositionData data(position); | 531 CharacterNumberAtPositionData data(position); |
511 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) | 532 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) |
512 return -1; | 533 return -1; |
513 | 534 |
514 return data.processedCharacters; | 535 return data.processedCharacters; |
515 } | 536 } |
516 | 537 |
517 } | 538 } |
OLD | NEW |