Copy link to clipboard
Copied
I have to re-size several documents and need to go through layer by layer to round the type to the nearest pt. size (i.e. 12.3pt --> 12pt, 12.6pt -->13 pt). Its pretty time consuming and I was hoping there might be a script that could speed up the process.
Thanks,
Dave
Copy link to clipboard
Copied
really curious if there's an answer to this too. i have big plans for the next phase of the project i've been working on but it's being held up by illustrator's moronic handling of text height.. Seems just about every font has a different amount of space above and below the text and as such, illustrator does not properly read/apply font sizes/scaling.
Please, if anyone has a good answer for this, we'd both love to hear it..
Copy link to clipboard
Copied
I can't see why this should not work.
var text = app.activeDocument.textFrames;
for(var i = 0; i < text.length; i++){
var chars = text.textRange.characters;
for(var j = 0; j < chars.length; j++){
chars
.size = Math.round(chars .size); }
}
and it does work for any size except 12.
Why the hell not?
it wont even let me do: chars
I can't work it out, maybe I have not had enough sleep!
Copy link to clipboard
Copied
here's a similar script...and it does not work with size 12 either ...weird
Copy link to clipboard
Copied
...hmm, convoluted workaround, we could set it to 24 pt, then resize to 50% 😕
Copy link to clipboard
Copied
didn't think of that.
i did try to set to some other value then re set it to 12 but that didn't work
I'm still a bit stuffed as to how to set to 50% on a single char.
my first thought was:
chars
chars
but that will just evaluate to 12 and bake to same issue.
if the how textRange needs to be 12 then you could resize the textFrame.
but if only 1 char needs to be 12 and the rest say 30 then it involves setting them all to double before shrinking the textFrame object.
this is a very "Adobe" bug.
here is the best I could work out how to do!
var text = app.activeDocument.textFrames;
for(var i = 0; i < text.length; i++){
var chars = text.textRange.characters;
for(var j = 0; j < chars.length; j++){
if(chars
.size > 11.4 && chars .size < 12.5){ chars
.size = 12.01; }else{
chars
.size = Math.round(chars .size); }
}
}
Copy link to clipboard
Copied
Was thinking of a characterStyle.
but I cant applyTo a single char.
very strange bug...
Copy link to clipboard
Copied
yeah, I meant resize the text frame itself, also my script in the link didn't round each character, it assumed the whole frame was the same size...yours is more complete.
Copy link to clipboard
Copied
doc = app.activeDocument ;
s = doc.selection ;
for ( var i = 0 ; i < s.length ; i ++ ) {
if ( s.typename == "TextFrame" ) {
//$.write( s.textRange.characterAttributes.size,"-->" ) ;
//$.writeln( Math.round(s.textRange.characterAttributes.size) ) ;
s.textRange.characterAttributes.size = Math.round(s.textRange.characterAttributes.size)
}
}
Copy link to clipboard
Copied
your missing var on the first two lines and a semicolon on line eight.
also if you have more then 1 size in the same textFrame it does not work correctly.
But importantly, it does not set text to 12pt.
11.6 pt should become 12 pt, but it stays at 11.6 pt.
Copy link to clipboard
Copied
Thank you for advice!
Font size "12 pt" is the default on "Character Styles" panel.
After I changed that default font size set to "1 pt", it works.
Please check it. I think it could be a bug.
Copy link to clipboard
Copied
true to that.
if default is 12pt (as is default...) then it is simple to fix any size except those that need to be 12pt.
but if you change the default then you just change the font size that cant be fixed.
ie.
if I change default to 10pt then 10.2 pt will not change to 10pt.
That said you did just provide the slap sideways I needed to make this work.
just need to change the default style to a point size that no one in there right mind would use. then set it back at the end.
var defaultStyle = app.activeDocument.characterStyles.getByName('[Normal Character Style]');
var myDefaultSize = defaultStyle.characterAttributes.size;
defaultStyle.characterAttributes.size = 1000;
var text = app.activeDocument.textFrames;
for(var i = 0; i < text.length; i++){
var chars = text.textRange.characters;
for(var j = 0; j < chars.length; j++){
chars
.size = Math.round(chars .size); }
}
defaultStyle.characterAttributes.size = myDefaultSize;
Copy link to clipboard
Copied
Anyway, So I add useless "Character Styles" that has any attribute.
First I applied that character style and than set rounded font size.
See blow script.
var doc = app.activeDocument ;
var s = doc.selection ;
var temp_size = 0 ;
var Useless_Style = doc.characterStyles.add("Useless");
for ( var i = 0 ; i < s.length ; i ++ ) {
if ( s.typename == "TextFrame" ) {
var temp_size = Math.round(s.textRange.characterAttributes.size) ;
Useless_Style.applyTo(s.textRange);
s.textRange.characterAttributes.size = temp_size ;
}
}
redraw() ;
Copy link to clipboard
Copied
that's not a bad way of solving it as well.
adding the "useless" style does not rely on the default '[Normal Character Style]' being present.
note your code does work on text frames as a whole, so if the frame contains more then 1 size font is will produce strange results.
but if you know each frame only contains 1 size font, it will run much faster then my per char snippet.