Debian Codegraph @

texmf-dist/source/latex/char2path/char2path.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: char2path.dtx
4 % -----------------------------------------------------------------------
5 % Copyright (C) 2025 by zongpingding <[email protected]> and *
6 % Mingyu Xia <[email protected]> *
7 % *
8 % This work may be distributed and/or modified under the conditions *
9 % of the LaTeX Project Public License (LPPL), either version 1.3c of *
10 % this license or (at your option) any later version. *
11 % The latest version of this license is in *
12 % *
13 % http://www.latex-project.org/lppl.txt *
14 % *
15 % and version 1.3c or later is part of all distributions of LaTeX *
16 % version 2008 or later. *
17 % *
18 % This work has the LPPL maintenance status `maintained'. *
19 % *
20 % The Current Maintainer of this work is zongpingding and Mingyu Xia. *
21 % *
22 % This work consists of the files char2path.dtx, *
23 % ctp-lmdata.dtx, *
24 % char2path.ins, *
25 % the derived files char2path.sty, *
26 % ctp-lmr-arabic.data.tex, *
27 % ctp-lmr-alpha-small.data.tex, *
28 % ctp-lmr-alpha-caps.data.tex, *
29 % ctp-lmr-others.data.tex, *
30 % ctp-lms-arabic.data.tex, *
31 % ctp-lms-alpha-small.data.tex, *
32 % ctp-lms-alpha-caps.data.tex, *
33 % ctp-lms-others.data.tex, *
34 % ctp-lmm-arabic.data.tex, *
35 % ctp-lmm-alpha-small.data.tex, *
36 % ctp-lmm-alpha-caps.data.tex, *
37 % ctp-lmm-others.data.tex, *
38 % the documentation files char2path.pdf, *
39 % and README.md. *
40 % -----------------------------------------------------------------------
41 %
42 % Any modification of this file should ensure that the copyright and
43 % license information is placed in the derived files.
44 %
45 % -----------------------------------------------------------------------
46 %
47 %<*internal>
48 \iffalse
49 %</internal>
50 %
51 %<*readme>
52 [![CTAN Version](https://img.shields.io/ctan/v/char2path)](https://ctan.org/pkg/char2path)
53 [![GitHub Release](https://img.shields.io/github/v/release/zongpingding/char2path)](https://github.com/zongpingding/char2path/releases/latest)
54 [![GitHub Last Commit](https://img.shields.io/github/last-commit/zongpingding/char2path)](https://github.com/zongpingding/char2path/commits)
55 [![Actions Status](https://github.com/zongpingding/char2path/actions/workflows/main.yaml/badge.svg?branch=main)](https://github.com/zongpingding/char2path/actions)
56 [![GitHub Repo stars](https://img.shields.io/github/stars/zongpingding/char2path)](https://github.com/zongpingding/char2path)
57
58 The `char2path` Package
59 =======================
60
61 The `char2path` package provides a LaTeX package for converting characters into TikZ paths.
62
63 Overview
64 --------
65
66 The package provides the `\chartopath` and `\chartoclip` macro
67
68 \chartopath [<keys>] {<string>}
69 \chartoclip [<keys>] {<string>}
70
71 to print Ti*k*Z paths for characters in a string.
72
73 See `char2path.pdf` for more. Happy TeXing!
74
75
76 Generate `tikz path` from font
77 ---
78 First, install the dependencies:
79 ```shell
80 cd resources/SVG/font2svg
81 pip install -r requirements.txt
82 ```
83
84 Next, define the following constants:
85 ```python
86 FONT_FOLDER = "../../Fonts/"
87 FONT_NAME = "lmmono10-regular.otf"
88 FONT_ALIAS = 'lmm'
89 ```
90
91 Finally, run the Python script below:
92 ``` shell
93 python font2path.py
94 ```
95
96 Issues
97 ------
98
99 The issue tracker for `char2path` is currently located
100 [on GitHub](https://github.com/zongpingding/char2path/issues).
101
102 Build status
103 ------------
104
105 This project uses [GitHub Actions](https://github.com/features/actions)
106 as a hosted continuous integration service. For each commit, the build status
107 is tested using the current release of TeX Live.
108
109 _Current build status:_ ![build status](https://github.com/zongpingding/char2path/actions/workflows/main.yaml/badge.svg?branch=main)
110
111 References
112 ----------
113
114 \[1\] https://www.gust.org.pl/projects/e-foundry/latin-modern/download
115
116 \[2\] https://www.unicode.org/standard/standard.html
117
118 Copyright and License
119 ---------------------
120
121 Copyright (C) 2023-2025 by zongpingding <[[email protected]](mailto:[email protected])> and
122 Mingyu Xia <[[email protected]](mailto:[email protected])>
123
124 This package's data is converted from
125 [Latin Modern family](https://www.gust.org.pl/projects/e-foundry/latin-modern),
126 which is based on the Computer Modern fonts released into public domain by
127 AMS (1997). It's under the license of
128 **[The GUS Font License (GFL)](https://ctan.org/license/gfl)**.
129
130 This work may be distributed and/or modified under the conditions
131 of the LaTeX Project Public License (LPPL), either version 1.3c of
132 this license or (at your option) any later version.
133 The latest version of this license is in
134
135 http://www.latex-project.org/lppl.txt
136
137 and version 1.3c or later is part of all distributions of LaTeX
138 version 2008 or later.
139
140 This work has the LPPL maintenance status `maintained'.
141
142 The Current Maintainer of this work is **zongpingding** and **Mingyu Xia**.
143 %</readme>
144 %
145 %<*internal>
146 \fi
147 %</internal>
148 %
149 %<*driver>
150 \documentclass[show-notes]{l3doc}
151 \usepackage[scale = 10pt]{char2path}
152 \usepackage{listings}
153 \lstset{basicstyle = \footnotesize\ttfamily, numbers = left}
154 \AddToHook{env/function/before}{\vspace*{-.5\baselineskip}}
155 \makeatletter
156 \def \@key #1{\textcolor{red}{\textbf{\texttt{#1}}}\:\texttt{=}\:}
157 \def \s@key #1{\textcolor{red}{\textbf{\texttt{#1}}}}
158 \DeclareDocumentCommand \key s {\IfBooleanTF{#1}\s@key\@key}
159 \DeclareCommandCopy \val \meta
160 \def \TFF {true\textup{\textbar\textbf{false}}}
161 \def \TTF {\textup{\textbf{true}\textbar}false}
162 \def \HoLogo@ApLaTeX #1{^^A
163 \HOLOGO@mbox {A\kern -.05em p\kern -.05em \hologo{LaTeX}}}
164 \newcounter{example}[subsection]
165 \renewcommand\theexample{\thesubsection.\arabic{example}}
166 \newwrite\example@out
167 \def\example@name{\jobname.example.aux}
168 \long\def\example@start{\begingroup\@bsphack
169 \immediate\openout\example@out=\example@name
170 \let\do\@makeother\dospecials\catcode`\^^M\active
171 \def\verbatim@processline{\immediate\write\example@out{\the\verbatim@line}}^^A
172 \verbatim@start}
173 \long\def\example@end{\immediate\closeout\example@out\@esphack\endgroup
174 \trivlist\item[]\relax
175 \leavevmode\hbox to \z@{^^A
176 \hbox to \z@{\hss{\footnotesize[\theexample]}\hskip4pt}
177 \begin{minipage}[c]{.72\textwidth}^^A
178 \small\VerbatimInput[gobble=2] \example@name^^A
179 \end{minipage}^^A
180 \fbox{^^A
181 \begin{minipage}[c]{.26\textwidth}^^A
182 \normalsize\input \example@name^^A
183 \end{minipage}^^A
184 }^^A
185 \hss}^^A
186 \endtrivlist}
187 \long\def\s@example@end{\immediate\closeout\example@out\@esphack\endgroup
188 \trivlist\item[]\relax
189 \leavevmode\hbox to \z@{^^A
190 \hbox to \z@{\hss{\footnotesize[\theexample]}\hskip4pt}\vbox{\noindent
191 \hskip-4pt
192 \begin{minipage}{\textwidth}^^A
193 \small\VerbatimInput[gobble=2]{\example@name}^^A
194 \end{minipage}\par\smallskip\noindent
195 \fbox{^^A
196 \begin{minipage}{\textwidth}^^A
197 \normalsize\input \example@name^^A
198 \end{minipage}^^A
199 }}^^A
200 \hss}^^A
201 \endtrivlist}
202 \newenvironment{example}
203 {\stepcounter{example}\example@start}{\example@end}
204 \newenvironment{example*}
205 {\stepcounter{example}\example@start}{\s@example@end}
206 \makeatother
207 \newlist{keyval}{itemize}{10}
208 \setlist[keyval]{leftmargin = 0pt, labelsep = 0pt, itemsep = 1pt}
209 \makeindex
210 \begin{document}
211 \DocInput{\jobname.dtx}
212 \end{document}
213 %</driver>
214 % \fi
215 % \title{^^A
216 % The \texorpdfstring{^^A
217 % \chartopath[hfading = {teal, purple}, font = lms]{char2path}^^A
218 % }{char2path} Package\thanks{^^A
219 % \url{https://ctan.org/pkg/char2path},
220 % \url{https://github.com/zongpingding/char2path}^^A
221 % }^^A
222 % }
223 % \author{^^A
224 % zongpingding\thanks{^^A
225 % \href{mailto:[email protected]}{\texttt{[email protected]}}},~
226 % Mingyu Xia\thanks{^^A
227 % \href{mailto:[email protected]}{\texttt{[email protected]}}^^A
228 % }^^A
229 % }
230 % \date{Released 2025-07-28\quad \texttt{v1.0.0}}
231 %
232 % \maketitle
233 %
234 % \begin{documentation}
235 %
236 % \section{Introduction}
237 %
238 % The \pkg{char2path} package provides a \LaTeX\ package for converting
239 % characters into Ti\textit k\/Z paths.
240 % It supports compilation methods including \hologo{pdfLaTeX},
241 % \hologo{XeLaTeX}, and \hologo{LuaLaTeX}.
242 %
243 % \vspace{3pt}
244 % \noindent\fbox{\vbox{\scriptsize\noindent
245 % This package's data is converted from
246 % \href{https://www.gust.org.pl/projects/e-foundry/latin-modern}{Latin Modern family},
247 % which is based on the Computer Modern fonts released into public domain by
248 % AMS (1997). It's under the license of
249 % \href{https://ctan.org/license/gfl}{The GUS Font License (GFL)}.}}
250 % \vskip-12pt
251 %
252 % \section{Usage}
253 %
254 % \noindent
255 % \begin{minipage}{.55\linewidth}
256 % To load this package, write the line
257 % \begin{Verbatim}[commandchars = \|\{\}]
258 % \usepackage[scale = |meta{choice}]|{char2path|}
259 % \end{Verbatim}
260 % The supported right listed \meta{choice} can
261 % scale the converted paths with corresponding factors.
262 % \end{minipage}
263 % \hspace*\fill
264 % \begin{minipage}{.43\linewidth}
265 % \begin{tabular}{*5{>{\small}c}}
266 % \toprule
267 % Choice & |10pt| & |11pt| & |12pt| & |13pt|\\
268 % Factor & |0.82| & |0.90| & |0.98| & |1.07|\\
269 % \midrule
270 % Choice & |14pt| & |15pt| & |16pt| & ... \\
271 % Factor & |1.15| & |1.23| & |1.31| & ... \\
272 % \bottomrule
273 % \end{tabular}
274 % \end{minipage}
275 %
276 % \begin{function}[updated = 2025-07-27]{\chartopath}
277 % \begin{syntax}
278 % \cs{chartopath} \oarg{key-vals} \marg{string}
279 % \end{syntax}
280 % The \oarg{key-vals} accepts the listed keys to set how the \marg{string}
281 % converts to path.
282 % \begin{keyval}
283 % \item [\key{font}] \val{lmr\textup\textbar lms\textup\textbar lmm}
284 % choose char's font.
285 % \item [\key{draw, fill}] \val{color} set the color of
286 % the outline/fill of string (Default: |black|).
287 % \item [\key{outline}] \val{dim} set the outline of the string
288 % to achieve the ``Fake Bold'' effect (Default: |0pt|).
289 % \item [\key{scale}] \val{fp num} set font's scale factor
290 % (Default: |1|).
291 % \item [\key{hfading, vfading}] \val{color clist} set the two colors for horizontally/vertically fading the whole string.
292 % \item [\key{rescan}] \val{\TTF} rescan tokens |$|, |&|, and |~| with catcode 12 (other).
293 % (Default: |true|).
294 % \end{keyval}
295 % \end{function}
296 %
297 % \begin{function}[updated = 2025-07-26]{\chartoclip}
298 % \begin{syntax}
299 % \cs{chartoclip} \oarg{key-vals} \marg{char}
300 % \end{syntax}
301 % The mandatory argument accepts a single character, and the optional
302 % argument accepts the following keys to set the style how the character clip
303 % the image.
304 % \par\medskip\noindent
305 % \begin{minipage}{.57\linewidth}
306 % \begin{keyval}
307 % \item [\key{font}] \val{lmr\textup\textbar lms\textup\textbar lmm}
308 % choose char's font.
309 % \item [\key{image}] \val{image} set image to clip.
310 % \item [\key{scale}] \val{fp num} set font's scale factor
311 % (Default: |1|).
312 % \end{keyval}
313 % \end{minipage}
314 % \hspace*\fill
315 % \begin{minipage}{.39\linewidth}
316 % \begin{keyval}
317 % \item [\key{anchor}] \val{tikz anchor} set image's anchor.
318 % \item [\key{offset}] \val{(x, y)} set imgae anchor's offset.
319 % \item [\key{height}] \val{dim} image's height.
320 % \end{keyval}
321 % \end{minipage}
322 % \end{function}
323 %
324 % \section{Examples}
325 %
326 % This package can convert the following characters to path by default:
327 % including \textrm{Latin Modern Roman}, \textrm{Latin Modern Sans},
328 % and \texttt{Latin Modern Mono}.
329 %
330 % \DeleteShortVerb\| \DeleteShortVerb\" \catcode`\^11\relax
331 % \begin{center}
332 % \begin{minipage}[t]{.32\linewidth}
333 % \fbox{\parbox[c][2.5\baselineskip]{\linewidth-8pt}{
334 % \scriptsize
335 % \chartopath[font = lmr, draw]{!\#$"\%&'()*+,-./012345678}\par
336 % \chartopath[font = lmr, draw]{9:;<=>?@ABCDEFGHIJKLMNOP}\par
337 % \chartopath[font = lmr, draw]{QRSTUVWXYZ[\ctpbackslash]^_`abcdefgh}\par
338 % \chartopath[font = lmr, draw]{ijklmnopqrstuvwxyz\{|\}~}
339 % }}
340 % \end{minipage}
341 % \hspace*\fill
342 % \begin{minipage}[t]{.32\linewidth}
343 % \fbox{\parbox[c][2.5\baselineskip]{\linewidth-8pt}{
344 % \scriptsize
345 % \chartopath[font = lms, draw]{!\#$"\%&'()*+,-./012345678}\par
346 % \chartopath[font = lms, draw]{9:;<=>?@ABCDEFGHIJKLMNOP}\par
347 % \chartopath[font = lms, draw]{QRSTUVWXYZ[\ctpbackslash]^_`abcdefgh}\par
348 % \chartopath[font = lms, draw]{ijklmnopqrstuvwxyz\{|\}~}
349 % }}
350 % \end{minipage}
351 % \hspace*\fill
352 % \begin{minipage}[t]{.32\linewidth}
353 % \fbox{\parbox[c][2.5\baselineskip]{\linewidth-8pt}{
354 % \scriptsize
355 % \chartopath[font = lmm, draw]{!\#$"\%&'()*+,-./012345678}\par
356 % \chartopath[font = lmm, draw]{9:;<=>?@ABCDEFGHIJKLMNOP}\par
357 % \chartopath[font = lmm, draw]{QRSTUVWXYZ[\ctpbackslash]^_`abcdefgh}\par
358 % \chartopath[font = lmm, draw]{ijklmnopqrstuvwxyz\{|\}~}
359 % }}
360 % \end{minipage}
361 % \end{center}
362 % \MakeShortVerb\| \MakeShortVerb\" \catcode`\^7\relax
363 %
364 % \subsection{Basic usage}
365 %
366 % \noindent
367 % \def\0{0123456789/ctp}
368 % The basic usage only print the outline of the inputted string.
369 % \begin{example}
370 % \def\0{0123456789/ctp}
371 % \chartopath\0
372 % \end{example}
373 % \noindent
374 % Users can specific the color of outline and fill,
375 % specific the fill-in pattern,
376 % and specific the scale and slant of inputted characters.
377 % Just like the keys in Ti\textit k\/Z.
378 % \begin{example}
379 % \chartopath[draw = none, fill = blue]\0
380 % \end{example}
381 %
382 % \begin{example}
383 % \chartopath[draw = blue, fill = red, scale = 1.2]\0
384 % \end{example}
385 %
386 % \begin{example}
387 % \chartopath[pattern = north west lines,
388 % draw, scale = 1.2] \0
389 % \end{example}
390 %
391 % \begin{example}
392 % \chartopath[draw, fill = green,
393 % xslant = .15, scale = 1.2] \0
394 % \end{example}
395 % Commands like \cs[no-index]{small} can be directly applied to \cs{chartopath}.
396 % A comparison of the text and the converted path under 4 different font size
397 % is shown in the following figure.
398 %
399 % \begin{center}
400 % \begin{tikzpicture}[every node/.style = {font = \ttfamily}]
401 % \draw [ -stealth, gray!25, line width = 1em, line cap = round ]
402 % (0,0) --++ (.93\linewidth,0) node [ left, black ] {\cs{f@size}};
403 % \node [ above = 1ex ] at (.06\linewidth,0) {\small \0};
404 % \node [ above = 1ex ] at (.24\linewidth,0) {\normalsize \0};
405 % \node [ above = 1ex ] at (.45\linewidth,0) {\large \0};
406 % \node [ above = 1ex ] at (.72\linewidth,0) {\LARGE \0};
407 % \node [ below = 1ex ] at (.06\linewidth,0)
408 % {\small \chartopath[fill = orange]\0};
409 % \node [ below = 1ex] at (.24\linewidth,0)
410 % {\normalsize\chartopath[fill = green]\0};
411 % \node [ below = 1ex ] at (.45\linewidth,0)
412 % {\large \chartopath[fill = blue]\0};
413 % \node [ below = 1ex ] at (.72\linewidth,0)
414 % {\LARGE \chartopath[fill = purple]\0};
415 % \makeatletter
416 % \node at (.06\linewidth,0)
417 % {\small \scalebox{\fpeval{8/\f@size}}
418 % {\small \f@size pt (\cs[no-index]{small})}};
419 % \node at (.24\linewidth,0)
420 % {\normalsize\scalebox{\fpeval{8/\f@size}}
421 % {\normalsize\f@size pt (\cs[no-index]{normalsize})}};
422 % \node at (.45\linewidth,0)
423 % {\large \scalebox{\fpeval{8/\f@size}}
424 % {\large \f@size pt (\cs[no-index]{large})}};
425 % \node at (.72\linewidth,0)
426 % {\LARGE \scalebox{\fpeval{8/\f@size}}
427 % {\LARGE \f@size pt (\cs[no-index]{LARGE})}};
428 % \makeatother
429 % \end{tikzpicture}
430 % \end{center}
431 %
432 % \subsection{Fading the path}
433 %
434 % \begin{example}
435 % \chartopath[hfading = {red, green}]\0
436 % \end{example}
437 %
438 % \begin{example}
439 % \chartopath[hfading = {blue, -}]\0
440 % \end{example}
441 %
442 % \begin{example}
443 % \chartopath[hfading = {-, violet}]\0
444 % \end{example}
445 %
446 % \begin{example}
447 % \chartopath[vfading = {teal, purple}]\0
448 % \end{example}
449 %
450 % \begin{example}
451 % \chartopath[vfading = {-, orange}]\0
452 % \end{example}
453 %
454 % \begin{example}
455 % \chartopath[vfading = {violet, -}]\0
456 % \end{example}
457 %
458 % \begin{texnote}
459 % Fading will cost too much time!!!
460 % \end{texnote}
461 %
462 % \section{Advanced Usage}
463 %
464 % \subsection{Use in \pkg{listings}}
465 %
466 % This package can be used within \pkg{listings} or \pkg{minted},
467 % then users could directly copy the source code from |.pdf| file
468 % without worry about including unwanted line numbers.
469 %
470 % \let\orithelstnumber\thelstnumber
471 % \def\thelstnumber{^^A
472 % \chartopath[rescan = false, hfading = {violet, blue}]{\orithelstnumber}^^A
473 % }
474 % \begin{verbatim}
475 % \let\orithelstnumber\thelstnumber
476 % \def\thelstnumber{%
477 % \chartopath[rescan = false, hfading = {violet, blue}]{\orithelstnumber}%
478 % }
479 % \end{verbatim}
480 %
481 % \begin{example}
482 % \begin{lstlisting}[language = {[LaTeX]TeX}, gobble = 2]
483 % \documentclass{article}
484 % \begin{document}
485 % Hello, \LaTeX!
486 % \end{document}
487 % \end{lstlisting}
488 % \end{example}
489 %
490 % \subsection{String clip}
491 % You can also define a command, \cs[no-index]{strpathclip},
492 % that accepts a string instead of a single character:
493 % \begin{example}
494 % \ExplSyntaxOn
495 % \NewDocumentCommand \strpathclip { O{} m }
496 % { \int_step_inline:nn { \exp_args:Ne \tl_count:n {#2} }
497 % { \chartoclip [ #1, offset = {(##1*1, 0pt)} ]
498 % { \tl_item:nn {#2}{##1}} \kern2pt } }
499 % \ExplSyntaxOff
500 % \strpathclip[scale = 2, font = lmr, image = example-grid-100x100bp]{Hello, c2p}
501 % \end{example}
502 %
503 % \subsection{\hologo{(La)TeX} logo}
504 % The logos \TeX\ and \LaTeX\ can be recreated using \cs{chartoclip}:
505 % \begin{example}
506 % \def\ctp#1{\chartoclip[font = lmr, image = example-grid-100x100bp]{#1}}
507 % \protected\def\ctpTeX{\ctp T\kern-.1667em \lower.5ex
508 % \hbox{\ctp E}\kern-.125em \ctp X}
509 % \protected\def\ctpLaTeX{\ctp L\kern-.36em^^A
510 % {\sbox0 T\vbox to\ht0{\vskip-.021em\hbox{^^A
511 % \kern.083em\scalebox{.7}{\ctp A}}\vss}}\kern-.15em\ctpTeX}
512 % \scalebox{2}{\ctpTeX} \scalebox{2}{\ctpLaTeX}
513 % \end{example}
514 %
515 % \subsection{Get path data}
516 % \begin{function}{\ctpdata}
517 % \begin{syntax}
518 % \cs{ctpdata}\marg{font name}\marg{character}
519 % \end{syntax}
520 % This function can output the path data (in \textsc{pgf} coordinates).
521 % \NB{Note}{This command is expandable.}
522 % \begin{example*}
523 % \def\0{\ctpdata{lmr}{-}} \scriptsize\ttfamily\detokenize\expandafter{\expanded{\0}}
524 % \end{example*}
525 % \end{function}
526 % \footnotesize
527 % \section{Todo List}
528 %
529 % \begin{itemize}
530 % \item [\textcolor{green}{\textsf{Warn}}] Resolve the font warning: Font shape \texttt{OMS/cmtt/m/n} undefined for \texttt{textbackslash}.
531 % \item [\textcolor{blue}{\textsf{Function}}] Support syntax
532 % "\chartopath{\usefont{T1}{cmr}{m}{sc} abc}",
533 % "\chartopath{\sffamily abc}".
534 % \end{itemize}
535 %
536 % \end{documentation}
537 %
538 % \begin{implementation}
539 %
540 % \section{The Source Code}
541 %
542 % \begin{macrocode}
543 %<*package>
544 % \end{macrocode}
545 %
546 % \begin{macrocode}
547 %<@@=ctp>
548 % \end{macrocode}
549 %
550 % \begin{macrocode}
551 \ProvidesExplPackage {char2path} {2025-07-28} {v1.0.0}
552 {A LaTeX package that converts characters into TikZ paths}
553 % \end{macrocode}
554 % \begin{variable}{\g_@@_scale_tl}
555 % Define the |scale| key for this package.
556 % \begin{macrocode}
557 \keys_define:nn { char2path }
558 {
559 scale .tl_gset:N = \g_@@_scale_tl,
560 scale .initial:n = { 10pt },
561 }
562 \ProcessKeyOptions [ char2path ]
563 % \end{macrocode}
564 % \end{variable}
565 % \begin{macrocode}
566 \RequirePackage{tikz, etoolbox}
567 \patchcmd{\pgfutil@InputIfFileExists}
568 { \input #1 }
569 {
570 \@pushfilename
571 \xdef\@currname{#1}
572 \input #1
573 \@popfilename
574 }{}{}
575 \usetikzlibrary{patterns, fadings, calc}
576 % \end{macrocode}
577 % Warning Broadcast
578 % \begin{macrocode}
579 \cs_new_protected:Npn \@@_msg_new:nn #1#2
580 { \msg_new:nnn { char2path } {#1} {#2} }
581 \cs_new_protected:Npn \@@_msg_warning:n #1
582 { \msg_warning:nn { char2path } {#1} }
583 \cs_new_protected:Npn \@@_msg_error:nn #1#2
584 { \msg_error:nne { char2path } {#1} {#2} }
585 \@@_msg_new:nn { fading } { Unsupport ~ multiple ~ fading ~ directions }
586 \@@_msg_new:nn { kernel } { file ~ not ~ found }
587 % \end{macrocode}
588 % \begin{variable}{\c_@@_tikz_folder_tl, \c_@@_global_scale_fp, \c_@@_scale_prop}
589 % Define global variables: \cmd{\c_@@_tikz_folder_tl} for future use,
590 % \cmd{\c_@@_global_scale_fp} for global scale factor, and
591 % \cmd{\c_@@_scale_prop} for storing scale choices respectly.
592 % \begin{macrocode}
593 \tl_const:Nn \c_@@_tikz_folder_tl { font_glyph }
594 \fp_const:Nn \c_@@_global_scale_fp { .0135 }
595 \prop_const_from_keyval:Nn \c_@@_scale_prop
596 {
597 10pt = 0.820, 11pt = 0.902, 12pt = 0.984, 13pt = 1.066,
598 14pt = 1.148, 15pt = 1.230, 16pt = 1.311,
599 }
600 % \end{macrocode}
601 % \end{variable}
602 % \begin{variable}{\l_@@_tikz_data_merge_tl}
603 % To merge a font's different parts of data into a \meta{token list}.
604 % \begin{macrocode}
605 \tl_new:N \l_@@_tikz_data_merge_tl
606 % \end{macrocode}
607 % \end{variable}
608 % \begin{macro}{\@@_load_font_data:nnn}
609 % Load fonts' path data from database file (|*.data.tex|).
610 % Due to the fact that character |~| is stored in the database,
611 % |\char_set_catcode:nn { 126 } { 12 }| should be applied
612 % to ensure it's path data could be correctly loaded in |expl3| syntax.
613 % \begin{macrocode}
614 \cs_new_protected_nopar:Npn \@@_load_font_data:nnn #1#2#3
615 {
616 \clist_map_inline:nn {#3}
617 {
618 \file_get:nnNTF
619 { ctp-#2-##1.data.tex } { \char_set_catcode:nn { 126 } { 12 } }
620 \l_@@_tikz_data_single_tl
621 {
622 \tl_gput_right:NV \l_@@_tikz_data_merge_tl
623 \l_@@_tikz_data_single_tl
624 } { \@@_msg_error:nn { kernel } { ctp-#2-##1.data.tex } }
625 }
626 \exp_args:NnV \prop_const_from_keyval:cn
627 { c_@@_tikz_#2_data_prop } { \l_@@_tikz_data_merge_tl }
628 \tl_set:cn { l_@@_font_#2_type_tl } {#1}
629 }
630 % \end{macrocode}
631 % \end{macro}
632 % \begin{macro}{\@@_protected_char:nn}
633 % To create a macro so that it couldn't be expanded.
634 % \begin{macrocode}
635 \cs_new:Npn \@@_protected_char:nn #1#2
636 { \cs_new_protected:cpn {#1} { \exp_not:n {#2} } }
637 \@@_protected_char:nn { ctpbackslash }{ \textbackslash }
638 % \end{macrocode}
639 % \end{macro}
640 % Load font's data for |lmr|, |lms| and |lmm|, including
641 % arabic (Unicode: 0030 -- 0039),
642 % alpha-small (Unicode: 0061-007A),
643 % alpha-caps (Unicode: 0041 -- 005A),
644 % and other symbols (anything left in Unicode: 0021 -- 007E).
645 % \begin{macrocode}
646 \@@_load_font_data:nnn { serif } { lmr }
647 { arabic, alpha-small, alpha-caps, others, }
648 \@@_load_font_data:nnn { sans } { lms }
649 { arabic, alpha-small, alpha-caps, others, }
650 \@@_load_font_data:nnn { mono } { lmm }
651 { arabic, alpha-small, alpha-caps, others, }
652 % \end{macrocode}
653 % \begin{variable}
654 % {
655 % \l_@@_char_clip_font, \l_@@_rescan_bool,
656 % \l_@@_draw_tl, \l_@@_outline_tl,
657 % \l_@@_hfading_clist, \l_@@_vfading_clist,
658 % \l_@@_fill_tl, \l_@@_scale_fp
659 % }
660 % Key--value definitions for the \cs{chartopath} command.
661 % \begin{macrocode}
662 \clist_new:N \l_@@_continous_color_left_clist
663 \clist_new:N \l_@@_continous_color_right_clist
664 \keys_define:nn { char2path / chartopath }
665 {
666 font .tl_set:N = \l_@@_char_clip_font,
667 font .initial:n = { lmm },
668 rescan .bool_set:N = \l_@@_rescan_bool,
669 rescan .initial:n = { true },
670 draw .tl_set:N = \l_@@_draw_tl,
671 draw .initial:n = { none },
672 fill .tl_set:N = \l_@@_fill_tl,
673 outline .dim_set:N = \l_@@_outline_tl,
674 outline .initial:n = { 0pt },
675 hfading .clist_set:N = \l_@@_hfading_clist,
676 vfading .clist_set:N = \l_@@_vfading_clist,
677 scale .fp_set:N = \l_@@_scale_fp,
678 scale .initial:n = { 1 },
679 unknown .code:n = \@@_parse_unknown_option:n {#1}
680 }
681 % \end{macrocode}
682 % \end{variable}
683 % \begin{variable}{\l_@@_options_clist}
684 % To store unknown key--values.
685 % \begin{macrocode}
686 \clist_new:N \l_@@_options_clist
687 % \end{macrocode}
688 % \end{variable}
689 % \begin{macro}{\@@_parse_unknown_option:n}
690 % Parsing unknown key--values and pass them into Ti\textit \/Z.
691 % \begin{macrocode}
692 \cs_new_protected_nopar:Npn \@@_parse_unknown_option:n #1
693 {
694 \tl_if_empty:nTF {#1}
695 { \clist_put_right:NV \l_@@_options_clist \l_keys_key_str }
696 {
697 \exp_args:NNx \clist_gput_right:Nn \l_@@_options_clist
698 { \l_keys_key_str = \exp_not:n {#1} }
699 }
700 }
701 % \end{macrocode}
702 % \end{macro}
703 % \begin{variable}{\l_@@_tmpa_tl, \l_@@_tmpb_tl}
704 % \begin{macrocode}
705 \tl_new:N \l_@@_tmpa_tl
706 \tl_new:N \l_@@_tmpb_tl
707 % \end{macrocode}
708 % \end{variable}
709 % \begin{macro}{\chartopath}
710 % The main command for this package.
711 % \begin{macrocode}
712 \NewDocumentCommand \chartopath { O{} m }
713 {
714 \group_begin:
715 \keys_set:nn { char2path / chartopath } {#1}
716 % \end{macrocode}
717 % If the optional argument is empty, then apply the rule:
718 % ``only print the outline of the inputted string''.
719 % \begin{macrocode}
720 \IfBlankT {#1} { \tl_set:Nn \l_@@_draw_tl { black } }
721 % \end{macrocode}
722 % Config the |rescan| boolean: set the catcode of |$|, |&|, and |~|
723 % to 12 (common letter).
724 % \begin{macrocode}
725 \bool_if:NTF \l_@@_rescan_bool
726 {
727 \tl_set_rescan:Nnn \l_@@_tmpa_tl
728 {
729 \char_set_catcode:nn { \int_from_hex:n { 24 } } { 12 } % '$'
730 \char_set_catcode:nn { \int_from_hex:n { 26 } } { 12 } % '&'
731 \char_set_catcode:nn { \int_from_hex:n { 7e } } { 12 } % '~'
732 } {#2}
733 } { \tl_set:Nn \l_@@_tmpa_tl {#2} }
734 % \end{macrocode}
735 % Warning information for fading: if both the |hfading|
736 % and the |vfading| key is valued, then a warning is returned.
737 % \begin{macrocode}
738 \bool_lazy_and:nnT
739 { !\clist_if_empty_p:N \l_@@_hfading_clist }
740 { !\clist_if_empty_p:N \l_@@_vfading_clist }
741 { \@@_msg_warning:n { fading } }
742 % \end{macrocode}
743 % Boolean judgment: if |hfading| and |vfading| are both empty at the same
744 % time, or |hfading| and |vfading| are not assigned at the same time
745 % \begin{macrocode}
746 \bool_lazy_or:nnTF
747 {
748 \bool_lazy_and_p:nn { \clist_if_empty_p:N \l_@@_hfading_clist }
749 { \clist_if_empty_p:N \l_@@_vfading_clist }
750 }
751 {
752 \bool_lazy_and_p:nn { !\clist_if_empty_p:N \l_@@_hfading_clist }
753 { !\clist_if_empty_p:N \l_@@_vfading_clist }
754 }
755 % \end{macrocode}
756 % If the situation is true, then use the basic usage for converting.
757 % \begin{macrocode}
758 {
759 \exp_args:Nno \@@_aux:nnnn
760 {
761 draw = \l_@@_draw_tl, line~width = \l_@@_outline_tl,
762 \tl_if_blank:VF \l_@@_fill_tl { fill = \l_@@_fill_tl, },
763 \clist_use:Nn \l_@@_options_clist { , }
764 } { \l_@@_tmpa_tl } { \l_@@_char_clip_font } { \l_@@_scale_fp }
765 }
766 % \end{macrocode}
767 % If the situation is false, then handle the vertical or horizontally
768 % fading due to user's input.
769 % \begin{macrocode}
770 {
771 % \end{macrocode}
772 % Vertically fading branch.
773 % \begin{macrocode}
774 \clist_if_empty:NF \l_@@_vfading_clist
775 {
776 % \end{macrocode}
777 % Split the color list into two \meta{token list}s.
778 % \begin{macrocode}
779 \@@_fading_parse_aux:NNN \l_@@_vfading_clist
780 \l_@@_color_i_tl \l_@@_color_ii_tl
781 % \end{macrocode}
782 % For single color: set the other color to |transparent!0|.
783 % \begin{macrocode}
784 \str_case_e:nn { - }
785 {
786 { \l_@@_color_i_tl }
787 { \tl_set:Nn \l_@@_color_i_tl { transparent!0 } }
788 { \l_@@_color_ii_tl }
789 { \tl_set:Nn \l_@@_color_ii_tl { transparent!0 } }
790 }
791 % \end{macrocode}
792 % Set the |top color| and |bottom color| accordingly.
793 % \begin{macrocode}
794 \@@_aux:nnnn
795 {
796 top~color = \l_@@_color_i_tl, bottom~color = \l_@@_color_ii_tl,
797 line~width = \l_@@_outline_tl, draw = \l_@@_draw_tl,
798 \clist_use:Nn \l_@@_options_clist { , }
799 } { \l_@@_tmpa_tl } { \l_@@_char_clip_font } { \l_@@_scale_fp }
800 }
801 % \end{macrocode}
802 % Horizontally fading branch.
803 % \begin{macrocode}
804 \clist_if_empty:NF \l_@@_hfading_clist
805 {
806 % \end{macrocode}
807 % Split the color list into two \meta{token list}s.
808 % \begin{macrocode}
809 \@@_fading_parse_aux:NNN \l_@@_hfading_clist
810 \l_@@_color_i_tl \l_@@_color_ii_tl
811 % \end{macrocode}
812 % Generate the color percentage list according to the number of
813 % characters in the input stream.
814 % \begin{macrocode}
815 \exp_args:Ne \@@_fading_color_aux:nNN { \l_@@_tmpa_tl }
816 \l_@@_continous_color_left_clist
817 \l_@@_continous_color_right_clist
818 % \end{macrocode}
819 % Set the |left color| and |right color|
820 % to every character with corresponding percentage.
821 % \begin{macrocode}
822 \int_step_inline:nn { \exp_args:Ne \tl_count:n { \l_@@_tmpa_tl } }
823 {
824 \tl_set:Nn \l_@@_continous_color_tmpa_tl
825 { \clist_item:Nn \l_@@_continous_color_left_clist {##1} }
826 \tl_set:Nn \l_@@_continous_color_tmpb_tl
827 { \clist_item:Nn \l_@@_continous_color_right_clist {##1} }
828 \str_case_e:nnF { - }
829 {
830 % \end{macrocode}
831 % Single color branch (left fading).
832 % \begin{macrocode}
833 { \l_@@_color_i_tl }
834 {
835 \exp_args:Nne \@@_aux:nnnn
836 {
837 draw = \l_@@_draw_tl,
838 line~width = \l_@@_outline_tl,
839 left~color =
840 \l_@@_color_ii_tl!
841 \fp_eval:n { 100 - \l_@@_continous_color_tmpa_tl },
842 right~color =
843 \l_@@_color_ii_tl!
844 \fp_eval:n { 100 - \l_@@_continous_color_tmpb_tl },
845 \clist_use:Nn \l_@@_options_clist { , }
846 } { \exp_args:Ne \tl_item:nn { \l_@@_tmpa_tl } {##1} }
847 { \l_@@_char_clip_font } { \l_@@_scale_fp }
848 }
849 % \end{macrocode}
850 % Single color branch (right fading).
851 % \begin{macrocode}
852 { \l_@@_color_ii_tl }
853 {
854 \exp_args:Nne \@@_aux:nnnn
855 {
856 draw = \l_@@_draw_tl,
857 line~width = \l_@@_outline_tl,
858 left~color =
859 \l_@@_color_i_tl!\l_@@_continous_color_tmpa_tl,
860 right~color =
861 \l_@@_color_i_tl!\l_@@_continous_color_tmpb_tl,
862 \clist_use:Nn \l_@@_options_clist { , }
863 } { \exp_args:Ne \tl_item:nn { \l_@@_tmpa_tl } {##1} }
864 { \l_@@_char_clip_font } { \l_@@_scale_fp }
865 }
866 }
867 % \end{macrocode}
868 % Double color branch.
869 % \begin{macrocode}
870 {
871 \exp_args:Nne \@@_aux:nnnn
872 {
873 draw = \l_@@_draw_tl,
874 line~width = \l_@@_outline_tl,
875 left~color =
876 \l_@@_color_i_tl!
877 \l_@@_continous_color_tmpa_tl!
878 \l_@@_color_ii_tl,
879 right~color =
880 \l_@@_color_ii_tl!
881 \fp_eval:n { 100 - \l_@@_continous_color_tmpb_tl }!
882 \l_@@_color_i_tl,
883 \clist_use:Nn \l_@@_options_clist { , }
884 } { \exp_args:Ne \tl_item:nn { \l_@@_tmpa_tl } {##1} }
885 { \l_@@_char_clip_font } { \l_@@_scale_fp }
886 }
887 }
888 }
889 }
890 % \end{macrocode}
891 % Make the keys' values only valid within the command.
892 % \begin{macrocode}
893 \group_end:
894 % \end{macrocode}
895 % Clean the unknown key--values' list.
896 % \begin{macrocode}
897 \clist_gclear:N \l_@@_options_clist
898 }
899 % \end{macrocode}
900 % \end{macro}
901 % \begin{variable}{\l_@@_mono_width_dim, \l_@@_mono_sep_dim, \l_@@_glyph_box}
902 % Dimension variables for store the width and sep of the mono font,
903 % and box for calculating the depths of inputted characters.
904 % \begin{macrocode}
905 \dim_new:N \l_@@_mono_width_dim
906 \dim_new:N \l_@@_mono_sep_dim
907 \box_new:N \l_@@_glyph_box
908 % \end{macrocode}
909 % \end{variable}
910 % \begin{macro}{\str_case:nn}
911 % Generate a |v-|type from \cmd{\str_case:nn} for later usage.
912 % \begin{macrocode}
913 \prg_generate_conditional_variant:Nnn \str_case:nn { v } { F }
914 % \end{macrocode}
915 % \end{macro}
916 % \begin{macro}{\@@_aux:nnnn}
917 % Define the auxiliary command of \cs{chartopath}: set the depth of
918 % every font's style (|roman|, |sans|, and |mono|),
919 % and then pass them to \cmd{\@@_draw:nnnnnn} to process.
920 % \begin{macrocode}
921 \cs_new_protected:Npn \@@_aux:nnnn #1#2#3#4
922 {
923 \exp_args:Ne \tl_map_inline:nn {#2}
924 {
925 \str_case:vnF { l_@@_font_#3_type_tl }
926 {
927 { serif }
928 {
929 \hbox_set:Nn \l_@@_glyph_box { \rmfamily ##1 }
930 \dim_set:Nn \l_@@_mono_width_dim { 0pt }
931 \dim_set:Nn \l_@@_mono_sep_dim { .52pt }
932 }
933 { sans }
934 {
935 \hbox_set:Nn \l_@@_glyph_box { \sffamily ##1 }
936 \dim_set:Nn \l_@@_mono_width_dim { 0pt }
937 \dim_set:Nn \l_@@_mono_sep_dim { .52pt }
938 }
939 { mono }
940 {
941 \hbox_set:Nn \l_@@_glyph_box { \ttfamily ##1 }
942 \dim_set:Nn \l_@@_mono_width_dim { 5.124975pt }
943 \dim_set:Nn \l_@@_mono_sep_dim { 0pt }
944 }
945 } { \hbox_set:Nn \l_@@_glyph_box {##1} }
946 \@@_draw:neennn { \int_use:N \box_dp:N \l_@@_glyph_box }
947 {#1} { \@@_data:nn {#3} {##1} } {#4}
948 { \l_@@_mono_width_dim } { \l_@@_mono_sep_dim }
949 }
950 }
951 % \end{macrocode}
952 % \end{macro}
953 % \begin{macro}{\@@_draw:nnnnnn}
954 % Auxiliary command for converting character to path:
955 % conducted with |\tikz|^^A
956 % \NB{TODO}{Avoid nesting \tikz command;
957 % use the character's natural dimensions instead}.
958 % \begin{macrocode}
959 \cs_new_protected:Npn \@@_draw:nnnnnn #1#2#3#4#5#6
960 {
961 \tikz [ baseline = #1 ] \node
962 [ above, minimum~width = #5 * \f@size/10, inner~sep = #6 * \f@size/10 ]
963 { \tikz [ scale = \prop_item:Ne \c_@@_scale_prop { \g_@@_scale_tl } *
964 \fp_eval:n { \f@size/8.4 * \c_@@_global_scale_fp * #4 }
965 ] \path [#2] #3; };
966 }
967 \cs_generate_variant:Nn \@@_draw:nnnnnn { neennn }
968 % \end{macrocode}
969 % \end{macro}
970 % \begin{macro}{\@@_data:nn}
971 % Auxiliary command for mapping character to the corresponding data.
972 % \begin{macrocode}
973 \cs_new:Npn \@@_data:nn #1#2
974 {
975 \prop_if_in:cnTF { c_@@_tikz_#1_data_prop } {#2}
976 { \prop_item:cn { c_@@_tikz_#1_data_prop } {#2} }
977 { node [ draw, rounded~corners = .5pt, inner~xsep = -.06pt ] {?} }
978 % \file_if_exist_input:n { \c_@@_tikz_folder_tl/#2.pgf.coor }
979 }
980 \cs_generate_variant:Nn \@@_data:nn { ne, ee }
981 % \end{macrocode}
982 % \end{macro}
983 % \begin{macro}{\@@_fading_parse_aux:NNN}
984 % Parsing fading color list.
985 % \begin{macrocode}
986 \cs_new_protected:Npn \@@_fading_parse_aux:NNN #1#2#3
987 {
988 \group_begin: \exp_args:NNNe \group_end:
989 \tl_set:Nn #2 { \clist_item:Nn #1 { 1 } }
990 \group_begin: \exp_args:NNNe \group_end:
991 \tl_set:Nn #3 { \clist_item:Nn #1 { 2 } }
992 }
993 % \end{macrocode}
994 % \end{macro}
995 % \begin{macro}{\@@_fading_color_aux:nNN}
996 % Generate color percentage clist due to the number ofinputted characters.
997 % \begin{macrocode}
998 \cs_new_protected:Npn \@@_fading_color_aux:nNN #1#2#3
999 {
1000 \int_step_inline:nn { \tl_count:n {#1} }
1001 {
1002 \clist_put_right:Ne #2
1003 {
1004 \fp_eval:n
1005 { 100 - (##1 - 1) * 100 / \tl_count:n {#1} }
1006 }
1007 \clist_put_right:Ne #3
1008 { \fp_eval:n { 100 - ##1 * 100 / \tl_count:n {#1} } }
1009 }
1010 }
1011
1012 % \end{macrocode}
1013 % \end{macro}
1014 % \begin{variable}
1015 % {
1016 % \l_@@_char_clip_font, \l_@@_image_tl,
1017 % \l_@@_char_clip_scale_fp, \l_@@_image_anchor_tl,
1018 % \l_@@_image_anchor_offset_tl, \l_@@_image_height_dim
1019 % }
1020 % Key--value definitions for the \cs{chartoclip} command^^A
1021 % \NB{TODO}{Change ``height'' to the height of char}.
1022 % \begin{macrocode}
1023 \keys_define:nn { char2path / chartoclip }
1024 {
1025 font .tl_set:N = \l_@@_char_clip_font,
1026 font .initial:n = { lmm },
1027 image .tl_set:N = \l_@@_image_tl,
1028 image .initial:n = { example-image },
1029 scale .fp_set:N = \l_@@_char_clip_scale_fp,
1030 scale .initial:n = { 1 },
1031 anchor .tl_set:N = \l_@@_image_anchor_tl,
1032 anchor .initial:n = { center },
1033 offset .tl_set:N = \l_@@_image_anchor_offset_tl,
1034 offset .initial:n = { (0pt, 0pt) },
1035 height .dim_set:N = \l_@@_image_height_dim,
1036 height .initial:n = { 3cm },
1037 }
1038 % \end{macrocode}
1039 % \end{variable}
1040 % \begin{macro}{\chartoclip}
1041 % Command for the converted path clipping an specific image.
1042 % \begin{macrocode}
1043 \NewDocumentCommand \chartoclip { O{} m }
1044 {
1045 \group_begin:
1046 \keys_set:nn { char2path / chartoclip }{#1}
1047 \exp_args:Nee \@@_image_clip_aux:nnnnnn
1048 { \prop_item:ce { c_@@_tikz_ \l_@@_char_clip_font _data_prop } { #2 } }
1049 { \l_@@_image_anchor_offset_tl }
1050 { \l_@@_image_tl }
1051 { \l_@@_image_height_dim }
1052 { \l_@@_char_clip_scale_fp }
1053 { \l_@@_image_anchor_tl }
1054 \group_end:
1055 }
1056 % \end{macrocode}
1057 % \end{macro}
1058 % \begin{macro}{\@@_image_clip_aux:nnnnnn}
1059 % The auxiliary command of \cs{chartoclip}:\par\noindent
1060 % |#1|: path data; |#2|: anchor offset; |#3|: image;
1061 % |#4|: image height; |#5|: scale; |#6|: anchor.
1062 % \begin{macrocode}
1063 \cs_new:Npn \@@_image_clip_aux:nnnnnn #1#2#3#4#5#6
1064 {
1065 \tikz [ scale = \fp_eval:n { \c_@@_global_scale_fp*#5 } ]
1066 \path [ path~picture = {
1067 \node at ($(path~picture~bounding~box.#6) + #2$)
1068 { \includegraphics [ height = #4 ] {#3} };
1069 } ] #1;
1070 }
1071 % \end{macrocode}
1072 % \end{macro}
1073 % \begin{macro}{\ctpdata}
1074 % Command for using \pkg{char2path}'s data.
1075 % \begin{macrocode}
1076 \newcommand \ctpdata [2] { \@@_data:nn {#1}{#2} }
1077 % \end{macrocode}
1078 % \end{macro}
1079 % \begin{macrocode}
1080 \file_input_stop:
1081 % \end{macrocode}
1082 %
1083 % \begin{macrocode}
1084 %</package>
1085 % \end{macrocode}
1086 %
1087 % \end{implementation}
1088 % \PrintIndex