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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# This file is part of mingw-cross-env.
# See doc/index.html for further information.
From 531d2a9af8c51ad8badc32bc9ba43bb3b87b0e9f Mon Sep 17 00:00:00 2001
From: Antony Dovgal <tony@daylessday.org>
Date: Mon, 10 Jan 2011 01:22:14 +0300
Subject: [PATCH] fix build with libpng 1.5.0 (reported by Tamas Tevesz)
(cherry picked from commit
e5bf8b01f6c3d5e3fe0e26ac5345e0da10c03934)
Conflicts:
CHANGES
---
src/hpdf_image_png.c | 109 +++++++++++++++++++++++++++-----------------------
1 files changed, 59 insertions(+), 50 deletions(-)
diff --git a/src/hpdf_image_png.c b/src/hpdf_image_png.c
index b8f831e..6057424 100644
--- a/src/hpdf_image_png.c
+++ b/src/hpdf_image_png.c
@@ -109,14 +109,15 @@ ReadPngData_Interlaced (HPDF_Dict image,
png_infop info_ptr)
{
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
+ png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
png_bytep* row_pointers = HPDF_GetMem (image->mmgr,
- info_ptr->height * sizeof (png_bytep));
+ height * sizeof (png_bytep));
if (row_pointers) {
HPDF_UINT i;
- HPDF_MemSet (row_pointers, 0, info_ptr->height * sizeof (png_bytep));
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ HPDF_MemSet (row_pointers, 0, height * sizeof (png_bytep));
+ for (i = 0; i < (HPDF_UINT)height; i++) {
row_pointers[i] = HPDF_GetMem (image->mmgr, len);
if (image->error->error_no != HPDF_OK)
@@ -126,7 +127,7 @@ ReadPngData_Interlaced (HPDF_Dict image,
if (image->error->error_no == HPDF_OK) {
png_read_image(png_ptr, row_pointers);
if (image->error->error_no == HPDF_OK) { /* add this line */
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
if (HPDF_Stream_Write (image->stream, row_pointers[i], len) !=
HPDF_OK)
break;
@@ -135,7 +136,7 @@ ReadPngData_Interlaced (HPDF_Dict image,
}
/* clean up */
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
HPDF_FreeMem (image->mmgr, row_pointers[i]);
}
@@ -151,12 +152,13 @@ ReadPngData (HPDF_Dict image,
png_infop info_ptr)
{
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
+ png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
png_bytep buf_ptr = HPDF_GetMem (image->mmgr, len);
if (buf_ptr) {
HPDF_UINT i;
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
png_read_rows(png_ptr, (png_byte**)&buf_ptr, NULL, 1);
if (image->error->error_no != HPDF_OK)
break;
@@ -182,14 +184,16 @@ ReadTransparentPaletteData (HPDF_Dict image,
HPDF_STATUS ret = HPDF_OK;
HPDF_UINT i, j;
png_bytep *row_ptr;
+ png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
+ png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
- row_ptr = HPDF_GetMem (image->mmgr, info_ptr->height * sizeof(png_bytep));
+ row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep));
if (!row_ptr) {
return HPDF_FAILD_TO_ALLOC_MEM;
} else {
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
row_ptr[i] = HPDF_GetMem(image->mmgr, len);
if (!row_ptr[i]) {
for (; i >= 0; i--) {
@@ -207,19 +211,19 @@ ReadTransparentPaletteData (HPDF_Dict image,
goto Error;
}
- for (j = 0; j < info_ptr->height; j++) {
- for (i = 0; i < info_ptr->width; i++) {
- smask_data[info_ptr->width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF;
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
+ smask_data[width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF;
}
- if (HPDF_Stream_Write (image->stream, row_ptr[j], info_ptr->width) != HPDF_OK) {
+ if (HPDF_Stream_Write (image->stream, row_ptr[j], width) != HPDF_OK) {
ret = HPDF_FILE_IO_ERROR;
goto Error;
}
}
Error:
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
HPDF_FreeMem (image->mmgr, row_ptr[i]);
}
@@ -238,6 +242,8 @@ ReadTransparentPngData (HPDF_Dict image,
HPDF_UINT i, j;
png_bytep *row_ptr, row;
png_byte color_type;
+ png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
+ png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
@@ -245,13 +251,13 @@ ReadTransparentPngData (HPDF_Dict image,
return HPDF_INVALID_PNG_IMAGE;
}
- row_ptr = HPDF_GetMem (image->mmgr, info_ptr->height * sizeof(png_bytep));
+ row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep));
if (!row_ptr) {
return HPDF_FAILD_TO_ALLOC_MEM;
} else {
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
row_ptr[i] = HPDF_GetMem(image->mmgr, len);
if (!row_ptr[i]) {
for (; i >= 0; i--) {
@@ -271,12 +277,12 @@ ReadTransparentPngData (HPDF_Dict image,
switch (color_type) {
case PNG_COLOR_TYPE_RGB_ALPHA:
- row_len = 3 * info_ptr->width * sizeof(png_byte);
- for (j = 0; j < info_ptr->height; j++) {
- for (i = 0; i < info_ptr->width; i++) {
+ row_len = 3 * width * sizeof(png_byte);
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
row = row_ptr[j];
memmove(row + (3 * i), row + (4*i), 3);
- smask_data[info_ptr->width * j + i] = row[4 * i + 3];
+ smask_data[width * j + i] = row[4 * i + 3];
}
if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) {
@@ -286,12 +292,12 @@ ReadTransparentPngData (HPDF_Dict image,
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
- row_len = info_ptr->width * sizeof(png_byte);
- for (j = 0; j < info_ptr->height; j++) {
- for (i = 0; i < info_ptr->width; i++) {
+ row_len = width * sizeof(png_byte);
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
row = row_ptr[j];
row[i] = row[2 * i];
- smask_data[info_ptr->width * j + i] = row[2 * i + 1];
+ smask_data[width * j + i] = row[2 * i + 1];
}
if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) {
@@ -306,7 +312,7 @@ ReadTransparentPngData (HPDF_Dict image,
}
Error:
- for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
+ for (i = 0; i < (HPDF_UINT)height; i++) {
HPDF_FreeMem (image->mmgr, row_ptr[i]);
}
@@ -415,7 +421,8 @@ LoadPngData (HPDF_Dict image,
{
HPDF_STATUS ret = HPDF_OK;
-
+ png_uint_32 width, height;
+ int bit_depth, color_type;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
@@ -447,8 +454,10 @@ LoadPngData (HPDF_Dict image,
goto Exit;
}
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
+
/* 16bit images are not supported. */
- if (info_ptr->bit_depth == 16) {
+ if (bit_depth == 16) {
png_set_strip_16(png_ptr);
}
@@ -458,7 +467,7 @@ LoadPngData (HPDF_Dict image,
}
/* check palette-based images for transparent areas and load them immediately if found */
- if (xref && PNG_COLOR_TYPE_PALETTE & info_ptr->color_type) {
+ if (xref && PNG_COLOR_TYPE_PALETTE & color_type) {
png_bytep trans;
int num_trans;
HPDF_Dict smask;
@@ -478,10 +487,10 @@ LoadPngData (HPDF_Dict image,
smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
ret = HPDF_Dict_AddName (smask, "Type", "XObject");
ret += HPDF_Dict_AddName (smask, "Subtype", "Image");
- ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)info_ptr->width);
- ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)info_ptr->height);
+ ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width);
+ ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height);
ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray");
- ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
+ ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth);
if (ret != HPDF_OK) {
HPDF_Dict_Free(smask);
@@ -489,7 +498,7 @@ LoadPngData (HPDF_Dict image,
goto Exit;
}
- smask_data = HPDF_GetMem(image->mmgr, info_ptr->width * info_ptr->height);
+ smask_data = HPDF_GetMem(image->mmgr, width * height);
if (!smask_data) {
HPDF_Dict_Free(smask);
ret = HPDF_FAILD_TO_ALLOC_MEM;
@@ -503,7 +512,7 @@ LoadPngData (HPDF_Dict image,
goto Exit;
}
- if (HPDF_Stream_Write(smask->stream, smask_data, info_ptr->width * info_ptr->height) != HPDF_OK) {
+ if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) {
HPDF_FreeMem(image->mmgr, smask_data);
HPDF_Dict_Free(smask);
ret = HPDF_FILE_IO_ERROR;
@@ -513,9 +522,9 @@ LoadPngData (HPDF_Dict image,
ret += CreatePallet(image, png_ptr, info_ptr);
- ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width);
- ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height);
- ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
+ ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width);
+ ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height);
+ ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth);
ret += HPDF_Dict_Add (image, "SMask", smask);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
@@ -526,7 +535,7 @@ no_transparent_color_in_palette:
/* read images with alpha channel right away
we have to do this because image transparent mask must be added to the Xref */
- if (xref && PNG_COLOR_MASK_ALPHA & info_ptr->color_type) {
+ if (xref && PNG_COLOR_MASK_ALPHA & color_type) {
HPDF_Dict smask;
png_bytep smask_data;
@@ -539,10 +548,10 @@ no_transparent_color_in_palette:
smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
ret = HPDF_Dict_AddName (smask, "Type", "XObject");
ret += HPDF_Dict_AddName (smask, "Subtype", "Image");
- ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)info_ptr->width);
- ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)info_ptr->height);
+ ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width);
+ ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height);
ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray");
- ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
+ ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth);
if (ret != HPDF_OK) {
HPDF_Dict_Free(smask);
@@ -550,7 +559,7 @@ no_transparent_color_in_palette:
goto Exit;
}
- smask_data = HPDF_GetMem(image->mmgr, info_ptr->width * info_ptr->height);
+ smask_data = HPDF_GetMem(image->mmgr, width * height);
if (!smask_data) {
HPDF_Dict_Free(smask);
ret = HPDF_FAILD_TO_ALLOC_MEM;
@@ -564,7 +573,7 @@ no_transparent_color_in_palette:
goto Exit;
}
- if (HPDF_Stream_Write(smask->stream, smask_data, info_ptr->width * info_ptr->height) != HPDF_OK) {
+ if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) {
HPDF_FreeMem(image->mmgr, smask_data);
HPDF_Dict_Free(smask);
ret = HPDF_FILE_IO_ERROR;
@@ -572,14 +581,14 @@ no_transparent_color_in_palette:
}
HPDF_FreeMem(image->mmgr, smask_data);
- if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
} else {
ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
}
- ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width);
- ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height);
- ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
+ ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width);
+ ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height);
+ ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth);
ret += HPDF_Dict_Add (image, "SMask", smask);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
@@ -589,9 +598,9 @@ no_transparent_color_in_palette:
/* if the image has color palette, copy the pallet of the image to
* create color map.
*/
- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
ret = CreatePallet(image, png_ptr, info_ptr);
- else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
+ else if (color_type == PNG_COLOR_TYPE_GRAY)
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
else
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
@@ -617,16 +626,16 @@ no_transparent_color_in_palette:
}
/* setting the info of the image. */
- if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width)
+ if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width)
!= HPDF_OK)
goto Exit;
- if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height)
+ if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height)
!= HPDF_OK)
goto Exit;
if (HPDF_Dict_AddNumber (image, "BitsPerComponent",
- (HPDF_UINT)info_ptr->bit_depth) != HPDF_OK)
+ (HPDF_UINT)bit_depth) != HPDF_OK)
goto Exit;
/* clean up */
--
1.7.8.3
Wt requires the following patch for libHaru to render arcs correctly.
This patch has been tested against libhar 2.1.0 and 2.2.0.
(see http://redmine.webtoolkit.eu/projects/wt/wiki/LibHaru)
diff -ur a/src/hpdf_page_operator.c b/src/hpdf_page_operator.c
--- a/src/hpdf_page_operator.c 2010-02-01 07:26:13.000000000 -0300
+++ b/src/hpdf_page_operator.c 2012-03-10 18:12:41.347028623 -0300
@@ -2192,7 +2192,7 @@
HPDF_PTRACE ((" HPDF_Page_Arc\n"));
- if (ang1 >= ang2 || (ang2 - ang1) >= 360)
+ if (fabs(ang2 - ang1) >= 360)
HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0);
if (ret != HPDF_OK)
@@ -2205,10 +2205,10 @@
for (;;) {
- if (ang2 - ang1 <= 90)
+ if (fabs(ang2 - ang1) <= 90)
return InternalArc (page, x, y, ray, ang1, ang2, cont_flg);
else {
- HPDF_REAL tmp_ang = ang1 + 90;
+ HPDF_REAL tmp_ang = (ang2 > ang1 ? ang1 + 90 : ang1 - 90);
if ((ret = InternalArc (page, x, y, ray, ang1, tmp_ang, cont_flg))
!= HPDF_OK)
@@ -2217,7 +2217,7 @@
ang1 = tmp_ang;
}
- if (ang1 >= ang2)
+ if (fabs(ang1 - ang2) < 0.1)
break;
cont_flg = HPDF_TRUE;
@@ -2280,7 +2280,11 @@
pbuf = HPDF_FToA (pbuf, (HPDF_REAL)x0, eptr);
*pbuf++ = ' ';
pbuf = HPDF_FToA (pbuf, (HPDF_REAL)y0, eptr);
- pbuf = (char *)HPDF_StrCpy (pbuf, " m\012", eptr);
+
+ if (attr->gmode == HPDF_GMODE_PATH_OBJECT)
+ pbuf = (char *)HPDF_StrCpy (pbuf, " l\012", eptr);
+ else
+ pbuf = (char *)HPDF_StrCpy (pbuf, " m\012", eptr);
}
pbuf = HPDF_FToA (pbuf, (HPDF_REAL)x1, eptr);
|