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

Unified Diff: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp

Issue 250593004: Change HarfBuzz selectionRect rounding to match simple text version (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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/TestExpectations ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp
diff --git a/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp b/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp
index b2cc9d20f4f83c29f3348055547a9aeb662be7ea..0582c1f9cedd11a489c791eefb3eed883c4ad381 100644
--- a/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp
+++ b/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp
@@ -34,6 +34,7 @@
#include "RuntimeEnabledFeatures.h"
#include "hb.h"
+#include "platform/LayoutUnit.h"
#include "platform/fonts/Character.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/harfbuzz/HarfBuzzFace.h"
@@ -1111,9 +1112,21 @@ FloatRect HarfBuzzShaper::selectionRect(const FloatPoint& point, int height, int
toX = m_run.rtl() ? 0 : m_totalWidth;
// Using floorf() and roundf() as the same as mac port.
- if (fromX < toX)
- return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - fromX), height);
- return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), height);
+ // 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 (fromX < toX) {
+ float pixelAlignedX = floorf(point.x() + fromX + LayoutUnit::epsilon());
+ return FloatRect(floorf(point.x() + fromX),
+ point.y(),
+ roundf(point.x() + toX) - pixelAlignedX,
+ height);
+ }
+
+ float pixelAlignedX = floorf(point.x() + toX + LayoutUnit::epsilon());
+ return FloatRect(floorf(point.x() + toX),
+ point.y(),
+ roundf(point.x() + fromX) - pixelAlignedX,
+ height);
}
} // namespace WebCore
« no previous file with comments | « LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698