Fixes #152
parent
d79e03f845
commit
013a1532f2
|
|
@ -5,7 +5,10 @@ module Squib
|
||||||
# @api private
|
# @api private
|
||||||
def save_png(batch)
|
def save_png(batch)
|
||||||
surface = if preprocess_save?(batch)
|
surface = if preprocess_save?(batch)
|
||||||
preprocessed_save(batch.angle, batch.trim, batch.trim_radius)
|
w, h = compute_dimensions(batch.rotate, batch.trim)
|
||||||
|
puts "Gonna preprocess! #{w}x#{h}"
|
||||||
|
puts "Batch: #{batch}"
|
||||||
|
preprocessed_save(w, h, batch)
|
||||||
else
|
else
|
||||||
@cairo_surface
|
@cairo_surface
|
||||||
end
|
end
|
||||||
|
|
@ -15,20 +18,32 @@ module Squib
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
# @api private
|
# @api private
|
||||||
def preprocess_save?(batch)
|
def preprocess_save?(batch)
|
||||||
batch.rotate || batch.trim > 0
|
batch.rotate != false || batch.trim > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def preprocessed_save(angle, trim, trim_radius)
|
def compute_dimensions(rotate, trim)
|
||||||
new_width, new_height = @width - 2 * trim, @height - 2 * trim
|
if rotate
|
||||||
new_cc = Cairo::Context.new(Cairo::ImageSurface.new(new_width, new_height))
|
[ @height - 2 * trim, @width - 2 * trim ]
|
||||||
new_cc.translate(new_width * 0.5, new_height * 0.5)
|
else
|
||||||
new_cc.rotate(angle)
|
[ @width - 2 * trim, @height - 2 * trim ]
|
||||||
new_cc.translate(new_width * -0.5, new_height * -0.5)
|
end
|
||||||
new_cc.set_source(@cairo_surface, -trim, -trim)
|
end
|
||||||
new_cc.rounded_rectangle(0, 0, new_width, new_height, trim_radius, trim_radius)
|
|
||||||
|
def preprocessed_save(width, height, batch)
|
||||||
|
new_cc = Cairo::Context.new(Cairo::ImageSurface.new(width, height))
|
||||||
|
trim_radius = batch.trim_radius
|
||||||
|
if batch.rotate != false
|
||||||
|
new_cc.translate(width * 0.5, height * 0.5)
|
||||||
|
new_cc.rotate(batch.angle)
|
||||||
|
new_cc.translate(height * -0.5, width * -0.5)
|
||||||
|
new_cc.rounded_rectangle(0, 0, height, width, trim_radius, trim_radius)
|
||||||
|
else
|
||||||
|
new_cc.rounded_rectangle(0, 0, width, height, trim_radius, trim_radius)
|
||||||
|
end
|
||||||
new_cc.clip
|
new_cc.clip
|
||||||
|
new_cc.set_source(@cairo_surface, -batch.trim, -batch.trim)
|
||||||
new_cc.paint
|
new_cc.paint
|
||||||
new_cc.target
|
return new_cc.target
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_png(surface, i, dir, prefix, count_format)
|
def write_png(surface, i, dir, prefix, count_format)
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,8 @@ module Squib
|
||||||
spacing = rule[:box].width[@index] * Pango::SCALE
|
spacing = rule[:box].width[@index] * Pango::SCALE
|
||||||
kindex = clean_str.index(key)
|
kindex = clean_str.index(key)
|
||||||
kindex = clean_str[0..kindex].bytesize # convert to byte index (bug #57)
|
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>")
|
# str = str.sub(key, "<span size=\"#{ZERO_WIDTH_CHAR_SIZE}\">a<span letter_spacing=\"#{spacing.to_i}\">a</span>a</span>")
|
||||||
|
str = str.sub(key, "\u0091<span letter_spacing=\"#{spacing.to_i}\">\u0091</span>\u0091")
|
||||||
layout.markup = str
|
layout.markup = str
|
||||||
clean_str = layout.text
|
clean_str = layout.text
|
||||||
searches << { index: kindex, rule: rule }
|
searches << { index: kindex, rule: rule }
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9bb3727e13a806d33b0b321e9f6fff85c7d8a943
|
Subproject commit 2b3a6498fdf4668f5d7a30aa2773e4a0f1f1c4f2
|
||||||
Loading…
Reference in New Issue