Skip to content

Commit

Permalink
Starting an idea for fill colors on text.
Browse files Browse the repository at this point in the history
 Can't get it to work at the moment.
  • Loading branch information
andymeneely committed Oct 16, 2014
1 parent 3b926d0 commit 28487fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/squib/api/text.rb
Expand Up @@ -38,10 +38,10 @@ class Deck
# @return [nil] Returns nothing
# @api public
def text(opts = {})
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :fill_color, :wrap,
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout])
opts[:range].each do |i|
@cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i],
@cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i], opts[:fill_color],
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
Expand Down
17 changes: 14 additions & 3 deletions lib/squib/graphics/text.rb
Expand Up @@ -83,13 +83,22 @@ def setwh(layout, width, height)
layout
end

def fill_background(x,y,layout,fill_color)
# when w,h < 0, it was never set. extents[1] are ink extents
w = layout.width / Pango::SCALE
w = layout.extents[1].width / Pango::SCALE if w < 0
h = layout.height / Pango::SCALE
h = layout.extents[1].height / Pango::SCALE if h < 0
rect(x,y,w,h,0,0,'#0000',fill_color, 0))
end

# :nodoc:
# @api private
def text(str, font, font_size, color,
def text(str, font, font_size, color, fill_color,
x, y, width, height,
markup, justify, wrap, ellipsize,
spacing, align, valign, hint)
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, etc."}
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, fill_color: #{fill_color} etc."}
use_cairo do |cc|
cc.set_source_color(color)
cc.move_to(x,y)
Expand All @@ -107,7 +116,9 @@ def text(str, font, font_size, color,
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
cc.update_pango_layout(layout)
valign(cc, layout, x,y, valign)
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
cc.update_pango_layout(layout)
fill_background(x,y,layout,fill_color)
cc.show_pango_layout(layout)
draw_text_hint(x,y,layout,hint)
end
end
Expand Down

0 comments on commit 28487fe

Please sign in to comment.