Skip to content

Commit

Permalink
Merge pull request prawnpdf#706 from prawnpdf/trailing-whitespace
Browse files Browse the repository at this point in the history
Trailing whitespace
  • Loading branch information
packetmonkey committed Apr 8, 2014
2 parents 1def63d + 92756c6 commit da5df99
Show file tree
Hide file tree
Showing 126 changed files with 449 additions and 451 deletions.
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ AlignHash:
Enabled: false
LineLength:
Enabled: false
TrailingWhitespace:
Enabled: false
SpaceBeforeBlockBraces:
Enabled: false
AlignParameters:
Expand Down
22 changes: 11 additions & 11 deletions bench/afm_text_bench.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# encoding: utf-8

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"
require "prawn"
require "benchmark"

N=2000
Benchmark.bmbm do |x|

Benchmark.bmbm do |x|
x.report("AFM text") do
Prawn::Document.new {
N.times do
Prawn::Document.new {
N.times do
(1..5).each do |i|
draw_text "Hello Prawn", :at => [200, i * 100]
end
start_new_page
end
}.render
end
end
start_new_page
end
}.render
end
end
20 changes: 10 additions & 10 deletions bench/png_type_6.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# encoding: utf-8

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"

N=100
Benchmark.bmbm do |x|
x.report("PNG Type 6") do

Benchmark.bmbm do |x|
x.report("PNG Type 6") do
N.times do
Prawn::Document.new do
Prawn::Document.new do
image "#{Prawn::DATADIR}/images/dice.png"
end.render_file("dice.pdf")
end
end
end
end
end
end
6 changes: 3 additions & 3 deletions bench/table_bench.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# encoding: utf-8

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"

# Helpers for benchmark

Expand Down
26 changes: 13 additions & 13 deletions bench/ttf_text_bench.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# encoding: utf-8

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require "prawn"
require "benchmark"

N=2000
Benchmark.bmbm do |x|

Benchmark.bmbm do |x|
x.report("TTF text") do
Prawn::Document.new {
font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
N.times do
Prawn::Document.new {
font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
N.times do
(1..5).each do |i|
draw_text "Hello Prawn", :at => [200, i * 100]
end
start_new_page
end
}.render
end
end
start_new_page
end
}.render
end
end
2 changes: 1 addition & 1 deletion lib/prawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Prawn
#
BASEDIR = File.expand_path(File.join(dir, '..'))
DATADIR = File.expand_path(File.join(dir, '..', 'data'))

FLOAT_PRECISION = 1.0e-9

# Whe set to true, Prawn will verify hash options to ensure only valid keys
Expand Down
12 changes: 6 additions & 6 deletions lib/prawn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def self.extensions
end

# @private
def self.inherited(base)
def self.inherited(base)
extensions.each { |e| base.extensions << e }
end

Expand Down Expand Up @@ -587,7 +587,7 @@ def compression_enabled?
#
# @private
def group(*a, &b)
raise NotImplementedError,
raise NotImplementedError,
"Document#group has been disabled because its implementation "+
"lead to corrupted documents whenever a page boundary was "+
"crossed. We will try to work on reimplementing it in a "+
Expand All @@ -596,7 +596,7 @@ def group(*a, &b)

# @private
def transaction
raise NotImplementedError,
raise NotImplementedError,
"Document#transaction has been disabled because its implementation "+
"lead to corrupted documents whenever a page boundary was "+
"crossed. We will try to work on reimplementing it in a "+
Expand Down Expand Up @@ -629,8 +629,8 @@ def page_match?(page_filter, page_number)
end

# @private
def mask(*fields)

def mask(*fields)
# Stores the current state of the named attributes, executes the block, and
# then restores the original values after the block has executed.
# -- I will remove the nodoc if/when this feature is a little less hacky
Expand Down Expand Up @@ -696,7 +696,7 @@ def generate_margin_box

# we must update bounding box if not flowing from the previous page
#
@bounding_box = @margin_box unless @bounding_box && @bounding_box.parent
@bounding_box = @margin_box unless @bounding_box && @bounding_box.parent
end

def apply_margin_options(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/document/bounding_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def init_bounding_box(user_block, options={}, &init_block)
# If the user actions did not modify the y position
# restore the original y position before the bounding
# box was created.

if y == @bounding_box.absolute_top
self.y = original_ypos
end
Expand Down
6 changes: 3 additions & 3 deletions lib/prawn/document/column_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class Document
#
# column_box accepts the same parameters as bounding_box, as well as the
# number of :columns and a :spacer (in points) between columns. If resetting
# the top margin is desired on a new page (e.g. to allow for initial page
# the top margin is desired on a new page (e.g. to allow for initial page
# wide column titles) the option :reflow_margins => true can be set.
#
# Defaults are :columns = 3, :spacer = font_size, and
# Defaults are :columns = 3, :spacer = font_size, and
# :reflow_margins => false
#
#
# Under PDF::Writer, "spacer" was known as "gutter"
#
def column_box(*args, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/document/internals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Document
# are you won't need anything you find here.
#
# @private
module Internals
module Internals
# Creates a new Prawn::Reference and adds it to the Document's object
# list. The +data+ argument is anything that Prawn::PdfObject() can convert.
#
Expand Down
8 changes: 4 additions & 4 deletions lib/prawn/font/afm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def find_font(file)
end

def parse_afm(file_name)
data = {:glyph_widths => {}, :bounding_boxes => {}, :kern_pairs => {}, :attributes => {}}
data = {:glyph_widths => {}, :bounding_boxes => {}, :kern_pairs => {}, :attributes => {}}
section = []

File.foreach(file_name) do |line|
Expand Down Expand Up @@ -187,7 +187,7 @@ def parse_afm(file_name)
parse_generic_afm_attribute(line, data)
end
end

# process data parsed from AFM file to build tables which
# will be used when measuring and kerning text
data[:glyph_table] = (0..255).map do |i|
Expand Down Expand Up @@ -234,9 +234,9 @@ def kern(string)
e.respond_to?(:force_encoding) ? e.force_encoding(::Encoding::Windows_1252) : e
}
end

private

def unscaled_width_of(string)
string.bytes.inject(0) do |s,r|
s + @glyph_table[r]
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/font_metric_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Prawn
# of various strings for layout purposes.
#
# @private
class FontMetricCache
class FontMetricCache

CacheEntry = Struct.new( :font, :options, :string )

Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Document
#
# Note that a completely new grid object is built each time define_grid()
# is called. This means that all subsequent calls to grid() will use
# the newly defined Grid object -- grids are not nestable like
# the newly defined Grid object -- grids are not nestable like
# bounding boxes are.

def define_grid(options = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/image_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module Prawn
# @group Extension API

def self.image_handler
@image_handler ||= ImageHandler.new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/images/jpg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Images
#
class JPG < Image
# @group Extension API

attr_reader :width, :height, :bits, :channels
attr_accessor :scaled_width, :scaled_height

Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/measurement_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Numeric
# 72 points per inch

# @group Experimental API

def mm
return mm2pt(self)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/outline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Prawn
class Document
# @group Stable API

# Lazily instantiates a Prawn::Outline object for document. This is used as point of entry
# to methods to build the outline tree for a document's table of contents.
def outline
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ module Core
# from the indirect object referencing obj.
#
# @private
def EncryptedPdfObject(obj, key, id, gen, in_content_stream=false)
def EncryptedPdfObject(obj, key, id, gen, in_content_stream=false)
case obj
when Array
"[" << obj.map { |e|
Expand Down
4 changes: 2 additions & 2 deletions lib/prawn/security/arcfour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(key)
# 1. Allocate an 256 element array of 8 bit bytes to be used as an S-box
# 2. Initialize the S-box. Fill each entry first with it's index
@sbox = (0..255).to_a

# 3. Fill another array of the same size (256) with the key, repeating
# bytes as necessary.
s2 = []
Expand All @@ -41,7 +41,7 @@ def initialize(key)
def encrypt(string)
string.unpack('c*').map{|byte| byte ^ key_byte}.pack('c*')
end

private

# Produces the next byte of key material in the stream (3.2 Stream Generation)
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/table/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def max_width
# this span group. They know their own width / height, but do not draw
# anything.
#
attr_reader :dummy_cells
attr_reader :dummy_cells

# Instantiates a Cell based on the given options. The particular class of
# cell returned depends on the :content argument. See the Prawn::Table
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/table/cells.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def aggregate_cell_values(row_or_column, meth, aggregate)
#calculate future return value
new_sum = cell.send(meth) * cell.colspan

#due to float rounding errors we need to ignore a small difference in the new
#due to float rounding errors we need to ignore a small difference in the new
#and the old sum the same had to be done in
#the column_width_calculator#natural_width
spanned_width_needs_fixing = ((new_sum - old_sum) > Prawn::FLOAT_PRECISION)
Expand Down
12 changes: 6 additions & 6 deletions lib/prawn/table/column_width_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Prawn
class Table
# @private
class ColumnWidthCalculator
class ColumnWidthCalculator
def initialize(cells)
@cells = cells

Expand All @@ -19,7 +19,7 @@ def natural_widths
#calculate natural column width for all rows that do not include a span dummy
@cells.each do |cell|
unless @rows_with_a_span_dummy[cell.row]
@widths_by_column[cell.column] =
@widths_by_column[cell.column] =
[@widths_by_column[cell.column], cell.width.to_f].max
end
end
Expand All @@ -31,20 +31,20 @@ def natural_widths
next if cell.is_a?(Cell::SpanDummy)

if cell.colspan == 1
@widths_by_column[cell.column] =
@widths_by_column[cell.column] =
[@widths_by_column[cell.column], cell.width.to_f].max
else
#calculate the current with of all cells that will be spanned by the current cell
current_width_of_spanned_cells =
current_width_of_spanned_cells =
@widths_by_column.to_a[cell.column..(cell.column + cell.colspan - 1)]
.collect{|key, value| value}.inject(0, :+)

#update the Hash only if the new with is at least equal to the old one
#due to arithmetic errors we need to ignore a small difference in the new and the old sum
#the same had to be done in the column_widht_calculator#natural_width
update_hash = ((cell.width.to_f - current_width_of_spanned_cells) >
update_hash = ((cell.width.to_f - current_width_of_spanned_cells) >
Prawn::FLOAT_PRECISION)

if update_hash
# Split the width of colspanned cells evenly by columns
width_per_column = cell.width.to_f / cell.colspan
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Text
Prawn::Text::SHY = "­"

# @group Stable API

# If you want text to flow onto a new page or between columns, this is the
# method to use. If, instead, if you want to place bounded text outside of
# the flow of a document (for captions, labels, charts, etc.), use Text::Box
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/text/formatted/arranger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Text
module Formatted #:nodoc:

# @private

class Arranger #:nodoc:
attr_reader :max_line_height
attr_reader :max_descender
Expand Down
Loading

0 comments on commit da5df99

Please sign in to comment.