如何在不丢失格式的情况下更改文本颜色

How to change color of Text without losing formatting

我可以更改文本颜色,但格式也会发生变化!我的文字一半是粗体,另一半是斜体。但最后所有的文字都变成了粗体。

var proj = app.project;
var theComposition = app.project.activeItem;
var theTextLayer = theComposition.layers[1];

var textProp1 = theTextLayer.property("Text").property("Source Text");
var textProp2 = theTextLayer.property("Source Text").value;
textProp2.fillColor = [1,1,1];  
textProp1.setValue(textProp2);

当您设置 TextDocument: textProp1.setValue(textProp2); 时,它会设置所有 TextDocument 属性。 Adobe 不通过 Extendscript(e.x.: fillColor、fontSize、fontFamily 等)支持每个文本层的多种格式,因此该层获取第一个字母的属性,在您的情况下为 Bold.

我可以建议你为图层添加填充效果并更改效果中的值。 这是一个代码:

var fillEffect = theTextLayer.property('ADBE Effect Parade').addProperty('ADBE Fill');
fillEffect.property('Color').setValue([1,1,1]);