Skip to main content
Nov 5, 2008 10:37 AM UTC
Question

[JS] Cap height and x height

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 is closed to new replies. Start a new post to keep the conversation going.

8 replies

Peter Kahrel
Community Expert
Community Expert
Nov 6, 2008 1:07 PM UTC
> 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
Translate
Nov 6, 2008 12:26 PM UTC
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.
Translate
Peter Kahrel
Community Expert
Community Expert
Nov 5, 2008 2:26 PM UTC
Thanks Martin. But I forgot to mention that this is in fact Teus de Jong's idea.

Peter
Translate
Inspiring
Nov 5, 2008 12:40 PM UTC
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
Translate
Peter Kahrel
Community Expert
Community Expert
Nov 5, 2008 11:31 AM UTC
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]
}
Translate
Harbs.
Legend
Nov 5, 2008 7:14 PM UTC
> 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
Translate
Inspiring
Nov 5, 2008 11:24 AM UTC
It's not a dumb question, but the answer is no, alas.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
Translate
Jongware
Community Expert
Community Expert
Nov 5, 2008 11:09 AM UTC
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.
Translate