Dear all,
I'm using prawn in a rails-app for generating very simple PDF's from ascii-text files generated elsewhere. The problem I'm facing is that the script hangs unpredictably from time to time.
The goal is to render characters aligned, hence I want to use courier as a font and am replacing multiple spaces by single nbsps. (Without this replacement, the issue doesn't occur)
From a failling input file, I was able to isolate a part (@results) and to put the following bit of code together to reproduce the problem.
I used a loop to determine the minimal string that cause the script to hang (it occurs when cnt==120).
If I inject that failing string (failText) directly, no hang occurs - unless whitespace is substituted (failTextcorr), but then it hangs at an earlier moment (cnt==18)
Am I grossly misunstanding something here or is this a bug? I found something similar
here.
I'd appreciate if anyone could help me with this.
#!ruby -w
require 'prawn'
Prawn::Font::AFM.hide_m17n_warning = true
@results="__run of 2017-05-31 19:23:28 +0200 version e018c5b932dde9a45b63c8344589f2e9fe29175b data_file: /var/folders/mr/0pl2p46j28s5j13r7vqgyhwh0000gn/T/RackMultipart20170531-55394-ithydk.txt"
failText="__run of 2017-05-31 19:23:28 +0200 version e018c5b932dde9a45b63c8344589f2e9fe29175b data_file: /var/folders/mr/0pl2p46j2"
text=@results.gsub(/\s+/, Prawn::Text::NBSP)
failTextcorr=failText.gsub(/\s+/, Prawn::Text::NBSP)
text2=text.split ''
myText=''
cnt=0
Prawn::Document.generate('out.pdf') do
text2.each do |ch|
cnt+=1
myText+=ch
puts "#{cnt} #{myText} #{myText==failText} #{myText==failTextcorr}"
text myText # fails at cnt==120 (when myText == failTextcorr)
#text failText # doesn't fail
#text failTextcorr # fails at cnt==18
end
#text failTextcorr # doesn't fail
#render_file "out.pdf"
end