- July 23, 2020 at 9:33 am
Like this (Rectangle size):
t = thisComp.layer("my_text");
tRect = t.sourceRectAtTime(time,false);
tUL = t.toComp([tRect.left,tRect.top]);
tLR = t.toComp([tRect.left+tRect.width,tRect.top+tRect.height]);
myRect = sourceRectAtTime(time,false);
myUL = toComp([myRect.left,myRect.top]);
myLR = toComp([myRect.left+myRect.width,myRect.top+myRect.height]);
textSize = t.text.sourceText.style.fontSize;
margin = textSize * 0.8;
[(tLR-tUL + 2*margin)/(myLR-myUL),(tLR-tUL+ 2*margin)/(myLR-myUL)]*100;
.style just looks at the fontSize of the very first Character, so if for some layout-reason that character was set at a smaller size and you want to look at a different character, you should use this:
textSize = t.text.sourceText.getStyleAt(1).fontSize;
the index is 0-based, so this example will look at the fontSize of the second character.
- July 23, 2020 at 9:48 am
instead of making the box with rectangle and two expressions, it is better to do it with a Path-shape:
expression for Path of a shapeLayer:
sr = t.sourceRectAtTime();
marginH = t.text.sourceText.style.fontSize * 0.5;
marginV = marginH * 0.75;
tl = fromCompToSurface(t.toComp([sr.left - marginH, sr.top - marginV]));
tr = fromCompToSurface(t.toComp([sr.left + sr.width + marginH, sr.top - marginV]));
br = fromCompToSurface(t.toComp([sr.left + sr.width + marginH, sr.top + sr.height + marginV]));
bl = fromCompToSurface(t.toComp([sr.left - marginH, sr.top + sr.height + marginV]));
createPath( [tl,tr,br,bl], , , true);
Add Fill, Stroke, rounded corners to taste.
The upside of this method is that the Path text-box can rotate with the Text. Even if the Text is rotating in 3D.
- July 23, 2020 at 1:08 pm
Asking for help and being blessed with someone else, whom you’ve never met and from any part of the world to collaborate and showing kindness is the most satisfying thing.
Thank you SO much Filip (and everyone else here) for your contributions.
Log in to reply.