Copy link to clipboard
Copied
Is there any way to retrieve the cap height of a font from Photoshop? When creating text with
textItemRef.position
the text gets positioned from the baseline, but I need to work out the cap height in order to position it correctly with items above it. Cheers
Okay,
here is a new „better“ version of the previous testscript:
...// based on WorkingWithText.jsx
// Copyright 2002-2007. Adobe Systems, Incorporated. All rights reserved.
// Create a new art layer and convert it to a text layer.
// Set its contents, size and color.
#target photoshop
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
var Resolution = 300;
app.preferences.rulerUnits = Units.POINTS; //INCHES
app.preferences.typeUnits = TypeUnits.POINTS;
var doc
Copy link to clipboard
Copied
You could just assess the layer’s bounds after creating it.
But some fonts may have varying ascenders …
Copy link to clipboard
Copied
I agree. Get the layer bounds of the text layer and position the layer using the top bounds plus whatever spacing you wish to have it correctly positioned with whatever is above it.
Copy link to clipboard
Copied
I take it from that there's no way of accessing that infomation internally then? Like this
textItemRef.capHeight
Copy link to clipboard
Copied
There is no way to access the cap height of a font in Photoshop that I am aware of. And even if there were that value would not tell you the top of the text if it contained A,O,etc. Those chars can exceed the cap height with some fonts.
Copy link to clipboard
Copied
Some years ago I tried the following:
// based on WorkingWithText.jsx
// Copyright 2002-2007. Adobe Systems, Incorporated. All rights reserved.
// Create a new art layer and convert it to a text layer.
// Set its contents, size and color.
#target photoshop
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.POINTS; //INCHES
app.preferences.typeUnits = TypeUnits.POINTS;
var docRef = app.documents.add(600, 600, 300); //(7, 5, 72)
// suppress all dialogs
app.displayDialogs = DialogModes.NO;
var textColor = new SolidColor;
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
var newTextLayer = docRef.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
var Con = newTextLayer.textItem.contents = "Hello, World!";
newTextLayer.textItem.position = Array(50, 200); //(0.75, 0.75)
newTextLayer.textItem.size = 36;
newTextLayer.textItem.color = textColor;
// --- modified by pixxxelschubser 2009
var TestCon = prompt ("cap height of? (e.g. A H L M T oder C G O)", "G");
newTextLayer.textItem.contents = TestCon;
var Temp = docRef.activeLayer;
alert ("CapHeight "+ TestCon + " = " +(Temp.bounds[3]-Temp.bounds[1]));
newTextLayer.textItem.contents = Con;
app.refresh();
// --- end
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
docRef = null;
textColor = null;
newTextLayer = null;
The result is almost exactly. Tested with PS CS3
Copy link to clipboard
Copied
Okay,
here is a new „better“ version of the previous testscript:
// based on WorkingWithText.jsx
// Copyright 2002-2007. Adobe Systems, Incorporated. All rights reserved.
// Create a new art layer and convert it to a text layer.
// Set its contents, size and color.
#target photoshop
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
var Resolution = 300;
app.preferences.rulerUnits = Units.POINTS; //INCHES
app.preferences.typeUnits = TypeUnits.POINTS;
var docRef = app.documents.add(500, 300, Resolution, null, NewDocumentMode.RGB, DocumentFill.TRANSPARENT); //(7, 5, 72)
// suppress all dialogs
app.displayDialogs = DialogModes.NO;
var textColor = new SolidColor();
textColor.rgb.red = 255;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
var newTextLayer = docRef.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
var TestCon = prompt ("cap height of? (e.g. A H L M T oder C G O)", "G");
newTextLayer.textItem.contents = TestCon;
newTextLayer.textItem.position = Array(50, 150); //(0.75, 0.75)
newTextLayer.textItem.size = 36;
newTextLayer.textItem.color = textColor;
var Temp = docRef.layers[0];
var links = Temp.bounds[0];
var oben = Temp.bounds[1];
var rechts = Temp.bounds[2];
var unten = Temp.bounds[3];
newTextLayer.textItem.contents = TestCon +" cap height" + " = " +(unten-oben);
app.refresh();
aColor = new SolidColor();
aColor.rgb.red = 0;
aColor.rgb.green = 0;
aColor.rgb.blue = 255;
links = links*Resolution/72;
oben =oben*Resolution/72;
rechts =rechts*Resolution/72;
unten = unten*Resolution/72;
app.activeDocument.selection.select([[links,oben],[links,unten],[rechts,unten],[rechts,oben]]);
app.activeDocument.activeLayer = app.activeDocument.layers[1];
app.activeDocument.selection.fill( aColor, ColorBlendMode.NORMAL, 100, false );
app.activeDocument.selection.deselect();
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
Run script and type one or more Capital letter.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now