Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Rather than tracing the border of a magnified character to find some critical points making the character as follows,

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-text,pst-eucl}

\DeclareFixedFont{\ps}{U}{psy}{m}{n}{12cm}% the symbol font
\DeclareFixedFont{\PS}{T1}{ptm}{m}{n}{11cm}% the times font

\def\x{4}

\psset
{
    showpoints=true,
    linecolor=red,
    PointName=none,
    dotscale=0.5,
}

\newpsstyle{gridstyle}
{
    subgriddiv=10,
    subgridcolor=lightgray,
    subgridwidth=0.05pt,
    subgriddots=0,
    gridcolor=black,
    gridwidth=0.1pt,
    griddots=0,
    gridlabels=5pt,
    gridlabelcolor=red,
}
\begin{document}

\begin{pspicture}[showgrid](-\x,\x)(\x,-\x)
    \rput(0,0){\pscharpath[linecolor=blue,linewidth=0.1pt]{\PS R}}
    \pstGeonode
    (-3.483, 3.700){n1}
    (-0.800, 3.700){n2}
    ( 1.260, 3.700){c1}
    ( 2.340, 3.200){c2}
    ( 2.340, 1.700){n3}

    \psline(n1)(n2)
    \psbezier(n2)(c1)(c2)(n3)
\end{pspicture}

\end{document}

I want to extract such points directly from the font file.

Is it possible to do that?

The objective is to recreate such a character to be used for clipping discussed in my previous question How to fill a region bounded by a character and a graphic object with a color?

share|improve this question
    
Maybe it'll be easier to render the clipped character as a (black&white) bitmap and then re-vectorize with potrace, for instance. –  Stephan Lehmke Jul 20 '12 at 15:27
3  
Fontforge can convert font information to svg paths which can then be converted to pgf paths. would that help? –  Loop Space Jul 20 '12 at 21:55
    
@Andrew Stacey: maybe you can expand your comment into an answer? :-) –  Kurt Pfeifle Jul 23 '12 at 22:36

2 Answers 2

up vote 15 down vote accepted
+50

Here's the steps needed to convert a font character to a PGF path. It works on a Unix-based system (tested on Linux and MacOSX). I don't know if the required programs are available on other systems. The dependencies are FontForge and Perl. The former is fairly important, the latter is just the non-TeX language I know best.

  1. Use FontForge to convert the font to SVG paths. You can do this in FontForge, or simply run the following script on the font file: x2svg.pe /path/to/font/font.ttf (ttf simply for example, FontForge reads everything, save script as x2svg.pe or change the calling command appropriately).

    #! /usr/bin/env fontforge
    
    Open($1)
    Generate($1:t:r + ".svg")
    
  2. Run the perl script svgtopgf.pl on the resulting file. Syntax is svgtopgf.pl font.svg prefix where prefix is to make the resulting stuff unique. This creates a file that defines a load of paths, one for each glyph, and also contains their bounding box information. The paths, and bounding boxes, are labelled according to the decimal unicode number. The path commands are PGF basic layer commands.

Then use these macros to define the relevant paths and the rest of the TikZ/PGF code to manipulate them as you wish. At the TeX-SX launchpad there's a PGF library that makes these letters into node shapes.

share|improve this answer

No, not without a lot of work.

At the postscript level you can convert the letter to a path and fill it or clip with it rather than stroke (draw) it. So you can for example do:

enter image description here

from this postscript (which you could convert to pstricks calls easily)

  gsave                                      % Save old clip path
    /Times-Roman findfont 350 scalefont setfont
    200 200 moveto (R) true charpath    % Set up the text's path
  gsave 0.8 1.8 scale 350 180 100 0 360 arc  eofill grestore

    grestore
  showpage

However you want to go further and find the points of intersection between the path extracted from R and the path of the ellipse, and work out which of those points go with which region. That is hard; requiring some equations to be solved. Probably more the preserve of metapost than postscript or tex but its a long time since I looked at that.

share|improve this answer
    
Note that LuaTeX integrates MetaPost so it may be doable (but probably not easy) there. –  Martin Schröder Jul 24 '12 at 15:05
    
@David Carlisle: I am not sure why you are saying "However you want to go further [...]"? As soon as you have access to the splines describing the character of interest, you can use them for clipping. How the final clipped objects appear on the screen will later be calculated by the graphic card. –  pluton Jul 26 '12 at 5:09
    
@pluton If you wanted to fill/clip all the regions in the same way as in my postscript example then what you say is true, but the OP wants to fill each of the regions with a different colour so you have to find out which of splines and segments making up each path surrounds which subregion. I think you have to do that by hand and solve the equations for the intersection of the path from R and the path from the elipse –  David Carlisle Jul 26 '12 at 9:17
    
I would embed two clipping commands, one driven by the portion of the R character on top of which I would use another clipping instruction driven by the ellipse. –  pluton Jul 26 '12 at 12:18
    
Yes sure but look at the weird shape black bit at the bottom of the image If you wanted (just) that to be green you need to find the portion of the R path and the portion of the ellipse path that relates to that or (probably easier) find another clipping path to overlay that includes that region but not any of the other black regions. I can't see how you can do that automatically without calculating intersection points. see the OP's image at i.stack.imgur.com/CbMIs.png –  David Carlisle Jul 26 '12 at 12:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.