Copy link to clipboard
Copied
Hi there… i couldn’t find the answer to this question in the forum, so…
I would like to create a rule above a heading that has always the same distance between the top of my heading and the paragraph rule above it. Independently the heading font size. Let me explain.
Say i have a heading font size of 72 pt and a heading rule above with an offset of 24 mm. When i change the heading font to example 36 pt the distance between the top of the heading and the heading rule increases, because the offset setting is still 24 mm. To keep the distance the same i need to change the heading rule offset. Is there a way or a work around to keep the distance always the same, independently the heading font size and without changing the heading rule offset manually every time?
Hope you understand what try to achieve! Thanks!
Copy link to clipboard
Copied
In scripting you can get the text’s ascent line, but not the exact cap height. So you could move the rule a set distance above the ascent, which isn't the percentage amount Uwe is looking for. The space between the cap height and the ascent line would vary with the font’s size and font’s design.
So this AppleScript (OSX only) sets the distance in a text selection to 4 points:
-- the distance in points from the selected texts ascent line to the bottom of the rule
set d to 4
tell application "Adobe InDesign CC 2018"
tell active document
set ov to properties of view preferences
set properties of view preferences to {horizontal measurement units:points, vertical measurement units:points}
set s to object reference of selection
if class of s is text then
set a to ascent of s
set rule above offset of s to a + d
end if
set properties of view preferences to ov
end tell
end tell
36 & 15 point text:
I would think you might also want the rule to be variable depending on the point size. That could be scripted as a percentage of the point size.
Copy link to clipboard
Copied
https://forums.adobe.com/people/rob+day wrote
In scripting you can get the text’s ascent line, but not the exact cap height. …
Hi Rob,
that could be done, but requires a workaround.
Two workarounds discussed below:
A. Think of property firstBaselineOffset in textFramePreferences where you can apply FirstBaseline.CAP_HEIGHT as value.
Then compare the geometric bounds of the text frame with value of baseline of the first baseline in the frame.
B. Convert a capital "T" character to outlines and get it's height by calculating the geometric bounds of the converted glyph.
Important Note: Both methods can yield different values depending on the used font.
Here some code to illustrate the first workaround for getting the cap height of the text with an applied paragraph style named "Test".
Note: This is done by using InDesign's own means to calculate cap height from an applied font. InDesign will not do it by meassuring the height of glyph "T":
/*
WORKAROUND 1 Using firstBaselineOffset set to CAP_HEIGHT
Precondition:
Have a paragraph style named "Test" in an open document.
*/
( function()
{
if( app.documents.length == 0 ){ return };
var doc = app.documents[0];
var paraStyle = doc.paragraphStyles.itemByName("Test");
if( !paraStyle.isValid ){ alert( "ERROR: Paragraph Style not found!" ); return };
var textFrame = doc.textFrames.add
(
{
geometricBounds : [0,0,"100mm","100mm"],
contents : "T" ,
parentStory : { appliedParagraphStyle : paraStyle } ,
textFramePreferences :
{
firstBaselineOffset : FirstBaseline.CAP_HEIGHT ,
insetSpacing : 0 ,
minimumFirstBaselineOffset : 0 ,
verticalJustification : VerticalJustification.TOP_ALIGN
}
}
);
var capHeight = textFrame.texts[0].insertionPoints[0].baseline;
// Optional:
textFrame.remove();
alert( "Cap Height According to Internal Font Info: " + capHeight );
}() )
If the visual approach of glyph "T" is the key, then we have to convert character "T" to outlines as duplicate to calculate "cap height" :
/*
WORKAROUND 2: Do outlines of glyph "T" and calculate height of the outlines.
Precondition:
Have some text selected with uniform point size.
*/
( function()
{
if( app.selection.length != 1 ){ return };
if( !app.selection[0].hasOwnProperty( "baselineShift") ){ return };
var selection = app.selection[0];
var insPoint = selection.insertionPoints[0];
var index = insPoint.index;
insPoint.contents = "T";
var characterAdded = insPoint.parentStory.characters[ index ];
// Create a duplicated outline, leave the original character intact:
var conversionResult = characterAdded.createOutlines( false )[0];
var gB = conversionResult.geometricBounds;
var height = gB[2] - gB[0];
characterAdded.remove();
conversionResult.remove();
alert( "Cap Height Visually: " + height );
}() )
Regards,
Uwe
Copy link to clipboard
Copied
Thanks Uwe, that’s a very clever way to measure cap height!
But I'm guessing font variability would still get in the way of a feature that changes how the offset is calculated. Here’s 20 pt Copperplate, where the cap height and the x-height are almost the same, and Voluta Script, where the cap height is exaggerated relative to the total point size.
And Universe
Copy link to clipboard
Copied
Hi Rob,
when in the design phase of a magazine where we test different layouts, point sizes and different fonts an automatism would be welcome, I think. What I also would appreciate is a means to visibly select a Rule Above or Rule Below in the text and drag it to a distinct position, change its stroke weight with the mouse and then reapply that change to the applied paragraph style.
Regards,
Uwe
Find more inspiration, events, and resources on the new Adobe Community
Explore Now