A class for storing Font properties. It is used when populating the font lookup dictionary.
| 391 | |
| 392 | @dataclasses.dataclass(frozen=True) |
| 393 | class FontEntry: |
| 394 | """ |
| 395 | A class for storing Font properties. |
| 396 | |
| 397 | It is used when populating the font lookup dictionary. |
| 398 | """ |
| 399 | |
| 400 | fname: str = '' |
| 401 | index: int = 0 |
| 402 | name: str = '' |
| 403 | style: str = 'normal' |
| 404 | variant: str = 'normal' |
| 405 | weight: str | int = 'normal' |
| 406 | stretch: str = 'normal' |
| 407 | size: str = 'medium' |
| 408 | |
| 409 | def _repr_html_(self) -> str: |
| 410 | png_stream = self._repr_png_() |
| 411 | png_b64 = b64encode(png_stream).decode() |
| 412 | return f"<img src=\"data:image/png;base64, {png_b64}\" />" |
| 413 | |
| 414 | def _repr_png_(self) -> bytes: |
| 415 | from matplotlib.figure import Figure # Circular import. |
| 416 | fig = Figure() |
| 417 | font_path = Path(self.fname) if self.fname != '' else None |
| 418 | fig.text(0, 0, self.name, font=font_path) |
| 419 | with BytesIO() as buf: |
| 420 | fig.savefig(buf, bbox_inches='tight', transparent=True) |
| 421 | return buf.getvalue() |
| 422 | |
| 423 | |
| 424 | def ttfFontProperty(font): |
no outgoing calls
searching dependent graphs…