Getting text to work

This commit is contained in:
Andy Meneely
2014-07-16 11:26:48 -04:00
parent 9c51b03783
commit c5bc1fc103
5 changed files with 30 additions and 9 deletions
+1
View File
@@ -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))
+20 -6
View File
@@ -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