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.

Without knowing anything about fonts, I innocently read an article on Postscript/Truetype Bezier curves.

The first picture in the article shows the letter Q, and it's Bezier control points. I'd like to look at more letters (also greek letters) and their Bezier construction.

I therefore installed the program fontforge and loaded a letter from the computer modern font (I belive) in /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb

Omega

This visualization is perhaps technically useful, but not very pleasing. So, I wonder, could it be done inside TeX? Maybe using TikZ controls function: enter image description here.

Clarification for this option: The letter can be drawn with TikZ as well, but I'm more interested in a nice visualization of the control points.

It surely isn't easy, as the font is stored in a binary format. Perhaps it can be converted?

EDIT

  • @g.kov shows a nice visualization using Asymptote.
  • I modified Andrew Stacy's script from this question, and am quite happy with it. See below.
share|improve this question
    
oops: related or duplicate? tex.stackexchange.com/questions/64087/… –  Sebastian May 18 at 15:00

2 Answers 2

up vote 13 down vote accepted

enter image description here

Control points of a glyph path(s) can be extracted with texpath() function in Asymptote:

// glyph.asy :
//
size(7cm);
import fontsize;

defaultpen(fontsize(9pt));

real wd=0.6bp;
pen dotPen=deepblue+wd;
pen dotFill=dotPen;

pen dotPenB=blue+wd;
pen dotPenC=red+wd;

pen linePen=deepblue+wd;
pen fillPen=lightgreen+opacity(0.1);

pen thinLinePen=black+wd/2;


guide[] g;

g=texpath("$\Omega$");

filldraw(g,fillPen,linePen);

pair a,b,c,d;
pair labdir;
int pointNo=0;

for(int i=0;i<g.length;++i){
  for(int j=0;j<size(g[i])-1;++j){
    a=point(g[i],j);
    d=point(g[i],j+1);
    if(straight(g[i],j)){
      draw(a--d,thinLinePen);    
    }else{
      b=postcontrol(g[i],j);
      c=precontrol(g[i],j+1);
      draw(a--b--c--d,thinLinePen);
      dot(b,dotPenB,UnFill);
      dot(c,dotPenC,UnFill);
    }
    dot(a,dotPen,Fill(dotFill));
    labdir=rotate(-90)*dir(g[i],j);
    label("$\scriptsize "+string(pointNo)+"$",a,labdir);
    ++pointNo;
  }
  dot(d,dotPen,Fill(dotFill));
  labdir=rotate(-90)*dir(g[i],size(g[i])-1);
  label("$\scriptsize "+string(pointNo)+"$",d,labdir);
}

To get glyph.pdf, run:

asy -f pdf glyph.asy
share|improve this answer

After modifying Andrew's script, I get:

enter image description here omega percent sign letter g

How to do it:

  1. fontforge script font2svg.fontforge

    #! /usr/bin/env fontforge
    Open($1)
    Generate($1:t:r + ".svg")
    
  2. running (chmod +x font2svg.fontforge)

    ./font2svg.fontforge /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb
    

    Puts a file cmr10.svg into your folder. E.g. letter 'Omega':

    <glyph glyph-name="Omega" unicode="&#x2126;" horiz-adv-x="722"              
    d="M677 162l-33 -162h-159c-23 0 -26 0 -26 21c0 69 32 159 47 201c29 82 56 158 56 233c0 156 -106 228 -202 228c-91 0 -201 -68 -201 -228c0 -75 28 -154 49 -212c23 -64 54 -152 54 -222c0 -21 -3 -21 -25 -21h-160l-33 162h25c5 -25 10 -51 18 -74c5 -15 8 -23 66 -23
    h80c-13 56 -45 104 -89 170c-47 71 -88 140 -88 219c0 137 133 251 305 251c169 0 304 -112 304 -251c0 -79 -41 -148 -88 -219c-45 -66 -76 -114 -89 -170h80c58 0 61 8 66 24c9 24 13 47 18 73h25z" />
    

    Nice, these are the path specifications.

  3. Running the modified script

    ./svgtopgf_mime.pl crm10.svg tmpstr
    

    My changes to Andrew's. It now writes (for each glyph), three files

    • chars/gly_<prefix>N, where N is the decimal unicode number. This file contains the glyph path (almost identical output of original script).
    • chars/bezier_<prefix>N containing the bezier control handles. TikZ 3.0 arrows.
    • chars/pts_<prefix>N containing all the points on the glyph outline (not used)
  4. Then, drawing a new glyph is as easy as including them in a tex file:

    \documentclass[a4paper]{article}
    \usepackage{tikz} % loads xcolor
    \usetikzlibrary{arrows.meta}
    \begin{document}
    \definecolor{solbglight}{HTML}{FDF6E3}
    \definecolor{solblue}{HTML}{268BD2}
    \definecolor{solmagenta}{HTML}{D33682}
    \pagecolor{solbglight}
    
    %Omega
    \begin{tikzpicture}[scale=18]
    \input{chars/gly_tmpstr8486}
    \pgfusepath{fill}%
    \begin{scope}[thick,solblue]
      \input{chars/bezier_tmpstr8486}
    \end{scope}
    \end{tikzpicture}
    
    %Percent sign
    \begin{tikzpicture}[scale=15]
    \input{chars/gly_tmpstr37}
    \pgfusepath{fill}%
    \begin{scope}[thick,solblue]
      \input{chars/bezier_tmpstr37}
    \end{scope}
    \end{tikzpicture}
    
    %g
    \begin{tikzpicture}[scale=25]
    \input{chars/gly_tmpstr103}
    \pgfusepath{fill}%
    \begin{scope}[thick,solblue]
      \input{chars/bezier_tmpstr103}
    \end{scope}
    \end{tikzpicture}
    
    \end{document}
    
share|improve this answer
    
BTW, you can use the SVG path data directly in PGF/TikZ; see the manual for SVG-Path Library. –  morbusg May 22 at 14:37

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.