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

Unified Diff: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp

Issue 1505713002: Include glyph overflow in SVG text bounding boxes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More expectations Created 5 years 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
Index: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp b/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
index 0e36470b531e96a7606c2db91c1a1ddbee5d4923..ff43950d1eb64cc72eec1ed29b1e8ffcc5df8e96 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
@@ -20,6 +20,7 @@
#include "config.h"
#include "core/layout/svg/SVGTextLayoutEngine.h"
+#include "core/layout/line/GlyphOverflow.h"
#include "core/layout/svg/LayoutSVGInlineText.h"
#include "core/layout/svg/LayoutSVGTextPath.h"
#include "core/layout/svg/SVGTextChunkBuilder.h"
@@ -110,6 +111,27 @@ void SVGTextLayoutEngine::updateRelativePositionAdjustmentsIfNeeded(float dx, fl
m_dy = dy;
}
+// Computes the glyph overflow without integer clamping (see: GlyphOverflow.h).
+static void computeGlyphOverflow(SVGInlineTextBox* textBox, SVGTextFragment& textFragment)
+{
+ LineLayoutSVGInlineText textLineLayout = LineLayoutSVGInlineText(textBox->lineLayoutItem());
+ TextRun run = SVGTextMetrics::constructTextRun(textLineLayout, textFragment.characterOffset, textFragment.length, textLineLayout.styleRef().direction());
+
+ float scalingFactor = textLineLayout.scalingFactor();
+ ASSERT(scalingFactor);
+ const Font& scaledFont = textLineLayout.scaledFont();
+ FloatRect glyphOverflowBounds;
+
+ float width = scaledFont.width(run, nullptr, &glyphOverflowBounds);
+ float ascent = scaledFont.fontMetrics().floatAscent();
+ float descent = scaledFont.fontMetrics().floatDescent();
+
+ textFragment.glyphOverflowTop = GlyphOverflow::topOverflow(glyphOverflowBounds, ascent) / scalingFactor;
+ textFragment.glyphOverflowBottom = GlyphOverflow::bottomOverflow(glyphOverflowBounds, descent) / scalingFactor;
+ textFragment.glyphOverflowLeft = GlyphOverflow::leftOverflow(glyphOverflowBounds) / scalingFactor;
+ textFragment.glyphOverflowRight = GlyphOverflow::rightOverflow(glyphOverflowBounds, width) / scalingFactor;
+}
+
void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox)
{
ASSERT(!m_currentTextFragment.length);
@@ -138,6 +160,7 @@ void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox)
}
}
+ computeGlyphOverflow(textBox, m_currentTextFragment);
textBox->textFragments().append(m_currentTextFragment);
m_currentTextFragment = SVGTextFragment();
}

Powered by Google App Engine
This is Rietveld 408576698