Invoke named XObject
(self, xobjid_arg: PDFStackT)
| 194 | return self.do_scn() |
| 195 | |
| 196 | def do_Do(self, xobjid_arg: PDFStackT) -> None: |
| 197 | # 重载设置 xobj 的 obj_patch |
| 198 | """Invoke named XObject""" |
| 199 | xobjid = literal_name(xobjid_arg) |
| 200 | try: |
| 201 | xobj = stream_value(self.xobjmap[xobjid]) |
| 202 | except KeyError: |
| 203 | if settings.STRICT: |
| 204 | raise PDFInterpreterError("Undefined xobject id: %r" % xobjid) |
| 205 | return |
| 206 | # log.debug("Processing xobj: %r", xobj) |
| 207 | subtype = xobj.get("Subtype") |
| 208 | if subtype is LITERAL_FORM and "BBox" in xobj: |
| 209 | interpreter = self.dup() |
| 210 | bbox = cast(Rect, list_value(xobj["BBox"])) |
| 211 | matrix = cast(Matrix, list_value(xobj.get("Matrix", MATRIX_IDENTITY))) |
| 212 | # According to PDF reference 1.7 section 4.9.1, XObjects in |
| 213 | # earlier PDFs (prior to v1.2) use the page's Resources entry |
| 214 | # instead of having their own Resources entry. |
| 215 | xobjres = xobj.get("Resources") |
| 216 | if xobjres: |
| 217 | resources = dict_value(xobjres) |
| 218 | else: |
| 219 | resources = self.resources.copy() |
| 220 | self.device.begin_figure(xobjid, bbox, matrix) |
| 221 | ctm = mult_matrix(matrix, self.ctm) |
| 222 | ops_base = interpreter.render_contents( |
| 223 | resources, |
| 224 | [xobj], |
| 225 | ctm=ctm, |
| 226 | ) |
| 227 | self.ncs = interpreter.ncs |
| 228 | self.scs = interpreter.scs |
| 229 | try: # 有的时候 form 字体加不上这里会烂掉 |
| 230 | self.device.fontid = interpreter.fontid |
| 231 | self.device.fontmap = interpreter.fontmap |
| 232 | ops_new = self.device.end_figure(xobjid) |
| 233 | ctm_inv = np.linalg.inv(np.array(ctm[:4]).reshape(2, 2)) |
| 234 | np_version = np.__version__ |
| 235 | if np_version.split(".")[0] >= "2": |
| 236 | pos_inv = -np.asmatrix(ctm[4:]) * ctm_inv |
| 237 | else: |
| 238 | pos_inv = -np.mat(ctm[4:]) * ctm_inv |
| 239 | a, b, c, d = ctm_inv.reshape(4).tolist() |
| 240 | e, f = pos_inv.tolist()[0] |
| 241 | self.obj_patch[self.xobjmap[xobjid].objid] = ( |
| 242 | f"q {ops_base}Q {a} {b} {c} {d} {e} {f} cm {ops_new}" |
| 243 | ) |
| 244 | except Exception: |
| 245 | pass |
| 246 | elif subtype is LITERAL_IMAGE and "Width" in xobj and "Height" in xobj: |
| 247 | self.device.begin_figure(xobjid, (0, 0, 1, 1), MATRIX_IDENTITY) |
| 248 | self.device.render_image(xobjid, xobj) |
| 249 | self.device.end_figure(xobjid) |
| 250 | else: |
| 251 | # unsupported xobject type. |
| 252 | pass |
| 253 |
nothing calls this directly
no test coverage detected