Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Unified Diff: Source/core/layout/svg/SVGTextQuery.cpp

Issue 1041693002: Adjust glyph positions in RTL runs in SVGTextQuery (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More TEs. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/svg/text/svgtextcontentelement-glyphqueries-rtl-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/svg/SVGTextQuery.cpp
diff --git a/Source/core/layout/svg/SVGTextQuery.cpp b/Source/core/layout/svg/SVGTextQuery.cpp
index 7de7003f55040e91f1bbf4e372dc34a8fd7dfd4b..85b8d7aa5aee51fa47b648255b4dcda9ba28f62a 100644
--- a/Source/core/layout/svg/SVGTextQuery.cpp
+++ b/Source/core/layout/svg/SVGTextQuery.cpp
@@ -283,13 +283,18 @@ static FloatPoint calculateGlyphPositionWithoutTransform(const SVGTextQuery::Dat
{
float glyphOffsetInDirection = 0;
if (offsetInFragment) {
- SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->textLayoutObject, fragment.characterOffset, offsetInFragment, queryData->textLayoutObject->styleRef().direction());
+ SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->textLayoutObject, fragment.characterOffset, offsetInFragment, queryData->textBox->direction());
if (queryData->isVerticalText)
glyphOffsetInDirection = metrics.height();
else
glyphOffsetInDirection = metrics.width();
}
+ if (!queryData->textBox->isLeftToRightDirection()) {
+ float fragmentExtent = queryData->isVerticalText ? fragment.height : fragment.width;
+ glyphOffsetInDirection = fragmentExtent - glyphOffsetInDirection;
+ }
+
FloatPoint glyphPosition(fragment.x, fragment.y);
if (queryData->isVerticalText)
glyphPosition.move(0, glyphOffsetInDirection);
@@ -424,8 +429,24 @@ static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const
glyphPosition.move(0, -queryData->textLayoutObject->scaledFont().fontMetrics().floatAscent() / scalingFactor);
extent.setLocation(glyphPosition);
- SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->textLayoutObject, fragment.characterOffset + startPosition, 1, queryData->textLayoutObject->styleRef().direction());
- extent.setSize(FloatSize(metrics.width(), metrics.height()));
+ // Use the SVGTextMetrics computed by SVGTextMetricsBuilder (which spends
+ // time attempting to compute more correct glyph bounds already, handling
+ // cursive scripts to some degree.)
+ Vector<SVGTextMetrics>& textMetricsValues = queryData->textLayoutObject->layoutAttributes()->textMetricsValues();
+ const SVGTextMetrics& metrics = textMetricsValues[fragment.characterOffset + startPosition];
fs 2015/03/30 12:01:19 This was missing a piece... =/ - Uploaded it as ht
+
+ // TODO(fs): Negative glyph extents seems kind of weird to have, but
+ // presently it can occur in some cases (like Arabic.)
+ FloatSize glyphSize(std::max<float>(metrics.width(), 0), std::max<float>(metrics.height(), 0));
+ extent.setSize(glyphSize);
+
+ // If RTL, adjust the starting point to align with the LHS of the glyph bounding box.
+ if (!queryData->textBox->isLeftToRightDirection()) {
+ if (queryData->isVerticalText)
+ extent.move(0, -glyphSize.height());
+ else
+ extent.move(-glyphSize.width(), 0);
+ }
AffineTransform fragmentTransform;
fragment.buildFragmentTransform(fragmentTransform, SVGTextFragment::TransformIgnoringTextLength);
« no previous file with comments | « LayoutTests/svg/text/svgtextcontentelement-glyphqueries-rtl-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698