Getting text to work
This commit is contained in:
@@ -4,6 +4,7 @@ module Squib
|
||||
def save_pdf
|
||||
#paper is 8.5x11
|
||||
# PDF points are 1/72 of an inch
|
||||
raise "Not implemented yet!"
|
||||
width = 8.5 * 72
|
||||
height = 11 * 72
|
||||
cc = Cairo::Context.new(Cairo::PDFSurface.new('_img/deck.pdf', width, height))
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
require 'pango'
|
||||
|
||||
module Squib
|
||||
class Card
|
||||
|
||||
|
||||
def text(str, font, x, y, options)
|
||||
cc = cairo_context
|
||||
cc.set_source_rgb(0.0,0.0,0.0)
|
||||
cc.select_font_face ("Helvetica");
|
||||
cc.set_font_size(36)
|
||||
cc.move_to(x,y + cc.text_extents(@str.to_s).height)
|
||||
cc.show_text(str.to_s)
|
||||
cc.set_source_color(:black) #black
|
||||
cc.move_to(x,y)
|
||||
layout = cc.create_pango_layout
|
||||
layout.text = str.to_s
|
||||
w = options[:width] ; h = options[:height]
|
||||
w ||= (@width - 2*x) ; h ||= (@height - 2*y) # default centers to x,y
|
||||
w *= Pango::SCALE ; h *= Pango::SCALE
|
||||
layout.width=w ; layout.height=h
|
||||
layout.wrap = Pango::WRAP_WORD
|
||||
layout.justify = true
|
||||
layout.alignment = Pango::ALIGN_LEFT
|
||||
layout.font_description = Pango::FontDescription.new(font)
|
||||
#Center it vertically?
|
||||
#puts "Height: #{layout.extents[1].height / Pango::SCALE}"
|
||||
#puts "Height: #{layout.pixel_size[1]*layout.line_count}"
|
||||
cc.update_pango_layout(layout)
|
||||
cc.show_pango_layout(layout)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user