Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[JS] Cap height and x height

Guest
Nov 05, 2008 Nov 05, 2008
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.
TOPICS
Scripting
3.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2008 Nov 05, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 05, 2008 Nov 05, 2008
It's not a dumb question, but the answer is no, alas.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2008 Nov 05, 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]
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 05, 2008 Nov 05, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 05, 2008 Nov 05, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2008 Nov 05, 2008
Thanks Martin. But I forgot to mention that this is in fact Teus de Jong's idea.

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 06, 2008 Nov 06, 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2008 Nov 06, 2008
LATEST
> 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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines