MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / _parse_da

Method _parse_da

src/__init__.py:25130–25182  ·  view source on GitHub ↗
(annot)

Source from the content-addressed store, hash-verified

25128
25129 @staticmethod
25130 def _parse_da(annot):
25131
25132 if g_use_extra:
25133 val = extra.Tools_parse_da( annot.this)
25134 else:
25135 def Tools__parse_da(annot):
25136 this_annot = annot.this
25137 assert isinstance(this_annot, mupdf.PdfAnnot)
25138 this_annot_obj = mupdf.pdf_annot_obj( this_annot)
25139 pdf = mupdf.pdf_get_bound_document( this_annot_obj)
25140 try:
25141 da = mupdf.pdf_dict_get_inheritable( this_annot_obj, PDF_NAME('DA'))
25142 if not da.m_internal:
25143 trailer = mupdf.pdf_trailer(pdf)
25144 da = mupdf.pdf_dict_getl(trailer,
25145 PDF_NAME('Root'),
25146 PDF_NAME('AcroForm'),
25147 PDF_NAME('DA'),
25148 )
25149 da_str = mupdf.pdf_to_text_string(da)
25150 except Exception:
25151 if g_exceptions_verbose: exception_info()
25152 return
25153 return da_str
25154 val = Tools__parse_da(annot)
25155
25156 if not val:
25157 return ((0,), "", 0)
25158 font = "Helv"
25159 fsize = 12
25160 col = (0, 0, 0)
25161 dat = val.split() # split on any whitespace
25162 for i, item in enumerate(dat):
25163 if item == "Tf":
25164 font = dat[i - 2][1:]
25165 fsize = float(dat[i - 1])
25166 dat[i] = dat[i-1] = dat[i-2] = ""
25167 continue
25168 if item == "g": # unicolor text
25169 col = [(float(dat[i - 1]))]
25170 dat[i] = dat[i-1] = ""
25171 continue
25172 if item == "rg": # RGB colored text
25173 col = [float(f) for f in dat[i - 3:i]]
25174 dat[i] = dat[i-1] = dat[i-2] = dat[i-3] = ""
25175 continue
25176 if item == "k": # CMYK colored text
25177 col = [float(f) for f in dat[i - 4:i]]
25178 dat[i] = dat[i-1] = dat[i-2] = dat[i-3] = dat[i-4] = ""
25179 continue
25180
25181 val = (col, font, fsize)
25182 return val
25183
25184 @staticmethod
25185 def _reset_widget(annot):

Callers 3

_get_redact_valuesMethod · 0.45
updateMethod · 0.45
JM_get_widget_propertiesFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected