| 1871 | |
| 1872 | |
| 1873 | class RendererPdf(_backend_pdf_ps.RendererPDFPSBase): |
| 1874 | |
| 1875 | _afm_font_dir = cbook._get_data_path("fonts/pdfcorefonts") |
| 1876 | _use_afm_rc_name = "pdf.use14corefonts" |
| 1877 | |
| 1878 | def __init__(self, file, image_dpi, height, width): |
| 1879 | super().__init__(width, height) |
| 1880 | self.file = file |
| 1881 | self.gc = self.new_gc() |
| 1882 | self.image_dpi = image_dpi |
| 1883 | |
| 1884 | def finalize(self): |
| 1885 | self.file.output(*self.gc.finalize()) |
| 1886 | |
| 1887 | def check_gc(self, gc, fillcolor=None): |
| 1888 | orig_fill = getattr(gc, '_fillcolor', (0., 0., 0.)) |
| 1889 | gc._fillcolor = fillcolor |
| 1890 | |
| 1891 | orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0)) |
| 1892 | |
| 1893 | if gc.get_rgb() is None: |
| 1894 | # It should not matter what color here since linewidth should be |
| 1895 | # 0 unless affected by global settings in rcParams, hence setting |
| 1896 | # zero alpha just in case. |
| 1897 | gc.set_foreground((0, 0, 0, 0), isRGBA=True) |
| 1898 | |
| 1899 | if gc._forced_alpha: |
| 1900 | gc._effective_alphas = (gc._alpha, gc._alpha) |
| 1901 | elif fillcolor is None or len(fillcolor) < 4: |
| 1902 | gc._effective_alphas = (gc._rgb[3], 1.0) |
| 1903 | else: |
| 1904 | gc._effective_alphas = (gc._rgb[3], fillcolor[3]) |
| 1905 | |
| 1906 | delta = self.gc.delta(gc) |
| 1907 | if delta: |
| 1908 | self.file.output(*delta) |
| 1909 | |
| 1910 | # Restore gc to avoid unwanted side effects |
| 1911 | gc._fillcolor = orig_fill |
| 1912 | gc._effective_alphas = orig_alphas |
| 1913 | |
| 1914 | def get_image_magnification(self): |
| 1915 | return self.image_dpi/72.0 |
| 1916 | |
| 1917 | def draw_image(self, gc, x, y, im, transform=None): |
| 1918 | # docstring inherited |
| 1919 | |
| 1920 | h, w = im.shape[:2] |
| 1921 | if w == 0 or h == 0: |
| 1922 | return |
| 1923 | |
| 1924 | if transform is None: |
| 1925 | # If there's no transform, alpha has already been applied |
| 1926 | gc.set_alpha(1.0) |
| 1927 | |
| 1928 | self.check_gc(gc) |
| 1929 | |
| 1930 | w = 72.0 * w / self.image_dpi |
no outgoing calls
no test coverage detected
searching dependent graphs…