2012-07-11 19:57:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SkAnnotation.h"
|
|
|
|
#include "SkCanvas.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkData.h"
|
2015-03-01 14:55:20 +00:00
|
|
|
#include "SkDocument.h"
|
|
|
|
#include "SkStream.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2012-07-11 19:57:55 +00:00
|
|
|
|
2013-03-08 09:09:10 +00:00
|
|
|
/** Returns true if data (may contain null characters) contains needle (null
|
|
|
|
* terminated). */
|
|
|
|
static bool ContainsString(const char* data, size_t dataSize, const char* needle) {
|
|
|
|
size_t nSize = strlen(needle);
|
|
|
|
for (size_t i = 0; i < dataSize - nSize; i++) {
|
|
|
|
if (strncmp(&data[i], needle, nSize) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Annotation_NoDraw, reporter) {
|
2012-07-11 19:57:55 +00:00
|
|
|
SkBitmap bm;
|
2014-02-13 22:00:04 +00:00
|
|
|
bm.allocN32Pixels(10, 10);
|
2012-12-06 21:47:40 +00:00
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
2012-07-11 19:57:55 +00:00
|
|
|
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(10), SkIntToScalar(10));
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
|
2012-07-11 19:57:55 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
|
|
|
|
SkAnnotateRectWithURL(&canvas, r, data.get());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Annotation_PdfLink, reporter) {
|
2015-08-11 20:35:12 +00:00
|
|
|
REQUIRE_PDF_DOCUMENT(Annotation_PdfLink, reporter);
|
2015-03-01 14:55:20 +00:00
|
|
|
SkDynamicMemoryWStream outStream;
|
2016-04-27 14:45:18 +00:00
|
|
|
sk_sp<SkDocument> doc(SkDocument::MakePDF(&outStream));
|
2015-03-01 14:55:20 +00:00
|
|
|
SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
|
|
|
|
REPORTER_ASSERT(reporter, canvas);
|
2012-07-13 20:06:02 +00:00
|
|
|
|
|
|
|
SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
|
|
|
|
SkIntToScalar(288), SkIntToScalar(72));
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeWithCString("http://www.gooogle.com"));
|
2015-03-01 14:55:20 +00:00
|
|
|
SkAnnotateRectWithURL(canvas, r, data.get());
|
2012-07-13 20:06:02 +00:00
|
|
|
|
2015-03-01 14:55:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, doc->close());
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> out(outStream.copyToData());
|
2015-02-19 16:29:24 +00:00
|
|
|
const char* rawOutput = (const char*)out->data();
|
2012-07-13 20:06:02 +00:00
|
|
|
|
2015-02-19 16:29:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, ContainsString(rawOutput, out->size(), "/Annots "));
|
2012-07-13 20:06:02 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Annotation_NamedDestination, reporter) {
|
2015-08-11 20:35:12 +00:00
|
|
|
REQUIRE_PDF_DOCUMENT(Annotation_NamedDestination, reporter);
|
2015-03-01 14:55:20 +00:00
|
|
|
SkDynamicMemoryWStream outStream;
|
2016-04-27 14:45:18 +00:00
|
|
|
sk_sp<SkDocument> doc(SkDocument::MakePDF(&outStream));
|
2015-03-01 14:55:20 +00:00
|
|
|
SkCanvas* canvas = doc->beginPage(612.0f, 792.0f);
|
|
|
|
REPORTER_ASSERT(reporter, canvas);
|
2013-03-08 09:09:10 +00:00
|
|
|
|
|
|
|
SkPoint p = SkPoint::Make(SkIntToScalar(72), SkIntToScalar(72));
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeWithCString("example"));
|
2015-03-01 14:55:20 +00:00
|
|
|
SkAnnotateNamedDestination(canvas, p, data.get());
|
2013-03-08 09:09:10 +00:00
|
|
|
|
2015-03-01 14:55:20 +00:00
|
|
|
REPORTER_ASSERT(reporter, doc->close());
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> out(outStream.copyToData());
|
2013-03-08 09:09:10 +00:00
|
|
|
const char* rawOutput = (const char*)out->data();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
ContainsString(rawOutput, out->size(), "/example "));
|
|
|
|
}
|