I'm trying to find the smallest textframe within a group and then matching that textframe font size to the minimum size allowed for printing. Everything else works, except I can't figure out how to resize the textframe while also resizing its parent, the group.
#target illustrator
docRef = app.activeDocument;
gpRef = docRef.groupItems[0];
var gpHeight = gpRef.height;
//this is the minimum print font size allowed
var minFntSize = 18;
var garbLay;
var txtFrmCount = gpRef.textFrames.length;
var container = { };
var i;
//put each textframe and height prop into json
for(i = 0; i < txtFrmCount; i++) {
container['prop'+i] = { 'gpTfHeight':gpRef.textFrames[i].height / 72, 'gpTarget':gpRef.textFrames[i] };
}
//find the min value of height prop in textframe; i have the max in there too just incase i need it in the future
var min = Infinity;
var max = -Infinity;
var x;
for (x in container) {
if( container[x]['gpTfHeight'] < min) {
min = container[x]['gpTfHeight'];
minTg = container[x]['gpTarget'];
}
if( container[x]['gpTfHeight'] > max) {
max = container[x]['gpTfHeight'];
}
}
//duplicate textframe, convert to ouline and get actual height
var txtFrmDup = minTg.duplicate();
txtFrmDup.position = [(minTg.position[0] - 100), (minTg.position[1] - 100)];
txtFrmDup.name = 'garbage';
var tOutline = txtFrmDup.createOutline();
tOutline.name = 'garbage';
var tLogHeight = Math.round(tOutline.height);
garbLay = gpRef.groupItems.getByName('garbage');
//this is the part where I might need to convert to a percentage? tgSize is the target size and I figured I could get the different of the 2 and then use that amount to resize down/up...
var tgSize = minFntSize - tLogHeight;
var perc = Math.round((tgSize/gpRef.height)*100);
$.writeln(minFntSize);
$.writeln(tLogHeight);
$.writeln(tgSize);
$.writeln(perc);
//resize gp so that min textframe font size meets minFntSize
if(tLogHeight < minFntSize) {
gpRef.resize(perc, perc);
$.writeln('smaller');
garbLay.remove();
} else if(tLogHeight > minFntSize) {
gpRef.resize(perc, perc);
$.writeln('bigger');
garbLay.remove();
} else if(tLogHeight == minFntSize) {
$.writeln('equal');
}
I'm not even sure if I'm going about this the right way. Hoping a fresh set of eyes can take a look and see what I'm doing wrong or not doing? Thanks!