繁体   English   中英

计算字符串的字体大小以使其适合框

[英]Calculate the font size of a string to make it fit on a box

在 After Effects 中,我有一个字符串,我有一个 TypeFace,我有一个合成的宽度和高度。 如何获得正确的字体大小以适合 comp 上的字符串,而不会溢出?

Noobie 程序员在这里。

您可以计算像素大小,但是(再次)Adobe 将大小限制为 1296 Px。 因此,您需要按文本图层的比例 go 。

在文本的比例参数中添加以下表达式:

var myTextSize = sourceRectAtTime();
var ratio = myTextSize.width / myTextSize.height;
var compRatio = thisComp.width/thisComp.height;
if(ratio >= compRatio) {
    var factor = thisComp.width / myTextSize.width;
    [scale[0] * factor, scale[1] * factor]
}
else{
    var factor = thisComp.height / myTextSize.height;
    [scale[0] * factor, scale[1] * factor]
}

此表达式根据您的 comp 的宽度和高度缩放文本。

但是它仍然没有居中。 如果需要,您需要添加另一个表达式。 这次在您的锚点上:

var boundingbox = sourceRectAtTime();
 
[boundingbox.left + boundingbox.width/2, boundingbox.top + boundingbox.height/2 ];

这应该可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM