I may be way out of league asking this question but is there a way to get the linear length of a letter or words. That is, if you were to take the word "super" and measured the outside border of the letters you'd get a measurement. Is there something out there that would tell me this measurement if I give the font and the font size? I'm a rookie here so be gentle. thanks in advance.

4 Answers 4


This is trivial to do using TeX/LaTeX (though you'll want to use a newer version such as xetex or luatex so as to be able to easily access OpenType and TrueType fonts):

\setmainfont{Myriad Pro Black Condensed}% <<-- change to desired font
\settowidth{\samplewidth}{Test} % <<-- change to the text which you wish to measure

which will output: 0.2060in

OpenType features are supported:

\settowidth{\samplewidth}{Test 0123456789}
\settowidth{\samplewidth}{Test 0123456789}

which outputs:



  • 1
    When it comes to contextual alternates, discretionary ligatures and the gamut of OpenType features/substitutions, I don't know that "trivial" is quite the word I'd use... :) [BTW: Haven't we met on the InDesign listserv, or are you a different LaTeX aficionado of the same name?] Commented May 12, 2014 at 17:37
  • 1
    Which OpenType feature would you like to turn on --- they all work and are accessible (enabling options in a pre-written program qualifies as trivial, no). Yes, I'm the willadams from the InDesign list.
    – WillAdams
    Commented May 12, 2014 at 17:39
  • <grinning widely> Only a true-blue, fully-paid-up, geek's geek could call 14 lines of code "trivial" in the first place, so I suppose on that basis that adding the necessary OTF parameters would similarly qualify. Commented May 12, 2014 at 17:46
  • Great to see you here, though. You have several areas of knowledge that aren't much represented here otherwise (said LaTeX being a good case in point). Commented May 12, 2014 at 17:48
  • @AlanGilbertson 14 lines can be hard but its not hard if they have no algorithmic effect, and are copied from a documentation, when used in exactly the scope they were designed. Line count does simply enter the picture.
    – joojaa
    Commented May 13, 2014 at 4:45

In terms of commonly-available tools, no, there's nothing that will take [random-font] [size] and [characters] as inputs and spit out a length. There are several reasons why this will always be true, but the main one is that every normal (not monospaced) font has its own kerning table that can and often does vary somewhat from one release of the font to the next, not to mention the fact that different type foundries publish their own versions of popular typefaces (Futura, Times, Gill Sans, etc.), with their own variations in character outlines and kerning. All that, and we haven't even mentioned ligatures, tracking, custom kerning or automatic character alternates or swashes such as are commonly available in OpenType fonts.

So although a measuring tool of the kind you're asking about could in theory be made, the practicalities involved in making it actually useful would probably make it too expensive to be worth the effort.

All is not lost, though. Every design application has some form of measuring tool (even, as WillAdams points out, specifically for type in the case of LaTeX) that can be used to measure anything on the page. In the Adobe applications it's found nested with the Eyedropper tool. It's manual, but it works.

  • Thanks for the detailed answer. Although over my head it's not completly difficult to understand what you're getting at.
    – mrbungle
    Commented May 12, 2014 at 17:34
  • 1
    If it seems over your head, just pick up the individual bits of terminology you're not familiar with and google them. Terminology is 90% of the battle in getting comfortable with and being able to become facile with any subject. Commented May 12, 2014 at 17:41
  • Indeed. I'm a dba/report writer thrown into the postion. This topic however is just for a personal project. :-)
    – mrbungle
    Commented May 12, 2014 at 17:47
  • In that case, you'll want to take a look at: pytex.org/texd
    – WillAdams
    Commented May 12, 2014 at 18:42
  • I'll check that out as well, looks interesting and something I'll probably end knowing too much of just for a personal side project, lol. Always learning!
    – mrbungle
    Commented May 12, 2014 at 19:23

There are many ways this could be done. I'm showing here how a engineer would approach the problem. The point is to show that the approach is in many ways analogous to many other fields. Enumerating it aloud seems boring and in simple cases like this its done silently in the head. This just illustrates the method.

Warning long explanation.

Stage 1: Define solution

  • Get width of string.
  • Using specific font.
  • Preferably in a technically usable way so minimal human intervention.
  • Using font encoding: Unknown ask clarification, affects solution
  • Purpose: Unknown ask clarification, affects solution
  • How often is the tool needed: Unknown ask clarification, affects solution if often
  • need batch processing: Unknown ask clarification, affects solution if needed
  • user input: string plus font? Disambiguate
  • output: for a automated process or for manual use?
  • use environment: What operating system? Unknown ask clarification, strongly affects solution
  • unit: Pixels, pt, inches or mm? Unknown ask clarification, affects solution

As you can see there's a lot of unknowns that need to be answered. Especially if one wants to have a good solution that could be shipped to client. Always strive to understand the problem.

Stage 2: Search for methods in literature (or brainstorm)

First stage is to list applications and methods that could yield answers:

Graphics applications (adobe has scripting api OK)
Page setters (TEX solution above)
Operating system (windows has methods for font metrics)
Manually parse fontfile (Infeasible, many formats in one need to implement a lot of routines)
postscript interpretters (solution known)
GUI toolkits (QT can do this)
Other Tookints (Graphing tools like Scipy have this info)

The list is sufficent go test

Stage 3: Prototype (sketch)

using postscript

Postscript is a known method, problem with postscript is what engine do you use to do this as they have slightly different effects. Using gohostscript following batch file works:

:: usage stringWidth string systemfont
set "ps=(%1) /%2 findfont 12 scalefont setfont 0 0 moveto true charpath pathbbox pop exch pop exch sub pstack"
gswin64c -dQUIET -dBATCH -r1200 -dNODISPLAY -sFONTPATH=%windir%\fonts -c %ps%

Works on windows, returns point width, probably also works linux with a few changes. Border constraints unknown. Ask clarification. Problems: need to fix char encoding or use intermediary ps file. Otherwise no spaced string works. Nasty encoding issues, manageable if using western languages.

Using Illustrator and javascipt

using illustrator manually: If you outline the path you can read the width of the text in the width box in the gui. Once this is understood it can be scripted.

This can be codified in javascript:

#target illustrator

var doc = app.documents.add();
var text = doc.textFrames.add();
text.contents = "test";
text.textRange.characterAttributes.size = 12;
text.textRange.characterAttributes.textFont = textFonts.getByName("Onyx");

var outline = text.createOutline();
var bounds = outline.geometricBounds
var width = bounds[1]-bounds[3]
alert(width+" pt")

Works, but needs Illustrator may or may not be a problem. Result may be refined for some technical aspects if needed. Same thing could be done in VB or applescript, or using COM with C, C++, python, perl, ruby etc. Can be used trough command line too if its necessary.

And after some of the ones above are tested choose one for refinement.

PS: Could op clarify?


It's easy to do in JavaScript. Here's a little tool I wrote that outputs a table of character widths for the ASCII character set 0 to 255. The numbers are expressed in proportions of font size, so for an uppercase "M" (ASCII code 77 decimal) you would take the number at array index 77 and multiply it by the font size to get the character width of “M”.

This was made for use with the OpenSCAD 3D design software, but it should be pretty self-explanatory. Usage instructions are at the bottom of the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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