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

Unified Diff: Source/core/platform/graphics/FontFastPath.cpp

Issue 25512005: Enable experimental support for sub-pixel font scaling (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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: Source/core/platform/graphics/FontFastPath.cpp
diff --git a/Source/core/platform/graphics/FontFastPath.cpp b/Source/core/platform/graphics/FontFastPath.cpp
index 7f871c19fa793426b01e074fece43207bb1be0bc..95849fb2f06dbde41747d46a7f1f4f0976bde37c 100644
--- a/Source/core/platform/graphics/FontFastPath.cpp
+++ b/Source/core/platform/graphics/FontFastPath.cpp
@@ -28,6 +28,7 @@
#include "core/platform/graphics/GlyphPageTreeNode.h"
#include "core/platform/graphics/SimpleFontData.h"
#include "core/platform/graphics/WidthIterator.h"
+#include "platform/LayoutUnit.h"
#include "platform/fonts/GlyphBuffer.h"
#include "platform/geometry/FloatRect.h"
#include "platform/graphics/TextRun.h"
@@ -556,14 +557,21 @@ FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint&
it.advance(to, &glyphBuffer);
float afterWidth = it.m_runWidthSoFar;
- // Using roundf() rather than ceilf() for the right edge as a compromise to ensure correct caret positioning.
+ // Using roundf() rather than ceilf() for the right edge as a compromise to
+ // ensure correct caret positioning.
+ // Use LayoutUnit::epsilon() to ensure that values that cannot be stored as
+ // an integer are floored to n and not n-1 due to floating point imprecision.
if (run.rtl()) {
it.advance(run.length(), &glyphBuffer);
float totalWidth = it.m_runWidthSoFar;
- return FloatRect(floorf(point.x() + totalWidth - afterWidth), point.y(), roundf(point.x() + totalWidth - beforeWidth) - floorf(point.x() + totalWidth - afterWidth), h);
+ float pixelAlignedX = floorf(point.x() + totalWidth - afterWidth + LayoutUnit::epsilon());
+ return FloatRect(pixelAlignedX, point.y(),
+ roundf(point.x() + totalWidth - beforeWidth) - pixelAlignedX, h);
}
- return FloatRect(floorf(point.x() + beforeWidth), point.y(), roundf(point.x() + afterWidth) - floorf(point.x() + beforeWidth), h);
+ float pixelAlignedX = floorf(point.x() + beforeWidth + LayoutUnit::epsilon());
+ return FloatRect(pixelAlignedX, point.y(),
+ roundf(point.x() + afterWidth) - pixelAlignedX, h);
}
int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool includePartialGlyphs) const

Powered by Google App Engine
This is Rietveld 408576698