2014-09-04 75 views
0

我無法爲新文本圖層設置像素的文本大小。無論我做什麼,我都會得到錯誤的大小。下面是我在做什麼一個精簡版: -以像素爲單位設置文本大小的問題

var docRef = app.activeDocument; 

app.preferences.rulerUnits = Units.PIXELS; 
app.preferences.typeUnits = TypeUnits.PIXELS; 

var fontSize = 100; //gives 416.67 px 
//var fontSize = "100px"; -- same result 

var txtLayerRef = docRef.artLayers.add(); 
txtLayerRef.kind = LayerKind.TEXT; 
var textItemRef = txtLayerRef.textItem; 
textItemRef.size = fontSize; 
textItemRef.contents = "A text string"; 

重要的是,我能夠在像素不點來定義我的文字大小。我在Windows 7上使用Photoshop CC 2014.

任何人都知道我在做什麼錯了?

謝謝。

回答

0

構造一個適當的UnitValue對象來指定您的大小。

var doc = app.activeDocument; 
var txt = doc.activeLayer.textItem; 
txt.size = new UnitValue(100, 'px'); 
相關問題