Lines 124-191
extern "C" void pdf_prepend_stream(pdf_t *doc,
Link Here
|
124 |
{ |
124 |
{ |
125 |
XRef *xref = doc->getXRef(); |
125 |
XRef *xref = doc->getXRef(); |
126 |
Ref *pageref = doc->getCatalog()->getPageRef(page); |
126 |
Ref *pageref = doc->getCatalog()->getPageRef(page); |
127 |
Object dict, lenobj, stream, streamrefobj; |
127 |
Object dict, stream; |
128 |
Object pageobj, contents; |
128 |
Object pageobj, contents; |
129 |
Object array; |
129 |
Object array; |
130 |
Ref r; |
130 |
Ref r; |
131 |
|
131 |
|
132 |
xref->fetch(pageref->num, pageref->gen, &pageobj); |
132 |
pageobj = xref->fetch(pageref->num, pageref->gen); |
133 |
if (!pageobj.isDict() || !pageobj.dictLookupNF("Contents", &contents)) { |
133 |
if (!pageobj.isDict()) { |
|
|
134 |
fprintf(stderr, "Error: malformed pdf\n"); |
135 |
return; |
136 |
} |
137 |
|
138 |
contents = pageobj.dictLookupNF("Contents"); |
139 |
if (contents.isNull()) { |
134 |
fprintf(stderr, "Error: malformed pdf\n"); |
140 |
fprintf(stderr, "Error: malformed pdf\n"); |
135 |
return; |
141 |
return; |
136 |
} |
142 |
} |
137 |
|
143 |
|
138 |
if (contents.isRef()) |
144 |
if (contents.isRef()) |
139 |
xref->fetch(contents.getRefNum(), contents.getRefGen(), &contents); |
145 |
contents = xref->fetch(contents.getRefNum(), contents.getRefGen()); |
140 |
|
146 |
|
141 |
lenobj.initInt(len); |
147 |
dict = Object(new Dict(xref)); |
142 |
dict.initDict(xref); |
148 |
dict.dictSet("Length", Object(int(len))); |
143 |
dict.dictSet("Length", &lenobj); |
149 |
MemStream *mem_stream = new MemStream(buf, 0, len, std::move(dict)); |
144 |
stream.initStream(new MemStream(buf, 0, len, &dict)); |
150 |
stream = Object(static_cast<Stream *>(mem_stream)); |
145 |
|
151 |
|
146 |
r = xref->addIndirectObject(&stream); |
152 |
r = xref->addIndirectObject(&stream); |
147 |
streamrefobj.initRef(r.num, r.gen); |
|
|
148 |
|
153 |
|
149 |
array.initArray(xref); |
154 |
array = Object(new Array(xref)); |
150 |
array.arrayAdd(&streamrefobj); |
155 |
array.arrayAdd(Object(r.num, r.gen)); |
151 |
|
156 |
|
152 |
if (contents.isStream()) { |
157 |
if (contents.isStream()) { |
153 |
pageobj.dictLookupNF("Contents", &contents); // streams must be indirect, i.e. not fetch()-ed |
158 |
contents = pageobj.dictLookupNF("Contents"); // streams must be indirect, i.e. not fetch()-ed |
154 |
array.arrayAdd(&contents); |
159 |
array.arrayAdd(std::move(contents)); |
155 |
} |
160 |
} |
156 |
else if (contents.isArray()) { |
161 |
else if (contents.isArray()) { |
157 |
int i, len = contents.arrayGetLength(); |
162 |
int i, len = contents.arrayGetLength(); |
158 |
Object obj; |
|
|
159 |
for (i = 0; i < len; i++) { |
163 |
for (i = 0; i < len; i++) { |
160 |
contents.arrayGetNF(i, &obj); |
164 |
array.arrayAdd(contents.arrayGetNF(i)); |
161 |
array.arrayAdd(&obj); |
|
|
162 |
} |
165 |
} |
163 |
} |
166 |
} |
164 |
else |
167 |
else |
165 |
fprintf(stderr, "Error: malformed pdf\n"); |
168 |
fprintf(stderr, "Error: malformed pdf\n"); |
166 |
|
169 |
|
167 |
pageobj.dictSet("Contents", &array); |
170 |
pageobj.dictSet("Contents", std::move(array)); |
168 |
|
171 |
|
169 |
xref->setModifiedObject(&pageobj, *pageref); |
172 |
xref->setModifiedObject(&pageobj, *pageref); |
170 |
pageobj.free(); |
|
|
171 |
} |
173 |
} |
172 |
|
174 |
|
173 |
|
175 |
|
174 |
static Object * name_object(const char *s) |
176 |
static Object name_object(const char *s) |
175 |
{ |
177 |
{ |
176 |
Object *o = new Object(); |
178 |
return Object(objName, s); |
177 |
o->initName((char *)s); |
|
|
178 |
return o; |
179 |
} |
179 |
} |
180 |
|
180 |
|
181 |
/* |
181 |
/* |
182 |
* Create new PDF integer type object. |
182 |
* Create new PDF integer type object. |
183 |
*/ |
183 |
*/ |
184 |
static Object * int_object(int i) |
184 |
static Object int_object(int i) |
185 |
{ |
185 |
{ |
186 |
Object *o = new Object(); |
186 |
return Object(i); |
187 |
o->initInt(i); |
|
|
188 |
return o; |
189 |
} |
187 |
} |
190 |
|
188 |
|
191 |
static Object * get_resource_dict(XRef *xref, |
189 |
static Object * get_resource_dict(XRef *xref, |
Lines 196-216
static Object * get_resource_dict(XRef *xref,
Link Here
|
196 |
Object res; |
194 |
Object res; |
197 |
|
195 |
|
198 |
/* TODO resource dict can also be inherited */ |
196 |
/* TODO resource dict can also be inherited */ |
199 |
if (!pagedict->lookupNF("Resources", &res)) |
197 |
res = pagedict->lookupNF("Resources"); |
|
|
198 |
if (res.isNull()) |
200 |
return NULL; |
199 |
return NULL; |
201 |
|
200 |
|
202 |
if (res.isRef()) { |
201 |
if (res.isRef()) { |
203 |
*resref = res.getRef(); |
202 |
*resref = res.getRef(); |
204 |
xref->fetch(resref->num, resref->gen, resdict); |
203 |
*resdict = xref->fetch(resref->num, resref->gen); |
205 |
} |
204 |
} |
206 |
else if (res.isDict()) { |
205 |
else if (res.isDict()) { |
207 |
res.copy(resdict); |
206 |
*resdict = res.copy(); |
208 |
resref->num = 0; |
207 |
resref->num = 0; |
209 |
} |
208 |
} |
210 |
else |
209 |
else |
211 |
resdict = NULL; |
210 |
resdict = NULL; |
212 |
|
211 |
|
213 |
res.free(); |
|
|
214 |
return resdict; |
212 |
return resdict; |
215 |
} |
213 |
} |
216 |
|
214 |
|
Lines 226-232
extern "C" void pdf_add_type1_font(pdf_t *doc,
Link Here
|
226 |
Object resdict; |
224 |
Object resdict; |
227 |
Ref resref; |
225 |
Ref resref; |
228 |
|
226 |
|
229 |
xref->fetch(pageref->num, pageref->gen, &pageobj); |
227 |
pageobj = xref->fetch(pageref->num, pageref->gen); |
230 |
if (!pageobj.isDict()) { |
228 |
if (!pageobj.isDict()) { |
231 |
fprintf(stderr, "Error: malformed pdf\n"); |
229 |
fprintf(stderr, "Error: malformed pdf\n"); |
232 |
return; |
230 |
return; |
Lines 234-254
extern "C" void pdf_add_type1_font(pdf_t *doc,
Link Here
|
234 |
|
232 |
|
235 |
if (!get_resource_dict(xref, pageobj.getDict(), &resdict, &resref)) { |
233 |
if (!get_resource_dict(xref, pageobj.getDict(), &resdict, &resref)) { |
236 |
fprintf(stderr, "Error: malformed pdf\n"); |
234 |
fprintf(stderr, "Error: malformed pdf\n"); |
237 |
pageobj.free(); |
|
|
238 |
return; |
235 |
return; |
239 |
} |
236 |
} |
240 |
|
237 |
|
241 |
font.initDict(xref); |
238 |
font = Object(new Dict(xref)); |
242 |
font.dictSet("Type", name_object("Font")); |
239 |
font.dictSet("Type", name_object("Font")); |
243 |
font.dictSet("Subtype", name_object("Type1")); |
240 |
font.dictSet("Subtype", name_object("Type1")); |
244 |
font.dictSet("BaseFont", name_object(name)); |
241 |
font.dictSet("BaseFont", name_object(name)); |
245 |
xref->addIndirectObject(&font); |
242 |
xref->addIndirectObject(&font); |
246 |
|
243 |
|
247 |
resdict.dictLookupNF("Font", &fonts); |
244 |
fonts = resdict.dictLookupNF("Font"); |
248 |
if (fonts.isNull()) { |
245 |
if (fonts.isNull()) { |
249 |
/* Create new font dic obj in page's resources */ |
246 |
/* Create new font dic obj in page's resources */ |
250 |
fonts.initDict(xref); |
247 |
fonts = Object(new Dict(xref)); |
251 |
resdict.dictSet("Font", &fonts); |
248 |
resdict.dictSet("Font", std::move(fonts)); |
252 |
} |
249 |
} |
253 |
|
250 |
|
254 |
Object *fonts_dic; |
251 |
Object *fonts_dic; |
Lines 259-265
extern "C" void pdf_add_type1_font(pdf_t *doc,
Link Here
|
259 |
fonts_dic = &fonts; |
256 |
fonts_dic = &fonts; |
260 |
} else if ( fonts.isRef() ) { |
257 |
} else if ( fonts.isRef() ) { |
261 |
/* "Font" resource is indirect reference object */ |
258 |
/* "Font" resource is indirect reference object */ |
262 |
xref->fetch(fonts.getRefNum(), fonts.getRefGen(), &dereferenced_obj); |
259 |
dereferenced_obj = xref->fetch(fonts.getRefNum(), fonts.getRefGen()); |
263 |
fonts_dic = &dereferenced_obj; |
260 |
fonts_dic = &dereferenced_obj; |
264 |
} |
261 |
} |
265 |
|
262 |
|
Lines 269-275
extern "C" void pdf_add_type1_font(pdf_t *doc,
Link Here
|
269 |
} |
266 |
} |
270 |
|
267 |
|
271 |
/* Add new entry to "Font" resource */ |
268 |
/* Add new entry to "Font" resource */ |
272 |
fonts_dic->dictSet("bannertopdf-font", &font); |
269 |
fonts_dic->dictSet("bannertopdf-font", std::move(font)); |
273 |
|
270 |
|
274 |
/* Notify poppler about changes */ |
271 |
/* Notify poppler about changes */ |
275 |
if ( fonts.isRef() ) { |
272 |
if ( fonts.isRef() ) { |
Lines 280-287
extern "C" void pdf_add_type1_font(pdf_t *doc,
Link Here
|
280 |
xref->setModifiedObject(&pageobj, *pageref); |
277 |
xref->setModifiedObject(&pageobj, *pageref); |
281 |
else |
278 |
else |
282 |
xref->setModifiedObject(&resdict, resref); |
279 |
xref->setModifiedObject(&resdict, resref); |
283 |
|
|
|
284 |
pageobj.free(); |
285 |
} |
280 |
} |
286 |
|
281 |
|
287 |
|
282 |
|
Lines 293-315
static bool dict_lookup_rect(Object *dict,
Link Here
|
293 |
Array *array; |
288 |
Array *array; |
294 |
int i; |
289 |
int i; |
295 |
|
290 |
|
296 |
if (!dict->dictLookup(key, &o)) |
291 |
o = dict->dictLookup(key); |
|
|
292 |
if (!o.isArray()) |
297 |
return false; |
293 |
return false; |
298 |
|
294 |
|
299 |
if (!o.isArray()) { |
|
|
300 |
o.free(); |
301 |
return false; |
302 |
} |
303 |
|
304 |
array = o.getArray(); |
295 |
array = o.getArray(); |
305 |
for (i = 0; i < 4; i++) { |
296 |
for (i = 0; i < 4; i++) { |
306 |
Object el; |
297 |
Object el; |
307 |
if (array->get(i, &el) && el.isNum()) |
298 |
el = array->get(i); |
|
|
299 |
if (el.isNum()) |
308 |
rect[i] = el.getNum(); |
300 |
rect[i] = el.getNum(); |
309 |
el.free(); |
|
|
310 |
} |
301 |
} |
311 |
|
302 |
|
312 |
o.free(); |
|
|
313 |
return i == 4; |
303 |
return i == 4; |
314 |
} |
304 |
} |
315 |
|
305 |
|
Lines 322-336
static void dict_set_rect(XRef *xref,
Link Here
|
322 |
Object array; |
312 |
Object array; |
323 |
int i; |
313 |
int i; |
324 |
|
314 |
|
325 |
array.initArray(xref); |
315 |
array = Object(new Array(xref)); |
326 |
|
316 |
|
327 |
for (i = 0; i < 4; i++) { |
317 |
for (i = 0; i < 4; i++) { |
328 |
Object el; |
318 |
array.arrayAdd(Object(double(rect[i]))); |
329 |
el.initReal(rect[i]); |
|
|
330 |
array.arrayAdd(&el); |
331 |
} |
319 |
} |
332 |
|
320 |
|
333 |
dict->dictSet(key, &array); |
321 |
dict->dictSet(key, std::move(array)); |
334 |
} |
322 |
} |
335 |
|
323 |
|
336 |
|
324 |
|
Lines 361-367
extern "C" void pdf_resize_page (pdf_t *doc,
Link Here
|
361 |
float mediabox[4] = { 0.0, 0.0, width, length }; |
349 |
float mediabox[4] = { 0.0, 0.0, width, length }; |
362 |
float old_mediabox[4]; |
350 |
float old_mediabox[4]; |
363 |
|
351 |
|
364 |
xref->fetch(pageref->num, pageref->gen, &pageobj); |
352 |
pageobj = xref->fetch(pageref->num, pageref->gen); |
365 |
if (!pageobj.isDict()) { |
353 |
if (!pageobj.isDict()) { |
366 |
fprintf(stderr, "Error: malformed pdf\n"); |
354 |
fprintf(stderr, "Error: malformed pdf\n"); |
367 |
return; |
355 |
return; |
Lines 381-387
extern "C" void pdf_resize_page (pdf_t *doc,
Link Here
|
381 |
dict_set_rect (xref, &pageobj, "BleedBox", mediabox); |
369 |
dict_set_rect (xref, &pageobj, "BleedBox", mediabox); |
382 |
|
370 |
|
383 |
xref->setModifiedObject(&pageobj, *pageref); |
371 |
xref->setModifiedObject(&pageobj, *pageref); |
384 |
pageobj.free(); |
|
|
385 |
} |
372 |
} |
386 |
|
373 |
|
387 |
|
374 |
|
Lines 391-414
extern "C" void pdf_duplicate_page (pdf_t *doc,
Link Here
|
391 |
{ |
378 |
{ |
392 |
XRef *xref = doc->getXRef(); |
379 |
XRef *xref = doc->getXRef(); |
393 |
Ref *pageref = doc->getCatalog()->getPageRef(pagenr); |
380 |
Ref *pageref = doc->getCatalog()->getPageRef(pagenr); |
394 |
Object page, parentref, parent, kids, ref, countobj; |
381 |
Object page, parentref, parent, kids; |
395 |
int i; |
382 |
int i; |
396 |
|
383 |
|
397 |
xref->fetch(pageref->num, pageref->gen, &page); |
384 |
page = xref->fetch(pageref->num, pageref->gen); |
398 |
if (!page.isDict("Page")) { |
385 |
if (!page.isDict("Page")) { |
399 |
fprintf(stderr, "Error: malformed pdf (invalid Page object)\n"); |
386 |
fprintf(stderr, "Error: malformed pdf (invalid Page object)\n"); |
400 |
return; |
387 |
return; |
401 |
} |
388 |
} |
402 |
|
389 |
|
403 |
page.dictLookupNF("Parent", &parentref); |
390 |
parentref = page.dictLookupNF("Parent"); |
404 |
parentref.fetch(xref, &parent); |
391 |
parent = parentref.fetch(xref); |
405 |
if (!parent.isDict("Pages")) { |
392 |
if (!parent.isDict("Pages")) { |
406 |
fprintf(stderr, "Error: malformed pdf (Page.Parent must point to a " |
393 |
fprintf(stderr, "Error: malformed pdf (Page.Parent must point to a " |
407 |
"Pages object)\n"); |
394 |
"Pages object)\n"); |
408 |
return; |
395 |
return; |
409 |
} |
396 |
} |
410 |
|
397 |
|
411 |
parent.dictLookup("Kids", &kids); |
398 |
kids = parent.dictLookup("Kids"); |
412 |
if (!kids.isArray()) { |
399 |
if (!kids.isArray()) { |
413 |
fprintf(stderr, "Error: malformed pdf (Pages.Kids must be an array)\n"); |
400 |
fprintf(stderr, "Error: malformed pdf (Pages.Kids must be an array)\n"); |
414 |
return; |
401 |
return; |
Lines 420-433
extern "C" void pdf_duplicate_page (pdf_t *doc,
Link Here
|
420 |
// the pages tree (not supported by major pdf implementations). |
407 |
// the pages tree (not supported by major pdf implementations). |
421 |
for (i = 1; i < count; i++) { |
408 |
for (i = 1; i < count; i++) { |
422 |
Ref r = xref->addIndirectObject(&page); |
409 |
Ref r = xref->addIndirectObject(&page); |
423 |
ref.initRef(r.num, r.gen); |
410 |
kids.arrayAdd(Object(r.num, r.gen)); |
424 |
kids.arrayAdd(&ref); |
|
|
425 |
ref.free(); |
426 |
} |
411 |
} |
427 |
|
412 |
|
428 |
countobj.initInt(count); |
413 |
parent.dictSet("Count", Object(count)); |
429 |
parent.dictSet("Count", &countobj); |
|
|
430 |
countobj.free(); |
431 |
|
414 |
|
432 |
xref->setModifiedObject(&parent, parentref.getRef()); |
415 |
xref->setModifiedObject(&parent, parentref.getRef()); |
433 |
} |
416 |
} |
Lines 521-529
extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt)
Link Here
|
521 |
fprintf(stderr, "Can't get page from PDF tamplate file.\n"); |
504 |
fprintf(stderr, "Can't get page from PDF tamplate file.\n"); |
522 |
return 0; |
505 |
return 0; |
523 |
} |
506 |
} |
524 |
Object pageobj; |
|
|
525 |
Ref pageref = page->getRef(); |
507 |
Ref pageref = page->getRef(); |
526 |
xref->fetch(pageref.num, pageref.gen, &pageobj); |
508 |
Object pageobj = xref->fetch(pageref.num, pageref.gen); |
527 |
|
509 |
|
528 |
const char *font_size = lookup_opt(opt, "banner-font-size"); |
510 |
const char *font_size = lookup_opt(opt, "banner-font-size"); |
529 |
if ( ! font_size ) { |
511 |
if ( ! font_size ) { |
Lines 613-621
extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt)
Link Here
|
613 |
appearance->append(" Tf"); |
595 |
appearance->append(" Tf"); |
614 |
|
596 |
|
615 |
/* Modify field's appearance */ |
597 |
/* Modify field's appearance */ |
616 |
Object appearance_obj; |
598 |
field_obj->getDict()->set("DA", Object(appearance)); |
617 |
appearance_obj.initString(appearance); |
|
|
618 |
field_obj->getDict()->set("DA", &appearance_obj); |
619 |
|
599 |
|
620 |
/* |
600 |
/* |
621 |
* Create /AP - entry stuff. |
601 |
* Create /AP - entry stuff. |
Lines 652-659
extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt)
Link Here
|
652 |
appearance_stream->append("ET\n"); |
632 |
appearance_stream->append("ET\n"); |
653 |
appearance_stream->append("EMC\n"); |
633 |
appearance_stream->append("EMC\n"); |
654 |
|
634 |
|
655 |
Object appearance_stream_dic; |
635 |
Object appearance_stream_dic = Object(new Dict(xref)); |
656 |
appearance_stream_dic.initDict(xref); |
|
|
657 |
|
636 |
|
658 |
/* |
637 |
/* |
659 |
* Appearance stream dic. |
638 |
* Appearance stream dic. |
Lines 663-710
extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt)
Link Here
|
663 |
appearance_stream_dic.dictSet("Type", name_object("XObject")); |
642 |
appearance_stream_dic.dictSet("Type", name_object("XObject")); |
664 |
appearance_stream_dic.dictSet("Subtype", name_object("Form")); |
643 |
appearance_stream_dic.dictSet("Subtype", name_object("Form")); |
665 |
appearance_stream_dic.dictSet("FormType", int_object(1)); |
644 |
appearance_stream_dic.dictSet("FormType", int_object(1)); |
666 |
Object obj_ref_x; |
645 |
appearance_stream_dic.dictSet("Resources", Object(resref.num, resref.gen)); |
667 |
obj_ref_x.initRef(resref.num, resref.gen); |
|
|
668 |
appearance_stream_dic.dictSet("Resources", &obj_ref_x); |
669 |
|
646 |
|
670 |
/* BBox array: TODO. currently out of the head. */ |
647 |
/* BBox array: TODO. currently out of the head. */ |
671 |
Object array; |
648 |
Object array = Object(new Array(xref)); |
672 |
array.initArray(xref); |
649 |
array.arrayAdd(Object(double(0))); |
673 |
Object el; |
650 |
array.arrayAdd(Object(double(0))); |
674 |
el.initReal(0); |
651 |
array.arrayAdd(Object(double(237))); |
675 |
array.arrayAdd(&el); |
652 |
array.arrayAdd(Object(double(25))); |
676 |
el.initReal(0); |
653 |
appearance_stream_dic.dictSet("BBox", std::move(array)); |
677 |
array.arrayAdd(&el); |
|
|
678 |
el.initReal(237); |
679 |
array.arrayAdd(&el); |
680 |
el.initReal(25); |
681 |
array.arrayAdd(&el); |
682 |
appearance_stream_dic.dictSet("BBox", &array); |
683 |
appearance_stream_dic.dictSet("Length", int_object(appearance_stream->getLength())); |
654 |
appearance_stream_dic.dictSet("Length", int_object(appearance_stream->getLength())); |
684 |
|
655 |
|
685 |
MemStream *mem_stream = new MemStream(appearance_stream->getCString(), |
656 |
MemStream *mem_stream = new MemStream(appearance_stream->getCString(), |
686 |
0, appearance_stream->getLength(), &appearance_stream_dic); |
657 |
0, appearance_stream->getLength(), std::move(appearance_stream_dic)); |
687 |
|
658 |
|
688 |
/* Make obj stream */ |
659 |
/* Make obj stream */ |
689 |
Object stream; |
660 |
Object stream = Object(static_cast<Stream *>(mem_stream)); |
690 |
stream.initStream(mem_stream); |
|
|
691 |
|
661 |
|
692 |
Ref r; |
662 |
Ref r; |
693 |
r = xref->addIndirectObject(&stream); |
663 |
r = xref->addIndirectObject(&stream); |
694 |
|
664 |
|
695 |
/* Update Xref table */ |
|
|
696 |
Object obj_ref; |
697 |
obj_ref.initRef(r.num, r.gen); |
698 |
|
699 |
/* |
665 |
/* |
700 |
* Fill Annotation's appearance streams dic /AP |
666 |
* Fill Annotation's appearance streams dic /AP |
701 |
* See: 8.4.4 Appearance Streams |
667 |
* See: 8.4.4 Appearance Streams |
702 |
*/ |
668 |
*/ |
703 |
Object appearance_streams_dic; |
669 |
Object appearance_streams_dic = Object(new Dict(xref)); |
704 |
appearance_streams_dic.initDict(xref); |
670 |
/* Update Xref table */ |
705 |
appearance_streams_dic.dictSet("N", &obj_ref); |
671 |
appearance_streams_dic.dictSet("N", Object(r.num, r.gen)); |
706 |
|
672 |
|
707 |
field_obj->getDict()->set("AP", &appearance_streams_dic); |
673 |
field_obj->getDict()->set("AP", std::move(appearance_streams_dic)); |
708 |
|
674 |
|
709 |
/* Notify poppler about changes */ |
675 |
/* Notify poppler about changes */ |
710 |
xref->setModifiedObject(field_obj, field_ref); |
676 |
xref->setModifiedObject(field_obj, field_ref); |
Lines 721-744
extern "C" int pdf_fill_form(pdf_t *doc, opt_t *opt)
Link Here
|
721 |
* OpenOffice - by default sets it to 'true'. |
687 |
* OpenOffice - by default sets it to 'true'. |
722 |
*/ |
688 |
*/ |
723 |
Object *obj_form = catalog->getAcroForm(); |
689 |
Object *obj_form = catalog->getAcroForm(); |
724 |
Object obj1; |
690 |
obj_form->dictSet("NeedAppearances", Object(gFalse)); |
725 |
obj1.initBool(gFalse); |
|
|
726 |
obj_form->dictSet("NeedAppearances", &obj1); |
727 |
/* Add AccroForm as indirect obj */ |
691 |
/* Add AccroForm as indirect obj */ |
728 |
Ref ref_form = xref->addIndirectObject(obj_form); |
692 |
Ref ref_form = xref->addIndirectObject(obj_form); |
729 |
|
693 |
|
730 |
/* |
694 |
/* |
731 |
* So update Catalog object. |
695 |
* So update Catalog object. |
732 |
*/ |
696 |
*/ |
733 |
Object* catObj = new Object(); |
697 |
Object catObj = xref->getCatalog(); |
734 |
catObj = xref->getCatalog(catObj); |
|
|
735 |
Ref catRef; |
698 |
Ref catRef; |
736 |
catRef.gen = xref->getRootGen(); |
699 |
catRef.gen = xref->getRootGen(); |
737 |
catRef.num = xref->getRootNum(); |
700 |
catRef.num = xref->getRootNum(); |
738 |
Object obj2; |
701 |
catObj.dictSet("AcroForm", Object(ref_form.num, ref_form.gen)); |
739 |
obj2.initRef(ref_form.num, ref_form.gen); |
702 |
xref->setModifiedObject(&catObj, catRef); |
740 |
catObj->dictSet("AcroForm", &obj2); |
|
|
741 |
xref->setModifiedObject(catObj, catRef); |
742 |
|
703 |
|
743 |
/* Success */ |
704 |
/* Success */ |
744 |
return 1; |
705 |
return 1; |
Lines 779-786
static int pdf_embed_font(pdf_t *doc,
Link Here
|
779 |
XRef *xref = doc->getXRef(); |
740 |
XRef *xref = doc->getXRef(); |
780 |
|
741 |
|
781 |
/* Font dictionary object for embeded font */ |
742 |
/* Font dictionary object for embeded font */ |
782 |
Object f_dic; |
743 |
Object f_dic = Object(new Dict(xref)); |
783 |
f_dic.initDict(xref); |
|
|
784 |
f_dic.dictSet("Type", name_object("Font")); |
744 |
f_dic.dictSet("Type", name_object("Font")); |
785 |
|
745 |
|
786 |
/* Stream lenght */ |
746 |
/* Stream lenght */ |
Lines 799-809
static int pdf_embed_font(pdf_t *doc,
Link Here
|
799 |
|
759 |
|
800 |
/* Create memory stream font. Add it to font dic. */ |
760 |
/* Create memory stream font. Add it to font dic. */ |
801 |
MemStream *mem_stream = new MemStream(font_stream->getCString(), |
761 |
MemStream *mem_stream = new MemStream(font_stream->getCString(), |
802 |
0, outlen, &f_dic); |
762 |
0, outlen, std::move(f_dic)); |
803 |
|
763 |
|
804 |
/* Make obj stream */ |
764 |
/* Make obj stream */ |
805 |
Object stream; |
765 |
Object stream = Object(static_cast<Stream *>(mem_stream)); |
806 |
stream.initStream(mem_stream); |
|
|
807 |
|
766 |
|
808 |
Ref r; |
767 |
Ref r; |
809 |
|
768 |
|
Lines 813-819
static int pdf_embed_font(pdf_t *doc,
Link Here
|
813 |
/* Get page object */ |
772 |
/* Get page object */ |
814 |
Object pageobj; |
773 |
Object pageobj; |
815 |
Ref pageref = page->getRef(); |
774 |
Ref pageref = page->getRef(); |
816 |
xref->fetch(pageref.num, pageref.gen, &pageobj); |
775 |
pageobj = xref->fetch(pageref.num, pageref.gen); |
817 |
if (!pageobj.isDict()) { |
776 |
if (!pageobj.isDict()) { |
818 |
fprintf(stderr, "Error: malformed pdf.\n"); |
777 |
fprintf(stderr, "Error: malformed pdf.\n"); |
819 |
return 0; |
778 |
return 0; |
Lines 825-842
static int pdf_embed_font(pdf_t *doc,
Link Here
|
825 |
Object *ret = get_resource_dict(xref, pageobj.getDict(), &resdict, &resref); |
784 |
Object *ret = get_resource_dict(xref, pageobj.getDict(), &resdict, &resref); |
826 |
if ( !ret ) { |
785 |
if ( !ret ) { |
827 |
fprintf(stderr, "Error: malformed pdf\n"); |
786 |
fprintf(stderr, "Error: malformed pdf\n"); |
828 |
pageobj.free(); |
|
|
829 |
return 0; |
787 |
return 0; |
830 |
} |
788 |
} |
831 |
|
789 |
|
832 |
/* Dictionary for all fonts in page's resources */ |
790 |
/* Dictionary for all fonts in page's resources */ |
833 |
Object fonts; |
791 |
Object fonts; |
834 |
|
792 |
|
835 |
resdict.dictLookupNF("Font", &fonts); |
793 |
fonts = resdict.dictLookupNF("Font"); |
836 |
if (fonts.isNull()) { |
794 |
if (fonts.isNull()) { |
837 |
/* Create new one, if doesn't exists */ |
795 |
/* Create new one, if doesn't exists */ |
838 |
fonts.initDict(xref); |
796 |
fonts = Object(new Dict(xref)); |
839 |
resdict.dictSet("Font", &fonts); |
797 |
resdict.dictSet("Font", std::move(fonts)); |
840 |
fprintf(stderr, "Create new font dict in page's resources.\n"); |
798 |
fprintf(stderr, "Create new font dict in page's resources.\n"); |
841 |
} |
799 |
} |
842 |
|
800 |
|
Lines 864-873
static int pdf_embed_font(pdf_t *doc,
Link Here
|
864 |
Object *cidfont_resource_dic = make_cidfont_dic(doc, Font, Fdes->fontname, r); |
822 |
Object *cidfont_resource_dic = make_cidfont_dic(doc, Font, Fdes->fontname, r); |
865 |
r = xref->addIndirectObject(cidfont_resource_dic); |
823 |
r = xref->addIndirectObject(cidfont_resource_dic); |
866 |
|
824 |
|
867 |
/* r - cid resource dic */ |
|
|
868 |
Object font_res_obj_ref; |
869 |
font_res_obj_ref.initRef(r.num, r.gen); |
870 |
|
871 |
Object *fonts_dic; |
825 |
Object *fonts_dic; |
872 |
Object dereferenced_obj; |
826 |
Object dereferenced_obj; |
873 |
|
827 |
|
Lines 876-882
static int pdf_embed_font(pdf_t *doc,
Link Here
|
876 |
fonts_dic = &fonts; |
830 |
fonts_dic = &fonts; |
877 |
} else if ( fonts.isRef() ) { |
831 |
} else if ( fonts.isRef() ) { |
878 |
/* "Font" resource is indirect reference object */ |
832 |
/* "Font" resource is indirect reference object */ |
879 |
xref->fetch(fonts.getRefNum(), fonts.getRefGen(), &dereferenced_obj); |
833 |
dereferenced_obj = xref->fetch(fonts.getRefNum(), fonts.getRefGen()); |
880 |
fonts_dic = &dereferenced_obj; |
834 |
fonts_dic = &dereferenced_obj; |
881 |
} |
835 |
} |
882 |
|
836 |
|
Lines 886-892
static int pdf_embed_font(pdf_t *doc,
Link Here
|
886 |
} |
840 |
} |
887 |
|
841 |
|
888 |
/* Add to fonts dic new font */ |
842 |
/* Add to fonts dic new font */ |
889 |
fonts_dic->dictSet("stanv_font", &font_res_obj_ref); |
843 |
/* r - cid resource dic */ |
|
|
844 |
fonts_dic->dictSet("stanv_font", Object(r.num, r.gen)); |
890 |
|
845 |
|
891 |
/* Notify poppler about changes in fonts dic */ |
846 |
/* Notify poppler about changes in fonts dic */ |
892 |
if ( fonts.isRef() ) { |
847 |
if ( fonts.isRef() ) { |
Lines 897-904
static int pdf_embed_font(pdf_t *doc,
Link Here
|
897 |
xref->setModifiedObject(&resdict, resref); |
852 |
xref->setModifiedObject(&resdict, resref); |
898 |
fprintf(stderr, "Resource dict was changed.\n"); |
853 |
fprintf(stderr, "Resource dict was changed.\n"); |
899 |
|
854 |
|
900 |
pageobj.free(); |
|
|
901 |
|
902 |
/* Success */ |
855 |
/* Success */ |
903 |
return 1; |
856 |
return 1; |
904 |
} |
857 |
} |
Lines 1104-1111
static Object *make_fontdescriptor_dic(
Link Here
|
1104 |
XRef *xref = doc->getXRef(); |
1057 |
XRef *xref = doc->getXRef(); |
1105 |
|
1058 |
|
1106 |
/* Font dictionary for embeded font */ |
1059 |
/* Font dictionary for embeded font */ |
1107 |
Object *dic = new Object(); |
1060 |
Object *dic = new Object(new Dict(xref)); |
1108 |
dic->initDict(xref); |
|
|
1109 |
|
1061 |
|
1110 |
dic->dictSet("Type", name_object("FontDescriptor")); |
1062 |
dic->dictSet("Type", name_object("FontDescriptor")); |
1111 |
dic->dictSet( |
1063 |
dic->dictSet( |
Lines 1119-1142
static Object *make_fontdescriptor_dic(
Link Here
|
1119 |
dic->dictSet("StemV", int_object(fdes->stemV)); |
1071 |
dic->dictSet("StemV", int_object(fdes->stemV)); |
1120 |
|
1072 |
|
1121 |
/* FontBox array */ |
1073 |
/* FontBox array */ |
1122 |
Object array; |
1074 |
Object array = Object(new Array(xref)); |
1123 |
array.initArray(xref); |
|
|
1124 |
|
1125 |
Object el; |
1126 |
|
1075 |
|
1127 |
el.initReal(fdes->bbxmin); |
1076 |
array.arrayAdd(Object(fdes->bbxmin)); |
1128 |
array.arrayAdd(&el); |
|
|
1129 |
|
1077 |
|
1130 |
el.initReal(fdes->bbymin); |
1078 |
array.arrayAdd(Object(fdes->bbymin)); |
1131 |
array.arrayAdd(&el); |
|
|
1132 |
|
1079 |
|
1133 |
el.initReal(fdes->bbxmax); |
1080 |
array.arrayAdd(Object(fdes->bbxmax)); |
1134 |
array.arrayAdd(&el); |
|
|
1135 |
|
1081 |
|
1136 |
el.initReal(fdes->bbymax); |
1082 |
array.arrayAdd(Object(fdes->bbymax)); |
1137 |
array.arrayAdd(&el); |
|
|
1138 |
|
1083 |
|
1139 |
dic->dictSet("FontBBox", &array); |
1084 |
dic->dictSet("FontBBox", std::move(array)); |
1140 |
|
1085 |
|
1141 |
if (fdes->xHeight) { |
1086 |
if (fdes->xHeight) { |
1142 |
dic->dictSet("XHeight", int_object(fdes->xHeight)); |
1087 |
dic->dictSet("XHeight", int_object(fdes->xHeight)); |
Lines 1148-1168
static Object *make_fontdescriptor_dic(
Link Here
|
1148 |
|
1093 |
|
1149 |
if (fdes->panose) { |
1094 |
if (fdes->panose) { |
1150 |
/* Font dictionary for embeded font */ |
1095 |
/* Font dictionary for embeded font */ |
1151 |
Object style_dic; |
1096 |
Object style_dic = Object(new Dict(xref)); |
1152 |
style_dic.initDict(xref); |
|
|
1153 |
|
1154 |
Object panose; |
1155 |
|
1097 |
|
1156 |
GooString *panose_str = new GooString(fdes->panose, 12); |
1098 |
GooString *panose_str = new GooString(fdes->panose, 12); |
1157 |
panose.initString(panose_str); |
1099 |
style_dic.dictSet("Panose", Object(panose_str)); |
1158 |
style_dic.dictSet("Panose", &panose); |
|
|
1159 |
|
1100 |
|
1160 |
dic->dictSet("Style", &style_dic); |
1101 |
dic->dictSet("Style", std::move(style_dic)); |
1161 |
} |
1102 |
} |
1162 |
|
1103 |
|
1163 |
Object ref_obj; |
1104 |
dic->dictSet(emb_pdf_get_fontfile_key(emb), Object(fontfile_obj_ref.num, fontfile_obj_ref.gen)); |
1164 |
ref_obj.initRef(fontfile_obj_ref.num, fontfile_obj_ref.gen); |
|
|
1165 |
dic->dictSet(emb_pdf_get_fontfile_key(emb), &ref_obj); |
1166 |
|
1105 |
|
1167 |
return dic; |
1106 |
return dic; |
1168 |
} |
1107 |
} |
Lines 1181-1188
static Object *make_font_dic(
Link Here
|
1181 |
/* Get XREF table */ |
1120 |
/* Get XREF table */ |
1182 |
XRef *xref = doc->getXRef(); |
1121 |
XRef *xref = doc->getXRef(); |
1183 |
|
1122 |
|
1184 |
Object *dic = new Object(); |
1123 |
Object *dic = new Object(new Dict(xref)); |
1185 |
dic->initDict(xref); |
|
|
1186 |
|
1124 |
|
1187 |
dic->dictSet("Type", name_object("Font")); |
1125 |
dic->dictSet("Type", name_object("Font")); |
1188 |
dic->dictSet( |
1126 |
dic->dictSet( |
Lines 1192-1223
static Object *make_font_dic(
Link Here
|
1192 |
"BaseFont", |
1130 |
"BaseFont", |
1193 |
name_object(copyString(emb_pdf_escape_name(fdes->fontname,-1)))); |
1131 |
name_object(copyString(emb_pdf_escape_name(fdes->fontname,-1)))); |
1194 |
|
1132 |
|
1195 |
Object ref_obj; |
1133 |
dic->dictSet("FontDescriptor", Object(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen)); |
1196 |
ref_obj.initRef(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen); |
|
|
1197 |
dic->dictSet("FontDescriptor", &ref_obj); |
1198 |
|
1134 |
|
1199 |
if ( emb->plan & EMB_A_MULTIBYTE ) { |
1135 |
if ( emb->plan & EMB_A_MULTIBYTE ) { |
1200 |
assert(fwid->warray); |
1136 |
assert(fwid->warray); |
1201 |
|
1137 |
|
1202 |
Object CIDSystemInfo_dic; |
1138 |
Object CIDSystemInfo_dic = Object(new Dict(xref)); |
1203 |
CIDSystemInfo_dic.initDict(xref); |
|
|
1204 |
|
1205 |
Object registry; |
1206 |
Object ordering; |
1207 |
|
1139 |
|
1208 |
GooString *str; |
1140 |
GooString *str; |
1209 |
|
1141 |
|
1210 |
str = new GooString(copyString(fdes->registry)); |
1142 |
str = new GooString(copyString(fdes->registry)); |
1211 |
registry.initString(str); |
1143 |
CIDSystemInfo_dic.dictSet("Registry", Object(str)); |
1212 |
CIDSystemInfo_dic.dictSet("Registry", ®istry); |
|
|
1213 |
|
1144 |
|
1214 |
str = new GooString(copyString(fdes->ordering)); |
1145 |
str = new GooString(copyString(fdes->ordering)); |
1215 |
ordering.initString(str); |
1146 |
CIDSystemInfo_dic.dictSet("Ordering", Object(str)); |
1216 |
CIDSystemInfo_dic.dictSet("Ordering", &ordering); |
|
|
1217 |
|
1147 |
|
1218 |
CIDSystemInfo_dic.dictSet("Supplement", int_object(fdes->supplement)); |
1148 |
CIDSystemInfo_dic.dictSet("Supplement", int_object(fdes->supplement)); |
1219 |
|
1149 |
|
1220 |
dic->dictSet("CIDSystemInfo", &CIDSystemInfo_dic); |
1150 |
dic->dictSet("CIDSystemInfo", std::move(CIDSystemInfo_dic)); |
1221 |
|
1151 |
|
1222 |
dic->dictSet("DW", int_object(fwid->default_width)); |
1152 |
dic->dictSet("DW", int_object(fwid->default_width)); |
1223 |
} |
1153 |
} |
Lines 1249-1256
static Object *make_cidfont_dic(
Link Here
|
1249 |
/* Get XREF table */ |
1179 |
/* Get XREF table */ |
1250 |
XRef *xref = doc->getXRef(); |
1180 |
XRef *xref = doc->getXRef(); |
1251 |
|
1181 |
|
1252 |
Object *dic = new Object(); |
1182 |
Object *dic = new Object(new Dict(xref)); |
1253 |
dic->initDict(xref); |
|
|
1254 |
|
1183 |
|
1255 |
dic->dictSet("Type", name_object("Font")); |
1184 |
dic->dictSet("Type", name_object("Font")); |
1256 |
dic->dictSet("Subtype", name_object("Type0")); |
1185 |
dic->dictSet("Subtype", name_object("Type0")); |
Lines 1266-1279
static Object *make_cidfont_dic(
Link Here
|
1266 |
|
1195 |
|
1267 |
dic->dictSet("Encoding", name_object(copyString(encoding))); |
1196 |
dic->dictSet("Encoding", name_object(copyString(encoding))); |
1268 |
|
1197 |
|
1269 |
Object obj; |
1198 |
Object array = Object(new Array(xref)); |
1270 |
obj.initRef(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen); |
1199 |
array.arrayAdd(Object(fontdescriptor_obj_ref.num, fontdescriptor_obj_ref.gen)); |
1271 |
|
|
|
1272 |
Object array; |
1273 |
array.initArray(xref); |
1274 |
array.arrayAdd(&obj); |
1275 |
|
1200 |
|
1276 |
dic->dictSet("DescendantFonts", &array); |
1201 |
dic->dictSet("DescendantFonts", std::move(array)); |
1277 |
|
1202 |
|
1278 |
return dic; |
1203 |
return dic; |
1279 |
} |
1204 |
} |