PhilterPaper / PDF-Table

Official repository for PDF::Table in Perl
https://www.catskilltech.com/FreeSW/product/PDF%2DTable/title/PDF%3A%3ATable/freeSW_full
Other
10 stars 15 forks source link

Code Block (treatment of spaces, tabs, newlines) #66

Open stefanalt opened 3 years ago

stefanalt commented 3 years ago

Hi,

for my PDF test report generator I need the ability to render table cells without changing spaceing. The same might be required if you want to render program code to a table cell.

I have implemtented a few simple changes to achieve this, which is sufficient for my purposes. If this feature is interesting for this project I'll be willing to polish it up and share it.

More details

PhilterPaper commented 3 years ago

When you say "without changing spacing", are you talking about the ASCII spaces between words? That is, you want to preserve spaces and not collapse them to single spaces? Would you treat a multispace gap as a word, or can it be split for word-wrap purposes? I can see it being useful to preserve spaces, but you have to be careful not to mess up the fitting of lines into a cell of given width. Compare this to HTML <pre> , where a long line doesn't get wrapped at all.

stefanalt commented 3 years ago

Yes exactly. I do something like this: code.pdf. You can't see it, but tabs are converted to spaces.

In "code blocks" no space should change, as the space itself is information. If rendering reaches the right border of the cell it wraps overlong text to the next line (See testing memory in my example). One might think of an option that clips overlong lines at the right cell border. But if in doubt, better to look bad than to loose content!

PhilterPaper commented 3 years ago

OK, there are several requests here:

  1. ability to preserve runs of spaces (not collapsed to single spaces)
  2. choice of wrapping around or truncating long lines
  3. tab expansion (really useful only if you have a fixed-pitch font such as Courier)

For tab expansion, would "tab stop every n-th column" be adequate? E.g., tabexp => 4 means tab stops at 4, 8, 12, etc.

stefanalt commented 3 years ago

not to forget:

I would prefer tabstop => 4 , but yes that's the right thing. My code currently has a fixed value of 8, I agree this is too limited.

BTW: I render my testreports with proportioal font to save column width. Even then handing tab is crucial.

PhilterPaper commented 3 years ago

OK, I think I understand what you're asking for. Into the hopper it goes...

stefanalt commented 3 years ago

codeblock.zip

PhilterPaper commented 3 years ago

I am in receipt of your codeblock patch and samples (thank you for your work). Let me think it over. I take it you want to do all these things (preserve spaces, tab expansion, word wrap, preserve line ends) as a unit and not separately. I might want to modify it a bit to allow these to be done separately. It looks like you might have been working with a slightly older version of the code (just some minor changes) -- I should be able to figure my way around the differences.

stefanalt commented 3 years ago

It's your playground ;-) If you come out with too manny single options, you might want to add a combo
codeblock =› 1

PhilterPaper commented 2 years ago

Something along these lines will need to be implemented anyway, so that PDF::API2 behaves the same as PDF::Builder. However, I expect to at some point have such capabilities in PDF::Builder itself (HTML markup), so it will become redundant then.