Generate value of one item of the names dictionary.
(val)
| 6349 | return JM_UnicodeFromBuffer(buffer) |
| 6350 | |
| 6351 | def get_array(val): |
| 6352 | """Generate value of one item of the names dictionary.""" |
| 6353 | templ_dict = {"page": -1, "dest": ""} # value template |
| 6354 | if val.pdf_is_indirect(): |
| 6355 | val = mupdf.pdf_resolve_indirect(val) |
| 6356 | if val.pdf_is_array(): |
| 6357 | array = obj_string(val) |
| 6358 | elif val.pdf_is_dict(): |
| 6359 | array = obj_string(mupdf.pdf_dict_gets(val, "D")) |
| 6360 | else: # if all fails return the empty template |
| 6361 | return templ_dict |
| 6362 | |
| 6363 | # replace PDF "null" by zero, omit the square brackets |
| 6364 | array = array.replace("null", "0")[1:-1] |
| 6365 | |
| 6366 | # find stuff before first "/" |
| 6367 | idx = array.find("/") |
| 6368 | if idx < 1: # this has no target page spec |
| 6369 | templ_dict["dest"] = array # return the orig. string |
| 6370 | return templ_dict |
| 6371 | |
| 6372 | subval = array[:idx].strip() # stuff before "/" |
| 6373 | array = array[idx:] # stuff from "/" onwards |
| 6374 | templ_dict["dest"] = array |
| 6375 | # if we start with /XYZ: extract x, y, zoom |
| 6376 | # 1, 2 or 3 of these values may actually be supplied |
| 6377 | if array.startswith("/XYZ"): |
| 6378 | del templ_dict["dest"] # don't return orig string in this case |
| 6379 | |
| 6380 | # make a list of the 3 tokens following "/XYZ" |
| 6381 | array_list = array.split()[1:4] # omit "/XYZ" |
| 6382 | |
| 6383 | # fill up missing tokens with "0" strings |
| 6384 | while len(array_list) < 3: # fill up if too short |
| 6385 | array_list.append("0") # add missing values |
| 6386 | |
| 6387 | # make list of 3 floats: x, y and zoom |
| 6388 | t = list(map(float, array_list)) # the resulting x, y, z values |
| 6389 | templ_dict["to"] = (t[0], t[1]) |
| 6390 | templ_dict["zoom"] = t[2] |
| 6391 | |
| 6392 | # extract page number |
| 6393 | if subval.endswith("0 R"): # page xref given? |
| 6394 | templ_dict["page"] = page_xrefs.get(int(subval.split()[0]),-1) |
| 6395 | else: # naked page number given |
| 6396 | templ_dict["page"] = int(subval) |
| 6397 | return templ_dict |
| 6398 | |
| 6399 | def fill_dict(dest_dict, pdf_dict): |
| 6400 | """Generate name resolution items for pdf_dict. |