rghost
rghost copied to clipboard
Changing text area alignment changes height between text rows
Changing the :text_align given to text_area produces a different entry tag. Left align starts with :text_area _default_font (abc) :text_proc, but any other alignment(center or right) starts with _default_font (abc) :text_proc_cr instead. Why is there a difference in the entry points?
The effects (or side effects) of this is that the row height is different on different alignments. Right align looks like:
Left align looks like
Please include the code snippet you're using
document.define_tags do
tag font_tag.to_sym, :name => font.rghost_font_name, :size => FONT_SIZE, :color => color
end
formatted_text = format_multiline_text text, font_tag
document.newpath do |path|
path.moveto :x => 1, :y => 49
path.text_area formatted_text, :text_align => text_alignment.to_sym
end
This is what the code snippet looks like. The only thing that has changed between the two images in the text_alignment variable.
@hiemanshu hard to figure out what's in format_multiline_text, rghost_font_name etc, can you create a file .rb which I can simply run it via ruby yourfile.rb
?
@shairontoledo Thats something we have to format text in the right format, and using fonts stored in the database. The important part of the code is below:
require 'rghost'
doc = RGhost::Document.new
doc.newpath do |path|
path.moveto :x => 1, :y => 49
path.text_area "abc", :text_align => :right
end
puts doc.inspect
doc2 = RGhost::Document.new
doc2.newpath do |path|
path.moveto :x => 1, :y => 49
path.text_area "abc", :text_align => :left
end
puts doc2.inspect
Just running this will show you the difference in the entry points. https://github.com/shairontoledo/rghost/blob/master/lib/rghost/parse_text.rb#L46 is the line which determines the entry point.
@shairontoledo Any update on this?
Got a free time now, going to debug that.
It's something else, RGhost uses different objects to align text at left and right, regardless of that, text_area is behaving as expected. I did simple test
doc = RGhost::Document.new row_height: 1
doc.define_tags do
tag :big, name: 'Helvetica', size: 24
end
text1 = '<big>%s</big>' % 12.times.map{|i| 'right'}.join(' ')
text2 = '<big>%s</big>' % 12.times.map{|i| 'left'}.join(' ')
doc.text_area text1, width: 6, text_align: :left, x: 12
doc.text_area text2, width: 6, text_align: :right, x: 6
doc.render(:pdf, filename: '/tmp/test.pdf')
It resulted in: