1 #include "qpdf_tools.h"
2
getMediaBox(QPDFObjectHandle page)3 QPDFObjectHandle getMediaBox(QPDFObjectHandle page) // {{{
4 {
5 return page.getKey("/MediaBox");
6 }
7 // }}}
8
getCropBox(QPDFObjectHandle page)9 QPDFObjectHandle getCropBox(QPDFObjectHandle page) // {{{
10 {
11 if (page.hasKey("/CropBox")) {
12 return page.getKey("/CropBox");
13 }
14 return page.getKey("/MediaBox");
15 }
16 // }}}
17
getBleedBox(QPDFObjectHandle page)18 QPDFObjectHandle getBleedBox(QPDFObjectHandle page) // {{{
19 {
20 if (page.hasKey("/BleedBox")) {
21 return page.getKey("/BleedBox");
22 }
23 return getCropBox(page);
24 }
25 // }}}
26
getTrimBox(QPDFObjectHandle page)27 QPDFObjectHandle getTrimBox(QPDFObjectHandle page) // {{{
28 {
29 if (page.hasKey("/TrimBox")) {
30 return page.getKey("/TrimBox");
31 }
32 return getCropBox(page);
33 }
34 // }}}
35
getArtBox(QPDFObjectHandle page)36 QPDFObjectHandle getArtBox(QPDFObjectHandle page) // {{{
37 {
38 if (page.hasKey("/ArtBox")) {
39 return page.getKey("/ArtBox");
40 }
41 return getCropBox(page);
42 }
43 // }}}
44
makePage(QPDF & pdf,const std::map<std::string,QPDFObjectHandle> & xobjs,QPDFObjectHandle mediabox,const std::string & content)45 QPDFObjectHandle makePage(QPDF &pdf,const std::map<std::string,QPDFObjectHandle> &xobjs,QPDFObjectHandle mediabox,const std::string &content) // {{{
46 {
47 QPDFObjectHandle ret=QPDFObjectHandle::newDictionary();
48 ret.replaceKey("/Type",QPDFObjectHandle::newName("/Page"));
49
50 auto resdict=QPDFObjectHandle::newDictionary();
51 resdict.replaceKey("/XObject",QPDFObjectHandle::newDictionary(xobjs));
52 ret.replaceKey("/Resources",resdict);
53 ret.replaceKey("/MediaBox",mediabox);
54 ret.replaceKey("/Contents",QPDFObjectHandle::newStream(&pdf,content));
55
56 return ret;
57 }
58 // }}}
59
makeBox(double x1,double y1,double x2,double y2)60 QPDFObjectHandle makeBox(double x1,double y1,double x2,double y2) // {{{
61 {
62 QPDFObjectHandle ret=QPDFObjectHandle::newArray();
63 ret.appendItem(QPDFObjectHandle::newReal(x1));
64 ret.appendItem(QPDFObjectHandle::newReal(y1));
65 ret.appendItem(QPDFObjectHandle::newReal(x2));
66 ret.appendItem(QPDFObjectHandle::newReal(y2));
67 return ret;
68 }
69 // }}}
70