z0u commited on
Commit
3ae03c9
·
unverified ·
1 Parent(s): be6b4d7

providing own font as CSS import

Browse files
Files changed (1) hide show
  1. src/sparky/sparky.py +14 -2
src/sparky/sparky.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import xml.etree.ElementTree as ET
2
 
3
  from .utils.dom import Element
@@ -107,7 +108,6 @@ class Sparky:
107
  text_elem = Element(
108
  parent,
109
  "text",
110
- font_family="Courier",
111
  font_size=self.font_size,
112
  y=baseline,
113
  text_anchor="middle",
@@ -145,7 +145,19 @@ class Sparky:
145
  xmlns="http://www.w3.org/2000/svg",
146
  style="background-color: var(--bg-color); box-shadow: 0 0 0 10px var(--bg-color);",
147
  )
148
- Element(svg, "style", text="text { white-space: pre; }")
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
  # Add text content and sparklines
151
  sparkline = Sparkline()
 
1
+ from textwrap import dedent
2
  import xml.etree.ElementTree as ET
3
 
4
  from .utils.dom import Element
 
108
  text_elem = Element(
109
  parent,
110
  "text",
 
111
  font_size=self.font_size,
112
  y=baseline,
113
  text_anchor="middle",
 
145
  xmlns="http://www.w3.org/2000/svg",
146
  style="background-color: var(--bg-color); box-shadow: 0 0 0 10px var(--bg-color);",
147
  )
148
+ Element(
149
+ svg,
150
+ "style",
151
+ text=dedent("""
152
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Source+Code+Pro&display=swap');
153
+ text {
154
+ font-family: "Source Code Pro", "Noto Sans Mono", monospace !important;
155
+ font-optical-sizing: auto;
156
+ font-weight: 400;
157
+ white-space: pre;
158
+ }
159
+ """),
160
+ )
161
 
162
  # Add text content and sparklines
163
  sparkline = Sparkline()