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

Unified Diff: third_party/WebKit/Source/platform/graphics/GraphicsContextTest.cpp

Issue 2416603002: Add ability to compute text intercepts to Font (Closed)
Patch Set: Rebased Created 4 years, 2 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
Index: third_party/WebKit/Source/platform/graphics/GraphicsContextTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsContextTest.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsContextTest.cpp
index ef82ea9c823c53a1501df385554c25ef81be0f6a..4aeea73519ec63475a9b2fd83e9accf0735bb25b 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsContextTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsContextTest.cpp
@@ -28,6 +28,9 @@
#include "platform/graphics/BitmapImage.h"
#include "platform/graphics/Path.h"
#include "platform/graphics/paint/PaintController.h"
+#include "platform/testing/FontTestHelpers.h"
+#include "platform/testing/UnitTestHelpers.h"
+#include "platform/text/TextRun.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
@@ -35,6 +38,8 @@
#include "third_party/skia/include/core/SkShader.h"
#include <memory>
+using blink::testing::createTestFont;
+
namespace blink {
#define EXPECT_EQ_RECT(a, b) \
@@ -146,4 +151,37 @@ TEST(GraphicsContextTest, UnboundedDrawsAreClipped) {
EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40));
}
+static inline String fontPath(String relativePath) {
+ return testing::blinkRootDir() + "/Source/platform/testing/data/" +
+ relativePath;
+}
+
+TEST(GraphicsContextTest, TextIntercepts) {
+ std::unique_ptr<PaintController> paintController = PaintController::create();
+ GraphicsContext context(*paintController);
+ Font font = createTestFont("Ahem", fontPath("Ahem.woff"), 16);
+ // A sequence of LATIN CAPITAL LETTER E WITH ACUTE and LATIN SMALL LETTER P
+ // characters. E ACUTES are squares above the baseline in Ahem, while p's
+ // are rectangles below the baseline.
+ UChar ahemAboveBelowBaselineString[] = {0xc9, 0x70, 0xc9, 0x70, 0xc9,
+ 0x70, 0xc9, 0x70, 0xc9};
+ TextRun ahemAboveBelowBaseline(ahemAboveBelowBaselineString, 9);
+
+ TextRunPaintInfo textRunPaintInfo(ahemAboveBelowBaseline);
+
+ SkScalar belowBaselineBounds[] = {2, 4};
+ // 4 intercept ranges for below baseline p glyphs in the test string = 8
+ // intercept coordinates.
+ EXPECT_EQ(context.getTextIntercepts(font, textRunPaintInfo,
+ belowBaselineBounds, nullptr),
+ 8);
+
+ SkScalar aboveBaselineBounds[] = {-4, -2};
+ // 5 intercept ranges for the above baseline E ACUTE glyphs = 10 intercept
+ // coordinates.
+ EXPECT_EQ(context.getTextIntercepts(font, textRunPaintInfo,
+ aboveBaselineBounds, nullptr),
+ 10);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698