From: Scott Worley Date: Sun, 31 Dec 2023 22:37:57 +0000 (-0800) Subject: Learning TeX: Render icon images with TeX command X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/5f230208bb5e858cfeadb3d9c822579d2b7b8300?ds=inline;hp=9afdb32a9385204c13018198a136637ad599df47 Learning TeX: Render icon images with TeX command --- diff --git a/glowfic.py b/glowfic.py index 4c108b8..b7e7ba7 100644 --- a/glowfic.py +++ b/glowfic.py @@ -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)) diff --git a/paperdoorknob.py b/paperdoorknob.py index 8183136..0fb3fe1 100644 --- a/paperdoorknob.py +++ b/paperdoorknob.py @@ -37,6 +37,9 @@ def process(spec: Spec) -> None: spec.texout.write(br'''\begin{document} \newcommand{\href}[2]{#2\footnote{\detokenize{#1}}} \def\glowiconsize{%fmm} +\newcommand{\glowicon}[1]{\includegraphics[ + width=\glowiconsize,height=\glowiconsize,keepaspectratio +]{#1}} ''' % spec.icon_size) url = flatURL(spec.url) spec.log('Fetching HTML...\r')