8 Replies Latest reply on Nov 6, 2008 5:07 AM by Peter Kahrel

    [JS] Cap height and x height

    (Simon_Paterson) Level 1
      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.
        • 1. Re: [JS] Cap height and x height
          [Jongware] Most Valuable Participant
          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.
          • 2. Re: [JS] Cap height and x height
            sstanleyau Level 4
            It's not a dumb question, but the answer is no, alas.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
            • 3. Re: [JS] Cap height and x height
              Peter Kahrel Adobe Community Professional & MVP
              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]
                 }
              • 4. Re: [JS] Cap height and x height
                Martin Fischer Level 2
                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
                • 5. Re: [JS] Cap height and x height
                  Peter Kahrel Adobe Community Professional & MVP
                  Thanks Martin. But I forgot to mention that this is in fact Teus de Jong's idea.

                  Peter
                  • 6. Re: [JS] Cap height and x height
                    Harbs. Level 6
                    > 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
                    • 7. Re: [JS] Cap height and x height
                      (Simon_Paterson) Level 1
                      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.
                      • 8. Re: [JS] Cap height and x height
                        Peter Kahrel Adobe Community Professional & MVP
                        > 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