Implemented new args design for svg and png
As part of that implementation, text_embed now supports singleton expansion. Closes #54
This commit is contained in:
+22
-19
@@ -1,5 +1,10 @@
|
||||
require 'squib/args/paint'
|
||||
require 'squib/args/card_range'
|
||||
require 'squib/args/paint'
|
||||
require 'squib/args/box'
|
||||
require 'squib/args/transform'
|
||||
require 'squib/args/input_file'
|
||||
require 'squib/args/svg_special'
|
||||
|
||||
module Squib
|
||||
class Deck
|
||||
|
||||
@@ -25,18 +30,13 @@ module Squib
|
||||
def png(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
|
||||
opts = needs(opts, [:range,
|
||||
:files,
|
||||
:x, :y, :width, :height,
|
||||
:angle,
|
||||
:alpha, :blend, :mask,
|
||||
:layout])
|
||||
box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
Dir.chdir(img_dir) do
|
||||
@progress_bar.start('Loading PNG(s)', opts[:range].size) do |bar|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i],
|
||||
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
||||
opts[:alpha][i], opts[:blend][i], opts[:angle][i], opts[:mask][i])
|
||||
@progress_bar.start('Loading PNG(s)', range.size) do |bar|
|
||||
range.each do |i|
|
||||
@cards[i].png(ifile[i].file, box[i], paint[i], trans[i])
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
@@ -66,14 +66,17 @@ module Squib
|
||||
# @return [nil] Returns nil
|
||||
# @api public
|
||||
def svg(opts = {})
|
||||
p = needs(opts,[:range, :files, :svgdata, :svgid, :force_svgid, :x, :y, :width, :height,
|
||||
:layout, :alpha, :blend, :angle, :mask])
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
paint = Args::Paint.new(custom_colors).load!(opts, expand_by: size, layout: layout)
|
||||
box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
ifile = Args::InputFile.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
svg_args = Args::SvgSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
Dir.chdir(img_dir) do
|
||||
@progress_bar.start('Loading SVG(s)', p[:range].size) do |bar|
|
||||
p[:range].each do |i|
|
||||
unless p[:force_id][i] && p[:id][i].to_s.empty?
|
||||
@cards[i].svg(p[:file][i], p[:data][i], p[:id][i], p[:x][i], p[:y][i],
|
||||
p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i], p[:angle][i],p[:mask][i])
|
||||
@progress_bar.start('Loading SVG(s)', range.size) do |bar|
|
||||
range.each do |i|
|
||||
if svg_args.render?(i)
|
||||
@cards[i].svg(ifile[i].file, svg_args[i], box[i], paint[i], trans[i])
|
||||
end
|
||||
bar.increment
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ module Squib
|
||||
box = Args::Box.new(self, {width: :auto, height: :auto}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
draw = Args::Draw.new(custom_colors, {stroke_width: 0.0}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
embed = TextEmbed.new
|
||||
embed = TextEmbed.new(size, custom_colors, layout, dpi)
|
||||
yield(embed) if block_given? #store the opts for later use
|
||||
extents = Array.new(@cards.size)
|
||||
range.each { |i| extents[i] = @cards[i].text(embed, para[i], box[i], trans[i], draw[i]) }
|
||||
|
||||
+46
-22
@@ -1,3 +1,10 @@
|
||||
require 'squib/args/box'
|
||||
require 'squib/args/card_range'
|
||||
require 'squib/args/embed_adjust'
|
||||
require 'squib/args/input_file'
|
||||
require 'squib/args/paint'
|
||||
require 'squib/args/transform'
|
||||
|
||||
module Squib
|
||||
class TextEmbed
|
||||
# :nodoc:
|
||||
@@ -6,7 +13,11 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def initialize
|
||||
def initialize(deck_size, custom_colors, layout, dpi)
|
||||
@deck_size = deck_size
|
||||
@custom_colors = custom_colors
|
||||
@layout = layout
|
||||
@dpi = dpi
|
||||
@rules = {} # store an array of options for later usage
|
||||
end
|
||||
|
||||
@@ -17,22 +28,29 @@ module Squib
|
||||
# @option opts id [String] (nil) if set, then only render the SVG element with the given id. Prefix '#' is optional. Note: the x-y coordinates are still relative to the SVG document's page. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts force_id [Boolean] (false) if set, then this svg will not be rendered at all if the id is empty or nil. If not set, the entire SVG is rendered. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts width [Integer] (32) the width of the image rendered.
|
||||
# @option opts height [Integer] (32) the height the height of the image rendered.
|
||||
# @option opts width [Integer] (:native) the width of the image rendered.
|
||||
# @option opts height [Integer] (:native) the height the height of the image rendered.
|
||||
# @option opts dx [Integer] (0) "delta x", or adjust the icon horizontally by x pixels
|
||||
# @option opts dy [Integer] (0) "delta y", or adjust the icon vertically by y pixels
|
||||
# @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @api public
|
||||
def svg(opts)
|
||||
opts = { width: 32, height: 32 }.merge(opts)
|
||||
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
||||
# TODO: add input validation here. We need the key for example.
|
||||
rule = {type: :svg}.merge(opts)
|
||||
rule[:draw] = Proc.new do |card, x,y|
|
||||
card.svg(rule[:file], rule[:data], rule[:id], x, y, rule[:width], rule[:height],
|
||||
rule[:alpha], rule[:blend], rule[:angle], rule[:mask])
|
||||
def svg(opts = {})
|
||||
# TODO: add input validation for key here
|
||||
range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
|
||||
paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
|
||||
box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
svg_args = Args::SvgSpecial.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
rule = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }
|
||||
rule[:draw] = Proc.new do |card, x, y|
|
||||
i = card.index
|
||||
b = box[i]
|
||||
b.x, b.y = x, y
|
||||
card.svg(ifile[i].file, svg_args[i], b, paint[i], trans[i])
|
||||
end
|
||||
@rules[opts[:key]] = rule
|
||||
end
|
||||
@@ -42,25 +60,31 @@ module Squib
|
||||
# @option opts key [String] ('*') the string to replace with the graphic. Can be multiple letters, e.g. ':tool:'
|
||||
# @option opts file [String] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts width [Fixnum] (32) the width of the image rendered
|
||||
# @option opts height [Fixnum] (32) the height of the image rendered
|
||||
# @option opts width [Fixnum] (:native) the width of the image rendered
|
||||
# @option opts height [Fixnum] (:native) the height of the image rendered
|
||||
# @option opts dx [Integer] (0) "delta x", or adjust the icon horizontally by x pixels
|
||||
# @option opts dy [Integer] (0) "delta y", or adjust the icon vertically by y pixels
|
||||
# @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
# @api public
|
||||
def png(opts)
|
||||
opts = { width: 32, height: 32 }.merge(opts)
|
||||
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
||||
# TODO: add input validation here. We need the key for example.
|
||||
rule = {type: :png}.merge(opts)
|
||||
rule[:draw] = Proc.new do |card, x,y|
|
||||
card.png(rule[:file], x, y, rule[:width], rule[:height],
|
||||
rule[:alpha], rule[:blend], rule[:angle], rule[:mask])
|
||||
def png(opts = {})
|
||||
# TODO: add input validation for key here
|
||||
range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
|
||||
paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
|
||||
box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
|
||||
rule = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }
|
||||
rule[:draw] = Proc.new do |card, x, y|
|
||||
i = card.index
|
||||
b = box[i]
|
||||
b.x, b.y = x, y
|
||||
card.png(ifile[i].file, b, paint[i], trans[i])
|
||||
end
|
||||
@rules[opts[:key]] = rule
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ module Squib
|
||||
|
||||
def self.parameters
|
||||
{ x: 0, y: 0,
|
||||
width: :native, height: :native,
|
||||
width: :deck, height: :deck,
|
||||
radius: nil, x_radius: 0, y_radius: 0
|
||||
}
|
||||
end
|
||||
@@ -29,13 +29,13 @@ module Squib
|
||||
|
||||
def validate_width(arg, _i)
|
||||
return arg if @deck.nil?
|
||||
return @deck.width if arg == :native
|
||||
return @deck.width if arg == :deck
|
||||
arg
|
||||
end
|
||||
|
||||
def validate_height(arg, _i)
|
||||
return arg if @deck.nil?
|
||||
return @deck.height if arg == :native
|
||||
return @deck.height if arg == :deck
|
||||
arg
|
||||
end
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ module Squib
|
||||
@range.each { |i| block.call(i) }
|
||||
end
|
||||
|
||||
def size
|
||||
@range.size
|
||||
end
|
||||
|
||||
private
|
||||
def validate(input, deck_size)
|
||||
input ||= :all # default
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
require 'squib/args/arg_loader'
|
||||
|
||||
module Squib
|
||||
# @api private
|
||||
module Args
|
||||
|
||||
class EmbedAdjust
|
||||
include ArgLoader
|
||||
|
||||
def self.parameters
|
||||
{ dx: 0, dy: 0 }
|
||||
end
|
||||
|
||||
def self.expanding_parameters
|
||||
parameters.keys # all of them
|
||||
end
|
||||
|
||||
def self.params_with_units
|
||||
parameters.keys # all of them
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
require 'squib/args/arg_loader'
|
||||
|
||||
module Squib
|
||||
# @api private
|
||||
module Args
|
||||
|
||||
class InputFile
|
||||
include ArgLoader
|
||||
|
||||
def initialize
|
||||
end
|
||||
|
||||
def self.parameters
|
||||
{ file: nil }
|
||||
end
|
||||
|
||||
def self.expanding_parameters
|
||||
parameters.keys # all of them
|
||||
end
|
||||
|
||||
def self.params_with_units
|
||||
[] # none of them
|
||||
end
|
||||
|
||||
def validate_file(arg, _i)
|
||||
return nil if arg.nil?
|
||||
raise "File #{File.expand_path(arg)} does not exist!" unless File.exists?(arg)
|
||||
File.expand_path(arg)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
require 'squib/args/arg_loader'
|
||||
|
||||
module Squib
|
||||
# @api private
|
||||
module Args
|
||||
|
||||
class SvgSpecial
|
||||
include ArgLoader
|
||||
|
||||
def self.parameters
|
||||
{ data: nil, id: nil, force_id: false }
|
||||
end
|
||||
|
||||
def self.expanding_parameters
|
||||
parameters.keys # all of them
|
||||
end
|
||||
|
||||
def self.params_with_units
|
||||
[]
|
||||
end
|
||||
|
||||
def validate_id(arg, _i)
|
||||
return nil if arg.nil?
|
||||
arg = '#' << arg unless arg.start_with? '#'
|
||||
arg
|
||||
end
|
||||
|
||||
# Only render if we have an ID specified, or we are forcing an ID
|
||||
def render?(i)
|
||||
return false if force_id[i] && id[i].to_s.empty?
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
+2
-1
@@ -8,7 +8,7 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
attr_reader :width, :height, :backend, :svgfile
|
||||
attr_reader :width, :height, :backend, :svgfile, :index
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
@@ -21,6 +21,7 @@ module Squib
|
||||
@width = width
|
||||
@height = height
|
||||
@backend = deck.backend
|
||||
@index = index
|
||||
@svgfile = "#{deck.dir}/#{deck.prefix}#{deck.count_format % index}.svg"
|
||||
@cairo_surface = make_surface(@svgfile, @backend)
|
||||
@cairo_context = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(@cairo_surface))
|
||||
|
||||
+32
-32
@@ -14,56 +14,56 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def png(file, x, y, width, height, alpha, blend, angle, mask)
|
||||
Squib.logger.debug {"Rendering: #{file} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}, mask: #{mask}"}
|
||||
def png(file, box, paint, trans)
|
||||
Squib.logger.debug {"RENDERING PNG: \n file: #{file}\n box: #{box}\n paint: #{paint}\n trans: #{trans}"}
|
||||
return if file.nil? or file.eql? ''
|
||||
png = Squib.cache_load_image(file)
|
||||
use_cairo do |cc|
|
||||
cc.translate(x, y)
|
||||
if width != :native || height != :native
|
||||
width == :native && width = png.width.to_f
|
||||
height == :native && height = png.height.to_f
|
||||
cc.translate(box.x, box.y)
|
||||
if box.width != :native || box.height != :native
|
||||
box.width == :native && box.width = png.width.to_f
|
||||
box.height == :native && box.height = png.height.to_f
|
||||
Squib.logger.warn "PNG scaling results in antialiasing."
|
||||
cc.scale(width.to_f / png.width.to_f, height.to_f / png.height.to_f)
|
||||
cc.scale(box.width.to_f / png.width.to_f, box.height.to_f / png.height.to_f)
|
||||
end
|
||||
cc.rotate(angle)
|
||||
cc.translate(-x, -y)
|
||||
cc.set_source(png, x, y)
|
||||
cc.operator = blend unless blend == :none
|
||||
if mask.nil?
|
||||
cc.paint(alpha)
|
||||
cc.rotate(trans.angle)
|
||||
cc.translate(-box.x, -box.y)
|
||||
cc.set_source(png, box.x, box.y)
|
||||
cc.operator = paint.blend unless paint.blend == :none
|
||||
if paint.mask.empty?
|
||||
cc.paint(paint.alpha)
|
||||
else
|
||||
cc.set_source_squibcolor(mask)
|
||||
cc.mask(png, x, y)
|
||||
cc.set_source_squibcolor(paint.mask)
|
||||
cc.mask(png, box.x, box.y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def svg(file, data, id, x, y, width, height, alpha, blend, angle, mask)
|
||||
def svg(file, svg_args, box, paint, trans)
|
||||
Squib.logger.debug {"Rendering: #{file}, id: #{id} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}, mask: #{mask}"}
|
||||
Squib.logger.warn 'Both an SVG file and SVG data were specified' unless file.to_s.empty? or data.to_s.empty?
|
||||
return if (file.nil? or file.eql? '') and data.nil? # nothing specified
|
||||
data = File.read(file) if data.to_s.empty?
|
||||
svg = RSVG::Handle.new_from_data(data)
|
||||
width = svg.width if width == :native
|
||||
height = svg.height if height == :native
|
||||
scale_width = width.to_f / svg.width.to_f
|
||||
scale_height = height.to_f / svg.height.to_f
|
||||
Squib.logger.warn 'Both an SVG file and SVG data were specified' unless file.to_s.empty? || svg_args.data.to_s.empty?
|
||||
return if (file.nil? or file.eql? '') and svg_args.data.nil? # nothing specified TODO Move this out to arg validator
|
||||
svg_args.data = File.read(file) if svg_args.data.to_s.empty?
|
||||
svg = RSVG::Handle.new_from_data(svg_args.data)
|
||||
box.width = svg.width if box.width == :native
|
||||
box.height = svg.height if box.height == :native
|
||||
scale_width = box.width.to_f / svg.width.to_f
|
||||
scale_height = box.height.to_f / svg.height.to_f
|
||||
use_cairo do |cc|
|
||||
cc.translate(x, y)
|
||||
cc.rotate(angle)
|
||||
cc.translate(box.x, box.y)
|
||||
cc.rotate(trans.angle)
|
||||
cc.scale(scale_width, scale_height)
|
||||
cc.operator = blend unless blend == :none
|
||||
cc.operator = paint.blend unless paint.blend == :none
|
||||
#FIXME Alpha is no longer used since we are not using cc.paint anymore
|
||||
if mask.nil?
|
||||
cc.render_rsvg_handle(svg, id)
|
||||
if paint.mask.to_s.empty?
|
||||
cc.render_rsvg_handle(svg, svg_args.id)
|
||||
else
|
||||
tmp = Cairo::ImageSurface.new(width / scale_width, height / scale_height)
|
||||
tmp = Cairo::ImageSurface.new(box.width / scale_width, box.height / scale_height)
|
||||
tmp_cc = Cairo::Context.new(tmp)
|
||||
tmp_cc.render_rsvg_handle(svg, id)
|
||||
cc.set_source_squibcolor(mask)
|
||||
tmp_cc.render_rsvg_handle(svg, svg_args.id)
|
||||
cc.set_source_squibcolor(paint.mask)
|
||||
cc.mask(tmp, 0, 0)
|
||||
end
|
||||
end
|
||||
|
||||
+12
-12
@@ -79,24 +79,24 @@ module Squib
|
||||
# @api private
|
||||
def process_embeds(embed, str, layout)
|
||||
return [] unless embed.rules.any?
|
||||
layout.markup = str
|
||||
clean_str = layout.text
|
||||
draw_calls = []
|
||||
searches = []
|
||||
layout.markup = str
|
||||
clean_str = layout.text
|
||||
draw_calls = []
|
||||
searches = []
|
||||
while (key = next_embed(embed.rules.keys, clean_str)) != nil
|
||||
rule = embed.rules[key]
|
||||
spacing = rule[:width] * Pango::SCALE
|
||||
index = clean_str.index(key)
|
||||
index = clean_str[0..index].bytesize #convert to byte index (bug #57)
|
||||
rule = embed.rules[key]
|
||||
spacing = rule[:box].width[@index] * Pango::SCALE
|
||||
kindex = clean_str.index(key)
|
||||
kindex = clean_str[0..kindex].bytesize #convert to byte index (bug #57)
|
||||
str = str.sub(key, "<span size=\"#{ZERO_WIDTH_CHAR_SIZE}\">a<span letter_spacing=\"#{spacing.to_i}\">a</span>a</span>")
|
||||
layout.markup = str
|
||||
clean_str = layout.text
|
||||
searches << { index: index, rule: rule }
|
||||
searches << { index: kindex, rule: rule }
|
||||
end
|
||||
searches.each do |search|
|
||||
rect = layout.index_to_pos(search[:index])
|
||||
x = Pango.pixels(rect.x) + search[:rule][:dx]
|
||||
y = Pango.pixels(rect.y) + search[:rule][:dy]
|
||||
rect = layout.index_to_pos(search[:index])
|
||||
x = Pango.pixels(rect.x) + search[:rule][:adjust].dx[@index]
|
||||
y = Pango.pixels(rect.y) + search[:rule][:adjust].dy[@index]
|
||||
draw_calls << {x: x, y: y, draw: search[:rule][:draw]} # defer drawing until we've valigned
|
||||
end
|
||||
return draw_calls
|
||||
|
||||
Reference in New Issue
Block a user