Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Retrieve cap height from font

Engaged ,
Mar 15, 2013 Mar 15, 2013

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

TOPICS
Actions and scripting
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 17, 2013 Mar 17, 2013

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

...
Translate
Adobe
Community Expert ,
Mar 15, 2013 Mar 15, 2013

You could just assess the layer’s bounds after creating it.

But some fonts may have varying ascenders …

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 15, 2013 Mar 15, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 15, 2013 Mar 15, 2013

I take it from that there's no way of accessing that infomation internally then? Like this

textItemRef.capHeight

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 15, 2013 Mar 15, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 15, 2013 Mar 15, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2013 Mar 17, 2013
LATEST

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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines