Sequence Problem -- Can't print white text on black line

14 views
Skip to first unread message

Harry Whitehouse

unread,
Aug 17, 2017, 3:48:31 PM8/17/17
to Prawn
I have a prawn app that accepts a series of line draw, rectangle draw, text draw commands to create a new document.  I'm having problems writing white text atop a black line.

In the sequence of things, the line draw comes first (before the specific text draw that should be atop the line).

  def draw_line(id, color, rotation, x1, y1, x2, y2, thickness, style)
    y1rev = @page_height - y1
    y2rev = @page_height - y2
    @pdf.line_width thickness.send(:in)
    @pdf.line [x1.send(:in), y1rev.send(:in)], [x2.send(:in), y2rev.send(:in)] 
    @pdf.stroke       
  end

When white text is requested, we set the color using 

@pdf.fill_color "ffffff" if color == :white 

The problem is that the white text doesn't appear (as if the line might be on top, layer-wise).  But I'm pretty sure prawn doesn't support true layers.

So I tried an experiment, putting the white text draw in the finish_drawing function:

 def finish_drawing
      puts "finish_drawing"
      x1 = 1.0
      yrev = 3.4
      width = 3.0
      height = 0.5
      @pdf.fill_color "ffffff"
      @pdf.text_box "White Text Test", :at => [x1.send(:in), yrev.send(:in)],
        :width => width.send(:in),
        :height => height.send(:in)

     @pdf.render_file "label.pdf"
  end

And that works!!

Here's the order of the commands (although I understand that the ruby debugger may not present information in the true order of execution so I printed the time stamp in milliseconds for the key events.  The "HOLD FOR PICKUP" text should be white on the black line background.  All the other  black text printing commands are honored.

rbapi_1     | draw line for hpfu                                    timestamp: "1502950501837"
rbapi_1     | ["X1"]
rbapi_1     | ["PRIORITY MAIL", " POSTAGE PAID", "247", "Taris"]
rbapi_1     | ["HOLD FOR PICKUP"]                          timestamp   "1502950501879"   
rbapi_1     | finish_drawing


Can anyone explain this behavior?

Best

Harry


Reply all
Reply to author
Forward
0 new messages