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

Paragraph text not wrapping with higher DPI (javascript)

New Here ,
May 25, 2020 May 25, 2020

I have a weird problem in Javascript with Paragraph text. My script creates text layers for labels and needs the text to fit the document width. For font attributes it uses a template text layer which is copied, changed to paragraph text, width and height set to document size and contents text set. This works as expected with DPI set to 72 which corresponds to 1 pixel= 1 pt . The ruler units are pixels.

 

If now I resize the image to 300 DPI, not reampling (i.e. page size changes, not pixel count) this does not work anymore. The template text layer is correctly scaled from roughly 69pt down to 16.56 pt (Unitvalues do correctly reflect the change to 300DPI in the baseUnit, thus conversion correct). When width and height of the text item are set to the document width and height they are automatically correctly scaled from 350ox to 84pt (as text item always uses pt). But when a text which would require 2 lines is assigned it flows out of the document on one single line.

 

So far I have checked a lot of things like nmoBreak set to false, useAutoLeading to true, autoLeadingAount=120% (i.e. nm problem to fit 2 16pt lines into 84pt). I did also try to force leading to fix value with nmo change in behavior. Once the same document is in 72pt again, the same script works as expected.

 

Am I missing something here, or is this a bug?

TOPICS
Actions and scripting
1.4K
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
Adobe
Community Expert ,
May 26, 2020 May 26, 2020

Do you really expect meaningful feedback without providing the Script and the layered file? 

So far we don’t even know if the Type Layer is Point Text or Paragraph Text. 

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
New Here ,
May 26, 2020 May 26, 2020

Yes, actually I do 😉 Providing the script is not possible because it is a very complex one with over 2000 lines of code. In rteturn I did provide all steps the script does. Also, and here sorry to say, reading helps, I mentioned 3 times that this is of course paragraph text, where one of the 3 does explicitely state that I change the textItem to paragraph text.


Below is the code extract as well as the bogous text with 300DPI. The same text in same size will render as expected on 2 lines with 72DPI.


Notes:

  • Document is 350x350px 300DPI
  • 72DPI & 69pt text all works fine, 300DPI 16.56pt(scaled) text not
  • textLayer is an object of my own layer class and textLayer.Layer is the ArtLayer
  • lt.Duplicate duplkicates the template text layer. Parameters do only impact naming and positioning in Layer tree
  • The template text layer has no special settings, only color & font size. I used fixed and auto leading, both working fine with 72DPI, and failing with 300DPI

 

grafik.pngexpand image

  var textLayer=lt.Duplicate(layer,ElementPlacement.PLACEBEFORE,"Label","none");

  // Now set the text attributes
  var ti=textLayer.Layer.textItem;
  ti.kind=TextType.PARAGRAPHTEXT;
  ti.width=doc.width;
  ti.height=doc.height;

  ti.contents=label;
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 ,
May 26, 2020 May 26, 2020

I do apologize, I did indeed miss that you had stated the kind of Type Layer. 

But I still suspect the description may be less clear than you think. 

 

»When width and height of the text item are set to the document width and height they are automatically correctly scaled from 350ox to 84pt (as text item always uses pt). But when a text which would require 2 lines is assigned it flows out of the document on one single line.«

Does this mean that the Type Layer is Paragraph Text but the actual type expands beyond the Paragraph bounds? 

 

Can you provide a file from prior and after the operation? 

What are the text object’s original and resulting bounds? 

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
New Here ,
May 26, 2020 May 26, 2020

As there are no real modifications to the contants (only added layers) I could provide the "after operation" file in 72 and 300 DPI.

 

Do I understand correcly that I cannot upload any file here, but have to upload it somewhere else and provide a download link ?

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 ,
May 26, 2020 May 26, 2020

One should be able to attach psd to the original post at least (see link to an example), so please try attaching the psds there. 

https://community.adobe.com/t5/photoshop/bug-can-t-save-file-with-custom-shaped-image-layer/td-p/111...

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 ,
May 26, 2020 May 26, 2020

Or post screenshots where we can see the Transform Controls of the type layer in the two resulting files. 

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
New Here ,
May 26, 2020 May 26, 2020

Thanks, got it, and attached files to original post.

 

Both files had the same initial state except for the image resolution (72 or 300DPI) and processed by the exact same script with same options (while options actually do not impact text creation). The created layers are visible in both files, once formatted as expected /72DPI) and once single line (300DPI).

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 ,
May 26, 2020 May 26, 2020

Have you tried using 

 

var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;

 

at the beginning and then resetting at the end of the Script? 

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
New Here ,
May 26, 2020 May 26, 2020

No I did not. One reason is that I am not a friend of workaround solutions. But the main reason is that this has side effects to my script, so that it is not as easy as quickly changing the ruler for a test in this case.

 

I have plans to eliminate thos side effects anyway but this being not trivial in this context it was planned for later as I have not yet identified the best and cleanest to do so. I will think again and see if I can do this test.

 

 

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 ,
May 26, 2020 May 26, 2020

You can just insert the rulerunit-switches before and after changing the Tyoe Layer’s bounds. 

Otherwise you will probably have to calculate the target dimensions to compensate for the resolution. 

I haven’t tested this but I doubt it would be faster. 

 

But if speed should be a concern you should probably change the DOM-code to AM-code anyway. 

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
New Here ,
May 26, 2020 May 26, 2020
LATEST

Resolution is only needed for pixels and handled by the baseUnit, so no need to compensate. Also in a 2000 line script it is not as easy as switching rulers at any moment without expecting side effects from previous code.

 

In my script I had to plan to normalize dimensions (eg. UnitValue) anyway because the user could set some dimensions including units, and PhotoShop scripting engine is very dumb when it comes to computing with UnitValue (thus px + in becomes NaN instead of px).

 

Now I added code to normalize everything to pt and the curious thing is that now it works fine even without changing the ruler untis. This is curious because the resulting data in the text layer width and height is exacterly the same (as expected).

 

Now it works but looks like a bug of the scripting engine to me.

 

Thanks.

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