# Convert font letters to vector format and fill with a pattern

I have worked with Illustrator and CorelDraw and I usually take fonts and convert them to curves after which I would fill in the curves with patterns, merge them with other vectors or the sort. Is it possible to do this in LaTeX. To some extent is like changing the color of the fonts but these would have to probably be zoomed for the pattern to be obvious.

If this is possible can it then the vector format be translated into TikZ or pstricks to facilitate the fill. An example of this would be appreciated.

-
PSTricks can get the outlines from Type1 fonts via pst-text package. Or you can use Asymptote for better control. TikZ has no such ability. See also tex.stackexchange.com/questions/21548 –  Leo Liu Jun 7 '12 at 4:04
Without access to the paths of each character, you can use fadings like in tex.stackexchange.com/a/63174/14500 –  Paul Gaborit Jul 24 '12 at 8:34

Run it with the sequence latex->dvips->ps2pdf

\documentclass{article}
\usepackage[tiling]{pst-fill}
\pagestyle{empty}
\begin{document}
\DeclareFixedFont{\pi}{U}{psy}{m}{n}{4mm}% the symbol font
\DeclareFixedFont{\ps}{U}{psy}{m}{n}{12cm}% the symbol font
\DeclareFixedFont{\PS}{T1}{ptm}{m}{n}{5cm}% the times font

\psboxfill{\black\Large\pi p}

\begin{pspicture}(10,6)
\rput(3,3){%
\pscharpath[fillstyle=solid,fillcolor=blue!20,
\rput(8.5,3){%
\pscharpath[fillstyle=solid,fillcolor=red!40]{\PS Pi}}
\end{pspicture}

\end{document}


-

TikZ/PGF has no direct access to the font shapes, but once it has been told the paths then it can work with them in exactly the same way as any other path. So whilst PSTricks is probably the better choice if you have a completely free choice, then if you're already using TikZ/PGF in your document you may prefer to use this method even though it is slightly more complicated.

The general idea is to convert a font to PGF paths. This is done via a combination of fontforge and some scripts. It has to be done once for each font, but obviously once it's been done then the results can be cached and reused without that overhead. I've done the conversion for the STIX fonts and the scripts I used are available on the TeX-SX Launchpad Site. Also there are some ideas for a TikZ library to make use of the paths in a "natural" way. If you download pgflibraryletter.shapes.dtx and run tex on it then the following code will work:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/58851/86}
\usepackage{tikz}
\usetikzlibrary{shapes.letters}
\pgfkeys{
/pgf/letter/.cd,
size=4,
}

\begin{document}
\begin{tikzpicture}
\node[draw,fill=blue!40,letter=π] (pi) {};
\node[draw,fill=red!40,letter=P,right of previous letter,] (P) at (pi.east) {};
\node[draw,fill=red!40,letter=i,right of previous letter,] (i) at (P.east) {};
\end{tikzpicture}
\end{document}


and produce the following picture:

This is by no means stable code - and I've found that doing complicated stuff (such as complicated decorations) on the paths quickly exhausts TeX's limits. It can do kerning, but not ligatures (well, you can always insert them manually but it won't automatically convert them).

This started out life in response to the question that Leo Liu linked to: Outlining (filling) glyph outline with text in TikZ and was also used in http://tex.stackexchange.com/a/51462/86. Contrary to the impression given in some of the comments on the first of these, the paths are faithful representations of the font glyphs in that cubic beziers are used at every stage of the process.

-

While it is true that tikz has no access to glyph paths, the PDF format allows stroking and clipping (besides filling) with text paths; cf. the use of \pdfliteral in the example below. 2 Tr means "fill, then stroke", and 5 Tr means "stroke text and add to clipping path". The most usual text rendering mode, which is simply filling glyphs, is activated with 0 Tr.

An interface to this functionality would make a nice tikz library...

\documentclass{article}
\usepackage{tikz,txfonts}

\begin{document}
\begin{tikzpicture}
\path (0,0) node {
\Huge
\pgfsetstrokecolor{red}
\pgfsetfillcolor{blue}
\pdfliteral{2 Tr} %Needs pdfTeX
Hello};

\path (0,-1) node {
\Huge
\pgfsetstrokecolor{red}
\pdfliteral{5 Tr}
Hello%
\tikz[trim left,baseline=1mm]
(0,0) rectangle (-20mm, 7mm);};
\end{tikzpicture}
\end{document}


-

The pstricks pst-text package offers some functionalities in that direction. I am not aware of anything equivalent with TikZ since it looks like by definition, TikZ has no access to the spline definition of fonts. Anyway, as you said, it is still possible to export text as splines from your preferred application and subsequently use these splines within pstricks or TikZ to perform what you want. To this end, you may want to have a look at the eps2pgf graphic package [for TikZ] and maybe the pst-verb command [for pstricks].

Unfortunately, all these merging commands (union, intersection, subtraction...) are quite involved and will not be available directly in LateX since they require some complicated operations I guess.

-
Could you maybe give an example of some working code to use with pst-text? It looks like that package is the right way to go, but I couldn't get it to work (with the examples from the documentation). –  JohnReed Jun 7 '12 at 5:43
here are some examples: tug.org/PSTricks/main.cgi?file=Examples/Text/WriteBig –  Herbert Jun 7 '12 at 6:26

A simple solution with only tikz :

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
\node[scale=20, transparent!0] at (0,0) {\bfseries A};