Class: TextLayout
- Inherits:
-
Object
- Object
- TextLayout
- Defined in:
- lib/Print/PrintItem/TextLayout.rb
Overview
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])
Instance Attribute Summary collapse
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
Instance Method Summary collapse
- #draw(cr) ⇒ Object
- #height ⇒ Object
-
#initialize(cr, txt, font, width, x, y, alignment = 'left') ⇒ TextLayout
constructor
A new instance of TextLayout.
- #set_alignment(alignment = @alignment) ⇒ Object
- #set_x(newx = x) ⇒ Object
- #set_y(newy = y) ⇒ Object
Constructor Details
#initialize(cr, txt, font, width, x, y, alignment = 'left') ⇒ TextLayout
Returns a new instance of TextLayout.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 6 def initialize(cr,txt,font,width,x,y,alignment='left') @cr=cr @font=font @layout=cr.create_pango_layout @txt=txt @layout.set_text(txt) @x=x @y=y @width=width @alignment=alignment @layout.set_font_description(Pango::FontDescription.new(@font)).set_width(@width*Pango::SCALE) @layout.set_wrap(Pango::Layout::WRAP_WORD_CHAR).set_ellipsize(Pango::Layout::ELLIPSIZE_NONE)#.set_single_paragraph_mode(true) set_alignment end |
Instance Attribute Details
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
20 21 22 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 20 def layout @layout end |
Instance Method Details
#draw(cr) ⇒ Object
41 42 43 44 45 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 41 def draw(cr) cr.move_to(@x,@y) cr.show_pango_layout(@layout) cr.stroke end |
#height ⇒ Object
36 37 38 39 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 36 def height w,h=@layout.size h/Pango::SCALE end |
#set_alignment(alignment = @alignment) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 28 def set_alignment(alignment=@alignment) @alignment=alignment case @alignment when 'left' then @layout.set_alignment(Pango::Layout::ALIGN_LEFT) when 'right' then @layout.set_alignment(Pango::Layout::ALIGN_RIGHT) when 'center' then @layout.set_alignment(Pango::Layout::ALIGN_CENTER) end end |
#set_x(newx = x) ⇒ Object
22 23 24 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 22 def set_x(newx=x) @x=newx end |
#set_y(newy = y) ⇒ Object
25 26 27 |
# File 'lib/Print/PrintItem/TextLayout.rb', line 25 def set_y(newy=y) @y=newy end |