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

How can I read paragraph box scale?

New Here ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

Hi,

I am trying to read the values off some text boxes in photoshop for an exporter script that I am working on. I ran into an issue that I can't  figure out, hopefully it's just a small thing.

When reading the values from paragraph text, there are some instances in which the values will come out wrong. For example:

I have a layer with paragraph text in it that says its paragraph size (text box) is 400 px by 400 px and the font size is 60 pt.

If I run a script similar to this:

// get the text layer and save ir to a variable named layer //

if (layer.textItem.kind == TextType.PARAGRAPHTEXT)

{

     log("Width: " +  layer.textItem.width.as('px'));

     log("Height: " + layer.textItem.height.as('px'));

     log("Font size: " + layer.textItem.size.as('pt'));

}

My output reads:

Width: 200

Height: 200

Font size: 30

Which is obviously wrong because all the values are half of what they should be. I have other paragraph text layers in the same file that print out the correct values!

After trying a bunch of different things I figured a way to reproduce the error, but not a way to correct it, here it is:

- Create a new paragraph text layer by clicking and dragging using the text tool, make the text box roughly 200 px by 200 px

- Type some text in the box

- Select the text and make it 30 pt in size

- Finish editing the text

- Make sure the text layer is selected

- Press command+t (ctrl+t in windows)

- In the free transform parameters, manually type 200% for both with and height

- Accept the transformation changes

- Use the text tool and select the text from the layer

At this point you will notice that the text box reports its size as 400 px by 400 px and the font size says 60 pt, so far everything makes sense, the issue comes when you look at the info tab, the scale is reported as 200% for both width and height and if I use the previous script the sizes printed are the original sizes of the text box: 200 px by 200 px and 30 pt for the font size.

At first I though it would be as easy as using the verticalScale and horizontalScale properties of TextItem like so:

log("Vertical scale: " + layer.textItem.verticalScale);

log("Horizontal scale: " + layer.textItem.horizontalScale);

But even though we know the scale is 200% the output reads:

Vertical scale: 100

Horizontal scale: 100

Unfortunatelly I do not have control over how the content is created so I can't avoid the use of the transform tool on pararaph text, or all text for that matter (this issue also affects the font size in single line text layers). So I need to find a reliable way to either read the correct values from the text or to read the scale which is affecting the text within my layer.

Any help would be appreciated. Thank you in advance.

Dario Segura

TOPICS
Actions and scripting

Views

3.8K

Translate

Translate

Report

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

Valorous Hero , Dec 05, 2012 Dec 05, 2012

The font size shown by the DOM is the original size of the font used, if the text has been transform it needs to multiplied by the transform factor.

As an example create a text layer and transform the text then run the following code on the text layer...

var domTextSize = activeDocument.activeLayer.textItem.size;
var amTextSize = getTextSize();
alert("DOM text size = " + domTextSize +"\rAction Manager text size = "+amTextSize);

function getTextSize(){
var ref = new ActionReference();
ref.putEnumerated(

...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Dec 05, 2012 Dec 05, 2012

Copy link to clipboard

Copied

The font size shown by the DOM is the original size of the font used, if the text has been transform it needs to multiplied by the transform factor.

As an example create a text layer and transform the text then run the following code on the text layer...

var domTextSize = activeDocument.activeLayer.textItem.size;
var amTextSize = getTextSize();
alert("DOM text size = " + domTextSize +"\rAction Manager text size = "+amTextSize);

function getTextSize(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
var textSize =  desc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getDouble (stringIDToTypeID('size'));
if (desc.hasKey(stringIDToTypeID('transform'))) {
            var mFactor = desc.getObjectValue(stringIDToTypeID('transform')).getUnitDoubleValue (stringIDToTypeID("yy") );
    textSize = (textSize* mFactor).toFixed(2);
    }
return textSize;
}

Votes

Translate

Translate

Report

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
New Here ,
Dec 06, 2012 Dec 06, 2012

Copy link to clipboard

Copied

Thank you so much, this solves my issues!

Votes

Translate

Translate

Report

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
New Here ,
May 14, 2013 May 14, 2013

Copy link to clipboard

Copied

Hi Paul. How do I use this on a text layer? Do I have to make & import a script? I've been looking for a fix to this type resize bug and this is the only response that gives me any hope.

Votes

Translate

Translate

Report

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
Valorous Hero ,
May 14, 2013 May 14, 2013

Copy link to clipboard

Copied

If you want to set the text size you would do something like this...

var wantedTextSize = 50;

app.activeDocument.activeLayer.textItem.size= (Number(wantedTextSize)/Number(getTextdivideFactor()));

function getTextdivideFactor(){

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));

var textSize =  desc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getDouble (stringIDToTypeID('size'));

if (desc.hasKey(stringIDToTypeID('transform'))) {

            var mFactor = desc.getObjectValue(stringIDToTypeID('transform')).getUnitDoubleValue (stringIDToTypeID("yy") );

            return mFactor;

    }

return 1;

};

N.B. This will only be valid with CS6 as it stands, if Adobe fixs the bug it will give the wrong results!

Votes

Translate

Translate

Report

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
Enthusiast ,
May 31, 2014 May 31, 2014

Copy link to clipboard

Copied

I can confirm that both issue and solution (Thanks Paul!) seem to be relevant also in Photoshop CC and CS6 Extended. Not understanding the Action-side of things, a few clarifications/questions

  • Is this with assumption of same horizontal/vertical transform? Is it "getUnitDoubleValue (stringIDToTypeID("xx"))" to get horizontal transform?
  • Is there way to observe this in the UI? I mean can you open some panel to see the same ratios? I'm thinking user troubleshooting perspective trying to validate situation.

Votes

Translate

Translate

Report

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
Enthusiast ,
Jun 01, 2014 Jun 01, 2014

Copy link to clipboard

Copied

Hmm, as usual, delving deeper just reveals more issues..

At least with this PSD the solution above does not give correct answer. The textbox width is 722px and calculating like above will give you width of 548px. The transform descriptor gives horizontal&vertical scale of 1.6, which corresponds to scaling the image from 480px to 768px. But in addition to that there is some additional transform of ~1.3 done to the layer that is not counted. I've checked the other keys in the transform descriptor and they are all 0's. Any ideas?

Link to example: Dropbox - text_box_extents.psd

Votes

Translate

Translate

Report

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
Enthusiast ,
Jun 02, 2014 Jun 02, 2014

Copy link to clipboard

Copied

After a few more experiments, you can get correct values from the 'bounds'-descriptor.


function getTextExtents(text_item) {

  app.activeDocument.activeLayer = text_item.parent

  var ref = new ActionReference()

  ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )

  var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'))

  var bounds = desc.getObjectValue(stringIDToTypeID('bounds'))

  var width = bounds.getUnitDoubleValue (stringIDToTypeID('right'))

  var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom'))

  var x_scale = 1

  var y_scale = 1

  if (desc.hasKey(stringIDToTypeID('transform'))) { 

  var transform = desc.getObjectValue(stringIDToTypeID('transform'))

  x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))

  y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))

  }

  return { x:Math.round(text_item.position[0]), y:Math.round(text_item.position[1]) , width:Math.round(width*x_scale), height:Math.round(height*y_scale) }

}

I tested that this returns correct values both when image and text box get scaled. There is some strange Photoshop behaviour to note though:

  • bounds.left seems to be always 0 like one could assume
  • bounds.top on the other had is most times -1-3px. This probably corresponds to the amount the actual text rises above the text box. I feel it's a bug, i.e. it should be part of content bounding box, not the text area. But maybe it's like it was specced and I'm just interpreting it wrong.
  • x_scale and y_scale seem to be always equal. For example if you create a 100x100px text box and scale it to 200px horizontally, both x_scale and y_scale will be 2 and text_item.height will be 50.

Votes

Translate

Translate

Report

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
New Here ,
Jun 25, 2014 Jun 25, 2014

Copy link to clipboard

Copied

LATEST

The 'Number' being what exactly or where would you take it from ?

EDIT: Nvm, figured it out. But it doesn't work. Read a lot of people having this issue. They should really make the font layer smart. If you resize it vertically, by means of transform, it should change the vertical scale as well, same goes for horizontal, or font size if you use constrained resizing (with shift pressed).

I'm so disappointed. Year after year, Adobe's products get progressively worse and dumber.

Votes

Translate

Translate

Report

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