-
Notifications
You must be signed in to change notification settings - Fork 692
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
Better table cell rotation #505
Conversation
I didn't do any documentation or examples. I'll do that before this code is accepted. |
This isn't ready, and I'm working on some cases that fail. Please do comment on the file structure or if it is desired. |
It would definitely be nice to see this work for non-orthogonal angles (such as 45 degrees). How difficult would that be? I know it would cause some issues around the |
I have some ideas for rewriting the wrap method for arbitrary angles. For a plain square it should be moderately straight forward. Given an angle, a cell, and line height, compute the length of text that can fit. Then, depending on if it fits or not, pick the right place of the cell to start with, and rotate/translate/place each line from there. Then you really only have top, bottom, left, right alignment if it is short. The challenge will be to make it simple to compute. I'll have to refresh my math brains! Can you think of any cases where rotate_around is useful for a table cell? I can't. Given the nature of a table cell, you want the text in the cell, so it should always rotate such that it stays in the cell. If that is the case, then rotate_around doesn't seem to apply, since rotating around any corner moves the text outside the cell. Angled text could be generalized for other boxes, but then rotate_around loses its meaning. You'd have to distinguish text rotation and box rotation. So I'm not sure if that is useful. Honestly, I'd love to see arbitrary polygon 'boxes', with text at an arbitrary angle flowing through the shape. Besides the math, that presents an api challenge too. I'll try to get more time on this next week. |
I need to restructure my fork into branches, and I was silly enough to do work on master. I'll close this and resubmit it when I have angled cells working. |
@straydogstudio - I am running in to this problem as well, so I hope you can push up your fix. Thanks! |
@MrPowers You can use the 'table_cell_rotation' branch on my fork: prawn. Specify the branch in your Gemfile: gem 'prawn', git: 'git://github.com/straydogstudio/prawn.git', branch: 'table_cell_rotation' Right now it only works for 90 degree rotations, left aligned text. (That works for most header applications.) You may still find better results if you specify the width of the cells. Please share data/code if you find problems, but post an issue on my branch. |
Is this still active? I need a working solution for 90 degrees text in my table headers. Would really appreciate any solution. Thank you for your work! |
@hmt: See this: prawnpdf/prawn-table#32 -- the main blockers right now are documentation and maybe some code cleanup, but you can try running from @straydogstudio's fork for the moment... it should work! |
@practicingruby oh, I don't know how I could miss that PR. I looked in all the wrong places. |
Here is some initial work to improve table cell rotation. Right now Prawn doesn't stay within the cell (partly because the text is wrapped before the content is rotated, and partly because rotate_around moves text outside the cell for all but the simplest of cases.) This fix keeps the text wrapped correctly on rotations of 9, 90, 180, 270, etc. Intermediate angles are at better than they were for now. Here is what it looks like:
Note that only table height is specified on that table.
I've created Table::Cell::Box and Table::Cell::Formatted::Box which inherit from Prawn::Text::Formatted::Box. There is also Table::Cell::Formatted::Wrap which inherits from Prawn::Core::Text::Formatted::Wrap. Only a few methods are overridden. If there is a better way to organize this, please let me know.
Intermediate angles still don't fit in the box, but they wrap reasonably well. The swap of height/width for wrapping happens on 45 degree angles. If this approach makes sense, sometime I'll tackle the wrap logic for other angles, and the text can still fit on an angle.
One last thing. This code ignores rotate_around. I overrode valid_options so including rotate_around throws an error. Perhaps it should just be ignored?
Needed:
Added a rotate test at the end of table_spec.rb. cell_spec.rb adjusted for new classes. All tests are passing.
Other: I added .ruby-version and .ruby-gemset to .gitignore for the latest rvm
Issues referenced: 409 & 112