diff --git a/README.md b/README.md index 45e7d58..ba21146 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ By default, prawn-svg has a fonts path of ["/Library/Fonts", "/System/Librar Mac OS X and Debian Linux users. You can add to the font path: ```ruby - Prawn::Svg::Interface.font_path << "/my/font/directory" + Prawn::SVG::Interface.font_path << "/my/font/directory" ``` diff --git a/lib/prawn-svg.rb b/lib/prawn-svg.rb index 488df58..d434f80 100644 --- a/lib/prawn-svg.rb +++ b/lib/prawn-svg.rb @@ -16,4 +16,8 @@ require 'prawn/svg/parser/text' require 'prawn/svg/parser/image' -Prawn::Document.extensions << Prawn::Svg::Extension +module Prawn + Svg = SVG # backwards compatibility +end + +Prawn::Document.extensions << Prawn::SVG::Extension diff --git a/lib/prawn/svg/calculators/aspect_ratio.rb b/lib/prawn/svg/calculators/aspect_ratio.rb index 31b6137..91af160 100644 --- a/lib/prawn/svg/calculators/aspect_ratio.rb +++ b/lib/prawn/svg/calculators/aspect_ratio.rb @@ -1,4 +1,4 @@ -module Prawn::Svg::Calculators +module Prawn::SVG::Calculators class AspectRatio attr_reader :align, :defer attr_reader :width, :height, :x, :y diff --git a/lib/prawn/svg/calculators/document_sizing.rb b/lib/prawn/svg/calculators/document_sizing.rb index d7e4c9a..15ccd88 100644 --- a/lib/prawn/svg/calculators/document_sizing.rb +++ b/lib/prawn/svg/calculators/document_sizing.rb @@ -1,4 +1,4 @@ -module Prawn::Svg::Calculators +module Prawn::SVG::Calculators class DocumentSizing DEFAULT_WIDTH = 300 DEFAULT_HEIGHT = 150 @@ -34,7 +34,7 @@ def calculate @output_height = Pixels.to_pixels(@document_height || @requested_height, container_height) if @view_box - values = @view_box.strip.split(Prawn::Svg::Parser::COMMA_WSP_REGEXP) + values = @view_box.strip.split(Prawn::SVG::Parser::COMMA_WSP_REGEXP) @x_offset, @y_offset, @viewport_width, @viewport_height = values.map {|value| value.to_f} @x_offset = -@x_offset diff --git a/lib/prawn/svg/calculators/pixels.rb b/lib/prawn/svg/calculators/pixels.rb index 3b321d5..dd67d5e 100644 --- a/lib/prawn/svg/calculators/pixels.rb +++ b/lib/prawn/svg/calculators/pixels.rb @@ -1,4 +1,4 @@ -module Prawn::Svg::Calculators +module Prawn::SVG::Calculators class Pixels extend Prawn::Measurements diff --git a/lib/prawn/svg/color.rb b/lib/prawn/svg/color.rb index 9b7e05e..ae7cd8b 100644 --- a/lib/prawn/svg/color.rb +++ b/lib/prawn/svg/color.rb @@ -1,4 +1,4 @@ -class Prawn::Svg::Color +class Prawn::SVG::Color UnresolvableURLWithNoFallbackError = Class.new(StandardError) HTML_COLORS = { diff --git a/lib/prawn/svg/document.rb b/lib/prawn/svg/document.rb index de85ae3..5bfb8d6 100644 --- a/lib/prawn/svg/document.rb +++ b/lib/prawn/svg/document.rb @@ -1,4 +1,4 @@ -class Prawn::Svg::Document +class Prawn::SVG::Document begin require 'css_parser' CSS_PARSER_LOADED = true @@ -27,7 +27,7 @@ def initialize(data, bounds, options) @cache_images = options[:cache_images] @fallback_font_name = options.fetch(:fallback_font_name, DEFAULT_FALLBACK_FONT_NAME) - @sizing = Prawn::Svg::Calculators::DocumentSizing.new(bounds, @root.attributes) + @sizing = Prawn::SVG::Calculators::DocumentSizing.new(bounds, @root.attributes) sizing.requested_width = options[:width] sizing.requested_height = options[:height] sizing.calculate @@ -50,10 +50,10 @@ def distance(value, axis = nil) end def points(value, axis = nil) - Prawn::Svg::Calculators::Pixels.to_pixels(value, @axis_to_size.fetch(axis, sizing.viewport_diagonal)) + Prawn::SVG::Calculators::Pixels.to_pixels(value, @axis_to_size.fetch(axis, sizing.viewport_diagonal)) end def url_loader - @url_loader ||= Prawn::Svg::UrlLoader.new(:enable_cache => cache_images) + @url_loader ||= Prawn::SVG::UrlLoader.new(:enable_cache => cache_images) end end diff --git a/lib/prawn/svg/element.rb b/lib/prawn/svg/element.rb index d80af96..6423dc1 100644 --- a/lib/prawn/svg/element.rb +++ b/lib/prawn/svg/element.rb @@ -1,4 +1,4 @@ -class Prawn::Svg::Element +class Prawn::SVG::Element attr_reader :document, :source, :parent_calls, :base_calls, :state, :attributes attr_accessor :calls @@ -72,7 +72,7 @@ def apply_drawing_call(draw_types) end def container? - Prawn::Svg::Parser::CONTAINER_TAGS.include?(name) + Prawn::SVG::Parser::CONTAINER_TAGS.include?(name) end def parse_transform_attribute_and_call @@ -155,10 +155,10 @@ def parse_fill_and_stroke_attributes_and_call color = @attributes[color_attribute] begin - hex = Prawn::Svg::Color.color_to_hex(color) + hex = Prawn::SVG::Color.color_to_hex(color) state[type.to_sym] = true add_call "#{type}_color", hex || '000000' - rescue Prawn::Svg::Color::UnresolvableURLWithNoFallbackError + rescue Prawn::SVG::Color::UnresolvableURLWithNoFallbackError state[type.to_sym] = false end end @@ -185,7 +185,7 @@ def parse_stroke_attributes_and_call when 'none' add_call('undash') else - array = dasharray.split(Prawn::Svg::Parser::COMMA_WSP_REGEXP) + array = dasharray.split(Prawn::SVG::Parser::COMMA_WSP_REGEXP) array *= 2 if array.length % 2 == 1 number_array = array.map {|value| @document.distance(value)} @@ -207,7 +207,7 @@ def parse_font_attributes_and_call end if weight = @attributes['font-weight'] font_updated = true - @state[:font_weight] = Prawn::Svg::Font.weight_for_css_font_weight(weight) + @state[:font_weight] = Prawn::SVG::Font.weight_for_css_font_weight(weight) end if style = @attributes['font-style'] font_updated = true @@ -225,7 +225,7 @@ def parse_font_attributes_and_call usable_font_families = [@state[:font_family], document.fallback_font_name] font_used = usable_font_families.compact.detect do |name| - if font = Prawn::Svg::Font.load(name, @state[:font_weight], @state[:font_style]) + if font = Prawn::SVG::Font.load(name, @state[:font_weight], @state[:font_style]) @state[:font_subfamily] = font.subfamily add_call_and_enter 'font', font.name, :style => @state[:font_subfamily] true diff --git a/lib/prawn/svg/extension.rb b/lib/prawn/svg/extension.rb index 459935d..f56cf05 100644 --- a/lib/prawn/svg/extension.rb +++ b/lib/prawn/svg/extension.rb @@ -1,5 +1,5 @@ module Prawn - module Svg + module SVG module Extension # # Draws an SVG document into the PDF. @@ -15,7 +15,7 @@ module Extension # svg IO.read("example.svg"), :at => [100, 300], :width => 600 # def svg(data, options = {}, &block) - svg = Prawn::Svg::Interface.new(data, self, options, &block) + svg = Prawn::SVG::Interface.new(data, self, options, &block) svg.draw {:warnings => svg.document.warnings, :width => svg.document.sizing.output_width, :height => svg.document.sizing.output_height} end diff --git a/lib/prawn/svg/font.rb b/lib/prawn/svg/font.rb index 1573f0c..ddc8f7c 100644 --- a/lib/prawn/svg/font.rb +++ b/lib/prawn/svg/font.rb @@ -1,4 +1,4 @@ -class Prawn::Svg::Font +class Prawn::SVG::Font GENERIC_CSS_FONT_MAPPING = { "serif" => "Times-Roman", "sans-serif" => "Helvetica", @@ -34,7 +34,7 @@ def self.weight_for_css_font_weight(weight) # This method is passed prawn's font_families hash. It'll be pre-populated with the fonts that prawn natively # supports. We'll add fonts we find in the font path to this hash. def self.load_external_fonts(fonts) - Prawn::Svg::Interface.font_path.uniq.collect {|path| Dir["#{path}/**/*"]}.flatten.each do |filename| + Prawn::SVG::Interface.font_path.uniq.collect {|path| Dir["#{path}/**/*"]}.flatten.each do |filename| information = font_information(filename) rescue nil if information && font_name = (information[16] || information[1]) subfamily = (information[17] || information[2] || "normal").gsub(/\s+/, "_").downcase.to_sym diff --git a/lib/prawn/svg/interface.rb b/lib/prawn/svg/interface.rb index e831a0a..29ab2f7 100644 --- a/lib/prawn/svg/interface.rb +++ b/lib/prawn/svg/interface.rb @@ -1,9 +1,9 @@ # -# Prawn::Svg::Interface makes a Prawn::Svg::Document instance, uses that object to parse the supplied +# Prawn::SVG::Interface makes a Prawn::SVG::Document instance, uses that object to parse the supplied # SVG into Prawn-compatible method calls, and then calls the Prawn methods. # module Prawn - module Svg + module SVG class Interface VALID_OPTIONS = [:at, :position, :vposition, :width, :height, :cache_images, :fallback_font_name] @@ -17,7 +17,7 @@ class << self; attr_accessor :font_path; end attr_reader :data, :prawn, :document, :options # - # Creates a Prawn::Svg object. + # Creates a Prawn::SVG object. # # +data+ is the SVG data to convert. +prawn+ is your Prawn::Document object. # @@ -40,7 +40,7 @@ def initialize(data, prawn, options, &block) @prawn = prawn @options = options - Prawn::Svg::Font.load_external_fonts(prawn.font_families) + Prawn::SVG::Font.load_external_fonts(prawn.font_families) @document = Document.new(data, [prawn.bounds.width, prawn.bounds.height], options, &block) end diff --git a/lib/prawn/svg/parser.rb b/lib/prawn/svg/parser.rb index 6e35b9f..033d6ce 100644 --- a/lib/prawn/svg/parser.rb +++ b/lib/prawn/svg/parser.rb @@ -1,17 +1,17 @@ require 'rexml/document' # -# Prawn::Svg::Parser is responsible for parsing an SVG file and converting it into a tree of +# Prawn::SVG::Parser is responsible for parsing an SVG file and converting it into a tree of # prawn-compatible method calls. # -# You probably do not want to use this class directly. Instead, use Prawn::Svg to draw +# You probably do not want to use this class directly. Instead, use Prawn::SVG to draw # SVG data to your Prawn::Document object. # # This class is not passed the prawn object, so knows nothing about # prawn specifically - this might be useful if you want to take this code and use it to convert # SVG to another format. # -class Prawn::Svg::Parser +class Prawn::SVG::Parser CONTAINER_TAGS = %w(g svg symbol defs clipPath) COMMA_WSP_REGEXP = /(?:\s+,?\s*|,\s*)/ @@ -56,7 +56,7 @@ def parse [] ] - root_element = Prawn::Svg::Element.new(@document, @document.root, calls, :ids => {}, :fill => true) + root_element = Prawn::SVG::Element.new(@document, @document.root, calls, :ids => {}, :fill => true) parse_element(root_element) calls @@ -184,7 +184,7 @@ def parse_path(element) begin commands = @svg_path.parse(element.attributes['d']) - rescue Prawn::Svg::Parser::Path::InvalidError => e + rescue Prawn::SVG::Parser::Path::InvalidError => e commands = [] @document.warnings << e.message end diff --git a/lib/prawn/svg/parser/image.rb b/lib/prawn/svg/parser/image.rb index 7a238a1..702fba3 100644 --- a/lib/prawn/svg/parser/image.rb +++ b/lib/prawn/svg/parser/image.rb @@ -1,4 +1,4 @@ -class Prawn::Svg::Parser::Image +class Prawn::SVG::Parser::Image Error = Class.new(StandardError) class FakeIO @@ -44,7 +44,7 @@ def parse(element) return if width.zero? || height.zero? raise Error, "width and height must be 0 or higher" if width < 0 || height < 0 - aspect = Prawn::Svg::Calculators::AspectRatio.new(attrs['preserveAspectRatio'], [width, height], image_dimensions(image)) + aspect = Prawn::SVG::Calculators::AspectRatio.new(attrs['preserveAspectRatio'], [width, height], image_dimensions(image)) if aspect.slice? element.add_call "save" diff --git a/lib/prawn/svg/parser/path.rb b/lib/prawn/svg/parser/path.rb index 1d95796..f00a016 100644 --- a/lib/prawn/svg/parser/path.rb +++ b/lib/prawn/svg/parser/path.rb @@ -1,5 +1,5 @@ module Prawn - module Svg + module SVG class Parser::Path # Raised if the SVG path cannot be parsed. InvalidError = Class.new(StandardError) diff --git a/lib/prawn/svg/parser/text.rb b/lib/prawn/svg/parser/text.rb index eec946a..6098631 100644 --- a/lib/prawn/svg/parser/text.rb +++ b/lib/prawn/svg/parser/text.rb @@ -1,4 +1,4 @@ -class Prawn::Svg::Parser::Text +class Prawn::SVG::Parser::Text def parse(element) element.add_call_and_enter "text_group" internal_parse(element, [element.document.x(0)], [element.document.y(0)]) @@ -34,7 +34,7 @@ def internal_parse(element, x_positions, y_positions, relative = false, preserve opts[:style] = element.state[:font_subfamily] # This is not a prawn option but we can't work out how to render it here - - # it's handled by Svg#rewrite_call_arguments + # it's handled by SVG#rewrite_call_arguments if (anchor = attrs['text-anchor'] || element.state[:text_anchor]) && ['start', 'middle', 'end'].include?(anchor) opts[:text_anchor] = anchor @@ -67,7 +67,7 @@ def internal_parse(element, x_positions, y_positions, relative = false, preserve elsif child.name == "tspan" element.add_call 'save' child.attributes['text-anchor'] ||= opts[:text_anchor] if opts[:text_anchor] - child_element = Prawn::Svg::Element.new(element.document, child, element.calls, element.state.dup) + child_element = Prawn::SVG::Element.new(element.document, child, element.calls, element.state.dup) internal_parse(child_element, x_positions, y_positions, relative, preserve_space) child_element.append_calls_to_parent element.add_call 'restore' diff --git a/lib/prawn/svg/url_loader.rb b/lib/prawn/svg/url_loader.rb index e808741..bd7fb15 100644 --- a/lib/prawn/svg/url_loader.rb +++ b/lib/prawn/svg/url_loader.rb @@ -1,7 +1,7 @@ require 'open-uri' require 'base64' -class Prawn::Svg::UrlLoader +class Prawn::SVG::UrlLoader attr_accessor :enable_cache, :enable_web attr_reader :url_cache diff --git a/lib/prawn/svg/version.rb b/lib/prawn/svg/version.rb index f38c440..c3e9cf9 100644 --- a/lib/prawn/svg/version.rb +++ b/lib/prawn/svg/version.rb @@ -1,5 +1,5 @@ module Prawn - module Svg + module SVG VERSION = '0.21.0' end end diff --git a/prawn-svg.gemspec b/prawn-svg.gemspec index d4d85a8..0243c76 100644 --- a/prawn-svg.gemspec +++ b/prawn-svg.gemspec @@ -3,7 +3,7 @@ require File.expand_path('../lib/prawn/svg/version', __FILE__) spec = Gem::Specification.new do |gem| gem.name = 'prawn-svg' - gem.version = Prawn::Svg::VERSION + gem.version = Prawn::SVG::VERSION gem.summary = "SVG renderer for Prawn PDF library" gem.description = "This gem allows you to render SVG directly into a PDF using the 'prawn' gem. Since PDF is vector-based, you'll get nice scaled graphics if you use SVG instead of an image." gem.has_rdoc = false diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 581a9f6..c32c195 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Prawn::Svg::Interface do +describe Prawn::SVG::Interface do root = "#{File.dirname(__FILE__)}/.." context "with option :position" do diff --git a/spec/prawn/svg/calculators/aspect_ratio_spec.rb b/spec/prawn/svg/calculators/aspect_ratio_spec.rb index 3f0131c..5f8b930 100644 --- a/spec/prawn/svg/calculators/aspect_ratio_spec.rb +++ b/spec/prawn/svg/calculators/aspect_ratio_spec.rb @@ -1,8 +1,8 @@ require File.dirname(__FILE__) + '/../../../spec_helper' -describe Prawn::Svg::Calculators::AspectRatio do +describe Prawn::SVG::Calculators::AspectRatio do def test(*args) - aspect = Prawn::Svg::Calculators::AspectRatio.new(*args) + aspect = Prawn::SVG::Calculators::AspectRatio.new(*args) [[aspect.width, aspect.height], [aspect.x, aspect.y]] end diff --git a/spec/prawn/svg/calculators/document_sizing_spec.rb b/spec/prawn/svg/calculators/document_sizing_spec.rb index 6c6ff36..15c8ecc 100644 --- a/spec/prawn/svg/calculators/document_sizing_spec.rb +++ b/spec/prawn/svg/calculators/document_sizing_spec.rb @@ -1,13 +1,13 @@ require File.dirname(__FILE__) + '/../../../spec_helper' -describe Prawn::Svg::Calculators::DocumentSizing do +describe Prawn::SVG::Calculators::DocumentSizing do let(:attributes) do {"width" => "150", "height" => "200", "viewBox" => "0 -30 300 800", "preserveAspectRatio" => "xMaxYMid meet"} end let(:bounds) { [1200, 800] } - let(:sizing) { Prawn::Svg::Calculators::DocumentSizing.new(bounds, attributes) } + let(:sizing) { Prawn::SVG::Calculators::DocumentSizing.new(bounds, attributes) } describe "#initialize" do it "takes bounds and a set of attributes and calls set_from_attributes" do @@ -17,7 +17,7 @@ end describe "#set_from_attributes" do - let(:sizing) { Prawn::Svg::Calculators::DocumentSizing.new(bounds) } + let(:sizing) { Prawn::SVG::Calculators::DocumentSizing.new(bounds) } it "sets ivars from the passed-in attributes hash" do sizing.set_from_attributes(attributes) diff --git a/spec/prawn/svg/color_spec.rb b/spec/prawn/svg/color_spec.rb index cadcefc..a093ca0 100644 --- a/spec/prawn/svg/color_spec.rb +++ b/spec/prawn/svg/color_spec.rb @@ -1,40 +1,40 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe Prawn::Svg::Color do +describe Prawn::SVG::Color do describe :color_to_hex do it "converts #xxx to a hex value" do - Prawn::Svg::Color.color_to_hex("#9ab").should == "99aabb" + Prawn::SVG::Color.color_to_hex("#9ab").should == "99aabb" end it "converts #xxxxxx to a hex value" do - Prawn::Svg::Color.color_to_hex("#9ab123").should == "9ab123" + Prawn::SVG::Color.color_to_hex("#9ab123").should == "9ab123" end it "converts an html colour name to a hex value" do - Prawn::Svg::Color.color_to_hex("White").should == "ffffff" + Prawn::SVG::Color.color_to_hex("White").should == "ffffff" end it "converts an rgb string to a hex value" do - Prawn::Svg::Color.color_to_hex("rgb(16, 32, 48)").should == "102030" - Prawn::Svg::Color.color_to_hex("rgb(-5, 50%, 120%)").should == "007fff" + Prawn::SVG::Color.color_to_hex("rgb(16, 32, 48)").should == "102030" + Prawn::SVG::Color.color_to_hex("rgb(-5, 50%, 120%)").should == "007fff" end it "scans the string and finds the first colour it can parse" do - Prawn::Svg::Color.color_to_hex("function(#someurl, 0) nonexistent rgb( 3 ,4,5 ) white").should == "030405" + Prawn::SVG::Color.color_to_hex("function(#someurl, 0) nonexistent rgb( 3 ,4,5 ) white").should == "030405" end it "ignores url()s" do - expect(Prawn::Svg::Color.color_to_hex("url(#someplace) red")).to eq 'ff0000' + expect(Prawn::SVG::Color.color_to_hex("url(#someplace) red")).to eq 'ff0000' end it "returns nil if the color doesn't exist" do - expect(Prawn::Svg::Color.color_to_hex("blurble")).to be nil + expect(Prawn::SVG::Color.color_to_hex("blurble")).to be nil end it "raises UnresolvableURLWithNoFallbackError if there's no fallback after a url()" do expect { - Prawn::Svg::Color.color_to_hex("url(#someplace)") - }.to raise_error(Prawn::Svg::Color::UnresolvableURLWithNoFallbackError) + Prawn::SVG::Color.color_to_hex("url(#someplace)") + }.to raise_error(Prawn::SVG::Color::UnresolvableURLWithNoFallbackError) end end end diff --git a/spec/prawn/svg/document_spec.rb b/spec/prawn/svg/document_spec.rb index 974ce05..de1e968 100644 --- a/spec/prawn/svg/document_spec.rb +++ b/spec/prawn/svg/document_spec.rb @@ -1,13 +1,13 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe Prawn::Svg::Document do +describe Prawn::SVG::Document do before do - sizing = instance_double(Prawn::Svg::Calculators::DocumentSizing, viewport_width: 600, viewport_height: 400, viewport_diagonal: 500, :requested_width= => nil, :requested_height= => nil) + sizing = instance_double(Prawn::SVG::Calculators::DocumentSizing, viewport_width: 600, viewport_height: 400, viewport_diagonal: 500, :requested_width= => nil, :requested_height= => nil) expect(sizing).to receive(:calculate) - expect(Prawn::Svg::Calculators::DocumentSizing).to receive(:new).and_return(sizing) + expect(Prawn::SVG::Calculators::DocumentSizing).to receive(:new).and_return(sizing) end - let(:document) { Prawn::Svg::Document.new("", [100, 100], {}) } + let(:document) { Prawn::SVG::Document.new("", [100, 100], {}) } describe :points do it "converts a variety of measurement units to points" do diff --git a/spec/prawn/svg/element_spec.rb b/spec/prawn/svg/element_spec.rb index ab1e8da..0909e1b 100644 --- a/spec/prawn/svg/element_spec.rb +++ b/spec/prawn/svg/element_spec.rb @@ -1,14 +1,14 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe Prawn::Svg::Element do +describe Prawn::SVG::Element do let(:document) { double(css_parser: nil) } let(:e) { double(:attributes => {}, :name => "path") } - let(:element) { Prawn::Svg::Element.new(document, e, [], {}) } + let(:element) { Prawn::SVG::Element.new(document, e, [], {}) } describe "#parse_font_attributes_and_call" do before do @document = Struct.new(:fallback_font_name, :css_parser, :warnings).new("Courier", nil, []) - @element = Prawn::Svg::Element.new(@document, e, [], {}) + @element = Prawn::SVG::Element.new(@document, e, [], {}) end it "uses a font if it can find it" do diff --git a/spec/prawn/svg/font_spec.rb b/spec/prawn/svg/font_spec.rb index 12df5b4..ff130dd 100644 --- a/spec/prawn/svg/font_spec.rb +++ b/spec/prawn/svg/font_spec.rb @@ -1,31 +1,31 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe Prawn::Svg::Font do +describe Prawn::SVG::Font do describe :load do it "matches a built in font" do - Prawn::Svg::Font.load("blah, 'courier', nothing").name.should == 'Courier' + Prawn::SVG::Font.load("blah, 'courier', nothing").name.should == 'Courier' end it "matches a default font" do - Prawn::Svg::Font.load("serif").name.should == 'Times-Roman' - Prawn::Svg::Font.load("blah, serif").name.should == 'Times-Roman' - Prawn::Svg::Font.load("blah, serif , test").name.should == 'Times-Roman' + Prawn::SVG::Font.load("serif").name.should == 'Times-Roman' + Prawn::SVG::Font.load("blah, serif").name.should == 'Times-Roman' + Prawn::SVG::Font.load("blah, serif , test").name.should == 'Times-Roman' end - if Prawn::Svg::Font.installed_fonts["Verdana"] + if Prawn::SVG::Font.installed_fonts["Verdana"] it "matches a font installed on the system" do - Prawn::Svg::Font.load("verdana, sans-serif").name.should == 'Verdana' - Prawn::Svg::Font.load("VERDANA, sans-serif").name.should == 'Verdana' - Prawn::Svg::Font.load("something, \"Times New Roman\", serif").name.should == "Times New Roman" - Prawn::Svg::Font.load("something, Times New Roman, serif").name.should == "Times New Roman" + Prawn::SVG::Font.load("verdana, sans-serif").name.should == 'Verdana' + Prawn::SVG::Font.load("VERDANA, sans-serif").name.should == 'Verdana' + Prawn::SVG::Font.load("something, \"Times New Roman\", serif").name.should == "Times New Roman" + Prawn::SVG::Font.load("something, Times New Roman, serif").name.should == "Times New Roman" end else it "not running font test because we couldn't find Verdana installed on the system" end it "returns nil if it can't find any such font" do - Prawn::Svg::Font.load("blah, thing").should be_nil - Prawn::Svg::Font.load("").should be_nil + Prawn::SVG::Font.load("blah, thing").should be_nil + Prawn::SVG::Font.load("").should be_nil end end end diff --git a/spec/prawn/svg/interface_spec.rb b/spec/prawn/svg/interface_spec.rb index 1b6c1e0..ff76e22 100644 --- a/spec/prawn/svg/interface_spec.rb +++ b/spec/prawn/svg/interface_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Prawn::Svg::Interface do +describe Prawn::SVG::Interface do let(:bounds) { double(width: 800, height: 600) } let(:prawn) { instance_double(Prawn::Document, font_families: {}, bounds: bounds, cursor: 600) } let(:svg) { '' } @@ -11,19 +11,19 @@ allow(Prawn).to receive(:debug).and_return(true) expect { - Prawn::Svg::Interface.new(svg, prawn, :invalid => "option") + Prawn::SVG::Interface.new(svg, prawn, :invalid => "option") }.to raise_error(Prawn::Errors::UnknownOption) end it "does nothing if an invalid option is given and debug is off" do - Prawn::Svg::Interface.new(svg, prawn, :invalid => "option") + Prawn::SVG::Interface.new(svg, prawn, :invalid => "option") end end end describe "#draw" do context "when the sizing object indicates the sizes are invalid" do - let(:interface) { Prawn::Svg::Interface.new('', prawn, {}) } + let(:interface) { Prawn::SVG::Interface.new('', prawn, {}) } it "doesn't draw anything and adds a warning" do interface.draw @@ -36,7 +36,7 @@ subject { interface.position } context "when options[:at] supplied" do - let(:interface) { Prawn::Svg::Interface.new(svg, prawn, at: [1, 2], position: :left) } + let(:interface) { Prawn::SVG::Interface.new(svg, prawn, at: [1, 2], position: :left) } it "returns options[:at]" do expect(subject).to eq [1, 2] @@ -44,7 +44,7 @@ end context "when only a position is supplied" do - let(:interface) { Prawn::Svg::Interface.new(svg, prawn, position: position) } + let(:interface) { Prawn::SVG::Interface.new(svg, prawn, position: position) } context "(:left)" do let(:position) { :left } @@ -68,7 +68,7 @@ end context "when a vposition is supplied" do - let(:interface) { Prawn::Svg::Interface.new(svg, prawn, vposition: vposition) } + let(:interface) { Prawn::SVG::Interface.new(svg, prawn, vposition: vposition) } context "(:top)" do let(:vposition) { :top } diff --git a/spec/prawn/svg/parser/path_spec.rb b/spec/prawn/svg/parser/path_spec.rb index ac8f0fc..825ab99 100644 --- a/spec/prawn/svg/parser/path_spec.rb +++ b/spec/prawn/svg/parser/path_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe Prawn::Svg::Parser::Path do - let(:path) { Prawn::Svg::Parser::Path.new } +describe Prawn::SVG::Parser::Path do + let(:path) { Prawn::SVG::Parser::Path.new } describe "command parsing" do it "correctly parses a valid path" do @@ -41,11 +41,11 @@ end it "raises on invalid characters in the path" do - lambda {path.parse("M 10 % 20")}.should raise_error(Prawn::Svg::Parser::Path::InvalidError) + lambda {path.parse("M 10 % 20")}.should raise_error(Prawn::SVG::Parser::Path::InvalidError) end it "raises on numerical data before a command letter" do - lambda {path.parse("10 P")}.should raise_error(Prawn::Svg::Parser::Path::InvalidError) + lambda {path.parse("10 P")}.should raise_error(Prawn::SVG::Parser::Path::InvalidError) end end diff --git a/spec/prawn/svg/parser/text_spec.rb b/spec/prawn/svg/parser/text_spec.rb index b29db99..3b5a586 100644 --- a/spec/prawn/svg/parser/text_spec.rb +++ b/spec/prawn/svg/parser/text_spec.rb @@ -1,9 +1,9 @@ require File.dirname(__FILE__) + '/../../../spec_helper' -describe Prawn::Svg::Parser::Text do - let(:document) { Prawn::Svg::Document.new(svg, [800, 600], {}) } - let(:element) { Prawn::Svg::Element.new(document, document.root, [], {}) } - let(:parser) { Prawn::Svg::Parser::Text.new } +describe Prawn::SVG::Parser::Text do + let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {}) } + let(:element) { Prawn::SVG::Element.new(document, document.root, [], {}) } + let(:parser) { Prawn::SVG::Parser::Text.new } describe "xml:space preserve" do let(:svg) { %(some\n\t text) } diff --git a/spec/prawn/svg/parser_spec.rb b/spec/prawn/svg/parser_spec.rb index 73503d4..9fbe8f8 100644 --- a/spec/prawn/svg/parser_spec.rb +++ b/spec/prawn/svg/parser_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Prawn::Svg::Parser do +describe Prawn::SVG::Parser do describe "document width and height" do it "handles the width and height being set as a %" do svg = <<-SVG @@ -9,8 +9,8 @@ SVG - document = Prawn::Svg::Document.new(svg, [2000, 2000], {}) - Prawn::Svg::Parser.new(document).parse[-2][-1].should == [["line", [100.0, 900.0, 900.0, 100.0], []]] + document = Prawn::SVG::Document.new(svg, [2000, 2000], {}) + Prawn::SVG::Parser.new(document).parse[-2][-1].should == [["line", [100.0, 900.0, 900.0, 100.0], []]] end it "handles the width and height being set in inches" do @@ -20,20 +20,20 @@ SVG - document = Prawn::Svg::Document.new(svg, [2000, 2000], {}) - Prawn::Svg::Parser.new(document).parse[-2][-1].should == [["line", [72.0, 720.0 - 72.0, 720.0 - 72.0, 72.0], []]] + document = Prawn::SVG::Document.new(svg, [2000, 2000], {}) + Prawn::SVG::Parser.new(document).parse[-2][-1].should == [["line", [72.0, 720.0 - 72.0, 720.0 - 72.0, 72.0], []]] end end describe "#parse_element" do before(:each) do - @document = Prawn::Svg::Document.new("", [100, 100], {}) - @parser = Prawn::Svg::Parser.new(@document) + @document = Prawn::SVG::Document.new("", [100, 100], {}) + @parser = Prawn::SVG::Parser.new(@document) end def mock_element(name, attributes = {}) e = double(:name => name, :attributes => attributes) - Prawn::Svg::Element.new(@document, e, [], {}) + Prawn::SVG::Element.new(@document, e, [], {}) end it "ignores tags it doesn't know about" do @@ -54,8 +54,8 @@ def mock_element(name, attributes = {}) end describe "#load_css_styles" do - let(:document) { Prawn::Svg::Document.new(svg, [100, 100], {}) } - let(:parser) { Prawn::Svg::Parser.new(document) } + let(:document) { Prawn::SVG::Document.new(svg, [100, 100], {}) } + let(:parser) { Prawn::SVG::Parser.new(document) } let(:svg) do <<-SVG diff --git a/spec/prawn/svg/url_loader_spec.rb b/spec/prawn/svg/url_loader_spec.rb index 52fc601..a5c1ab7 100644 --- a/spec/prawn/svg/url_loader_spec.rb +++ b/spec/prawn/svg/url_loader_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe Prawn::Svg::UrlLoader do - let(:loader) { Prawn::Svg::UrlLoader.new(:enable_cache => true, :enable_web => true) } +describe Prawn::SVG::UrlLoader do + let(:loader) { Prawn::SVG::UrlLoader.new(:enable_cache => true, :enable_web => true) } describe "#initialize" do it "sets options" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1ae7377..f64b6cb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,4 +15,4 @@ end end -Prawn::Svg::Font.load_external_fonts(Prawn::Document.new.font_families) +Prawn::SVG::Font.load_external_fonts(Prawn::Document.new.font_families)