MCPcopy Create free account
hub / github.com/TeXworks/texworks / toPDFDestination

Function toPDFDestination

modules/QtPDF/src/backends/MuPDFBackend.cpp:72–254  ·  view source on GitHub ↗

TODO: Find a better place to put this

Source from the content-addressed store, hash-verified

70
71// TODO: Find a better place to put this
72PDFDestination toPDFDestination(pdf_xref * xref, fz_obj * dest)
73{
74 PDFDestination retVal;
75
76 if (!dest)
77 return PDFDestination();
78 if (fz_is_name(dest))
79 return PDFDestination(QString::fromAscii(fz_to_name(dest)));
80 if (fz_is_string(dest))
81 return PDFDestination(QString::fromAscii(fz_to_str_buf(dest)));
82
83 if (fz_is_array(dest)) {
84 // Structure of pdf_link->dest:
85 // array w/ >= 2 entries:
86 // - dict which can be passed to pdf_find_page_number
87 // - name: /XYZ, /FIT, ...
88 // - numbers or nulls as required by /XYZ, /FIT, ...
89 // TODO: How do external links look like? Or are remote gotos not
90 // included in pdf_link structures? Do we need to go through all
91 // annotations, then?
92 // TODO: Check other types than /XYZ
93 if (fz_array_len(dest) < 2)
94 return PDFDestination();
95
96 fz_obj * obj;
97
98 obj = fz_array_get(dest, 0);
99 if (fz_is_int(obj))
100 retVal.setPage(fz_to_int(obj));
101 else if (fz_is_dict(obj))
102 retVal.setPage(pdf_find_page_number(xref, obj));
103 else
104 return PDFDestination();
105
106 if (!fz_is_name(fz_array_get(dest, 1)))
107 return PDFDestination();
108 QString type = QString::fromAscii(fz_to_name(fz_array_get(dest, 1)));
109
110 // /XYZ left top zoom
111 if (type == QString::fromUtf8("XYZ")) {
112 float left, top, zoom;
113 if (fz_array_len(dest) != 5)
114 return PDFDestination();
115 obj = fz_array_get(dest, 2);
116 if (fz_is_real(obj) || fz_is_int(obj))
117 left = fz_to_real(obj);
118 else if (fz_is_null(obj))
119 left = -1;
120 else
121 return PDFDestination();
122 obj = fz_array_get(dest, 3);
123 if (fz_is_real(obj) || fz_is_int(obj))
124 top = fz_to_real(obj);
125 else if (fz_is_null(obj))
126 top = -1;
127 else
128 return PDFDestination();
129 obj = fz_array_get(dest, 4);

Callers 3

resolveDestinationMethod · 0.70
recursiveConvertToCMethod · 0.70
loadLinksMethod · 0.70

Calls 5

PDFDestinationClass · 0.85
setTypeMethod · 0.80
setPageMethod · 0.45
setRectMethod · 0.45
setZoomMethod · 0.45

Tested by

no test coverage detected