OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... |
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
23 * DAMAGE. | 23 * DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "platform/graphics/GraphicsContext.h" | 26 #include "platform/graphics/GraphicsContext.h" |
27 | 27 |
28 #include "platform/graphics/BitmapImage.h" | 28 #include "platform/graphics/BitmapImage.h" |
29 #include "platform/graphics/Path.h" | 29 #include "platform/graphics/Path.h" |
30 #include "platform/graphics/paint/PaintController.h" | 30 #include "platform/graphics/paint/PaintController.h" |
| 31 #include "platform/testing/FontTestHelpers.h" |
| 32 #include "platform/testing/UnitTestHelpers.h" |
| 33 #include "platform/text/TextRun.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
32 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
33 #include "third_party/skia/include/core/SkCanvas.h" | 36 #include "third_party/skia/include/core/SkCanvas.h" |
34 #include "third_party/skia/include/core/SkPicture.h" | 37 #include "third_party/skia/include/core/SkPicture.h" |
35 #include "third_party/skia/include/core/SkShader.h" | 38 #include "third_party/skia/include/core/SkShader.h" |
36 #include <memory> | 39 #include <memory> |
37 | 40 |
| 41 using blink::testing::createTestFont; |
| 42 |
38 namespace blink { | 43 namespace blink { |
39 | 44 |
40 #define EXPECT_EQ_RECT(a, b) \ | 45 #define EXPECT_EQ_RECT(a, b) \ |
41 EXPECT_EQ(a.x(), b.x()); \ | 46 EXPECT_EQ(a.x(), b.x()); \ |
42 EXPECT_EQ(a.y(), b.y()); \ | 47 EXPECT_EQ(a.y(), b.y()); \ |
43 EXPECT_EQ(a.width(), b.width()); \ | 48 EXPECT_EQ(a.width(), b.width()); \ |
44 EXPECT_EQ(a.height(), b.height()); | 49 EXPECT_EQ(a.height(), b.height()); |
45 | 50 |
46 #define EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, opaqueRect) \ | 51 #define EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, opaqueRect) \ |
47 { \ | 52 { \ |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 SkPaint paint; | 144 SkPaint paint; |
140 paint.setColor(alpha.rgb()); | 145 paint.setColor(alpha.rgb()); |
141 paint.setBlendMode(SkBlendMode::kSrcOut); | 146 paint.setBlendMode(SkBlendMode::kSrcOut); |
142 context.drawPath(path.getSkPath(), paint); | 147 context.drawPath(path.getSkPath(), paint); |
143 | 148 |
144 picture = context.endRecording(); | 149 picture = context.endRecording(); |
145 canvas.drawPicture(picture.get()); | 150 canvas.drawPicture(picture.get()); |
146 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); | 151 EXPECT_OPAQUE_PIXELS_IN_RECT(bitmap, IntRect(20, 10, 30, 40)); |
147 } | 152 } |
148 | 153 |
| 154 static inline String fontPath(String relativePath) { |
| 155 return testing::blinkRootDir() + "/Source/platform/testing/data/" + |
| 156 relativePath; |
| 157 } |
| 158 |
| 159 TEST(GraphicsContextTest, TextIntercepts) { |
| 160 std::unique_ptr<PaintController> paintController = PaintController::create(); |
| 161 GraphicsContext context(*paintController); |
| 162 Font font = createTestFont("Ahem", fontPath("Ahem.woff"), 16); |
| 163 // A sequence of LATIN CAPITAL LETTER E WITH ACUTE and LATIN SMALL LETTER P |
| 164 // characters. E ACUTES are squares above the baseline in Ahem, while p's |
| 165 // are rectangles below the baseline. |
| 166 UChar ahemAboveBelowBaselineString[] = {0xc9, 0x70, 0xc9, 0x70, 0xc9, |
| 167 0x70, 0xc9, 0x70, 0xc9}; |
| 168 TextRun ahemAboveBelowBaseline(ahemAboveBelowBaselineString, 9); |
| 169 |
| 170 TextRunPaintInfo textRunPaintInfo(ahemAboveBelowBaseline); |
| 171 |
| 172 SkScalar belowBaselineBounds[] = {2, 4}; |
| 173 // 4 intercept ranges for below baseline p glyphs in the test string = 8 |
| 174 // intercept coordinates. |
| 175 EXPECT_EQ(context.getTextIntercepts(font, textRunPaintInfo, |
| 176 belowBaselineBounds, nullptr), |
| 177 8); |
| 178 |
| 179 SkScalar aboveBaselineBounds[] = {-4, -2}; |
| 180 // 5 intercept ranges for the above baseline E ACUTE glyphs = 10 intercept |
| 181 // coordinates. |
| 182 EXPECT_EQ(context.getTextIntercepts(font, textRunPaintInfo, |
| 183 aboveBaselineBounds, nullptr), |
| 184 10); |
| 185 } |
| 186 |
149 } // namespace blink | 187 } // namespace blink |
OLD | NEW |