Saturday, June 17, 2006

 

Sometimes, You Need a Blunt Instrument

I have a very complex script that does a lot of automatic page composition. One of the elements it has to work with is an inline group of figures with a caption. During the process of importing the images into this group, the group changes size. Because of the way the group is constructed, it is impossible to keep the inline sitting properly on the baseline as this happens.

So, the solution is to move it back inline. Well, I already had a function at hand that does this:
function moveInlineToBaseline(theGraph) {
var myBase = theGraph.parent.baseline;
var myBounds = theGraph.geometricBounds;
theGraph.move(undefined, [0, myBase - myBounds[2]]);
theGraph.parent.parentStory.recompose();
}
I wrote this for any inline graphic; hence the argument name theGraph. But for some reason, this logic failed on one instance in a very long document. The move command threw up an error to the effect that the object couldn't be moved by the requested amount because it would fall outside the bounding box of the containing frame. This was not true based on my measurements and examining the data, and I cannot see anything wrong with the logic, but attempting some debugging in ESTK, I discovered that the group in question couldn't be moved at all. Clearly, something odd was going on, but what?

Well, sometimes you just have to bite the bullet and try some other approach. In this case, I went for the Cut/Paste blunt instrument approach:
function moveInlineToBaseline(theGraph) {
var myBase = theGraph.parent.baseline;
var myBounds = theGraph.geometricBounds;
try {
theGraph.move(undefined, [0, myBase - myBounds[2]]);
} catch (e) {
// I don't know why this should ever fail, but I have an example, so let's go at it a different way in this case
var myIPindex = theGraph.parent.index;
var myStory = theGraph.parent.parentStory;
app.select(theGraph);
app.cut();
app.select(myStory.insertionPoints[myIPindex]);
app.paste();
myStory.recompose();
return
}
theGraph.parent.parentStory.recompose();
}
And that worked. With any luck, that Cut/Paste path through the script will never again be used, but if it is, I can be confident it will work because it solved my problem.

Note that when you paste a frame or group inline, it sits on the baseline properly, even if, as in this case, it was not on the baseline when it was cut. That's because I selected the object and not the character containing the object. Had I done the latter, the position relative to the baseline would have been part of the cut information.

Friday, June 16, 2006

 

Smart Title Case Revisited

In response to a request, I've updated the Smart Title Case script I posted last August (and wrote about here). The new version is now available in the Featured Scripts Downloads section.

I've made two changes, one trivial and one significant. The significant change is that the script now adds an initial cap to the first word after a forward slash, so, instead of having:
absolutely/positively
convert to:
Absolutely/positively
it now converts to:
Absolutely/Positively
The lesser change is a clean-up of the built-in list of words to ignore. I had "is" in there. To my eye, capitalizing "is" in title case text looks wrong, but because it is a verb, it apparently ought to be capitalized according to the style guides I have read. My reaction to this is to avoid using "is" in a title, but I don't always have control over the contents of titles in the documents for which I do the composition.

Usage Note

This script includes two word lists you can edit to customize it to your own use. Or, you can use an external word list in a text file for each of the two lists.

If you don't use the script very often, it is easy to confuse yourself by creating an external word list and then forgetting that you did this. I've done it myself and found myself trying to debug a non-existent problem because the script was apparently ignoring my changes to the word lists -- it wasn't ignoring my change: it was ignoring the whole list.

I suggest if you do decide to add an external list you should edit the corresponding list in the script to say so. For example, change the ignoreWords line to read:
var ignoreWords = ["using external file"]
Then, when you come back to the script a month or so later and want to add another word to the list, the script itself will remind you what you did.

Thursday, June 15, 2006

 

Section Prefixes

I'm sure there are people who think section prefixes are wonderful, but most of the time I bend over backwards to eliminate them. But you do have to remember to do it when you set up the sections. So, if you're in an after-the-fact situation and you want to eliminate them, how hard can it be?
//DESCRIPTION: Delete all section prefixes

if (app.documents.length > 0) {
aDoc = app.activeDocument;
aDoc.sections.everyItem().sectionPrefix = "";
aDoc.sections.everyItem().includeSectionPrefix = false;
}

I know I've been neglecting the blog lately, but I hope people are still finding useful stuff here.

Dave

This page is powered by Blogger. Isn't yours?