2009-09-30

Collapse InDesign Text Frame to Descenders

It used to be as I taught Adobe InDesign to QuarkXPress users that I would always get asked why Adobe InDesign collapses the frame to the baseline instead of forcing the frame to the descenders as QuarkXPress does. For whatever reason, I don't get asked the question much anymore, but this function will make Adobe InDesign behave the same as QuarkXPress, and maybe even better.

If you pass this function a reference to a text frame it will automatically collapse it to the position of the final descender. It is great for headlines. However, if you pass it a second argument, a real in points, it will add that number of points to the frame. Great if you still haven't adopted a baseline grid (baseline grids make building pages easy).

I wrote this function for a project nearly a year ago and I know it gets used every day multiple times by the client who uses it. Now anybody that wants it can have it too.

This function could very easily be given an alternate keyboard shortcut to replace the default
control alt c
or
command option c
keyboard shortcuts for Fit Frame to Content.


function holdDescenders ( aTextFrame_o , extraHeight_n ) {
//-------------------------------------------------------------------------
//-- H O L D D E S C E N D E R S
//-------------------------------------------------------------------------
//-- Generic: Yes.
//-------------------------------------------------------------------------
//-- Purpose: To increase the height of the passed frame by the amount
//-- that Adobe InDesign indicates is the height of the largest
//-- descender of the frame.
//-- Assumptions: 2
//-- 1: This function assumes that the frame has already been collapsed
//-- to the baseline of the last line of text as if you had used
//-- its 'Fit Frame to Contents' function. Call this function
//-- _after_ collapseing the frame using your desired method.
//-- 2: The measurement system is assumed to be points.
//-- Warning: There is no error checking for text that is not visible.
//-------------------------------------------------------------------------
//-- Parameters: 2
//-- aTextFrame_o: A single text frame object. The frame whose height
//-- you want to increase the height of by adding the maximum
//-- descender height.
//-- extraHeight_n: a point value. If not supplied, zero is assumed.
//-- Returns: Nothing. The passed object is modified.
//-------------------------------------------------------------------------
//-- Written by Jon S. Winters on 2008.10.29
//-- eps@electronicpublishingsupport.com
//-------------------------------------------------------------------------
//-- Verify argument 2. If it isn't a number, make it zero.
extraHeight_n = parseFloat ( extraHeight_n ) ;
if ( isNaN ( extraHeight_n ) ) { extraHeight_n = 0 } ;
//-- Get the descender value
var descenderHeight = aTextFrame_o.parentStory.characters[-1].descent ;
//-- Increase the frame height
var currentBounds = aTextFrame_o.geometricBounds ;
currentBounds[2] = currentBounds[2] + descenderHeight + extraHeight_n ;
aTextFrame_o.geometricBounds = currentBounds ;
}

No comments:

Post a Comment