rbpdf 1.18.6 → 1.18.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/rbpdf.rb +7 -1
- data/lib/rbpdf/version.rb +1 -1
- data/rbpdf.gemspec +2 -0
- data/test/rbpdf_html_test.rb +154 -0
- data/test/rbpdf_image_rmagick_test.rb +36 -1
- metadata +16 -4
- data/test/test_helper.rb_ +0 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15432b181857328b6ed5f8c5bbfa2ffce4d69782
|
|
4
|
+
data.tar.gz: 3d8ef59f34b8bd101d6cbbd67ff30fb2fbdbfd04
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3aae8a53859e23684be355730099acfd1770abf1de5f71d0e8adac27cb0862eef72585c9166affa8442c7f4c158e4a379ac32b9bdabfc57837a8006c329e767
|
|
7
|
+
data.tar.gz: 6d6e239b6aa135886d4499cedcd8d2df2c20c57aa5f58646112907acabc3d2ec3e427d5af48d84d295410880d2e6b336de7a08d57a4d4e904725775ebf674c48
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
1.18.7 2015-10-18
|
|
2
|
+
- Fixed case of missing HTML <pre> tag texts with whitespace. (use htmlentities gem liblary.)
|
|
3
|
+
- Fixed HTML Image function y position problem with png alpha image.
|
|
4
|
+
|
|
1
5
|
1.18.6 2015-06-20
|
|
2
6
|
- Fixed page boxes problem for iOS.
|
|
3
7
|
- The dependence to the Rails environment was reduced.
|
data/lib/rbpdf.rb
CHANGED
|
@@ -4930,7 +4930,7 @@ class RBPDF
|
|
|
4930
4930
|
if info == 'pngalpha' and ismask == false and Object.const_defined?(:Magick)
|
|
4931
4931
|
info = ImagePngAlpha(file, x, y, w, h, 'PNG', link, align, resize, dpi, palign)
|
|
4932
4932
|
if false != info
|
|
4933
|
-
return
|
|
4933
|
+
return true
|
|
4934
4934
|
end
|
|
4935
4935
|
end
|
|
4936
4936
|
end
|
|
@@ -5274,6 +5274,8 @@ class RBPDF
|
|
|
5274
5274
|
# remove temp files
|
|
5275
5275
|
tempfile_alpha.delete
|
|
5276
5276
|
tempfile_plain.delete
|
|
5277
|
+
|
|
5278
|
+
return true
|
|
5277
5279
|
end
|
|
5278
5280
|
protected :ImagePngAlpha
|
|
5279
5281
|
|
|
@@ -10738,6 +10740,10 @@ protected
|
|
|
10738
10740
|
# preserve newlines on <pre> tag
|
|
10739
10741
|
html_b = html_b.gsub(/<xre([^\>]*)>(.*?)\n(.*?)<\/pre>/mi, "<xre\\1>\\2<br />\\3</pre>")
|
|
10740
10742
|
end
|
|
10743
|
+
while html_b =~ /<xre([^\>]*)>(.*?)[\s](.*?)<\/pre>/mi
|
|
10744
|
+
# preserve whitespace on <pre> tag
|
|
10745
|
+
html_b = html_b.gsub(/<xre([^\>]*)>(.*?)[\s](.*?)<\/pre>/mi, "<xre\\1>\\2 \\3</pre>")
|
|
10746
|
+
end
|
|
10741
10747
|
html = html_a + html_b + html[(pos + 6)..-1]
|
|
10742
10748
|
offset = (html_a + html_b).length
|
|
10743
10749
|
end
|
data/lib/rbpdf/version.rb
CHANGED
data/rbpdf.gemspec
CHANGED
|
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
31
31
|
spec.require_paths = ["lib"]
|
|
32
32
|
|
|
33
|
+
spec.add_runtime_dependency "htmlentities", "= 4.3.1"
|
|
34
|
+
|
|
33
35
|
spec.add_development_dependency "bundler", "~> 1.6"
|
|
34
36
|
spec.add_development_dependency "rake"
|
|
35
37
|
end
|
data/test/rbpdf_html_test.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# coding: ASCII-8BIT
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
4
|
class RbpdfTest < ActiveSupport::TestCase
|
|
@@ -5,6 +6,20 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
5
6
|
def getPageBuffer(page)
|
|
6
7
|
super
|
|
7
8
|
end
|
|
9
|
+
|
|
10
|
+
# get text from pdf page
|
|
11
|
+
def get_html_text(page)
|
|
12
|
+
content = []
|
|
13
|
+
contents = getPageBuffer(page)
|
|
14
|
+
contents.each_line {|line| content.push line.chomp }
|
|
15
|
+
pdf_text = ''
|
|
16
|
+
content.each do |line|
|
|
17
|
+
if line =~ /\[\((.*)\)\] TJ ET/
|
|
18
|
+
pdf_text << $1
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
return pdf_text
|
|
22
|
+
end
|
|
8
23
|
end
|
|
9
24
|
|
|
10
25
|
test "write_html Basic test" do
|
|
@@ -576,4 +591,143 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
576
591
|
end
|
|
577
592
|
assert_equal count, 1
|
|
578
593
|
end
|
|
594
|
+
|
|
595
|
+
test "write_html <b> tag test" do
|
|
596
|
+
pdf = MYPDF.new
|
|
597
|
+
pdf.set_print_header(false)
|
|
598
|
+
pdf.add_page()
|
|
599
|
+
|
|
600
|
+
text = ' ' + 'A' * 70
|
|
601
|
+
htmlcontent = '<b>' + text + '</b>'
|
|
602
|
+
|
|
603
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
|
604
|
+
pdf_text = pdf.get_html_text(1)
|
|
605
|
+
assert_equal 'A' * 70, pdf_text
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
test "write_html <i> tag test" do
|
|
609
|
+
pdf = MYPDF.new
|
|
610
|
+
pdf.set_print_header(false)
|
|
611
|
+
pdf.add_page()
|
|
612
|
+
|
|
613
|
+
text = ' ' + 'A' * 70
|
|
614
|
+
htmlcontent = '<i>' + text + '</i>'
|
|
615
|
+
|
|
616
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
|
617
|
+
pdf_text = pdf.get_html_text(1)
|
|
618
|
+
assert_equal 'A' * 70, pdf_text
|
|
619
|
+
end
|
|
620
|
+
|
|
621
|
+
test "write_html <u> tag test" do
|
|
622
|
+
pdf = MYPDF.new
|
|
623
|
+
pdf.set_print_header(false)
|
|
624
|
+
pdf.add_page()
|
|
625
|
+
|
|
626
|
+
text = ' ' + 'A' * 70
|
|
627
|
+
htmlcontent = '<u>' + text + '</u>'
|
|
628
|
+
|
|
629
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
|
630
|
+
pdf_text = pdf.get_html_text(1)
|
|
631
|
+
assert_equal 'A' * 70, pdf_text
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
test "write_html <pre> tag space 1 test" do
|
|
635
|
+
pdf = MYPDF.new
|
|
636
|
+
pdf.set_print_header(false)
|
|
637
|
+
pdf.add_page()
|
|
638
|
+
|
|
639
|
+
text = ' ' + 'A' * 70
|
|
640
|
+
htmlcontent = '<pre>' + text + '</pre>'
|
|
641
|
+
|
|
642
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
|
643
|
+
pdf_text = pdf.get_html_text(1)
|
|
644
|
+
assert_equal "\xa0" + 'A' * 70, pdf_text
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
test "write_html <pre> tag space 2 test" do
|
|
648
|
+
pdf = MYPDF.new
|
|
649
|
+
pdf.set_print_header(false)
|
|
650
|
+
pdf.add_page()
|
|
651
|
+
|
|
652
|
+
text = ' ' + 'A' * 70
|
|
653
|
+
htmlcontent = '<pre>' + text + '</pre>'
|
|
654
|
+
|
|
655
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
|
656
|
+
pdf_text = pdf.get_html_text(1)
|
|
657
|
+
assert_equal "\xa0" * 2 + 'A' * 70, pdf_text
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
test "write_html Character Entities test" do
|
|
661
|
+
pdf = MYPDF.new
|
|
662
|
+
pdf.set_print_header(false)
|
|
663
|
+
|
|
664
|
+
character_entities = {
|
|
665
|
+
'<' => '<',
|
|
666
|
+
'>' => '>',
|
|
667
|
+
'&' => '&',
|
|
668
|
+
'"' => '"',
|
|
669
|
+
' ' => "\xa0",
|
|
670
|
+
'¢' => "\xa2",
|
|
671
|
+
'£' => "\xa3",
|
|
672
|
+
'¥' => "\xa5",
|
|
673
|
+
'©' => "\xa9",
|
|
674
|
+
'®' => "\xae",
|
|
675
|
+
'€' => "\x80",
|
|
676
|
+
}
|
|
677
|
+
character_entities.each {|ce, c|
|
|
678
|
+
pdf.add_page()
|
|
679
|
+
page = pdf.get_page
|
|
680
|
+
pdf.write_html(ce, true, 0, true, 0)
|
|
681
|
+
pdf_text = pdf.get_html_text(page)
|
|
682
|
+
assert_equal '[' + ce + ']:' + c, '[' + ce + ']:' + pdf_text
|
|
683
|
+
}
|
|
684
|
+
end
|
|
685
|
+
|
|
686
|
+
test "write_html Character Entities test pre mode" do
|
|
687
|
+
pdf = MYPDF.new
|
|
688
|
+
pdf.set_print_header(false)
|
|
689
|
+
|
|
690
|
+
character_entities = {
|
|
691
|
+
'<' => '<',
|
|
692
|
+
'>' => '>',
|
|
693
|
+
'&' => '&',
|
|
694
|
+
'"' => '"',
|
|
695
|
+
' ' => "\xa0",
|
|
696
|
+
'¢' => "\xa2",
|
|
697
|
+
'£' => "\xa3",
|
|
698
|
+
'¥' => "\xa5",
|
|
699
|
+
'©' => "\xa9",
|
|
700
|
+
'®' => "\xae",
|
|
701
|
+
'€' => "\x80",
|
|
702
|
+
}
|
|
703
|
+
character_entities.each {|ce, c|
|
|
704
|
+
pdf.add_page()
|
|
705
|
+
page = pdf.get_page
|
|
706
|
+
pdf.write_html('<pre>' + ce + '</pre>', true, 0, true, 0)
|
|
707
|
+
pdf_text = pdf.get_html_text(page)
|
|
708
|
+
assert_equal '[' + ce + ']:' + c, '[' + ce + ']:' + pdf_text
|
|
709
|
+
}
|
|
710
|
+
end
|
|
711
|
+
|
|
712
|
+
test "unhtmlentities test" do
|
|
713
|
+
pdf = RBPDF.new
|
|
714
|
+
character_entities = {
|
|
715
|
+
'<' => '<',
|
|
716
|
+
'>' => '>',
|
|
717
|
+
'&' => '&',
|
|
718
|
+
'"' => '"',
|
|
719
|
+
' ' => "\xc2\xa0",
|
|
720
|
+
'¢' => "\xc2\xa2",
|
|
721
|
+
'£' => "\xc2\xa3",
|
|
722
|
+
'¥' => "\xc2\xa5",
|
|
723
|
+
'©' => "\xc2\xa9",
|
|
724
|
+
'®' => "\xc2\xae",
|
|
725
|
+
'€' => "\xe2\x82\xac",
|
|
726
|
+
}
|
|
727
|
+
character_entities.each {|ce, c|
|
|
728
|
+
text = pdf.unhtmlentities(ce)
|
|
729
|
+
text.force_encoding('ASCII-8BIT') if text.respond_to?(:force_encoding)
|
|
730
|
+
assert_equal '[' + ce + ']:' + c, '[' + ce + ']:' + text
|
|
731
|
+
}
|
|
732
|
+
end
|
|
579
733
|
end
|
|
@@ -225,7 +225,7 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
225
225
|
pdf.add_page
|
|
226
226
|
img_file = File.join(File.dirname(__FILE__), 'png_test_alpha.png')
|
|
227
227
|
info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
|
|
228
|
-
assert_equal info,
|
|
228
|
+
assert_equal info, true
|
|
229
229
|
end
|
|
230
230
|
|
|
231
231
|
test "Image GIF test" do
|
|
@@ -257,4 +257,39 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
257
257
|
info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
|
|
258
258
|
assert_equal info, 1
|
|
259
259
|
end
|
|
260
|
+
|
|
261
|
+
test "HTML Image test" do
|
|
262
|
+
return unless Object.const_defined?(:Magick)
|
|
263
|
+
|
|
264
|
+
images = {
|
|
265
|
+
'png_test_alpha.png' => 40.11,
|
|
266
|
+
'png_test_msk_alpha.png' => 40.11,
|
|
267
|
+
'png_test_non_alpha.png' => 40.11,
|
|
268
|
+
'logo_rbpdf_8bit.png' => 36.58,
|
|
269
|
+
'logo_rbpdf_8bit.gif' => 36.58,
|
|
270
|
+
'logo_rbpdf_8bit_alpha.gif' => 36.58,
|
|
271
|
+
'logo_rbpdf_8bit.jpg' => 36.58,
|
|
272
|
+
'logo_rbpdf_mono_gray.jpg' => 36.58,
|
|
273
|
+
'logo_rbpdf_mono_gray.png' => 36.58,
|
|
274
|
+
'logo_rbpdf_mono_rgb.jpg' => 36.58,
|
|
275
|
+
'logo_rbpdf_mono_rgb.png' => 36.58,
|
|
276
|
+
'ng.png' => 9.42
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
pdf = RBPDF.new
|
|
280
|
+
images.each {|image, h|
|
|
281
|
+
pdf.add_page
|
|
282
|
+
img_file = File.join(File.dirname(__FILE__), image)
|
|
283
|
+
htmlcontent = '<img src="'+ img_file + '"/>'
|
|
284
|
+
|
|
285
|
+
x_org = pdf.get_x
|
|
286
|
+
y_org = pdf.get_y
|
|
287
|
+
pdf.write_html(htmlcontent, true, 0, true, 0)
|
|
288
|
+
x = pdf.get_x
|
|
289
|
+
y = pdf.get_y
|
|
290
|
+
|
|
291
|
+
assert_equal '[' + image + ']:' + x_org.to_s, '[' + image + ']:' + x.to_s
|
|
292
|
+
assert_equal '[' + image + ']:' + (y_org + h).round(2).to_s, '[' + image + ']:' + y.round(2).to_s
|
|
293
|
+
}
|
|
294
|
+
end
|
|
260
295
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbpdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.18.
|
|
4
|
+
version: 1.18.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- NAITOH Jun
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: htmlentities
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 4.3.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 4.3.1
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: bundler
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -176,7 +190,6 @@ files:
|
|
|
176
190
|
- test/rbpdf_viewerpreferences_test.rb
|
|
177
191
|
- test/rbpdf_write_test.rb
|
|
178
192
|
- test/test_helper.rb
|
|
179
|
-
- test/test_helper.rb_
|
|
180
193
|
- test_unicode.rbpdf
|
|
181
194
|
- utf8test.txt
|
|
182
195
|
homepage: ''
|
|
@@ -242,4 +255,3 @@ test_files:
|
|
|
242
255
|
- test/rbpdf_viewerpreferences_test.rb
|
|
243
256
|
- test/rbpdf_write_test.rb
|
|
244
257
|
- test/test_helper.rb
|
|
245
|
-
- test/test_helper.rb_
|
data/test/test_helper.rb_
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
#require 'test/unit'
|
|
3
|
-
#require 'active_support'
|
|
4
|
-
require 'rbpdf'
|
|
5
|
-
|
|
6
|
-
=begin
|
|
7
|
-
if Rails::VERSION::MAJOR >= 4
|
|
8
|
-
# require 'active_support/testing/autorun' # Rails 4.2
|
|
9
|
-
|
|
10
|
-
gem 'test-unit'
|
|
11
|
-
require 'test/unit'
|
|
12
|
-
#Test::Unit::AutoRunner.new(true).run
|
|
13
|
-
Test::Unit::AutoRunner.new(false).run
|
|
14
|
-
#(r = Test::Unit::AutoRunner.new(true)).process_args(ARGV) or
|
|
15
|
-
# abort r.options.banner + " tests..."
|
|
16
|
-
#exit r.run
|
|
17
|
-
|
|
18
|
-
# require 'active_support/testing/autorun' # Rails 4.2
|
|
19
|
-
|
|
20
|
-
#gem 'minitest'
|
|
21
|
-
#require 'minitest'
|
|
22
|
-
#Minitest.autorun
|
|
23
|
-
|
|
24
|
-
else
|
|
25
|
-
=end
|
|
26
|
-
# require 'rails/all'
|
|
27
|
-
require "rails"
|
|
28
|
-
|
|
29
|
-
class Application < Rails::Application
|
|
30
|
-
end
|
|
31
|
-
#end
|