Description: use system fonts when possible
 Upstream ships embedded copies of several truetype fonts. Some of them are
 available in Debian. These copies have been removed from the Debian source
 package, and system fonts are used instead. 
Author: Cédric Boutillier <cedric.boutillier@gmail.com>
Last-Update: 2011-11-21

--- a/spec/line_wrap_spec.rb
+++ b/spec/line_wrap_spec.rb
@@ -51,7 +51,7 @@
   end
 
   it "should break on zero-width space" do
-    @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
+    @pdf.font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
     @arranger.format_array = array
     string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -61,7 +61,7 @@
   end
 
   it "should not display zero-width space" do
-    @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
+    @pdf.font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
     @arranger.format_array = array
     string = @line_wrap.wrap_line(:arranger => @arranger,
@@ -116,7 +116,7 @@
     expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
     string.should == expected
 
-    @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
+    @pdf.font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
 
     string = "hello#{Prawn::Text::SHY}world"
@@ -137,7 +137,7 @@
                                   :document => @pdf)
     string.should == "helloworld"
 
-    @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
+    @pdf.font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
 
     string = "hello#{Prawn::Text::SHY}world"
@@ -166,7 +166,7 @@
                                   :document => @pdf)
     string.should == "hello"
 
-    @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
+    @pdf.font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
     enough_width_for_hello_world = 68
 
@@ -205,7 +205,7 @@
     expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
     string.should == expected
 
-    @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
+    @pdf.font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
 
     string = "hello#{Prawn::Text::SHY}-"
--- a/spec/text_spec.rb
+++ b/spec/text_spec.rb
@@ -257,9 +257,11 @@
     lambda { @pdf.font "Pao bu" }.should.raise(Prawn::Errors::UnknownFont)
   end
   
+  # replace non-free comicsans.ttf by system DejaVuSans.ttf (Debian patch)
   it "should not raise an exception when providing Pathname instance as font" do
     lambda {
-      @pdf.font Pathname.new("#{Prawn::DATADIR}/fonts/comicsans.ttf")
+      # @pdf.font Pathname.new("#{Prawn::DATADIR}/fonts/comicsans.ttf")
+      @pdf.font Pathname.new("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     }.should.not.raise(Prawn::Errors::UnknownFont)
   end
 
@@ -274,7 +276,7 @@
 
   it "should correctly render a utf-8 string when using a TTF font" do
     str = "©" # copyright symbol
-    @pdf.font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
+    @pdf.font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
     @pdf.text str
 
     # grab the text from the rendered PDF and ensure it matches
@@ -317,7 +319,7 @@
     it "should not raise an exception when a shift-jis string is rendered" do
       datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
       sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
-      @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
+      @pdf.font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf")
       lambda { @pdf.text sjis_str }.should.not.raise(
         Prawn::Errors::IncompatibleStringEncoding)
     end
--- a/spec/text_spacing_spec.rb
+++ b/spec/text_spacing_spec.rb
@@ -42,7 +42,7 @@
   #
   it "should calculate character spacing widths by characters, not bytes" do
     create_pdf
-    @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
+    @pdf.font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf")
 
     str = "こんにちは世界"
     @pdf.character_spacing(0) do
--- a/spec/formatted_text_box_spec.rb
+++ b/spec/formatted_text_box_spec.rb
@@ -21,7 +21,7 @@
   it "should not raise Encoding::CompatibilityError when keeping a TTF and an " +
     "AFM font together" do
     ruby_19 do
-      file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+      file = "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
       @pdf.font_families["Kai"] = {
         :normal => { :file => file, :font => "Kai" }
       }
@@ -121,7 +121,7 @@
   "a Chinese font and set of Chinese glyphs not in the current font" do
   it "should change the font to the Chinese font for the Chinese glyphs" do
     create_pdf
-    file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+    file = "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
     @pdf.font_families["Kai"] = {
       :normal => { :file => file, :font => "Kai" }
     }
@@ -149,7 +149,7 @@
   "an AFM font and Win-Ansi glyph not in the current Chinese font" do
   it "should change the font to the AFM font for the Win-Ansi glyph" do
     create_pdf
-    file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+    file = "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
     @pdf.font_families["Kai"] = {
       :normal => { :file => file, :font => "Kai" }
     }
@@ -178,7 +178,7 @@
   "level font" do
   it "should use the fragment level font except for glyphs not in that font" do
     create_pdf
-    file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+    file = "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
     @pdf.font_families["Kai"] = {
       :normal => { :file => file, :font => "Kai" }
     }
@@ -205,7 +205,7 @@
 describe "Text::Formatted::Box" do
   before(:each) do
     create_pdf
-    file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+    file = "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
     @pdf.font_families["Kai"] = {
       :normal => { :file => file, :font => "Kai" }
     }
--- a/spec/font_spec.rb
+++ b/spec/font_spec.rb
@@ -24,7 +24,7 @@
   it "should exclude newlines" do
     create_pdf
     # Use a TTF font that has a non-zero width for \n
-    @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
+    @pdf.font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf")
 
     @pdf.width_of("\nhello world\n").should ==
       @pdf.width_of("hello world")
@@ -253,15 +253,19 @@
   end
 
   it "should return true when present in a TTF font" do
-    font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
+    # replace non-free Activa.ttf by system DejaVuSans.ttf (Debian patch)
+    # font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
+    font = @pdf.find_font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     font.glyph_present?("H").should.be true
   end
 
   it "should return false when absent in a TTF font" do
-    font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
+    # replace non-free Activa.ttf by system DejaVuSans.ttf (Debian patch)
+    # font = @pdf.find_font("#{Prawn::DATADIR}/fonts/Activa.ttf")
+    font = @pdf.find_font("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf")
     font.glyph_present?("再").should.be false
 
-    font = @pdf.find_font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
+    font = @pdf.find_font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf")
     font.glyph_present?("€").should.be false
   end
 end
@@ -270,7 +274,9 @@
   
   setup do
     create_pdf
-    @activa = @pdf.find_font "#{Prawn::DATADIR}/fonts/Activa.ttf"
+    # replace non-free Activa.ttf by system DejaVuSans.ttf (Debian patch)
+    # @activa = @pdf.find_font "#{Prawn::DATADIR}/fonts/Activa.ttf"
+    @activa = @pdf.find_font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
   end
   
   it "should calculate string width taking into account accented characters" do
@@ -336,7 +342,7 @@
     it "should allow TTF fonts to be used alongside document transactions" do
       lambda {
         Prawn::Document.new do
-          font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
+          font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
           text "Hi there"
           transaction { text "Nice, thank you" }
         end
@@ -346,7 +352,7 @@
     it "should allow TTF fonts to be used inside transactions" do
       pdf = Prawn::Document.new do
         transaction do
-          font "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
+          font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
           text "Hi there"
         end
       end
@@ -403,7 +409,7 @@
 describe "#character_count(text)" do
   it "should work on TTF fonts" do
     create_pdf
-    @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
+    @pdf.font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf")
     @pdf.font.character_count("こんにちは世界").should == 7
     @pdf.font.character_count("Hello, world!").should == 13
   end
--- a/spec/text_box_spec.rb
+++ b/spec/text_box_spec.rb
@@ -74,7 +74,7 @@
     @pdf.text_direction(:rtl)
     @pdf.text_direction = :rtl
     @pdf.text_direction = :rtl
-    @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :size => 16) do
+    @pdf.font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf", :size => 16) do
       @pdf.text "写个小"
     end
     text = PDF::Inspector::Text.analyze(@pdf.render)
@@ -800,7 +800,7 @@
       :height => 162.0,
       :document => @pdf
     }
-    @pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+    @pdf.font "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
     @options[:overflow] = :truncate
     text_box = Prawn::Text::Box.new(@text, @options)
     text_box.render
--- a/spec/text_at_spec.rb
+++ b/spec/text_at_spec.rb
@@ -109,7 +109,7 @@
     it "should not raise an exception when a shift-jis string is rendered" do
       datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
       sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
-      @pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
+      @pdf.font("/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf")
       lambda { @pdf.draw_text(sjis_str, :at => [0, 0]) }.should.not.raise(
         Prawn::Errors::IncompatibleStringEncoding)
     end
--- a/spec/template_spec.rb
+++ b/spec/template_spec.rb
@@ -141,7 +141,9 @@
   it "should correctly add a TTF font to a template that has existing fonts" do
     filename = "#{Prawn::DATADIR}/pdfs/contains_ttf_font.pdf"
     @pdf = Prawn::Document.new(:template => filename)
-    @pdf.font "#{Prawn::DATADIR}/fonts/Chalkboard.ttf"
+    # replace non-free Chalkboard.ttf by system DejaVuSans.ttf (Debian patch)
+    # @pdf.font "#{Prawn::DATADIR}/fonts/Chalkboard.ttf"
+    @pdf.font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
     @pdf.move_down(40)
     @pdf.text "Hi There"
 
@@ -270,7 +272,9 @@
     filename = "#{Prawn::DATADIR}/pdfs/contains_ttf_font.pdf"
     @pdf = Prawn::Document.new()
     @pdf.start_new_page(:template => filename)
-    @pdf.font "#{Prawn::DATADIR}/fonts/Chalkboard.ttf"
+    # replace non-free Chalkboard.ttf by system DejaVuSans.ttf (Debian patch)
+    # @pdf.font "#{Prawn::DATADIR}/fonts/Chalkboard.ttf"
+    @pdf.font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"
     @pdf.move_down(40)
     @pdf.text "Hi There"
 
--- a/spec/document_spec.rb
+++ b/spec/document_spec.rb
@@ -235,7 +235,7 @@
     doc_uncompressed = Prawn::Document.new
     doc_compressed   = Prawn::Document.new(:compress => true)
     [doc_compressed, doc_uncompressed].each do |pdf|
-       pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
+       pdf.font "/usr/share/fonts/truetype/arphic-gkai00mp/gkai00mp.ttf"
        pdf.text "更可怕的是，同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
     end
 
