Respect DPI settings in text, add pt unit

This has the compatibility impact that all font sizes should be divided by 3 to maintain their same sizes.

Based on PR #225. Thanks @felixleong!!

Conflicts:
	bin/squib
	lib/squib/graphics/text.rb
This commit is contained in:
Seh Hui, Leong
2017-10-05 16:37:46 -04:00
committed by Andy Meneely
parent 06970b77a6
commit f800c131ff
43 changed files with 144 additions and 111 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ module Squib
embed = TextEmbed.new(size, custom_colors, layout, dpi, img_dir)
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]) }
range.each { |i| extents[i] = @cards[i].text(embed, para[i], box[i], trans[i], draw[i], dpi) }
return extents
end
+5
View File
@@ -8,6 +8,11 @@ module Squib
@dpi * n.to_f
end
# DSL method. See http://squib.readthedocs.io
def points(n)
@dpi / Squib::POINTS_PER_IN * n.to_f
end
# DSL method. See http://squib.readthedocs.io
def cm(n)
@dpi * Squib::INCHES_IN_CM * n.to_f
+1 -1
View File
@@ -17,7 +17,7 @@ module Squib
args[:layout] = prep_layout_args(args[:layout], expand_by: expand_by)
expand_and_set_and_defaultify(args: args, by: expand_by, layout: layout)
validate
convert_units
convert_units dpi: dpi
self
end
+2
View File
@@ -13,6 +13,8 @@ module Squib
case arg.to_s.rstrip
when /in$/ # ends with "in"
arg.rstrip[0..-2].to_f * dpi
when /pt$/ # ends with "in"
arg.rstrip[0..-2].to_f * dpi / POINTS_PER_IN
when /cm$/ # ends with "cm"
arg.rstrip[0..-2].to_f * dpi * INCHES_IN_CM
when /mm$/ # ends with "mm"
+6 -1
View File
@@ -3,10 +3,15 @@ module Squib
# System-wide default font
# :nodoc:
# @api public
DEFAULT_FONT = 'Arial 36'
DEFAULT_FONT = 'Arial 12'
# Used for inch-cm conversion
# :nodoc:
# @api private
INCHES_IN_CM = 0.393700787
# Used for points-inch conversion
# :nodoc:
# @api private
POINTS_PER_IN = 72.0
end
+3 -3
View File
@@ -12,7 +12,7 @@ module Squib
# @api private
def render_pdf(range, sheet)
cc = init_cc(sheet)
cc.scale(72.0 / @deck.dpi, 72.0 / @deck.dpi) # for bug #62
cc.scale(POINTS_PER_IN / @deck.dpi, POINTS_PER_IN / @deck.dpi) # for bug #62
x, y = sheet.margin, sheet.margin
card_width = @deck.width - 2 * sheet.trim
card_height = @deck.height - 2 * sheet.trim
@@ -59,8 +59,8 @@ module Squib
def init_cc(sheet)
Cairo::Context.new(Cairo::PDFSurface.new(
"#{sheet.dir}/#{sheet.file}",
sheet.width * 72.0 / @deck.dpi, #PDF thinks in 72 DPI "points"
sheet.height * 72.0 / @deck.dpi)
sheet.width * POINTS_PER_IN / @deck.dpi, #PDF thinks in 72 DPI "points"
sheet.height * POINTS_PER_IN / @deck.dpi)
)
end
+2 -1
View File
@@ -123,7 +123,7 @@ module Squib
# :nodoc:
# @api private
def text(embed, para, box, trans, draw)
def text(embed, para, box, trans, draw, dpi)
Squib.logger.debug {"Rendering text with: \n#{para} \nat:\n #{box} \ndraw:\n #{draw} \ntransform: #{trans}"}
extents = nil
use_cairo do |cc|
@@ -137,6 +137,7 @@ module Squib
layout = cc.create_pango_layout
layout.font_description = font_desc
layout.text = para.str.to_s
layout.context.resolution = dpi
if para.markup
para.str = @deck.typographer.process(layout.text)
layout.markup = para.str.to_s
+4 -4
View File
@@ -19,7 +19,7 @@ description:
height: 275
valign: middle
align: center
font_size: 18
font_size: 6
desc: # alias
extends: description
@@ -35,7 +35,7 @@ lower_right:
y: 975
width: 75
height: 75
font_size: 18
font_size: 6
valign: bottom
align: right
lr: #alias
@@ -46,7 +46,7 @@ lower_left:
y: 975
width: 75
height: 75
font_size: 18
font_size: 6
valign: bottom
align: left
ll: # alias
@@ -57,7 +57,7 @@ copyright:
y: 1025
width: 675
height: 25
font_size: 16
font_size: 5
align: center
valign: bottom
#aliases for copyright
+4 -4
View File
@@ -42,7 +42,7 @@ description:
height: 275
valign: middle
align: center
font_size: 18
font_size: 6
desc: # alias
extends: description
@@ -51,7 +51,7 @@ lower_right:
y: 975
width: 75
height: 75
font_size: 18
font_size: 6
valign: bottom
align: right
lr: #alias
@@ -62,7 +62,7 @@ lower_left:
y: 975
width: 75
height: 75
font_size: 18
font_size: 6
valign: bottom
align: left
ll: # alias
@@ -73,7 +73,7 @@ copyright:
y: 1025
width: 675
height: 25
font_size: 16
font_size: 5
align: center
valign: bottom
#aliases for copyright
+1 -1
View File
@@ -43,4 +43,4 @@ front_curve:
cx1: 1575
cy1: 565
cx2: 1740
cy2: 565
cy2: 565
+1 -1
View File
@@ -24,7 +24,7 @@ module Squib
text str: str, x: 460, y: @sample_y - 40,
width: 540, height: 180,
valign: 'middle', align: 'center',
font: 'Times New Roman,Serif 24'
font: 'Times New Roman,Serif 8'
yield @sample_x, @sample_y
@sample_y += 200
end