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

Method _set_opacity

src/__init__.py:10212–10243  ·  view source on GitHub ↗
(self, gstate=None, CA=1, ca=1, blendmode=None)

Source from the content-addressed store, hash-verified

10210 self._annot_refs.clear()
10211
10212 def _set_opacity(self, gstate=None, CA=1, ca=1, blendmode=None):
10213
10214 if CA >= 1 and ca >= 1 and blendmode is None:
10215 return
10216 tCA = int(round(max(CA , 0) * 100))
10217 if tCA >= 100:
10218 tCA = 99
10219 tca = int(round(max(ca, 0) * 100))
10220 if tca >= 100:
10221 tca = 99
10222 gstate = f"fitzca{tCA:02d}{tca:02d}"
10223
10224 if not gstate:
10225 return
10226 page = _as_pdf_page(self.this)
10227 resources = mupdf.pdf_dict_get(page.obj(), PDF_NAME('Resources'))
10228 if not resources.m_internal:
10229 resources = mupdf.pdf_dict_put_dict(page.obj(), PDF_NAME('Resources'), 2)
10230 extg = mupdf.pdf_dict_get(resources, PDF_NAME('ExtGState'))
10231 if not extg.m_internal:
10232 extg = mupdf.pdf_dict_put_dict(resources, PDF_NAME('ExtGState'), 2)
10233 n = mupdf.pdf_dict_len(extg)
10234 for i in range(n):
10235 o1 = mupdf.pdf_dict_get_key(extg, i)
10236 name = mupdf.pdf_to_name(o1)
10237 if name == gstate:
10238 return gstate
10239 opa = mupdf.pdf_new_dict(page.doc(), 3)
10240 mupdf.pdf_dict_put_real(opa, PDF_NAME('CA'), CA)
10241 mupdf.pdf_dict_put_real(opa, PDF_NAME('ca'), ca)
10242 mupdf.pdf_dict_puts(extg, gstate, opa)
10243 return gstate
10244
10245 def _set_pagebox(self, boxtype, rect):
10246 doc = self.parent

Callers 7

insert_htmlboxMethod · 0.80
insert_textMethod · 0.80
insert_textboxMethod · 0.80
finishMethod · 0.80
insert_textMethod · 0.80
insert_textboxMethod · 0.80
finishMethod · 0.80

Calls 2

_as_pdf_pageFunction · 0.85
PDF_NAMEFunction · 0.85

Tested by

no test coverage detected