OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "skia/ext/analysis_canvas.h" | 6 #include "skia/ext/analysis_canvas.h" |
7 #include "skia/ext/refptr.h" | 7 #include "skia/ext/refptr.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/skia/include/core/SkShader.h" | 9 #include "third_party/skia/include/core/SkShader.h" |
10 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" | 10 #include "third_party/skia/include/effects/SkOffsetImageFilter.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 TransparentFill(canvas); | 274 TransparentFill(canvas); |
275 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); | 275 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
276 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); | 276 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
277 | 277 |
278 SolidColorFill(canvas); | 278 SolidColorFill(canvas); |
279 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); | 279 EXPECT_TRUE(canvas.GetColorIfSolid(&outputColor)); |
280 EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); | 280 EXPECT_NE(static_cast<SkColor>(SK_ColorTRANSPARENT), outputColor); |
281 } | 281 } |
282 | 282 |
283 TEST(AnalysisCanvasTest, HasText) { | |
284 int width = 200; | |
285 int height = 100; | |
286 | |
287 const char* text = "A"; | |
288 size_t byteLength = 1; | |
289 | |
290 SkPoint point = SkPoint::Make(SkIntToScalar(25), SkIntToScalar(25)); | |
291 SkPath path; | |
292 path.moveTo(point); | |
293 path.lineTo(SkIntToScalar(75), SkIntToScalar(75)); | |
294 | |
295 SkPaint paint; | |
296 paint.setColor(SK_ColorGRAY); | |
297 paint.setTextSize(SkIntToScalar(10)); | |
298 | |
299 { | |
300 skia::AnalysisCanvas canvas(width, height); | |
301 // Test after initialization. | |
302 EXPECT_FALSE(canvas.HasText()); | |
303 // Test drawing anything other than text. | |
304 canvas.drawRect(SkRect::MakeWH(width/2, height), paint); | |
305 EXPECT_FALSE(canvas.HasText()); | |
306 } | |
307 { | |
308 // Test SkCanvas::drawText. | |
309 skia::AnalysisCanvas canvas(width, height); | |
310 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
311 EXPECT_TRUE(canvas.HasText()); | |
312 } | |
313 { | |
314 // Test SkCanvas::drawPosText. | |
315 skia::AnalysisCanvas canvas(width, height); | |
316 canvas.drawPosText(text, byteLength, &point, paint); | |
317 EXPECT_TRUE(canvas.HasText()); | |
318 } | |
319 { | |
320 // Test SkCanvas::drawPosTextH. | |
321 skia::AnalysisCanvas canvas(width, height); | |
322 canvas.drawPosTextH(text, byteLength, &point.fX, point.fY, paint); | |
323 EXPECT_TRUE(canvas.HasText()); | |
324 } | |
325 { | |
326 // Test SkCanvas::drawTextOnPathHV. | |
327 skia::AnalysisCanvas canvas(width, height); | |
328 canvas.drawTextOnPathHV(text, byteLength, path, point.fX, point.fY, paint); | |
329 EXPECT_TRUE(canvas.HasText()); | |
330 } | |
331 { | |
332 // Test SkCanvas::drawTextOnPath. | |
333 skia::AnalysisCanvas canvas(width, height); | |
334 canvas.drawTextOnPath(text, byteLength, path, NULL, paint); | |
335 EXPECT_TRUE(canvas.HasText()); | |
336 } | |
337 { | |
338 // Text under opaque rect. | |
339 skia::AnalysisCanvas canvas(width, height); | |
340 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
341 EXPECT_TRUE(canvas.HasText()); | |
342 canvas.drawRect(SkRect::MakeWH(width, height), paint); | |
343 EXPECT_FALSE(canvas.HasText()); | |
344 } | |
345 { | |
346 // Text under translucent rect. | |
347 skia::AnalysisCanvas canvas(width, height); | |
348 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
349 EXPECT_TRUE(canvas.HasText()); | |
350 SkPaint translucentPaint; | |
351 translucentPaint.setColor(0x88FFFFFF); | |
352 canvas.drawRect(SkRect::MakeWH(width, height), translucentPaint); | |
353 EXPECT_TRUE(canvas.HasText()); | |
354 } | |
355 { | |
356 // Text under rect in clear mode. | |
357 skia::AnalysisCanvas canvas(width, height); | |
358 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
359 EXPECT_TRUE(canvas.HasText()); | |
360 SkPaint clearModePaint; | |
361 clearModePaint.setXfermodeMode(SkXfermode::kClear_Mode); | |
362 canvas.drawRect(SkRect::MakeWH(width, height), clearModePaint); | |
363 EXPECT_FALSE(canvas.HasText()); | |
364 } | |
365 { | |
366 // Clear. | |
367 skia::AnalysisCanvas canvas(width, height); | |
368 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
369 EXPECT_TRUE(canvas.HasText()); | |
370 canvas.clear(SK_ColorGRAY); | |
371 EXPECT_FALSE(canvas.HasText()); | |
372 } | |
373 { | |
374 // Text inside clip region. | |
375 skia::AnalysisCanvas canvas(width, height); | |
376 canvas.clipRect(SkRect::MakeWH(100, 100)); | |
377 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
378 EXPECT_TRUE(canvas.HasText()); | |
379 } | |
380 { | |
381 // Text outside clip region. | |
382 skia::AnalysisCanvas canvas(width, height); | |
383 canvas.clipRect(SkRect::MakeXYWH(100, 0, 100, 100)); | |
384 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
385 // Analysis device does not do any clipping. | |
386 // So even when text is outside the clip region, | |
387 // it is marked as having the text. | |
388 // TODO(alokp): We may be able to do some trivial rejection. | |
389 EXPECT_TRUE(canvas.HasText()); | |
390 } | |
391 } | |
392 | |
393 } // namespace skia | 283 } // namespace skia |
OLD | NEW |