From: Kouhei S. <nu...@co...> - 2017-11-06 15:20:08
|
Kouhei Sutou 2017-11-07 00:19:26 +0900 (Tue, 07 Nov 2017) New Revision: bd3a7b334eeb478894d3332ba12ab52923d17b1a https://github.com/ruby-gnome2/ruby-gnome2/commit/bd3a7b334eeb478894d3332ba12ab52923d17b1a Message: poppler: use memory input stream Modified files: poppler/lib/poppler/document.rb poppler/test/test-document.rb Modified: poppler/lib/poppler/document.rb (+4 -19) =================================================================== --- poppler/lib/poppler/document.rb 2017-11-03 01:13:30 +0900 (d490b344c) +++ poppler/lib/poppler/document.rb 2017-11-07 00:19:26 +0900 (808ff0d54) @@ -14,8 +14,6 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -require "tempfile" - module Poppler class Document include Enumerable @@ -53,24 +51,11 @@ module Poppler # string. So UTF-8 validation is failed. # # TODO: Enable the following: - # initialize_new_from_data(data, password - - # Whey does not the following work? - # stream = Gio::MemoryInputStream.new(data) - # begin - # initialize_new_from_stream(stream, data.bytesize, password) - # ensure - # stream.close - # end + # initialize_new_from_data(data, password) - file = Tempfile.new(["poppler", ".pdf"]) - begin - file.print(data) - file.flush - initialize_new_from_file(ensure_uri(file.path), password) - ensure - file.close! - end + @bytes = GLib::Bytes.new(data) + @stream = Gio::MemoryInputStream.new(@bytes) + initialize_new_from_stream(@stream, data.bytesize, password) elsif uri initialize_new_from_file(uri, password) elsif path Modified: poppler/test/test-document.rb (+8 -4) =================================================================== --- poppler/test/test-document.rb 2017-11-03 01:13:30 +0900 (35bbd01d6) +++ poppler/test/test-document.rb 2017-11-07 00:19:26 +0900 (3db649f71) @@ -1,10 +1,14 @@ class TestDocument < Test::Unit::TestCase sub_test_case("#initialize") do def test_data - data = File.read(outline_pdf, :encoding => "ASCII-8BIT") - document = Poppler::Document.new(:data => data) - assert_equal("Heading1\nHeading2\nHeading3", - document[0].text) + pdf = StringIO.new + surface = Cairo::PDFSurface.new(pdf, 100, 100) + context = Cairo::Context.new(surface) + context.show_text("Hello") + surface.finish + + document = Poppler::Document.new(:data => pdf.string) + assert_equal("Hello", document[0].text) end end |