Friday, August 31, 2007
Overset Text
The question came up this morning on how to get the overset text in a story. I interpreted that as meaning how to get a reference to it and banged out a quick reply. But this got me musing about how to write a release independent function that would do this for either a story or a cell in a table. I came up with this function (which expects to receive either a story or a cell):
But notice the assymetry between working with cells and working with stories. Even though the contents of a cell returns only the non-overset text, if you access the characters of a cell you get the lot, overset or not. So, to get the index of the first overset character in a cell, I had to use the length of the contents rather than the index of the last character plus 1, which is what I first tried to use.
function getOversetText(textFlow) {I confess that I haven't tested this in CS, but I have in both CS2 and CS3 where it works. It should work in CS also.
if (!textFlow.overflows) return null;
var start = textFlow.characters[0];
if (textFlow instanceof Cell) {
if (textFlow.characters.length > 0) {
start = textFlow.texts[0].characters[textFlow.contents.length];
}
} else {
if (Number(String(app.version.split(".")[0])) > 4) {
var myTFs = textFlow.textContainers;
} else {
var myTFs = textFlow.textFrames;
}
for (var j = myTFs.length - 1; j >= 0; j--) {
if (myTFs[j].characters.length > 0) {
start = textFlow.characters[myTFs[j].characters[-1].index + 1];
break;
}
}
}
return textFlow.texts.itemByRange(start, textFlow.texts[0].characters[-1]);
}
But notice the assymetry between working with cells and working with stories. Even though the contents of a cell returns only the non-overset text, if you access the characters of a cell you get the lot, overset or not. So, to get the index of the first overset character in a cell, I had to use the length of the contents rather than the index of the last character plus 1, which is what I first tried to use.
Comments:
<< Home
I saved to ExtendScript Toolkit. Not working in document. Doesn't return a dialog saying where to find the overset in the cell.
Rita,
This is not a complete script. It's a function that can be used by a script to find overset text. It doesn't itself create or display a dialog of any kind.
Dave
This is not a complete script. It's a function that can be used by a script to find overset text. It doesn't itself create or display a dialog of any kind.
Dave
hi, I need a script that automatically reduce overflowing text in cells. I have an Indesign document containing a lot of tables and this script could be very useful! Do you think it's possible?
I use this formula:
while (myTextFrame.overflows)
myTextFrame.parentStory.pointSize −= 0.5;
It's ok for text frames but it doesn't work with table cells. Can you help me?
I use this formula:
while (myTextFrame.overflows)
myTextFrame.parentStory.pointSize −= 0.5;
It's ok for text frames but it doesn't work with table cells. Can you help me?
You need to analyze why a table cell is overset. It could be, for example, that it has a fixed height that is too small for the leading of the text you're using, so reducing the point size isn't going to make any difference.
My tables' cells have height and length that cannot be changed. When I automatically import text in cells, some of them disappear due to overflowing text. What I need is a script that reduces step by step the overflowing text until it fixes cell's height and length.
Do you think it exists?
I wrote the following script but It doesn't work: the while loop never stops. When I stop the script from ESTK, the result, in the InDesign document, is a a text with 0.1 pointSize height.
var doc = app.activeDocument
var mytable = app.activeDocument.stories.everyItem().tables.everyItem();
var celle = app.activeDocument.stories.everyItem().tables.everyItem().columns.everyItem().cells.everyItem();
while (celle.overflows)
celle.texts[0].pointSize -=0.1;
Do you think it exists?
I wrote the following script but It doesn't work: the while loop never stops. When I stop the script from ESTK, the result, in the InDesign document, is a a text with 0.1 pointSize height.
var doc = app.activeDocument
var mytable = app.activeDocument.stories.everyItem().tables.everyItem();
var celle = app.activeDocument.stories.everyItem().tables.everyItem().columns.everyItem().cells.everyItem();
while (celle.overflows)
celle.texts[0].pointSize -=0.1;
raja,
That question doesn't have much to do with this topic, but a search of the blog reveals that this topic hasn't been covered, so I'll write a new entry sometime soon. Meanwhile, look at the Folder class in ESTK's Object Model Viewer at the Core JavaScript Objects. You'll see that there's a create method that will do the job for you.
Dave
That question doesn't have much to do with this topic, but a search of the blog reveals that this topic hasn't been covered, so I'll write a new entry sometime soon. Meanwhile, look at the Folder class in ESTK's Object Model Viewer at the Core JavaScript Objects. You'll see that there's a create method that will do the job for you.
Dave
Dave, first off thanks for the wonderful blog. It seems that whenever I Google for InDesign help, I end up here one way or another.
I have a quick question that I just can't seem to find an answer for.
I wrote a small script that loops through all of the frames on the page and grabs its' content. The problem (as you know) is that if the frame overflows, then the "contents" property only contains the text that can be shown on the screen.
So, how can I get ALL of the text in that frame, regardless of if it's showing?
THANK YOU!
pb_
I have a quick question that I just can't seem to find an answer for.
I wrote a small script that loops through all of the frames on the page and grabs its' content. The problem (as you know) is that if the frame overflows, then the "contents" property only contains the text that can be shown on the screen.
So, how can I get ALL of the text in that frame, regardless of if it's showing?
THANK YOU!
pb_
pb: Assuming that the frames on the page are not threaded, you can get all the text associated with each by getting the contents of the parent story of each.
Holy buckets batman it worked! THANK YOU. So one last question and I'll be on my way - if I want to replace the text in a frame, would I want to set it's "contents" property or the "parentStory.contents" property? Does it matter?
Of course it matters. If you replace the contents of the text frame, then that which was not part of the contents before -- the overset stuff -- will still be there. So you need to replace the contents of the parent story.
Post a Comment
<< Home