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

formatted_text_box and shrink_to_fit don't work #1118

Open
donnfelker opened this issue Jun 23, 2019 · 2 comments
Open

formatted_text_box and shrink_to_fit don't work #1118

donnfelker opened this issue Jun 23, 2019 · 2 comments

Comments

@donnfelker
Copy link

First - thank you for the library. This thing is great. :) I think I found a bug I'd like to report. I'd fix it, I'm just not sure how/where to go to fix it.

Steps to reproduce:

Save this file as example.rb and run it via ruby example.rb

require 'date'
require 'prawn'

timestamp = (Time.now.to_f * 1000).to_i

generated_pdf_name = "render-#{timestamp}.pdf"
Prawn::Document.generate(generated_pdf_name, page_layout: :landscape, page_size: "A0") do 
    formatted_text_box [{ 
        text: "This really long text should fit inside of the box and it should shrink to fit as this is a test.", 
        size: 124, 
        styles: [:bold]
    }], 
        at: [485, 1700], 
        width: 2240, 
        height: 345,
        overflow: :shrink_to_fit
end 

You'll notice that the text looks like this:
image

The text is truncated.

Next, change the shrink_to_fit to expand (overflow: :expand) and re-run the file and you'll get this:
image

The :expand option seems to work, yet the :shrink_to_fit does not.

Expected results: :shrink_to_fit would shrink the text to fill the box as it does with text_box.

I cannot use text_box because I need additional formatting (highlighters). Those have been removed in this example for brevity. The :shrink_to_fit option works fine on a regular `text_box though.

TLDR; It seems that the shrink_to_fit option does not work with the formatted_text_box. Why would that occur? Am I doing something incorrectly?

@xijo
Copy link

xijo commented Apr 9, 2022

Same problem here, did you find a workaround?

@xijo
Copy link

xijo commented Apr 9, 2022

So it does work if you apply the overflow option to the formatted_text_box itself:

doc.formatted_text_box [
  {
    text: "This is my text",
    styles: [:bold, :italic],
    callback: PrawnCustomUnderline.new(document: doc),
  }
], at: [0, 340], overflow: :shrink_to_fit, size: 20, height: 20, width: 500

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

No branches or pull requests

2 participants