]> git.scottworley.com Git - paperdoorknob/blobdiff - glowfic.py
Learning TeX: Render icon images with TeX command
[paperdoorknob] / glowfic.py
index 4c108b8310dc3441e373c08c11854f4ff8405c0d..b7e7ba740b33f82fbebd43ea9c1c4ffa36bc1973 100644 (file)
@@ -111,14 +111,6 @@ def makeChunk(chunk_dom: Tag, image_store: ImageStore) -> Chunk:
                  content)
 
 
-def renderIcon(icon_path: str | None) -> bytes | None:
-    if icon_path is None:
-        return None
-    return (
-        br'\includegraphics[width=\glowiconsize,height=\glowiconsize,keepaspectratio]{%s}' %
-        icon_path.encode('UTF-8'))
-
-
 class Layout(ABC):
 
     @abstractmethod
@@ -141,8 +133,9 @@ class BelowIconLayout(Layout):
         self._texifier = texifier
 
     def renderChunk(self, chunk: Chunk) -> bytes:
-        icon = renderIcon(chunk.icon)
-        meta = [icon] if icon else []
+        meta = []
+        if chunk.icon:
+            meta += [br'\glowicon{%s}' % chunk.icon.encode('UTF-8')]
         meta += [self._texifier.texify(x)
                  for x in [chunk.character, chunk.screen_name, chunk.author]
                  if x is not None]
@@ -179,7 +172,6 @@ class BesideIconLayout(Layout):
         self._texifier = texifier
 
     def renderChunk(self, chunk: Chunk) -> bytes:
-        icon = renderIcon(chunk.icon)
         meta = [
             chunk.character,
             chunk.screen_name,
@@ -202,6 +194,6 @@ class BesideIconLayout(Layout):
 \strut
 
 ''' % (
-            icon if icon else b'',
+            br'\glowicon{%s}' % chunk.icon.encode('UTF-8') if chunk.icon else b'',
             br'\\*'.join(self._texifier.texify(x) for x in meta if x is not None),
             self._texifier.texify(chunk.content))