-
Dynamic text scale/fontsize up or down base on text length
Hi,
I’ve searched the forum, and found this similar post.
Scaling text to text box expression
But the text layer in my project is based on a JSON file, and that doesn’t seem to work with this expression setup.So the idea is to have the text size down if it doesn’t fit in the width of the white square. I guess have the expression on the scale parameter works best, you then can parent other text layers so the scale with it?
This was Kalle’s take on it in above mentioned post.
txt = value;
margin = effect("margin")("Slider");
char_count = txt.length;
lead_ratio = effect("leading ratio")("Slider");
rect_height = thisComp.layer("Rect").height*thisComp.layer("Rect").scale[1]/100-2*margin;
rect_width = thisComp.layer("Rect").width*thisComp.layer("Rect").scale[0]/100-2*margin;
rect_ratio = rect_width/rect_height;
char_per_line = Math.round(Math.sqrt(char_count*rect_ratio*lead_ratio));
lines = Math.ceil(char_count/(char_per_line));
done = 0;
esc = 0;
len =0;
//row = Math.floor(thisComp.layer("Rect").sourceRectAtTime(time).width*thisComp.layer("Rect").scale[0]/1220);//divisor depends on type size
row = char_per_line;
while (done == 0){
esc ++;
len+=row;
if (txt.length >= len+1){
for (i = len; i > len-row; i--) if (txt[i] == " ") break;
if (i > len-row){
txt=txt.substr(0,i) + "\r" + txt.substr(i+1,9999);
}
}
len = i;
if (esc>100){done=1}
}
txt

