-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathPNGImageTest.cpp
141 lines (107 loc) · 3.5 KB
/
PNGImageTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
Source File : JPGImageTest.cpp
Copyright 2011 Gal Kahana PDFWriter
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef PDFHUMMUS_NO_PNG
#include "PDFWriter.h"
#include "PDFPage.h"
#include "PageContentContext.h"
#include "PDFFormXObject.h"
#include <iostream>
#include "testing/TestIO.h"
using namespace std;
using namespace PDFHummus;
EStatusCode RunImageTest(char* argv[], const string& inImageName) {
PDFWriter pdfWriter;
EStatusCode status;
do
{
status = pdfWriter.StartPDF(BuildRelativeOutputPath(argv, "PNGTest_" + inImageName + ".pdf"), ePDFVersion14, LogConfiguration(true, true,
BuildRelativeOutputPath(argv, "PNGTest_" + inImageName + ".log")));
if (status != PDFHummus::eSuccess)
{
cout << "failed to start PDF\n";
break;
}
PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, 595, 842));
PageContentContext* pageContentContext = pdfWriter.StartPageContentContext(page);
if (NULL == pageContentContext)
{
status = PDFHummus::eFailure;
cout << "failed to create content context for page\n";
}
// place a large red rectangle all over the page
AbstractContentContext::GraphicOptions pathFillOptions(AbstractContentContext::eFill,
AbstractContentContext::eRGB,
0xFF0000);
pageContentContext->DrawRectangle(0, 0, 595, 842, pathFillOptions);
// place the image on top...hopefully we can see soem transparency
AbstractContentContext::ImageOptions imageOptions;
imageOptions.transformationMethod = AbstractContentContext::eMatrix;
imageOptions.matrix[0] = imageOptions.matrix[3] = 0.5;
pageContentContext->DrawImage(10, 200, BuildRelativeInputPath(argv, "images/png/" + inImageName + ".png"), imageOptions);
status = pdfWriter.EndPageContentContext(pageContentContext);
if (status != PDFHummus::eSuccess)
{
cout << "failed to end page content context\n";
break;
}
status = pdfWriter.WritePageAndRelease(page);
if (status != PDFHummus::eSuccess)
{
cout << "failed to write page\n";
break;
}
status = pdfWriter.EndPDF();
if (status != PDFHummus::eSuccess)
{
cout << "failed in end PDF\n";
break;
}
} while (false);
return status;
}
int PNGImageTest(int argc, char* argv[])
{
EStatusCode status;
do
{
status = RunImageTest(argv, "original");
if (status != eSuccess) {
cout << "failed in original.png test" << "\n";
}
status = RunImageTest(argv, "original_transparent");
if (status != eSuccess) {
cout << "failed in original.png test" << "\n";
}
status = RunImageTest(argv, "gray-alpha-8-linear");
if (status != eSuccess) {
cout << "failed in original.png test" << "\n";
}
status = RunImageTest(argv, "gray-16-linear");
if (status != eSuccess) {
cout << "failed in original.png test" << "\n";
}
status = RunImageTest(argv, "pnglogo-grr");
if (status != eSuccess) {
cout << "failed in original.png test" << "\n";
}
} while (false);
return status == eSuccess ? 0:1;
}
#else //PDFHUMMUS_NO_PNG
int PNGImageTest(int argc, char* argv[])
{
return 0;
}
#endif