The renderer handles all the drawing primitives using a graphics context instance that controls the colors/styles.
| 395 | |
| 396 | |
| 397 | class RendererPS(_backend_pdf_ps.RendererPDFPSBase): |
| 398 | """ |
| 399 | The renderer handles all the drawing primitives using a graphics |
| 400 | context instance that controls the colors/styles. |
| 401 | """ |
| 402 | |
| 403 | _afm_font_dir = cbook._get_data_path("fonts/afm") |
| 404 | _use_afm_rc_name = "ps.useafm" |
| 405 | |
| 406 | def __init__(self, width, height, pswriter, imagedpi=72): |
| 407 | # Although postscript itself is dpi independent, we need to inform the |
| 408 | # image code about a requested dpi to generate high resolution images |
| 409 | # and then scale them before embedding them. |
| 410 | super().__init__(width, height) |
| 411 | self._pswriter = pswriter |
| 412 | if mpl.rcParams['text.usetex']: |
| 413 | self.textcnt = 0 |
| 414 | self.psfrag = [] |
| 415 | self.imagedpi = imagedpi |
| 416 | |
| 417 | # current renderer state (None=uninitialised) |
| 418 | self.color = None |
| 419 | self.linewidth = None |
| 420 | self.linejoin = None |
| 421 | self.linecap = None |
| 422 | self.linedash = None |
| 423 | self.fontname = None |
| 424 | self.fontsize = None |
| 425 | self._hatches = {} |
| 426 | self.image_magnification = imagedpi / 72 |
| 427 | self._clip_paths = {} |
| 428 | self._path_collection_id = 0 |
| 429 | |
| 430 | self._character_tracker = _backend_pdf_ps.CharacterTracker( |
| 431 | _backend_pdf_ps._FONT_MAX_GLYPH.get(mpl.rcParams['ps.fonttype'], 0)) |
| 432 | self._logwarn_once = functools.cache(_log.warning) |
| 433 | |
| 434 | def _is_transparent(self, rgb_or_rgba): |
| 435 | if rgb_or_rgba is None: |
| 436 | return True # Consistent with rgbFace semantics. |
| 437 | elif len(rgb_or_rgba) == 4: |
| 438 | if rgb_or_rgba[3] == 0: |
| 439 | return True |
| 440 | if rgb_or_rgba[3] != 1: |
| 441 | self._logwarn_once( |
| 442 | "The PostScript backend does not support transparency; " |
| 443 | "partially transparent artists will be rendered opaque.") |
| 444 | return False |
| 445 | else: # len() == 3. |
| 446 | return False |
| 447 | |
| 448 | def set_color(self, r, g, b, store=True): |
| 449 | if (r, g, b) != self.color: |
| 450 | self._pswriter.write(f"{_nums_to_str(r)} setgray\n" |
| 451 | if r == g == b else |
| 452 | f"{_nums_to_str(r, g, b)} setrgbcolor\n") |
| 453 | if store: |
| 454 | self.color = (r, g, b) |
no outgoing calls
no test coverage detected
searching dependent graphs…