OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/fonts/Font.h" |
| 6 |
| 7 #include "platform/testing/FontTestHelpers.h" |
| 8 #include "platform/testing/UnitTestHelpers.h" |
| 9 #include "platform/text/TextRun.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 using blink::testing::createTestFont; |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 static inline String fontPath(String relativePath) { |
| 17 return testing::blinkRootDir() + "/Source/platform/testing/data/" + |
| 18 relativePath; |
| 19 } |
| 20 |
| 21 TEST(FontTest, TextIntercepts) { |
| 22 Font font = createTestFont("Ahem", fontPath("Ahem.woff"), 16); |
| 23 // A sequence of LATIN CAPITAL LETTER E WITH ACUTE and LATIN SMALL LETTER P |
| 24 // characters. E ACUTES are squares above the baseline in Ahem, while p's |
| 25 // are rectangles below the baseline. |
| 26 UChar ahemAboveBelowBaselineString[] = {0xc9, 0x70, 0xc9, 0x70, 0xc9, |
| 27 0x70, 0xc9, 0x70, 0xc9}; |
| 28 TextRun ahemAboveBelowBaseline(ahemAboveBelowBaselineString, 9); |
| 29 TextRunPaintInfo textRunPaintInfo(ahemAboveBelowBaseline); |
| 30 SkPaint defaultPaint; |
| 31 float deviceScaleFactor = 1; |
| 32 |
| 33 std::tuple<float, float> belowBaselineBounds = std::make_tuple(2, 4); |
| 34 Vector<Font::TextIntercept> textIntercepts; |
| 35 // 4 intercept ranges for below baseline p glyphs in the test string |
| 36 font.getTextIntercepts(textRunPaintInfo, deviceScaleFactor, defaultPaint, |
| 37 belowBaselineBounds, textIntercepts); |
| 38 EXPECT_EQ(textIntercepts.size(), 4u); |
| 39 for (auto textIntercept : textIntercepts) { |
| 40 EXPECT_GT(textIntercept.m_end, textIntercept.m_begin); |
| 41 } |
| 42 |
| 43 std::tuple<float, float> aboveBaselineBounds = std::make_tuple(-4, -2); |
| 44 // 5 intercept ranges for the above baseline E ACUTE glyphs |
| 45 font.getTextIntercepts(textRunPaintInfo, deviceScaleFactor, defaultPaint, |
| 46 aboveBaselineBounds, textIntercepts); |
| 47 EXPECT_EQ(textIntercepts.size(), 5u); |
| 48 for (auto textIntercept : textIntercepts) { |
| 49 EXPECT_GT(textIntercept.m_end, textIntercept.m_begin); |
| 50 } |
| 51 } |
| 52 |
| 53 } // namespace blink |
OLD | NEW |