Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlessone committed May 5, 2018
1 parent 5b5ffe5 commit 37303f5
Show file tree
Hide file tree
Showing 198 changed files with 439 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require: rubocop-rspec

AllCops:
TargetRubyVersion: 2.3

RSpec/ExampleLength:
Enabled: false

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler'
Bundler.setup

Expand Down
2 changes: 2 additions & 0 deletions bench/afm_text_bench.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'prawn'
require 'benchmark'
Expand Down
2 changes: 2 additions & 0 deletions bench/png_type_6.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'prawn'
require 'benchmark'
Expand Down
2 changes: 2 additions & 0 deletions bench/png_type_6_objects.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

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

Expand Down
2 changes: 2 additions & 0 deletions bench/table_bench.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'prawn'
require 'benchmark'
Expand Down
2 changes: 2 additions & 0 deletions bench/ttf_text_bench.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'prawn'
require 'benchmark'
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Welcome to Prawn, the best PDF Generation library ever.
# This documentation covers user level functionality.
#
Expand Down
4 changes: 3 additions & 1 deletion lib/prawn/document.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# document.rb : Implements PDF document generation for Prawn
#
# Copyright April 2008, Gregory Brown. All Rights Reserved.
Expand Down Expand Up @@ -269,7 +271,7 @@ def start_new_page(options = {})

# erase the color space so that it gets reset on new page for fussy
# pdf-readers
new_graphic_state.color_space = {} if new_graphic_state
new_graphic_state&.color_space = {}

page_options[:graphic_state] = new_graphic_state
end
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/document/bounding_box.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# bounding_box.rb : Implements a mechanism for shifting the coordinate space
#
# Copyright May 2008, Gregory Brown. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/document/column_box.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# column_box.rb: Extends BoundingBox to allow for columns of text
#
# Author Paul Ostazeski.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/document/internals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# internals.rb : Implements document internals for Prawn
#
# Copyright August 2008, Gregory Brown. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/document/span.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# span.rb : Implements text columns
#
# Copyright September 2008, Gregory Brown. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/encoding.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Copyright September 2008, Gregory Brown, James Healy All Rights Reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# errors.rb : Implements custom error classes for Prawn
#
# Copyright April 2008, Gregory Brown. All Rights Reserved.
Expand Down
7 changes: 6 additions & 1 deletion lib/prawn/font.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# font.rb : The Prawn font class
#
# Copyright May 2008, Gregory Brown / James Healy. All Rights Reserved.
Expand Down Expand Up @@ -355,8 +357,11 @@ def normalize_encoding(_string)
# Destructive version of normalize_encoding; normalizes the encoding of a
# string in place.
#
# @deprecated
def normalize_encoding!(str)
str.replace(normalize_encoding(str))
warn 'Font#normalize_encoding! is deprecated. ' \
'Please use non-mutating version Font#normalize_encoding instead.'
str.dup.replace(normalize_encoding(str))
end

# Gets height of current font in PDF points at the given font size
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/font/afm.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# prawn/font/afm.rb : Implements AFM font support for Prawn
#
# Copyright May 2008, Gregory Brown / James Healy. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/font/dfont.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'ttf'

module Prawn
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/font/ttc.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'ttf'

module Prawn
Expand Down
6 changes: 4 additions & 2 deletions lib/prawn/font/ttf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# prawn/font/ttf.rb : Implements AFM font support for Prawn
#
# Copyright May 2008, Gregory Brown / James Healy / Jamis Buck
Expand Down Expand Up @@ -182,7 +184,7 @@ def to_utf8(text)

def glyph_present?(char)
code = char.codepoints.first
cmap[code] > 0
cmap[code].positive?
end

# Returns the number of characters in +str+ (a UTF-8-encoded string).
Expand Down Expand Up @@ -313,7 +315,7 @@ def embed(reference, subset)
ranges.last << format('<%02x><%04x>', code, unicode)
end

range_blocks = ranges.inject('') do |s, list|
range_blocks = ranges.inject(+'') do |s, list|
s << format(
"%d beginbfchar\n%s\nendbfchar\n",
list.length, list.join("\n")
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/font_metric_cache.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# font_metric_cache.rb : The Prawn font class
#
# Copyright Dec 2012, Kenneth Kalmer. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# graphics.rb : Implements PDF drawing primitives
#
# Copyright April 2008, Gregory Brown. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/blend_mode.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# blend_mode.rb : Implements blend modes
#
# Contributed by John Ford. October, 2015
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/cap_style.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# cap_style.rb : Implements stroke cap styling
#
# Contributed by Daniel Nelson. October, 2009
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/color.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# color.rb : Implements color handling
#
# Copyright June 2008, Gregory Brown. All Rights Reserved.
Expand Down
4 changes: 3 additions & 1 deletion lib/prawn/graphics/dash.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# dash.rb : Implements stroke dashing
#
# Contributed by Daniel Nelson. October, 2009
Expand Down Expand Up @@ -61,7 +63,7 @@ def dash(length = nil, options = {})
if length.all?(&:zero?)
raise ArgumentError,
'Zero length dashes are invalid. Call #undash to disable dashes.'
elsif length.any? { |e| e < 0 }
elsif length.any?(&:negative?)
raise ArgumentError,
'Negative numbers are not allowed for dash lengths.'
end
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/join_style.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# join_style.rb : Implements stroke join styling
#
# Contributed by Daniel Nelson. October, 2009
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/patterns.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'digest/sha1'

# patterns.rb : Implements axial & radial gradients
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/transformation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# transformation.rb: Implements rotate, translate, skew, scale and a generic
# transformation_matrix
#
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/graphics/transparency.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# transparency.rb : Implements transparency
#
# Copyright October 2009, Daniel Nelson. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/grid.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# grid.rb: Provides a basic grid layout system for Prawn
#
# Contributed by Andrew O'Brien in March 2009
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/image_handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# ImageHandler provides a way to register image processors with Prawn
#
# Contributed by Evan Sharp in November 2013.
Expand Down
3 changes: 3 additions & 0 deletions lib/prawn/images.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# encoding: ASCII-8BIT

# frozen_string_literal: true

# images.rb : Implements PDF image embedding
#
# Copyright April 2008, James Healy, Gregory Brown. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/images/image.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# image.rb : Base class for image info objects
#
# Copyright September 2011, Brad Ediger. All rights reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/images/jpg.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# encoding: ASCII-8BIT

# frozen_string_literal: true

# jpg.rb : Extracts the data from a JPG that is needed for embedding
#
# Copyright April 2008, James Healy. All Rights Reserved.
Expand Down
6 changes: 4 additions & 2 deletions lib/prawn/images/png.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# encoding: ASCII-8BIT

# frozen_string_literal: true

# png.rb : Extracts the data from a PNG that is needed for embedding
#
# Based on some similar code in PDF::Writer by Austin Ziegler
Expand Down Expand Up @@ -38,8 +40,8 @@ def initialize(data)

data.read(8) # Skip the default header

@palette = ''
@img_data = ''
@palette = +''
@img_data = +''
@transparency = {}

loop do
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/measurement_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# measurement_extensions.rb: Core extensions for Prawn::Measurements
#
# Copyright December 2008, Florian Witteler. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/measurements.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# measurements.rb: Conversions from other measurements to PDF points
#
# Copyright December 2008, Florian Witteler. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/outline.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Prawn
class Document
# @group Stable API
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/repeater.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# repeater.rb : Implements repeated page elements.
# Heavy inspired by repeating_element() in PDF::Wrapper
# http://pdf-wrapper.rubyforge.org/
Expand Down
30 changes: 16 additions & 14 deletions lib/prawn/security.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# encryption.rb : Implements encrypted PDF and access permissions.
#
# Copyright August 2008, Brad Ediger. All Rights Reserved.
Expand Down Expand Up @@ -215,9 +217,9 @@ module Core
def encrypted_pdf_object(obj, key, id, gen, in_content_stream = false)
case obj
when Array
'[' << obj.map do |e|
'[' + obj.map do |e|
encrypted_pdf_object(e, key, id, gen, in_content_stream)
end.join(' ') << ']'
end.join(' ') + ']'
when LiteralString
obj = ByteString.new(
Prawn::Document::Security.encrypt_string(obj, key, id, gen)
Expand All @@ -237,16 +239,16 @@ def encrypted_pdf_object(obj, key, id, gen, in_content_stream = false)
in_content_stream
)
when ::Hash
output = '<< '
obj.each do |k, v|
unless k.is_a?(String) || k.is_a?(Symbol)
raise PDF::Core::Errors::FailedObjectConversion,
'A PDF Dictionary must be keyed by names'
end
output << pdf_object(k.to_sym, in_content_stream) << ' ' <<
encrypted_pdf_object(v, key, id, gen, in_content_stream) << "\n"
end
output << '>>'
'<< ' +
obj.map do |k, v|
unless k.is_a?(String) || k.is_a?(Symbol)
raise PDF::Core::Errors::FailedObjectConversion,
'A PDF Dictionary must be keyed by names'
end
pdf_object(k.to_sym, in_content_stream) + ' ' +
encrypted_pdf_object(v, key, id, gen, in_content_stream) + "\n"
end.join('') +
'>>'
when NameTree::Value
pdf_object(obj.name) + ' ' +
encrypted_pdf_object(obj.value, key, id, gen, in_content_stream)
Expand Down Expand Up @@ -276,9 +278,9 @@ class Reference
# Returns the object definition for the object this references, keyed from
# +key+.
def encrypted_object(key)
@on_encode.call(self) if @on_encode
@on_encode&.call(self)

output = "#{@identifier} #{gen} obj\n"
output = +"#{@identifier} #{gen} obj\n"
if @stream.empty?
output <<
PDF::Core.encrypted_pdf_object(data, key, @identifier, gen) << "\n"
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/security/arcfour.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Implementation of the "ARCFOUR" algorithm ("alleged RC4 (tm)"). Implemented
# as described at:
# http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/soft_mask.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# soft_mask.rb : Implements soft-masking
#
# Copyright September 2012, Alexander Mankuta. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions lib/prawn/stamp.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# stamp.rb : Implements a repeatable stamp
#
# Copyright October 2009, Daniel Nelson. All Rights Reserved.
Expand Down
Loading

0 comments on commit 37303f5

Please sign in to comment.