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

Unified Diff: Source/platform/fonts/Font.cpp

Issue 986493002: Simplify text emphasis painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments 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 | « Source/platform/fonts/Font.h ('k') | Source/platform/fonts/shaping/HarfBuzzShaper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/Font.cpp
diff --git a/Source/platform/fonts/Font.cpp b/Source/platform/fonts/Font.cpp
index 454425c6a3accb2450555a1f2fc049310bd6bf69..73d21597cd7f5f1173ef81c22ad30bec7d55a53d 100644
--- a/Source/platform/fonts/Font.cpp
+++ b/Source/platform/fonts/Font.cpp
@@ -99,18 +99,16 @@ void Font::update(PassRefPtrWillBeRawPtr<FontSelector> fontSelector) const
}
float Font::buildGlyphBuffer(const TextRunPaintInfo& runInfo, GlyphBuffer& glyphBuffer,
- ForTextEmphasisOrNot forTextEmphasis) const
+ const GlyphData* emphasisData) const
{
if (codePath(runInfo) == ComplexPath) {
- HarfBuzzShaper shaper(this, runInfo.run, (forTextEmphasis == ForTextEmphasis)
- ? HarfBuzzShaper::ForTextEmphasis : HarfBuzzShaper::NotForTextEmphasis);
+ HarfBuzzShaper shaper(this, runInfo.run, emphasisData);
shaper.setDrawRange(runInfo.from, runInfo.to);
shaper.shape(&glyphBuffer);
return shaper.totalWidth();
}
- SimpleShaper shaper(this, runInfo.run, nullptr /* fallbackFonts */,
- nullptr, forTextEmphasis);
+ SimpleShaper shaper(this, runInfo.run, emphasisData, nullptr /* fallbackFonts */, nullptr);
shaper.advance(runInfo.from);
shaper.advance(runInfo.to, &glyphBuffer);
float width = shaper.runWidthSoFar();
@@ -204,13 +202,23 @@ void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& r
if (shouldSkipDrawing())
return;
+ FontCachePurgePreventer purgePreventer;
+
+ GlyphData emphasisGlyphData;
+ if (!getEmphasisMarkGlyphData(mark, emphasisGlyphData))
+ return;
+
+ ASSERT(emphasisGlyphData.fontData);
+ if (!emphasisGlyphData.fontData)
+ return;
+
GlyphBuffer glyphBuffer;
- buildGlyphBuffer(runInfo, glyphBuffer, ForTextEmphasis);
+ buildGlyphBuffer(runInfo, glyphBuffer, &emphasisGlyphData);
if (glyphBuffer.isEmpty())
return;
- drawEmphasisMarks(context, runInfo, glyphBuffer, mark, point);
+ drawGlyphBuffer(context, runInfo, glyphBuffer, point);
}
static inline void updateGlyphOverflowFromBounds(const IntRectOutsets& glyphBounds,
@@ -781,7 +789,7 @@ void Font::drawTextBlob(GraphicsContext* gc, const SkTextBlob* blob, const SkPoi
float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, IntRectOutsets* glyphBounds) const
{
FloatRect bounds;
- HarfBuzzShaper shaper(this, run, HarfBuzzShaper::NotForTextEmphasis, fallbackFonts, glyphBounds ? &bounds : 0);
+ HarfBuzzShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &bounds : 0);
if (!shaper.shape())
return 0;
@@ -853,54 +861,10 @@ void Font::drawGlyphBuffer(GraphicsContext* context,
runInfo.bounds);
}
-inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph glyph, FontOrientation orientation = Horizontal)
-{
- FloatRect bounds = fontData->boundsForGlyph(glyph);
- if (orientation == Horizontal)
- return bounds.x() + bounds.width() / 2;
- return bounds.y() + bounds.height() / 2;
-}
-
-void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& runInfo, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) const
-{
- FontCachePurgePreventer purgePreventer;
-
- GlyphData markGlyphData;
- if (!getEmphasisMarkGlyphData(mark, markGlyphData))
- return;
-
- const SimpleFontData* markFontData = markGlyphData.fontData;
- ASSERT(markFontData);
- if (!markFontData)
- return;
-
- GlyphBuffer markBuffer;
- bool drawVertically = markFontData->platformData().orientation() == Vertical && markFontData->verticalData();
- for (unsigned i = 0; i < glyphBuffer.size(); ++i) {
- // Skip marks for suppressed glyphs.
- if (!glyphBuffer.glyphAt(i))
- continue;
-
- // We want the middle of the emphasis mark aligned with the middle of the glyph.
- // The input offsets are already adjusted to point to the middle of the glyph, so all
- // is left to do is adjust for 1/2 mark width.
- // FIXME: we could avoid this by passing some additional info to the shaper,
- // and perform all adjustments at buffer build time.
- if (!drawVertically) {
- markBuffer.add(markGlyphData.glyph, markFontData, glyphBuffer.xOffsetAt(i) - offsetToMiddleOfGlyph(markFontData, markGlyphData.glyph));
- } else {
- markBuffer.add(markGlyphData.glyph, markFontData, FloatPoint(- offsetToMiddleOfGlyph(markFontData, markGlyphData.glyph),
- glyphBuffer.xOffsetAt(i) - offsetToMiddleOfGlyph(markFontData, markGlyphData.glyph, Vertical)));
- }
- }
-
- drawGlyphBuffer(context, runInfo, markBuffer, point);
-}
-
float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, IntRectOutsets* glyphBounds) const
{
FloatRect bounds;
- SimpleShaper shaper(this, run, fallbackFonts, glyphBounds ? &bounds : 0);
+ SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds ? &bounds : 0);
shaper.advance(run.length());
float runWidth = shaper.runWidthSoFar();
@@ -916,7 +880,7 @@ float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
{
FloatRect bounds;
- SimpleShaper shaper(this, run, 0, accountForGlyphBounds ? &bounds : 0);
+ SimpleShaper shaper(this, run, nullptr, nullptr, accountForGlyphBounds ? &bounds : nullptr);
shaper.advance(from);
float fromX = shaper.runWidthSoFar();
shaper.advance(to);
« no previous file with comments | « Source/platform/fonts/Font.h ('k') | Source/platform/fonts/shaping/HarfBuzzShaper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698