Skip to main content
November 5, 2008
Question

[JS] Cap height and x height

  • November 5, 2008
  • 7 replies
  • 4004 views
Am I going crazy or is there no way to find the cap height and x height of text? Obviously you can specify these settings in the first baseline offset of a text frame and I would like to know what these values are going to be. Apologies if this is a dumb question.
This topic has been closed for replies.

7 replies

Peter Kahrel
Community Expert
Community Expert
November 6, 2008
> you do not need to enter a different character to determine the x-height or the cap height ... even the character 'x' at all. In fact, it doesn't matter what character you enter

That's correct.

Peter
November 6, 2008
Peter,

Thank you for your post. I was already using that approach and wanted to find out if I was going crazy or if there really was no alternative.

In case this helps anybody, however, it is worth noting that you do not need to enter a different character to determine the x-height or the cap height (the function doesn't actually do that) or even the character 'x' at all. In fact, it doesn't matter what character you enter, even a space band, as any character in the same font and size will return the same results.

Most importantly, thank you for taking the time to respond.
Peter Kahrel
Community Expert
Community Expert
November 5, 2008
Thanks Martin. But I forgot to mention that this is in fact Teus de Jong's idea.

Peter
Inspiring
November 5, 2008
Hi Peter,

> function x_cap (ip)

Fantastic!

Thank you very much for this nice function.
In the past I did this measurement with the outline method.
But now I prefer your function.

Thanks
Martin
Peter Kahrel
Community Expert
Community Expert
November 5, 2008
As jongware mentioned, you don't have much access to fonts. His idea of converting to outlines and measuring the height of the resulting frame is one possibilty. I've been using a different approach (which might in fact be slower than jongware's). The idea is to add a temporary text frame, enter "x", set the first baseline offset to capheight and measure the baseline: that's the capheight. Remove the X, enter x (lower case), set the first baseline offset to xheight, mease the baseline again: now you have the xheight.

Peter

// "ip" is an insertion point
function x_cap (ip)

{
var tf = app.activeDocument.textFrames.add (
{
geometricBounds: [0,0,40,40],
textFramePreferences : {firstBaselineOffset: FirstBaseline.capHeight},
contents: 'X'}
);
tf.parentStory.appliedFont = ip.appliedFont;
tf.parentStory.pointSize = ip.parentStory.characters[ip.index-1].pointSize;
var cap_height = tf.characters[0].baseline;
tf.textFramePreferences.firstBaselineOffset = FirstBaseline.xHeight;
x_height = tf.characters[0].baseline;
tf.remove();
return [cap_height, x_height]
}
Harbs.
Legend
November 5, 2008
> I've been using a different approach (which might in fact be slower than jongware's).
I don't think anything can be slower than converting to outlines. I
think it's the most processor intensive (and buggy) function in
InDesign. I've used this convert to outline trick for many things
including getting x/caps height, but I like your function way better.
Thanks!

--
Harbs
http://www.in-tools.com
Inspiring
November 5, 2008
It's not a dumb question, but the answer is no, alas.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
Jongware
Community Expert
Community Expert
November 5, 2008
Scripting does not provide direct access to fonts. But you can find the values you need by taking a sample character and convert it to outlines. It has been mentioned before in this forum, perhaps a search will locate it.