Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text rectangles are incorrect #78

Open
catmando opened this issue Oct 27, 2014 · 9 comments
Open

text rectangles are incorrect #78

catmando opened this issue Oct 27, 2014 · 9 comments

Comments

@catmando
Copy link
Contributor

I have a simple test registration document.

It contains a single text field called "text"

the dimensions and of the text in the document are much different from the original PSD, and from what is rendered.

The dimensions in the psd (viewed on a photoshop) are top = 1", left = 1", width=3", height=1"

The doc is 300 DPI, but the dimensions as read by psd.rb are top = 308, left = 464, width = 592, height = 101. (should be 300, 300, 900, 300)

For comparison the document has a grey image layer under the text with the same position and dimensions.

The photo layer position and dimensions ARE reported correctly by psd.rb.

My guess is that psd.rb is giving back some kind of minimal bounding box for the text, not the actual text rect in the psd file.

However as the psd file actually knows, and remembers the complete size of the text rect this looks like a problem.

The file can be accessed here: (I hope) http://832069e906a4cb1cbeba-356812981dd62c6b48c695351cd5444e.r90.cf2.rackcdn.com/uploads/background/psd/35/ce452152-cba1-4ca8-ade2-7d6d6e24c1e820141027-2-jzu8rh

@catmando
Copy link
Contributor Author

BTW - this is a "paragraph text" layer NOT a "point text" layer. It seems like psd.rb is treating the object as point text even if its paragraph text. I am pretty sure things work fine if its point text.

@catmando
Copy link
Contributor Author

Digging around in this I discovered this perhaps related discrepancy:

Adobe spec says that the "left, top, right, bottom" info are all 8 byte values, the parser is reading these as ints (which are too short and wrong type.)

Compare for example the transform values.

But its not that simple: patching the code to read left/top/right/bottom as double gives really strange values.

I am using this document as reference: http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_21585

spec might be wrong, as every place else where a rect is specified its done with 4 byte values, not 8.

@meltingice
Copy link
Member

According to the PSD you gave me, the folder is named "text" but the actual text layer is named "Craig & Tessa". Are you looking at the correct position data?

@catmando
Copy link
Contributor Author

Yes I was giving the folder name, but the folder only contains the single layer, so the story is the same. Sorry about that.

@catmando
Copy link
Contributor Author

This seems extremely cludgy and brittle, but you can extract the correct dimensions (at least for simple cases) as follows:

      box_bounds = layer.type.engine_data.EngineDict["Rendered"]["Shapes"]["Children"][0]["Cookie"]["Photoshop"]["BoxBounds"]
      top = layer.text[:transform][:ty]
      left = layer.text[:transform][:tx] 
      height = box_bounds[3] 
      width = box_bounds[2]

This only seems to work if layer.type.engine_data.EngineDict["Rendered"]["Shapes"]["Children"][0]["ShapeType"]==1 which I am guessing means the text block is a paragraph

@sanjithg
Copy link

sanjithg commented Apr 8, 2018

I'm also facing the same issue.
The solution provided by @catmando is not working for me all the times. I even tried in latest version of PSD.rb gem (3.9.0).

Can anybody provide the solution for this?

Thanks in advance.

@catmando
Copy link
Contributor Author

@sanjithg @dwillist might be able to check in our code and see if the above hack is still being used, or perhaps it changed slightly...

@dwillist
Copy link

We still use this exact same hack.

@sanjithg
Copy link

Below logic given me the exact values for me.

bounds = layer.adjustments[:type].data[:text]["bounds"]
layer_tree = layer.to_hash
transform = layer_tree[:text][:transform]

top = transform[:ty] + bounds["Top "][:value]
left = transform[:tx]
width = bounds["Rght"][:value]
height = bounds["Btom"][:value] - bounds["Top "][:value]

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants