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

Unified Diff: third_party/WebKit/Source/platform/fonts/FontTest.cpp

Issue 2416603002: Add ability to compute text intercepts to Font (Closed)
Patch Set: Nits addressed 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
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/Font.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/FontTest.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/FontTest.cpp b/third_party/WebKit/Source/platform/fonts/FontTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..29a0f58d7b27cf66a0170e165d6e8d6883c7cacb
--- /dev/null
+++ b/third_party/WebKit/Source/platform/fonts/FontTest.cpp
@@ -0,0 +1,53 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/fonts/Font.h"
+
+#include "platform/testing/FontTestHelpers.h"
+#include "platform/testing/UnitTestHelpers.h"
+#include "platform/text/TextRun.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using blink::testing::createTestFont;
+
+namespace blink {
+
+static inline String fontPath(String relativePath) {
+ return testing::blinkRootDir() + "/Source/platform/testing/data/" +
+ relativePath;
+}
+
+TEST(FontTest, TextIntercepts) {
+ 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);
+ SkPaint defaultPaint;
+ float deviceScaleFactor = 1;
+
+ std::tuple<float, float> belowBaselineBounds = std::make_tuple(2, 4);
+ Vector<Font::TextIntercept> textIntercepts;
+ // 4 intercept ranges for below baseline p glyphs in the test string
+ font.getTextIntercepts(textRunPaintInfo, deviceScaleFactor, defaultPaint,
+ belowBaselineBounds, textIntercepts);
+ EXPECT_EQ(textIntercepts.size(), 4u);
+ for (auto textIntercept : textIntercepts) {
+ EXPECT_GT(textIntercept.m_end, textIntercept.m_begin);
+ }
+
+ std::tuple<float, float> aboveBaselineBounds = std::make_tuple(-4, -2);
+ // 5 intercept ranges for the above baseline E ACUTE glyphs
+ font.getTextIntercepts(textRunPaintInfo, deviceScaleFactor, defaultPaint,
+ aboveBaselineBounds, textIntercepts);
+ EXPECT_EQ(textIntercepts.size(), 5u);
+ for (auto textIntercept : textIntercepts) {
+ EXPECT_GT(textIntercept.m_end, textIntercept.m_begin);
+ }
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/Font.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698