rbpdf 1.20.1 → 1.21.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +22 -0
- data/README.md +12 -2
- data/lib/core/mini_magick.rb +7 -3
- data/lib/core/rmagick.rb +6 -2
- data/lib/rbpdf/version.rb +2 -2
- data/lib/rbpdf.rb +181 -137
- data/lib/unicode_data.rb +29 -0
- data/rbpdf.gemspec +7 -18
- metadata +26 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7fe46482c5272d1a1e3c050c4c421648ba584ddf21225655fbce7f86309050e8
|
4
|
+
data.tar.gz: 504808a1ddc2e1b0720bd8d1b0ce2960ef598ae808ce1af6173502e537a0ce4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34cb1673c7bb205ff539e8f8f9bf7b2b90ef2e0dc0bf0cd5cbea47dff4d4cb6ac0287f74001fe5418506b53d8dac93aaa5438018ab015a308991b31916f19dbe
|
7
|
+
data.tar.gz: 667285f30d8d889877a63bf23e897ebd2f2e7929392eb48b135994ff678c331cfb90adae6682aaedbd2b798ef64e187ce4931d34182b32235cb3acf6101c21d8
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
1.21.1 2023-03-20
|
2
|
+
- Changed version description of PDF PRODUCER. (#83)
|
3
|
+
- fix isValidCSSSelectorForTag method. (#82)
|
4
|
+
- Improved compatibility with ImageMagick 7.1.1-0 and later when using mini_magick. (#81)
|
5
|
+
- Fixed parsepng method to support transparent GIF and PNG tRNS transparency. (#80)
|
6
|
+
- ImageMagick7 support in RMagick 5.2.0. (#79)
|
7
|
+
- Add support WebP image. (#77)
|
8
|
+
|
9
|
+
1.21.0 2023-02-13
|
10
|
+
- Support for Ruby 3.0.0, 3.1.0, 3.2.0. (Drop support for Ruby 2.2 and earlier.) (#66)
|
11
|
+
- Support Rails 6 and Rails 7. (Drop support for Rails 3.x, 4.x) (#66, #72)
|
12
|
+
- Fix RMagick 5.0 compatible. (#66)
|
13
|
+
- Infinite loop has been resolved. (#68, #74)
|
14
|
+
- Fixed a bug that caused the x position to shift when an <img> tag was behind a <li> tag in HTML. (#74)
|
15
|
+
- fix: Incorrect characters when copying out of a generated PDF with Unicode fonts. (#71)
|
16
|
+
- Suppresses output for Circle(), Ellipse(), PieSector(), and PieSectorXY() when the radius is 0. (#67)
|
17
|
+
- Don't change an object while iterating over it (#59) (by thegcat)
|
18
|
+
- fix : bidi bug (#56) (by ahorek)
|
19
|
+
- Avoid rdoc stack level too deep (SystemStackError) in gem install. (#76)
|
20
|
+
- PDF example output option OUTPUT=true added (#70)
|
21
|
+
- Make the image file path acquisition process extensible (#58) (by yui-har)
|
22
|
+
|
1
23
|
1.20.1 2019-08-21
|
2
24
|
- fix license warning. (by pavel)
|
3
25
|
- Removed test resource from distribution target in gemspec.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://
|
1
|
+
[![Build Status](https://github.com/naitoh/rbpdf/workflows/test/badge.svg)](https://github.com/naitoh/rbpdf/actions)
|
2
2
|
|
3
3
|
# RBPDF Template Plugin
|
4
4
|
|
@@ -16,7 +16,7 @@ A template plugin allowing the inclusion of ERB-enabled RBPDF template files.
|
|
16
16
|
* CSS minimum support.
|
17
17
|
* Image
|
18
18
|
- 8bit PNG image support without MiniMagick/RMagick library.
|
19
|
-
- PNG(with alpha channel)/JPEG/GIF image support. (use MiniMagick or RMagick library)
|
19
|
+
- PNG(with alpha channel)/JPEG/GIF/WebP image support. (use MiniMagick or RMagick library)
|
20
20
|
|
21
21
|
|
22
22
|
##
|
@@ -59,6 +59,16 @@ RBPDF Japanese Example of simple use in .html.erb:
|
|
59
59
|
%><%==@pdf.output()%>
|
60
60
|
```
|
61
61
|
|
62
|
+
PDF example output
|
63
|
+
```
|
64
|
+
$ OUTPUT=true bundle exec rake test TEST=test/rbpdf_examples_test.rb
|
65
|
+
$ ls -1 *.pdf
|
66
|
+
example001.pdf
|
67
|
+
example002.pdf
|
68
|
+
example003.pdf
|
69
|
+
:
|
70
|
+
```
|
71
|
+
|
62
72
|
See the following files for sample of useage:
|
63
73
|
|
64
74
|
test_unicode.rbpdf
|
data/lib/core/mini_magick.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: ASCII-8BIT
|
1
2
|
# The MIT License
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -55,6 +56,7 @@ module Rbpdf
|
|
55
56
|
width = image.width
|
56
57
|
height = image.height
|
57
58
|
|
59
|
+
out['mime'] = image.mime_type
|
58
60
|
out[0] = width
|
59
61
|
out[1] = height
|
60
62
|
|
@@ -67,17 +69,19 @@ module Rbpdf
|
|
67
69
|
out[2] = "JPEG"
|
68
70
|
when "image/png"
|
69
71
|
out[2] = "PNG"
|
70
|
-
when "
|
72
|
+
when "image/webp", "image/x-webp"
|
73
|
+
out[2] = "WEBP"
|
74
|
+
out['mime'] = "image/webp"
|
75
|
+
when "image/vnd.wap.wbmp"
|
71
76
|
out[2] = "WBMP"
|
72
77
|
when "image/x-xpixmap"
|
73
78
|
out[2] = "XPM"
|
74
79
|
end
|
75
80
|
out[3] = "height=\"#{height}\" width=\"#{width}\""
|
76
|
-
out['mime'] = image.mime_type
|
77
81
|
|
78
82
|
# This needs work to cover more situations
|
79
83
|
# I can't see how to just list the number of channels with ImageMagick / mini_magick
|
80
|
-
case image["%[channels]"].downcase
|
84
|
+
case image["%[channels]"].downcase.split.first
|
81
85
|
when 'cmyk'
|
82
86
|
out['channels'] = 4
|
83
87
|
when 'rgb', 'rgba', 'srgb', 'srgba' # Mac OS X : sRGB
|
data/lib/core/rmagick.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: ASCII-8BIT
|
1
2
|
# The MIT License
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -55,6 +56,7 @@ module Rbpdf
|
|
55
56
|
|
56
57
|
width = image.columns
|
57
58
|
height = image.rows
|
59
|
+
out['mime'] = image.mime_type
|
58
60
|
out[0] = width
|
59
61
|
out[1] = height
|
60
62
|
|
@@ -67,13 +69,15 @@ module Rbpdf
|
|
67
69
|
out[2] = "JPEG"
|
68
70
|
when "image/png"
|
69
71
|
out[2] = "PNG"
|
70
|
-
when "
|
72
|
+
when "image/webp", "image/x-webp"
|
73
|
+
out[2] = "WEBP"
|
74
|
+
out['mime'] = "image/webp"
|
75
|
+
when "image/vnd.wap.wbmp"
|
71
76
|
out[2] = "WBMP"
|
72
77
|
when "image/x-xpixmap"
|
73
78
|
out[2] = "XPM"
|
74
79
|
end
|
75
80
|
out[3] = "height=\"#{height}\" width=\"#{width}\""
|
76
|
-
out['mime'] = image.mime_type
|
77
81
|
|
78
82
|
# This needs work to cover more situations
|
79
83
|
# I can't see how to just list the number of channels with ImageMagick / rmagick
|
data/lib/rbpdf/version.rb
CHANGED
data/lib/rbpdf.rb
CHANGED
@@ -49,7 +49,7 @@
|
|
49
49
|
require "rbpdf/version"
|
50
50
|
|
51
51
|
require 'htmlentities'
|
52
|
-
require 'rbpdf-font'
|
52
|
+
require 'rbpdf-font'
|
53
53
|
require 'erb'
|
54
54
|
|
55
55
|
begin
|
@@ -89,7 +89,7 @@ require 'net/http'
|
|
89
89
|
#
|
90
90
|
|
91
91
|
|
92
|
-
PDF_PRODUCER =
|
92
|
+
PDF_PRODUCER = "RBPDF #{Rbpdf::VERSION}"
|
93
93
|
|
94
94
|
# == This is a Ruby class for generating PDF files on-the-fly without requiring external extensions.
|
95
95
|
# * This class is a Ruby port of the TCPDF class by Nicola Asuni (http://www.tcpdf.org).
|
@@ -4790,7 +4790,7 @@ class RBPDF
|
|
4790
4790
|
# * explicit width and height (expressed in user unit)
|
4791
4791
|
# * one explicit dimension, the other being calculated automatically in order to keep the original proportions
|
4792
4792
|
# * no explicit dimension, in which case the image is put at 72 dpi
|
4793
|
-
# Supported formats are PNG images whitout RMagick/MiniMagick library and JPEG and GIF images supported by RMagick/MiniMagick.
|
4793
|
+
# Supported formats are PNG images whitout RMagick/MiniMagick library and JPEG and GIF and WebP images supported by RMagick/MiniMagick.
|
4794
4794
|
# For JPEG, all flavors are allowed:
|
4795
4795
|
# * gray scales
|
4796
4796
|
# * true colors (24 bits)
|
@@ -4808,7 +4808,7 @@ class RBPDF
|
|
4808
4808
|
# [@param float :y] Ordinate of the upper-left corner.
|
4809
4809
|
# [@param float :w] Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
|
4810
4810
|
# [@param float :h] Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
|
4811
|
-
# [@param string :type] Image format. Possible values are (case insensitive): JPG, JPEG, PNG. If not specified, the type is inferred from the file extension.
|
4811
|
+
# [@param string :type] Image format. Possible values are (case insensitive): JPG, JPEG, PNG, GIF, WebP. If not specified, the type is inferred from the file extension.
|
4812
4812
|
# [@param mixed :link] URL or identifier returned by AddLink().
|
4813
4813
|
# [@param string :align]
|
4814
4814
|
# Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:
|
@@ -4974,12 +4974,19 @@ class RBPDF
|
|
4974
4974
|
|
4975
4975
|
info = false
|
4976
4976
|
if !resize
|
4977
|
-
|
4977
|
+
case type
|
4978
|
+
when 'jpeg'
|
4978
4979
|
info=parsejpeg(file)
|
4979
|
-
|
4980
|
-
info=parsepng(file)
|
4981
|
-
|
4982
|
-
tmpFile = imageToPNG(file)
|
4980
|
+
when 'png'
|
4981
|
+
info=parsepng(file)
|
4982
|
+
when 'webp'
|
4983
|
+
tmpFile = imageToPNG(file, false)
|
4984
|
+
if tmpFile != false
|
4985
|
+
info=parsepng(tmpFile.path)
|
4986
|
+
tmpFile.close(true)
|
4987
|
+
end
|
4988
|
+
when 'gif'
|
4989
|
+
tmpFile = imageToPNG(file, false)
|
4983
4990
|
if tmpFile != false
|
4984
4991
|
info=parsepng(tmpFile.path)
|
4985
4992
|
tmpFile.close(true)
|
@@ -4992,6 +4999,7 @@ class RBPDF
|
|
4992
4999
|
end
|
4993
5000
|
info=send(mtd, file);
|
4994
5001
|
end
|
5002
|
+
|
4995
5003
|
if info == 'pngalpha' and ismask == false and (Object.const_defined?(:MiniMagick) or Object.const_defined?(:Magick))
|
4996
5004
|
info = ImagePngAlpha(file, x, y, w, h, 'PNG', link, align, resize, dpi, palign)
|
4997
5005
|
if false != info
|
@@ -5030,7 +5038,7 @@ class RBPDF
|
|
5030
5038
|
tmpname = Tempfile.new(File::basename(file), @@k_path_cache)
|
5031
5039
|
tmpname.binmode
|
5032
5040
|
jpeg_quality = @jpeg_quality
|
5033
|
-
tmpname.print img.to_blob {
|
5041
|
+
tmpname.print img.to_blob { |image| image.quality = jpeg_quality }
|
5034
5042
|
else
|
5035
5043
|
return false
|
5036
5044
|
end
|
@@ -5156,29 +5164,38 @@ class RBPDF
|
|
5156
5164
|
end
|
5157
5165
|
protected :parsejpeg
|
5158
5166
|
|
5159
|
-
def imageToPNG(file)
|
5167
|
+
def imageToPNG(file, delete_alpha=true)
|
5160
5168
|
if Object.const_defined?(:MiniMagick)
|
5161
5169
|
# MiniMagick library
|
5162
5170
|
|
5163
5171
|
img = MiniMagick::Image.open(file)
|
5164
|
-
img.format 'png'
|
5165
|
-
if
|
5166
|
-
img.
|
5167
|
-
|
5168
|
-
|
5169
|
-
|
5170
|
-
|
5172
|
+
img.format 'png'
|
5173
|
+
if delete_alpha
|
5174
|
+
if ['rgba', 'srgba', 'graya'].include?(img["%[channels]"].downcase.split.first)
|
5175
|
+
img.combine_options do |mogrify|
|
5176
|
+
mogrify.alpha 'off'
|
5177
|
+
end
|
5178
|
+
if ['rgba', 'srgba', 'graya'].include?(img["%[channels]"].downcase.split.first)
|
5179
|
+
return false
|
5180
|
+
end
|
5171
5181
|
end
|
5172
5182
|
end
|
5173
5183
|
elsif Object.const_defined?(:Magick)
|
5174
5184
|
# RMagick library
|
5175
5185
|
|
5176
5186
|
img = Magick::ImageList.new(file)
|
5177
|
-
img.format = '
|
5178
|
-
if
|
5179
|
-
img.alpha Magick::DeactivateAlphaChannel # PNG alpha channel delete
|
5187
|
+
img.format = 'png'
|
5188
|
+
if delete_alpha
|
5180
5189
|
if img.alpha?
|
5181
|
-
|
5190
|
+
# PNG alpha channel delete
|
5191
|
+
if Magick.const_defined?(:OffAlphaChannel) # RMagick 5.2.0 and later
|
5192
|
+
img.alpha Magick::OffAlphaChannel
|
5193
|
+
else # RMagick 5.1.0 and before for ImageMagick 6.x
|
5194
|
+
img.alpha Magick::DeactivateAlphaChannel
|
5195
|
+
end
|
5196
|
+
if img.alpha?
|
5197
|
+
return false
|
5198
|
+
end
|
5182
5199
|
end
|
5183
5200
|
end
|
5184
5201
|
else
|
@@ -5199,45 +5216,45 @@ class RBPDF
|
|
5199
5216
|
# [@access protected]
|
5200
5217
|
#
|
5201
5218
|
def parsepng(file)
|
5202
|
-
f=open(file,'rb')
|
5203
|
-
#Check signature
|
5204
|
-
if
|
5205
|
-
Error('Not a PNG file: ' + file)
|
5206
|
-
end
|
5207
|
-
#Read header chunk
|
5208
|
-
f.read(4)
|
5209
|
-
if
|
5210
|
-
Error('Incorrect PNG file: ' + file)
|
5211
|
-
end
|
5212
|
-
w=freadint(f)
|
5213
|
-
h=freadint(f)
|
5214
|
-
bpc=f.read(1).unpack('C')[0]
|
5215
|
-
|
5216
|
-
ct
|
5217
|
-
|
5218
|
-
colspace='DeviceGray'
|
5219
|
-
|
5220
|
-
colspace='DeviceRGB'
|
5221
|
-
|
5222
|
-
colspace='Indexed'
|
5219
|
+
f = open(file,'rb')
|
5220
|
+
# Check signature
|
5221
|
+
if f.read(8) != 137.chr + 'PNG' + 13.chr + 10.chr + 26.chr + 10.chr
|
5222
|
+
Error('Not a PNG file: ' + file)
|
5223
|
+
end
|
5224
|
+
# Read header chunk
|
5225
|
+
f.read(4)
|
5226
|
+
if f.read(4) != 'IHDR'
|
5227
|
+
Error('Incorrect PNG file: ' + file)
|
5228
|
+
end
|
5229
|
+
w = freadint(f)
|
5230
|
+
h = freadint(f)
|
5231
|
+
bpc = f.read(1).unpack('C')[0]
|
5232
|
+
ct = f.read(1).unpack('C')[0]
|
5233
|
+
case ct
|
5234
|
+
when 0
|
5235
|
+
colspace = 'DeviceGray'
|
5236
|
+
when 2
|
5237
|
+
colspace = 'DeviceRGB'
|
5238
|
+
when 3
|
5239
|
+
colspace = 'Indexed'
|
5223
5240
|
else
|
5224
5241
|
if Object.const_defined?(:MiniMagick) or Object.const_defined?(:Magick)
|
5225
5242
|
# alpha channel
|
5226
5243
|
return 'pngalpha'
|
5227
5244
|
else
|
5228
|
-
Error('No RMagick/MiniMagick : Alpha channel not supported: ' + file)
|
5245
|
+
Error('No RMagick/MiniMagick : Alpha channel not supported: ' + file)
|
5229
5246
|
end
|
5230
5247
|
end
|
5231
|
-
if
|
5248
|
+
if f.read(1).unpack('C')[0] != 0
|
5232
5249
|
# Error('Unknown compression method: ' + file)
|
5233
5250
|
return false
|
5234
5251
|
end
|
5235
|
-
if
|
5252
|
+
if f.read(1).unpack('C')[0] != 0
|
5236
5253
|
# Error('Unknown filter method: ' + file)
|
5237
5254
|
return false
|
5238
5255
|
end
|
5239
5256
|
|
5240
|
-
if
|
5257
|
+
if bpc > 8
|
5241
5258
|
if Object.const_defined?(:MiniMagick) or Object.const_defined?(:Magick)
|
5242
5259
|
return false
|
5243
5260
|
else
|
@@ -5245,48 +5262,50 @@ class RBPDF
|
|
5245
5262
|
end
|
5246
5263
|
end
|
5247
5264
|
|
5248
|
-
if
|
5265
|
+
if f.read(1).unpack('C')[0] != 0
|
5249
5266
|
# Error('Interlacing not supported: ' + file)
|
5250
5267
|
return false
|
5251
5268
|
end
|
5252
|
-
f.read(4)
|
5253
|
-
parms='/DecodeParms <</Predictor 15 /Colors ' + (ct==2 ? 3 : 1).to_s + ' /BitsPerComponent ' + bpc.to_s + ' /Columns ' + w.to_s + '>>'
|
5254
|
-
#Scan chunks looking for palette, transparency and image data
|
5255
|
-
pal=''
|
5256
|
-
trns=''
|
5257
|
-
data=''
|
5269
|
+
f.read(4)
|
5270
|
+
parms='/DecodeParms <</Predictor 15 /Colors ' + (ct == 2 ? 3 : 1).to_s + ' /BitsPerComponent ' + bpc.to_s + ' /Columns ' + w.to_s + '>>'
|
5271
|
+
# Scan chunks looking for palette, transparency and image data
|
5272
|
+
pal = ''
|
5273
|
+
trns = ''
|
5274
|
+
data = ''
|
5258
5275
|
begin
|
5259
|
-
n=freadint(f)
|
5260
|
-
type=f.read(4)
|
5261
|
-
|
5262
|
-
|
5263
|
-
|
5264
|
-
f.read(
|
5265
|
-
|
5266
|
-
|
5267
|
-
|
5268
|
-
|
5269
|
-
|
5270
|
-
|
5271
|
-
trns = t[
|
5272
|
-
|
5273
|
-
|
5274
|
-
|
5275
|
-
|
5276
|
-
|
5277
|
-
|
5278
|
-
|
5279
|
-
|
5280
|
-
|
5281
|
-
|
5282
|
-
|
5283
|
-
|
5284
|
-
|
5276
|
+
n = freadint(f)
|
5277
|
+
type = f.read(4)
|
5278
|
+
case type
|
5279
|
+
when 'PLTE'
|
5280
|
+
# Read palette
|
5281
|
+
pal = f.read(n)
|
5282
|
+
f.read(4)
|
5283
|
+
when 'tRNS'
|
5284
|
+
# Read transparency info
|
5285
|
+
t = f.read(n)
|
5286
|
+
case ct
|
5287
|
+
when 0 # DeviceGray
|
5288
|
+
trns = [t[1].unpack('C')[0]]
|
5289
|
+
when 2 # DeviceRGB
|
5290
|
+
trns = [t[1].unpack('C')[0], t[3].unpack('C')[0], t[5].unpack('C')[0]]
|
5291
|
+
else # Indexed
|
5292
|
+
trns = []
|
5293
|
+
n.times do |i|
|
5294
|
+
trns << t[i].unpack('C')[0]
|
5295
|
+
end
|
5296
|
+
end
|
5297
|
+
f.read(4)
|
5298
|
+
when 'IDAT'
|
5299
|
+
# Read image data block
|
5300
|
+
data << f.read(n)
|
5301
|
+
f.read(4)
|
5302
|
+
when 'IEND'
|
5303
|
+
break
|
5285
5304
|
else
|
5286
|
-
f.read(
|
5305
|
+
f.read(n + 4)
|
5287
5306
|
end
|
5288
5307
|
end while(n)
|
5289
|
-
if (colspace=='Indexed' and pal.empty?)
|
5308
|
+
if (colspace == 'Indexed' and pal.empty?)
|
5290
5309
|
# Error('Missing palette in ' + file)
|
5291
5310
|
return false
|
5292
5311
|
end
|
@@ -5302,7 +5321,7 @@ class RBPDF
|
|
5302
5321
|
|
5303
5322
|
img = MiniMagick::Image.open(file)
|
5304
5323
|
img.format('png')
|
5305
|
-
if ['rgba', 'srgba', 'graya'].include?(img["%[channels]"].downcase)
|
5324
|
+
if ['rgba', 'srgba', 'graya'].include?(img["%[channels]"].downcase.split.first)
|
5306
5325
|
img.combine_options do |mogrify|
|
5307
5326
|
mogrify.channel 'matte'
|
5308
5327
|
mogrify.separate '+matte'
|
@@ -5314,6 +5333,7 @@ class RBPDF
|
|
5314
5333
|
# RMagick library
|
5315
5334
|
|
5316
5335
|
img = Magick::ImageList.new(file)
|
5336
|
+
img.format = 'png'
|
5317
5337
|
if img.alpha?
|
5318
5338
|
img.alpha Magick::ExtractAlphaChannel # PNG alpha channel Mask
|
5319
5339
|
else
|
@@ -5333,13 +5353,13 @@ class RBPDF
|
|
5333
5353
|
protected :image_alpha_mask
|
5334
5354
|
|
5335
5355
|
#
|
5336
|
-
# Extract info from a PNG image with alpha channel using the
|
5356
|
+
# Extract info from a PNG image with alpha channel using the RMagick/MiniMagick library.
|
5337
5357
|
# [@param string :file] Name of the file containing the image.
|
5338
5358
|
# [@param float :x] Abscissa of the upper-left corner.
|
5339
5359
|
# [@param float :y] Ordinate of the upper-left corner.
|
5340
5360
|
# [@param float :w] Width of the image in the page. If not specified or equal to zero, it is automatically calculated.
|
5341
5361
|
# [@param float :h] Height of the image in the page. If not specified or equal to zero, it is automatically calculated.
|
5342
|
-
# [@param string :type]
|
5362
|
+
# [@param string :type] Possible values are (case insensitive): JPEG and PNG (without RMagick/MiniMagick library) and PNG(with alpha channel) and JPEG and GIF and WebP supported by RMagick/MiniMagick. If not specified, the type is inferred from the file extension.
|
5343
5363
|
# [@param mixed :link] URL or identifier returned by AddLink().
|
5344
5364
|
# [@param string :align]
|
5345
5365
|
# Indicates the alignment of the pointer next to image insertion relative to image height. The value can be:
|
@@ -5347,7 +5367,7 @@ class RBPDF
|
|
5347
5367
|
# * M: middle-right for LTR or middle-left for RTL
|
5348
5368
|
# * B: bottom-right for LTR or bottom-left for RTL
|
5349
5369
|
# * N: next line
|
5350
|
-
# [@param boolean :resize] If true resize (reduce) the image to fit :w and :h (requires
|
5370
|
+
# [@param boolean :resize] If true resize (reduce) the image to fit :w and :h (requires RMagick/MiniMagick library).
|
5351
5371
|
# [@param int :dpi] dot-per-inch resolution used on resize
|
5352
5372
|
# [@param string :palign]
|
5353
5373
|
# Allows to center or align the image on the current line. Possible values are:
|
@@ -6796,9 +6816,12 @@ protected
|
|
6796
6816
|
# sort glyphs by key
|
6797
6817
|
#ksort(subsetglyphs)
|
6798
6818
|
# add composite glyps to subsetglyphs and remove missing glyphs
|
6819
|
+
subsetglyphs_tmp = []
|
6799
6820
|
subsetglyphs.each_with_index {|val, key|
|
6800
6821
|
next if val.nil?
|
6822
|
+
|
6801
6823
|
if indexToLoc[key]
|
6824
|
+
subsetglyphs_tmp[key] = val
|
6802
6825
|
offset = table['glyf']['offset'] + indexToLoc[key]
|
6803
6826
|
numberOfContours = getSHORT(font, offset); offset += 2
|
6804
6827
|
if numberOfContours < 0 # composite glyph
|
@@ -6808,7 +6831,7 @@ protected
|
|
6808
6831
|
glyphIndex = getUSHORT(font, offset); offset += 2
|
6809
6832
|
if subsetglyphs[glyphIndex].nil? and indexToLoc[glyphIndex]
|
6810
6833
|
# add missing glyphs
|
6811
|
-
|
6834
|
+
subsetglyphs_tmp[glyphIndex] = true
|
6812
6835
|
end
|
6813
6836
|
# skip some bytes by case
|
6814
6837
|
if (flags & 1) != 0
|
@@ -6827,10 +6850,10 @@ protected
|
|
6827
6850
|
break if (flags & 32) == 0
|
6828
6851
|
}
|
6829
6852
|
end
|
6830
|
-
else
|
6831
|
-
subsetglyphs.delete_at(key)
|
6832
6853
|
end
|
6833
6854
|
}
|
6855
|
+
subsetglyphs = subsetglyphs_tmp
|
6856
|
+
|
6834
6857
|
# build new glyf table with only used glyphs
|
6835
6858
|
glyf = ''
|
6836
6859
|
glyfSize = 0
|
@@ -7241,11 +7264,19 @@ protected
|
|
7241
7264
|
out << ' /BaseFont /' + fontname + ''
|
7242
7265
|
out << ' /Name /F' + font['i'].to_s
|
7243
7266
|
out << ' /Encoding /' + font['enc']
|
7244
|
-
out <<
|
7267
|
+
out << " /ToUnicode #{@n + 1} 0 R"
|
7268
|
+
out << " /DescendantFonts [#{@n + 2} 0 R]"
|
7245
7269
|
out << ' >>'
|
7246
7270
|
out << ' endobj'
|
7247
7271
|
out(out)
|
7248
7272
|
|
7273
|
+
# ToUnicode Object
|
7274
|
+
newobj()
|
7275
|
+
filter = @compress ? '/Filter /FlateDecode ' : ''
|
7276
|
+
stream = @compress ? Zlib::Deflate.deflate(@@cmap_identity_h) : @@cmap_identity_h
|
7277
|
+
stream = getrawstream(stream)
|
7278
|
+
out("<<#{filter}/Length #{stream.length}>> stream\n#{stream}\nendstream\nendobj")
|
7279
|
+
|
7249
7280
|
# CIDFontType2
|
7250
7281
|
# A CIDFont whose glyph descriptions are based on TrueType font technology
|
7251
7282
|
newobj();
|
@@ -7435,7 +7466,7 @@ protected
|
|
7435
7466
|
trns='';
|
7436
7467
|
count_info = info['trns'].length
|
7437
7468
|
count_info.times do |i|
|
7438
|
-
trns << info['trns'][i] + ' ' + info['trns'][i] + ' '
|
7469
|
+
trns << info['trns'][i].to_s + ' ' + info['trns'][i].to_s + ' '
|
7439
7470
|
end
|
7440
7471
|
out << ' /Mask [' + trns + ']'
|
7441
7472
|
end
|
@@ -8076,18 +8107,27 @@ protected
|
|
8076
8107
|
end
|
8077
8108
|
|
8078
8109
|
#
|
8079
|
-
#
|
8110
|
+
# get raw output stream.
|
8080
8111
|
# @param string :s string to output.
|
8081
8112
|
# @param int :n object reference for encryption mode
|
8082
8113
|
# @access protected
|
8083
8114
|
#
|
8084
|
-
def
|
8115
|
+
def getrawstream(s, n=0)
|
8085
8116
|
if n <= 0
|
8086
8117
|
# default to current object
|
8087
8118
|
n = @n
|
8088
8119
|
end
|
8089
|
-
|
8090
|
-
|
8120
|
+
encrypt_data(n, s)
|
8121
|
+
end
|
8122
|
+
|
8123
|
+
#
|
8124
|
+
# Format output stream
|
8125
|
+
# @param string :s string to output.
|
8126
|
+
# @param int :n object reference for encryption mode
|
8127
|
+
# @access protected
|
8128
|
+
#
|
8129
|
+
def getstream(s, n=0)
|
8130
|
+
"stream\n" + getrawstream(s, n=0) + "\nendstream"
|
8091
8131
|
end
|
8092
8132
|
|
8093
8133
|
#
|
@@ -8855,7 +8895,7 @@ public
|
|
8855
8895
|
dash = style['dash']
|
8856
8896
|
dash_string = ''
|
8857
8897
|
if dash != 0 and dash != ''
|
8858
|
-
if dash =~ /^.+,/
|
8898
|
+
if dash.is_a?(String) && dash =~ /^.+,/
|
8859
8899
|
tab = dash.split(',')
|
8860
8900
|
else
|
8861
8901
|
tab = [dash]
|
@@ -9131,6 +9171,8 @@ public
|
|
9131
9171
|
# [@since 4.9.019 (2010-04-26)]
|
9132
9172
|
#
|
9133
9173
|
def outellipticalarc(xc, yc, rx, ry, xang=0, angs=0, angf=360, pie=false, nc=2)
|
9174
|
+
return if rx == 0 && ry == 0
|
9175
|
+
|
9134
9176
|
k = @k
|
9135
9177
|
if nc < 2
|
9136
9178
|
nc = 2
|
@@ -9768,7 +9810,7 @@ public
|
|
9768
9810
|
end
|
9769
9811
|
when @@k_pdf
|
9770
9812
|
# X7. With each PDF, determine the matching embedding or override code. If there was a valid matching code, restore (pop) the last remembered (pushed) embedding level and directional override.
|
9771
|
-
|
9813
|
+
unless remember.empty?
|
9772
9814
|
last = remember.length - 1
|
9773
9815
|
case remember[last][:num]
|
9774
9816
|
when @@k_rle, @@k_lre, @@k_rlo, @@k_lro
|
@@ -10176,12 +10218,7 @@ public
|
|
10176
10218
|
end
|
10177
10219
|
end
|
10178
10220
|
# remove marked characters
|
10179
|
-
chardata2.
|
10180
|
-
if value[:char] == false
|
10181
|
-
chardata2.delete_at(key)
|
10182
|
-
end
|
10183
|
-
end
|
10184
|
-
chardata = chardata2
|
10221
|
+
chardata = chardata2.reject {|value| value[:char] == false }
|
10185
10222
|
numchars = chardata.size
|
10186
10223
|
chardata2 = nil
|
10187
10224
|
arabicarr = nil
|
@@ -11024,16 +11061,20 @@ protected
|
|
11024
11061
|
cssblocks[key] = block.split('{')
|
11025
11062
|
}
|
11026
11063
|
# split groups of selectors (comma-separated list of selectors)
|
11064
|
+
cssblocks_tmp = []
|
11027
11065
|
cssblocks.each_with_index { |block, key|
|
11028
11066
|
# index 0 contains the CSS selector, index 1 contains CSS properties
|
11029
11067
|
if block[0].index(',')
|
11030
11068
|
selectors = block[0].split(',')
|
11031
11069
|
selectors.each {|sel|
|
11032
|
-
|
11070
|
+
cssblocks_tmp.push [sel.strip, block[1]]
|
11033
11071
|
}
|
11034
|
-
|
11072
|
+
else
|
11073
|
+
cssblocks_tmp.push [block[0], block[1]]
|
11035
11074
|
end
|
11036
11075
|
}
|
11076
|
+
cssblocks = cssblocks_tmp
|
11077
|
+
|
11037
11078
|
# covert array to selector => properties
|
11038
11079
|
cssdata = {}
|
11039
11080
|
cssblocks.each { |block|
|
@@ -11081,7 +11122,7 @@ protected
|
|
11081
11122
|
operator = ''
|
11082
11123
|
lasttag = ''
|
11083
11124
|
attrib = ''
|
11084
|
-
while selector_offset = selector.index(/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([
|
11125
|
+
while selector_offset = selector.index(/([\>\+\~\s]{1})([a-zA-Z0-9\*]+)([^\>\+\s]*)/mi, selector_offset)
|
11085
11126
|
offset = selector_offset
|
11086
11127
|
selector_offset += $&.length
|
11087
11128
|
operator = $1
|
@@ -11101,18 +11142,19 @@ protected
|
|
11101
11142
|
when '[' # attribute
|
11102
11143
|
attrmatch = attrib.scan(/\[([a-zA-Z0-9]*)[\s]*([\~\^\$\*\|\=]*)[\s]*["]?([^"\]]*)["]?\]/i)
|
11103
11144
|
if !attrmatch.empty?
|
11104
|
-
att = attrmatch[0].downcase
|
11105
|
-
val = attrmatch[2]
|
11145
|
+
att = attrmatch[0][0].downcase
|
11146
|
+
val = attrmatch[0][2]
|
11147
|
+
|
11106
11148
|
if dom[key]['attribute'][att]
|
11107
|
-
case attrmatch[1]
|
11149
|
+
case attrmatch[0][1]
|
11108
11150
|
when '='
|
11109
11151
|
valid = true if dom[key]['attribute'][att] == val
|
11110
11152
|
when '~='
|
11111
11153
|
valid = true if dom[key]['attribute'][att].split(' ').include?(val)
|
11112
11154
|
when '^='
|
11113
|
-
valid = true if val ==
|
11155
|
+
valid = true if val == dom[key]['attribute'][att][0, val.length]
|
11114
11156
|
when '$='
|
11115
|
-
valid = true if val ==
|
11157
|
+
valid = true if val == dom[key]['attribute'][att][-val.length..-1]
|
11116
11158
|
when '*='
|
11117
11159
|
valid = true if dom[key]['attribute'][att].index(val) != nil
|
11118
11160
|
when '|='
|
@@ -11312,11 +11354,11 @@ protected
|
|
11312
11354
|
while html_b =~ /<xre([^\>]*)>(.*?)\n(.*?)<\/pre>/mi
|
11313
11355
|
# preserve newlines on <pre> tag
|
11314
11356
|
html_b = html_b.gsub(/<xre([^\>]*)>(.*?)\n(.*?)<\/pre>/mi) do
|
11315
|
-
if ($2 != '') and ($3 != '')
|
11357
|
+
if ($2 != '') and ($3 != '')
|
11316
11358
|
"<xre#{$1}>#{$2}<br />#{$3}</pre>"
|
11317
|
-
elsif ($2 == '') and ($3 != '')
|
11359
|
+
elsif ($2 == '') and ($3 != '')
|
11318
11360
|
"<xre#{$1}>#{$3}</pre>"
|
11319
|
-
elsif ($2 != '') and ($3 == '')
|
11361
|
+
elsif ($2 != '') and ($3 == '')
|
11320
11362
|
"<xre#{$1}>#{$2}</pre>"
|
11321
11363
|
else
|
11322
11364
|
"<xre#{$1}></pre>"
|
@@ -12879,7 +12921,7 @@ public
|
|
12879
12921
|
startlinepage = @page
|
12880
12922
|
end
|
12881
12923
|
end
|
12882
|
-
elsif dom[key]['value'].
|
12924
|
+
elsif dom[key]['value'].length > 0
|
12883
12925
|
# print list-item
|
12884
12926
|
if !empty_string(@lispacer)
|
12885
12927
|
SetFont(pfontname, pfontstyle, pfontsize)
|
@@ -12898,7 +12940,7 @@ public
|
|
12898
12940
|
end
|
12899
12941
|
end
|
12900
12942
|
# text
|
12901
|
-
@htmlvspace = 0
|
12943
|
+
@htmlvspace = 0 unless dom[key]['value'].strip.length == 0
|
12902
12944
|
if !@premode and isRTLTextDir()
|
12903
12945
|
# reverse spaces order
|
12904
12946
|
len1 = dom[key]['value'].length
|
@@ -13331,27 +13373,10 @@ public
|
|
13331
13373
|
SetLeftMargin(@l_margin + @c_margin)
|
13332
13374
|
SetRightMargin(@r_margin + @c_margin)
|
13333
13375
|
|
13334
|
-
|
13335
|
-
|
13336
|
-
|
13337
|
-
|
13338
|
-
else
|
13339
|
-
img_file = tag['attribute']['src']
|
13340
|
-
end
|
13341
|
-
# if (type == 'eps') or (type == 'ai')
|
13342
|
-
# ImageEps(img_file, xpos, @y, iw, ih, imglink, true, align, '', border, true)
|
13343
|
-
# elsif type == 'svg'
|
13344
|
-
# ImageSVG(img_file, xpos, @y, iw, ih, imglink, align, '', border, true)
|
13345
|
-
# else
|
13346
|
-
result_img = Image(img_file, xpos, @y, iw, ih, '', imglink, align, false, 300, '', false, false, border, false, false, true)
|
13347
|
-
# end
|
13348
|
-
rescue => err
|
13349
|
-
logger.error "pdf: Image: error: #{err.message}"
|
13350
|
-
result_img = false
|
13351
|
-
ensure
|
13352
|
-
# remove temp files
|
13353
|
-
tmpFile.close(true) unless tmpFile.nil?
|
13354
|
-
end
|
13376
|
+
result_img =
|
13377
|
+
proc_image_file(tag['attribute']['src']) do |img_file|
|
13378
|
+
Image(img_file, xpos, @y, iw, ih, '', imglink, align, false, 300, '', false, false, border, false, false, true)
|
13379
|
+
end
|
13355
13380
|
|
13356
13381
|
if result_img or ih != 0
|
13357
13382
|
case align
|
@@ -13487,6 +13512,25 @@ public
|
|
13487
13512
|
end
|
13488
13513
|
protected :openHTMLTagHandler
|
13489
13514
|
|
13515
|
+
def proc_image_file(src, &block)
|
13516
|
+
tmpFile = nil
|
13517
|
+
img_file =
|
13518
|
+
if src =~ /^http/
|
13519
|
+
tmpFile = get_image_file(src)
|
13520
|
+
tmpFile.path
|
13521
|
+
else
|
13522
|
+
src
|
13523
|
+
end
|
13524
|
+
yield img_file
|
13525
|
+
rescue => err
|
13526
|
+
logger.error "pdf: Image: error: #{err.message}"
|
13527
|
+
false
|
13528
|
+
ensure
|
13529
|
+
# remove temp files
|
13530
|
+
tmpFile.close(true) if tmpFile
|
13531
|
+
end
|
13532
|
+
private :proc_image_file
|
13533
|
+
|
13490
13534
|
#
|
13491
13535
|
# Process closing tags.
|
13492
13536
|
# [@param array :dom] html dom array
|
data/lib/unicode_data.rb
CHANGED
@@ -18326,6 +18326,35 @@ module Unicode_data
|
|
18326
18326
|
382=>158 # zcaron2
|
18327
18327
|
}
|
18328
18328
|
|
18329
|
+
#
|
18330
|
+
# ToUnicode map for Identity-H
|
18331
|
+
# CMapType : 1 = Convert to CID, 2 = Convert to Unicode
|
18332
|
+
#
|
18333
|
+
@@cmap_identity_h = <<-CMap
|
18334
|
+
/CIDInit /ProcSet findresource begin
|
18335
|
+
12 dict begin
|
18336
|
+
begincmap
|
18337
|
+
/CMapName /Adobe-Identity-UCS def
|
18338
|
+
/CMapType 2 def
|
18339
|
+
/CIDSystemInfo <<
|
18340
|
+
/Registry (Adobe)
|
18341
|
+
/Ordering (UCS)
|
18342
|
+
/Supplement 0
|
18343
|
+
>> def
|
18344
|
+
/WMode 0 def
|
18345
|
+
1 begincodespacerange
|
18346
|
+
<0000> <FFFF>
|
18347
|
+
endcodespacerange
|
18348
|
+
|
18349
|
+
1 beginbfrange
|
18350
|
+
<0000> <ffff> <0000>
|
18351
|
+
endbfrange
|
18352
|
+
endcmap
|
18353
|
+
CMapName currentdict /CMap defineresource pop
|
18354
|
+
end
|
18355
|
+
end
|
18356
|
+
CMap
|
18357
|
+
|
18329
18358
|
end
|
18330
18359
|
|
18331
18360
|
#============================================================+
|
data/rbpdf.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
# Copyright (c) 2011-
|
2
|
+
# Copyright (c) 2011-2023 NAITOH Jun
|
3
3
|
# Released under the MIT license
|
4
4
|
# http://www.opensource.org/licenses/MIT
|
5
5
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
["Rakefile", "rbpdf.gemspec", "Gemfile",
|
24
24
|
"CHANGELOG", "test_unicode.rbpdf", "README.md", "LICENSE.TXT", "MIT-LICENSE",
|
25
25
|
"utf8test.txt", "logo_example.png" ]
|
26
|
-
spec.rdoc_options += [ '--exclude', 'lib/
|
26
|
+
spec.rdoc_options += [ '--exclude', 'lib/core/mini_magick.rb',
|
27
27
|
'--exclude', 'lib/htmlcolors.rb',
|
28
28
|
'--exclude', 'lib/unicode_data.rb' ]
|
29
29
|
|
@@ -31,23 +31,12 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
|
-
|
35
|
-
spec.add_runtime_dependency "htmlentities", "= 4.3.1"
|
36
|
-
else
|
37
|
-
spec.add_runtime_dependency "htmlentities"
|
38
|
-
end
|
34
|
+
spec.add_runtime_dependency "htmlentities"
|
39
35
|
spec.add_runtime_dependency "rbpdf-font", "~> 1.19.0"
|
40
|
-
spec.required_ruby_version = '>=
|
36
|
+
spec.required_ruby_version = '>= 2.3.0'
|
41
37
|
|
42
38
|
spec.add_development_dependency "bundler"
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
spec.add_development_dependency "rake"
|
47
|
-
end
|
48
|
-
if RUBY_VERSION <'1.9' # Ruby 1.8.7
|
49
|
-
spec.add_development_dependency "test-unit", "<= 3.1.5"
|
50
|
-
else
|
51
|
-
spec.add_development_dependency "test-unit", "~> 3.2"
|
52
|
-
end
|
39
|
+
spec.add_development_dependency "rake"
|
40
|
+
spec.add_development_dependency "test-unit"
|
41
|
+
spec.add_development_dependency "webrick"
|
53
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbpdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.21.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NAITOH Jun
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -70,16 +70,30 @@ dependencies:
|
|
70
70
|
name: test-unit
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webrick
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '0'
|
83
97
|
description: A template plugin allowing the inclusion of ERB-enabled RBPDF template
|
84
98
|
files.
|
85
99
|
email:
|
@@ -109,10 +123,10 @@ licenses:
|
|
109
123
|
- MIT
|
110
124
|
- LGPL-2.1-or-later
|
111
125
|
metadata: {}
|
112
|
-
post_install_message:
|
126
|
+
post_install_message:
|
113
127
|
rdoc_options:
|
114
128
|
- "--exclude"
|
115
|
-
- lib/
|
129
|
+
- lib/core/mini_magick.rb
|
116
130
|
- "--exclude"
|
117
131
|
- lib/htmlcolors.rb
|
118
132
|
- "--exclude"
|
@@ -123,16 +137,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
137
|
requirements:
|
124
138
|
- - ">="
|
125
139
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
140
|
+
version: 2.3.0
|
127
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
130
144
|
- !ruby/object:Gem::Version
|
131
145
|
version: '0'
|
132
146
|
requirements: []
|
133
|
-
|
134
|
-
|
135
|
-
signing_key:
|
147
|
+
rubygems_version: 3.3.7
|
148
|
+
signing_key:
|
136
149
|
specification_version: 4
|
137
150
|
summary: RBPDF via TCPDF.
|
138
151
|
test_files: []
|