: Any automated system to compute the linear length of a letter(s) in a word or phrase? I may be way out of league asking this question but is there a way to get the linear length of a letter
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.
More posts by @Courtney577
3 Comments
Sorted by latest first Latest Oldest Best
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?
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):
documentclass{standalone}
usepackage{fontspec}
setmainfont{Myriad Pro Black Condensed}% <<-- change to desired font
usepackage[nomessages]{fp}
makeatletter
newcommand{printer}[3][in]{%
FPevaltemp{round(expandafterstrip@ptcsname#2endcsname/72.27:#3)}%
temp#1}
makeatother
begin{document}
newlength{samplewidth}
settowidth{samplewidth}{Test} % <<-- change to the text which you wish to measure
printer{samplewidth}{4}
end{document}
which will output: 0.2060in
OpenType features are supported:
settowidth{samplewidth}{Test 0123456789}
printer{samplewidth}{4}par
addfontfeature{Numbers={Proportional,Lining}}
settowidth{samplewidth}{Test 0123456789}
printer{samplewidth}{4}
which outputs:
0.8425in
0.7911in
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.