Copy link to clipboard
Copied
HI All
I have a illustrator document contain lot of text frames. Some of the text frames content over-set text.( half portion of text is hidden)
I already using the java script to change the text frame height I have attached script and screen shot for your reference.
var includeExtraLines = 0.5;
if(documents.length > 0) {
doc = activeDocument;
mySelection = activeDocument.selection;
// If there are enough to process
if (mySelection instanceof Array)
{
// For each of the selected items
for(i=0; i<mySelection.length; i++) {
// That are textFrames
if (mySelection.typename == "TextFrame" && mySelection.kind == TextType.AREATEXT ) {
obj = mySelection;
// We only want to do this on rectangular text areas
// TODO: Take care of rotation issues from MakePointType script
if( obj.textPath.pathPoints.length == 4 ) {
objTop = obj.top;
objLeft = obj.left;
// Make the new point type object and locate it
// Make sure the new object is in the same Z stacking order as the original
copy1 = obj.duplicate(obj, ElementPlacement.PLACEBEFORE);
//copy1.move(obj, ElementPlacement.PLACEBEFORE);
// now make the text box much bigger, but not absurdly big
// TODO: This could be better approximated by itterating thru all the WORDS in the textFrame and
// comparing it to all the WORDS in each of the visible text LINES. Then apply the difference / total words to the scaling
if( copy1.height * 10 < 2000 ) {
copy1.textPath.height = copy1.height * 10;
} else {
copy1.textPath.height = 2000;
}
howManyLines = copy1.lines.length;
outlineObject = copy1.duplicate();
outlineObject = outlineObject.createOutline();
targetHeight = outlineObject.height + includeExtraLines * (outlineObject.height / howManyLines );
// Now assign y-axis depth of the point text to the area text box
rect = obj.parent.pathItems.rectangle(copy1.textPath.top, copy1.textPath.left, obj.width, targetHeight);
copy2 = obj.parent.textFrames.areaText(rect);
copy2.selected = true;
rect.selected = true;
// Always delete these intermediate objects
outlineObject.remove();
copy1.remove();
// Now take care of the end and original objects
obj.textRange.duplicate(copy2);
obj.remove();
}
}
}
}
}
But I need to reduce the overset text frame font size.
Please advise me
Thanks in advance.
Ashok
This function can apply to all textFrames.
function reduceSizeOfOversetText(t) {
var d;
while (
d = t.duplicate(),
d.name = 'temp',
d.convertAreaObjectToPointObject(),
d = t.parent.textFrames['temp'],
d.contents.replace(/[\x03\r]/g, '') !== t.contents.replace(/[\x03\r]/g, '')
) {
d.remove();
t.textRange.characterAttributes.size -= 1;
}
d.remove();
}
reduceSizeOfOversetText(app.selection[0]);
Another way: you can create an temp textFrame
...Copy link to clipboard
Copied
Let's make a text overset function which detects the overset on multiline text.
There may be several ways to accomplish this, I am thinking of the following:
Here is a snippet to start you off:
#target illustrator
function test(){
var doc = app.activeDocument;
var sel = doc.selection[0];
var contents = sel.contents;
for(var i = 0; i < sel.lines.length; i++){
contents = contents.replace(sel.lines.contents, "");
}
alert(contents);
};
test();
Copy link to clipboard
Copied
Thank you for your reply. the above code is for selected text frame(frame need to selected manually) but my request is in an illustrator document where there are more than 100 textframes and i need to identify the overset text and reduce the fontsize of the overset text in all the 100 text frame.
Kindly help me on this please.
Regards
Ashok
Copy link to clipboard
Copied
Hi Silly-V
As per your guidance selected text frame overset text is showing correctly. but i want to identify the overset text and reduce the font to fix the overset text.below code shows only the entire line like screenshot & code attached below.
function texts(){
if(documents.length > 0)
{
var docRef = activeDocument;
// clear the old selection
var piArr=[];
activeDocument.selection = null;
//var contents = sel.contents;
// select all text art items that contain the target string
for (j = 0; j < docRef.textFrames.length; j++){
// var t=docRef.textFrames
//var t=docRef.textFrames
var t=docRef.textFrames
contents=t.contents
for(var i = 0; i < t.lines.length; i++){
contents = contents.replace(t.lines.contents, "");
//piArr.push(contents);
alert(contents)
piArr.push(contents);
// alert(t.textRange.size);
if(contents!=""){
var fs=t.textRange.size
if (fs<=6)
{
alert(fs+"small font"+"Still overset")
//exit();
}
else
{
t.textRange.characterAttributes.size = fs-1
s()
}
}
else
{
}
//var t=docRef.textFrames
//contentString = docRef.textFrames.contents;// contentString.lines.length;
// var contents = docRef.textFrames.contents;
//contentString.length;
}
}}
function s(){
if(piArr=="")
{
exit()
}else{
alert("still overset")
texts()
}}
}
//redraw();
//}
//}
texts()
Regards
Ashok
Copy link to clipboard
Copied
This function can apply to all textFrames.
function reduceSizeOfOversetText(t) {
var d;
while (
d = t.duplicate(),
d.name = 'temp',
d.convertAreaObjectToPointObject(),
d = t.parent.textFrames['temp'],
d.contents.replace(/[\x03\r]/g, '') !== t.contents.replace(/[\x03\r]/g, '')
) {
d.remove();
t.textRange.characterAttributes.size -= 1;
}
d.remove();
}
reduceSizeOfOversetText(app.selection[0]);
Another way: you can create an temp textFrame and set .nextFrame property to it, then compare TextFrame's contents to Story's contents.
Copy link to clipboard
Copied
Hey, nice job! what is the character "\x03" ?
Copy link to clipboard
Copied
So called "soft return"? Use centents.toSource() to get it.
When convert area text to point text, line end will add a soft return, and if orginal line end is soft return, it will convert to hard return.
Copy link to clipboard
Copied
Thank you so much for your help.
But the script only run on selected text frame.
i want to identify the overset text and reduce the font size for all overset text frames.
#target illustrator
function test(){
var doc = app.activeDocument;
var sel = doc.selection[0];
var contents = sel.contents;
for(var i = 0; i < sel.lines.length; i++){
contents = contents.replace(sel.lines.contents, "");
}
alert(contents);
reduceSizeOfOversetText(app.selection[0]);
};
test();
function reduceSizeOfOversetText(t) {
var d;
while (
d = t.duplicate(),
d.name = 'temp',
d.convertAreaObjectToPointObject(),
d = t.parent.textFrames['temp'],
d.contents.replace(/[\x03\r]/g, '') !== t.contents.replace(/[\x03\r]/g, '')
) {
d.remove();
t.textRange.characterAttributes.size -= 1;
}
d.remove();
}
kindly help on this.
Regards
Ashok
Copy link to clipboard
Copied
Hi all, for anyone finding this old thread, also please have a look at @femkeblanco's answer here. - Mark