mirror of
https://github.com/jdejaegh/irm-kmi-ha.git
synced 2025-06-27 03:35:56 +02:00
Use inlined base64 representation of the font instead of opening the file
This commit is contained in:
parent
7f9cca4960
commit
ea23f0da2c
2 changed files with 1966 additions and 7 deletions
|
@ -12,10 +12,12 @@ from aiofile import async_open
|
||||||
from homeassistant.util import dt
|
from homeassistant.util import dt
|
||||||
from svgwrite import Drawing
|
from svgwrite import Drawing
|
||||||
from svgwrite.animate import Animate
|
from svgwrite.animate import Animate
|
||||||
|
from svgwrite.container import FONT_TEMPLATE
|
||||||
from svgwrite.utils import font_mimetype
|
from svgwrite.utils import font_mimetype
|
||||||
|
|
||||||
from .api import IrmKmiApiClient
|
from .api import IrmKmiApiClient
|
||||||
from .radar_data import AnimationFrameData, RadarAnimationData
|
from .radar_data import AnimationFrameData, RadarAnimationData
|
||||||
|
from .roboto import roboto_b64
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -149,15 +151,11 @@ class RainGraph:
|
||||||
|
|
||||||
async def draw_svg_frame(self):
|
async def draw_svg_frame(self):
|
||||||
"""Create the global area to draw the other items"""
|
"""Create the global area to draw the other items"""
|
||||||
font_file = os.path.join(self._config_dir, 'custom_components/irm_kmi/resources/roboto_medium.ttf')
|
mimetype = "application/x-font-ttf"
|
||||||
_LOGGER.debug(f"Opening font file at {font_file}")
|
|
||||||
|
|
||||||
async with async_open(font_file, 'rb') as font:
|
content = FONT_TEMPLATE.format(name="Roboto Medium", data=f"data:{mimetype};charset=utf-8;base64,{roboto_b64}")
|
||||||
data = await font.read()
|
self._dwg.embed_stylesheet(content)
|
||||||
|
|
||||||
# Need to use the private class method as the public one does not offer an async call
|
|
||||||
# As this is run in the main loop, we cannot afford a blocking open() call
|
|
||||||
self._dwg._embed_font_data("Roboto Medium", data, font_mimetype(font_file))
|
|
||||||
self._dwg.embed_stylesheet("""
|
self._dwg.embed_stylesheet("""
|
||||||
.roboto {
|
.roboto {
|
||||||
font-family: "Roboto Medium";
|
font-family: "Roboto Medium";
|
||||||
|
|
1961
custom_components/irm_kmi/roboto.py
Normal file
1961
custom_components/irm_kmi/roboto.py
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue