hexapdf 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTERS +1 -1
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/hexapdf +1 -1
- data/examples/text_layouter_styling.rb +1 -2
- data/lib/hexapdf.rb +2 -2
- data/lib/hexapdf/cli.rb +3 -3
- data/lib/hexapdf/cli/batch.rb +5 -5
- data/lib/hexapdf/cli/command.rb +15 -17
- data/lib/hexapdf/cli/files.rb +3 -3
- data/lib/hexapdf/cli/images.rb +3 -4
- data/lib/hexapdf/cli/info.rb +5 -5
- data/lib/hexapdf/cli/inspect.rb +6 -6
- data/lib/hexapdf/cli/merge.rb +6 -6
- data/lib/hexapdf/cli/modify.rb +4 -4
- data/lib/hexapdf/cli/optimize.rb +3 -3
- data/lib/hexapdf/configuration.rb +4 -5
- data/lib/hexapdf/content.rb +2 -2
- data/lib/hexapdf/content/canvas.rb +35 -36
- data/lib/hexapdf/content/color_space.rb +9 -14
- data/lib/hexapdf/content/graphic_object.rb +2 -2
- data/lib/hexapdf/content/graphic_object/arc.rb +3 -3
- data/lib/hexapdf/content/graphic_object/endpoint_arc.rb +2 -2
- data/lib/hexapdf/content/graphic_object/solid_arc.rb +4 -8
- data/lib/hexapdf/content/graphics_state.rb +4 -13
- data/lib/hexapdf/content/operator.rb +33 -35
- data/lib/hexapdf/content/parser.rb +28 -18
- data/lib/hexapdf/content/processor.rb +4 -5
- data/lib/hexapdf/content/transformation_matrix.rb +2 -2
- data/lib/hexapdf/data_dir.rb +2 -2
- data/lib/hexapdf/dictionary.rb +8 -9
- data/lib/hexapdf/dictionary_fields.rb +7 -10
- data/lib/hexapdf/document.rb +18 -18
- data/lib/hexapdf/document/files.rb +12 -10
- data/lib/hexapdf/document/fonts.rb +2 -2
- data/lib/hexapdf/document/images.rb +3 -3
- data/lib/hexapdf/document/pages.rb +4 -4
- data/lib/hexapdf/encryption.rb +2 -2
- data/lib/hexapdf/encryption/aes.rb +2 -2
- data/lib/hexapdf/encryption/arc4.rb +4 -4
- data/lib/hexapdf/encryption/fast_aes.rb +2 -2
- data/lib/hexapdf/encryption/fast_arc4.rb +4 -4
- data/lib/hexapdf/encryption/identity.rb +5 -4
- data/lib/hexapdf/encryption/ruby_aes.rb +147 -139
- data/lib/hexapdf/encryption/ruby_arc4.rb +4 -4
- data/lib/hexapdf/encryption/security_handler.rb +11 -12
- data/lib/hexapdf/encryption/standard_security_handler.rb +6 -9
- data/lib/hexapdf/error.rb +7 -9
- data/lib/hexapdf/filter.rb +2 -3
- data/lib/hexapdf/filter/ascii85_decode.rb +3 -3
- data/lib/hexapdf/filter/ascii_hex_decode.rb +2 -2
- data/lib/hexapdf/filter/dct_decode.rb +2 -2
- data/lib/hexapdf/filter/encryption.rb +2 -2
- data/lib/hexapdf/filter/flate_decode.rb +16 -33
- data/lib/hexapdf/filter/jpx_decode.rb +2 -2
- data/lib/hexapdf/filter/lzw_decode.rb +4 -4
- data/lib/hexapdf/filter/predictor.rb +2 -6
- data/lib/hexapdf/filter/run_length_decode.rb +2 -2
- data/lib/hexapdf/font/cmap.rb +2 -3
- data/lib/hexapdf/font/cmap/parser.rb +11 -11
- data/lib/hexapdf/font/cmap/writer.rb +25 -25
- data/lib/hexapdf/font/encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/base.rb +2 -2
- data/lib/hexapdf/font/encoding/difference_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/glyph_list.rb +6 -6
- data/lib/hexapdf/font/encoding/mac_expert_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/mac_roman_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/standard_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/symbol_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/win_ansi_encoding.rb +2 -2
- data/lib/hexapdf/font/encoding/zapf_dingbats_encoding.rb +2 -2
- data/lib/hexapdf/font/invalid_glyph.rb +7 -7
- data/lib/hexapdf/font/true_type.rb +2 -2
- data/lib/hexapdf/font/true_type/builder.rb +13 -7
- data/lib/hexapdf/font/true_type/font.rb +2 -3
- data/lib/hexapdf/font/true_type/optimizer.rb +2 -2
- data/lib/hexapdf/font/true_type/subsetter.rb +4 -4
- data/lib/hexapdf/font/true_type/table.rb +3 -5
- data/lib/hexapdf/font/true_type/table/cmap.rb +2 -2
- data/lib/hexapdf/font/true_type/table/cmap_subtable.rb +9 -16
- data/lib/hexapdf/font/true_type/table/directory.rb +4 -4
- data/lib/hexapdf/font/true_type/table/glyf.rb +2 -2
- data/lib/hexapdf/font/true_type/table/head.rb +3 -2
- data/lib/hexapdf/font/true_type/table/hhea.rb +2 -2
- data/lib/hexapdf/font/true_type/table/hmtx.rb +2 -2
- data/lib/hexapdf/font/true_type/table/kern.rb +3 -3
- data/lib/hexapdf/font/true_type/table/loca.rb +3 -3
- data/lib/hexapdf/font/true_type/table/maxp.rb +2 -2
- data/lib/hexapdf/font/true_type/table/name.rb +3 -5
- data/lib/hexapdf/font/true_type/table/os2.rb +4 -3
- data/lib/hexapdf/font/true_type/table/post.rb +3 -7
- data/lib/hexapdf/font/true_type_wrapper.rb +20 -22
- data/lib/hexapdf/font/type1.rb +2 -2
- data/lib/hexapdf/font/type1/afm_parser.rb +7 -7
- data/lib/hexapdf/font/type1/character_metrics.rb +2 -2
- data/lib/hexapdf/font/type1/font.rb +3 -3
- data/lib/hexapdf/font/type1/font_metrics.rb +2 -4
- data/lib/hexapdf/font/type1/pfb_parser.rb +2 -2
- data/lib/hexapdf/font/type1_wrapper.rb +8 -9
- data/lib/hexapdf/font_loader.rb +2 -2
- data/lib/hexapdf/font_loader/from_configuration.rb +2 -2
- data/lib/hexapdf/font_loader/from_file.rb +2 -2
- data/lib/hexapdf/font_loader/standard14.rb +2 -2
- data/lib/hexapdf/image_loader.rb +2 -2
- data/lib/hexapdf/image_loader/jpeg.rb +6 -4
- data/lib/hexapdf/image_loader/pdf.rb +2 -2
- data/lib/hexapdf/image_loader/png.rb +6 -6
- data/lib/hexapdf/importer.rb +6 -4
- data/lib/hexapdf/layout.rb +2 -2
- data/lib/hexapdf/layout/box.rb +4 -4
- data/lib/hexapdf/layout/inline_box.rb +2 -2
- data/lib/hexapdf/layout/line.rb +6 -6
- data/lib/hexapdf/layout/numeric_refinements.rb +2 -2
- data/lib/hexapdf/layout/style.rb +17 -8
- data/lib/hexapdf/layout/text_fragment.rb +86 -48
- data/lib/hexapdf/layout/text_layouter.rb +40 -21
- data/lib/hexapdf/layout/text_shaper.rb +2 -2
- data/lib/hexapdf/name_tree_node.rb +2 -2
- data/lib/hexapdf/number_tree_node.rb +2 -2
- data/lib/hexapdf/object.rb +6 -8
- data/lib/hexapdf/parser.rb +10 -10
- data/lib/hexapdf/rectangle.rb +4 -4
- data/lib/hexapdf/reference.rb +2 -2
- data/lib/hexapdf/revision.rb +4 -4
- data/lib/hexapdf/revisions.rb +5 -5
- data/lib/hexapdf/serializer.rb +27 -24
- data/lib/hexapdf/stream.rb +4 -4
- data/lib/hexapdf/task.rb +2 -2
- data/lib/hexapdf/task/dereference.rb +4 -4
- data/lib/hexapdf/task/optimize.rb +5 -4
- data/lib/hexapdf/tokenizer.rb +12 -14
- data/lib/hexapdf/type.rb +2 -2
- data/lib/hexapdf/type/action.rb +3 -3
- data/lib/hexapdf/type/actions.rb +2 -2
- data/lib/hexapdf/type/actions/go_to.rb +2 -2
- data/lib/hexapdf/type/actions/go_to_r.rb +2 -2
- data/lib/hexapdf/type/actions/launch.rb +2 -2
- data/lib/hexapdf/type/actions/uri.rb +3 -3
- data/lib/hexapdf/type/annotation.rb +3 -3
- data/lib/hexapdf/type/annotations.rb +2 -2
- data/lib/hexapdf/type/annotations/link.rb +2 -2
- data/lib/hexapdf/type/annotations/markup_annotation.rb +2 -2
- data/lib/hexapdf/type/annotations/text.rb +2 -2
- data/lib/hexapdf/type/catalog.rb +4 -4
- data/lib/hexapdf/type/cid_font.rb +4 -5
- data/lib/hexapdf/type/embedded_file.rb +3 -3
- data/lib/hexapdf/type/file_specification.rb +6 -7
- data/lib/hexapdf/type/font.rb +4 -4
- data/lib/hexapdf/type/font_descriptor.rb +3 -4
- data/lib/hexapdf/type/font_simple.rb +12 -16
- data/lib/hexapdf/type/font_true_type.rb +2 -2
- data/lib/hexapdf/type/font_type0.rb +5 -5
- data/lib/hexapdf/type/font_type1.rb +4 -4
- data/lib/hexapdf/type/form.rb +3 -3
- data/lib/hexapdf/type/graphics_state_parameter.rb +3 -3
- data/lib/hexapdf/type/image.rb +13 -14
- data/lib/hexapdf/type/info.rb +2 -2
- data/lib/hexapdf/type/names.rb +2 -2
- data/lib/hexapdf/type/object_stream.rb +5 -5
- data/lib/hexapdf/type/page.rb +9 -10
- data/lib/hexapdf/type/page_tree_node.rb +5 -6
- data/lib/hexapdf/type/resources.rb +11 -11
- data/lib/hexapdf/type/trailer.rb +3 -3
- data/lib/hexapdf/type/viewer_preferences.rb +2 -2
- data/lib/hexapdf/type/xref_stream.rb +8 -4
- data/lib/hexapdf/utils/bit_field.rb +4 -4
- data/lib/hexapdf/utils/bit_stream.rb +4 -4
- data/lib/hexapdf/utils/graphics_helpers.rb +2 -2
- data/lib/hexapdf/utils/lru_cache.rb +2 -2
- data/lib/hexapdf/utils/math_helpers.rb +2 -2
- data/lib/hexapdf/utils/object_hash.rb +3 -3
- data/lib/hexapdf/utils/pdf_doc_encoding.rb +3 -3
- data/lib/hexapdf/utils/sorted_tree_node.rb +12 -11
- data/lib/hexapdf/version.rb +3 -3
- data/lib/hexapdf/writer.rb +8 -8
- data/lib/hexapdf/xref_section.rb +3 -3
- data/test/hexapdf/common_tokenizer_tests.rb +6 -7
- data/test/hexapdf/content/graphic_object/test_endpoint_arc.rb +0 -1
- data/test/hexapdf/content/test_canvas.rb +28 -36
- data/test/hexapdf/content/test_color_space.rb +4 -0
- data/test/hexapdf/content/test_graphics_state.rb +2 -0
- data/test/hexapdf/content/test_operator.rb +6 -7
- data/test/hexapdf/content/test_parser.rb +2 -2
- data/test/hexapdf/content/test_processor.rb +1 -1
- data/test/hexapdf/document/test_files.rb +1 -0
- data/test/hexapdf/document/test_images.rb +1 -1
- data/test/hexapdf/encryption/common.rb +3 -3
- data/test/hexapdf/encryption/test_aes.rb +10 -4
- data/test/hexapdf/encryption/test_identity.rb +1 -1
- data/test/hexapdf/encryption/test_security_handler.rb +13 -17
- data/test/hexapdf/encryption/test_standard_security_handler.rb +12 -12
- data/test/hexapdf/filter/test_ascii85_decode.rb +2 -3
- data/test/hexapdf/filter/test_ascii_hex_decode.rb +6 -1
- data/test/hexapdf/filter/test_flate_decode.rb +2 -2
- data/test/hexapdf/filter/test_lzw_decode.rb +10 -10
- data/test/hexapdf/filter/test_predictor.rb +10 -2
- data/test/hexapdf/filter/test_run_length_decode.rb +1 -1
- data/test/hexapdf/font/cmap/test_parser.rb +40 -40
- data/test/hexapdf/font/cmap/test_writer.rb +29 -29
- data/test/hexapdf/font/test_true_type_wrapper.rb +3 -2
- data/test/hexapdf/font/true_type/common.rb +2 -0
- data/test/hexapdf/font/true_type/table/test_cmap.rb +1 -1
- data/test/hexapdf/font/true_type/table/test_cmap_subtable.rb +5 -4
- data/test/hexapdf/font/true_type/table/test_glyf.rb +2 -2
- data/test/hexapdf/font/true_type/table/test_head.rb +2 -2
- data/test/hexapdf/font/true_type/table/test_name.rb +9 -6
- data/test/hexapdf/font/true_type/test_builder.rb +8 -3
- data/test/hexapdf/font/true_type/test_optimizer.rb +1 -2
- data/test/hexapdf/font/type1/test_afm_parser.rb +2 -2
- data/test/hexapdf/image_loader/test_jpeg.rb +1 -1
- data/test/hexapdf/image_loader/test_pdf.rb +1 -1
- data/test/hexapdf/image_loader/test_png.rb +3 -3
- data/test/hexapdf/layout/test_inline_box.rb +10 -1
- data/test/hexapdf/layout/test_line.rb +4 -4
- data/test/hexapdf/layout/test_style.rb +19 -7
- data/test/hexapdf/layout/test_text_fragment.rb +73 -27
- data/test/hexapdf/layout/test_text_layouter.rb +84 -68
- data/test/hexapdf/layout/test_text_shaper.rb +4 -6
- data/test/hexapdf/task/test_dereference.rb +2 -2
- data/test/hexapdf/task/test_optimize.rb +16 -7
- data/test/hexapdf/test_configuration.rb +1 -1
- data/test/hexapdf/test_data_dir.rb +2 -2
- data/test/hexapdf/test_dictionary.rb +6 -3
- data/test/hexapdf/test_dictionary_fields.rb +15 -14
- data/test/hexapdf/test_document.rb +47 -48
- data/test/hexapdf/test_filter.rb +30 -26
- data/test/hexapdf/test_importer.rb +14 -0
- data/test/hexapdf/test_object.rb +16 -4
- data/test/hexapdf/test_parser.rb +36 -36
- data/test/hexapdf/test_reference.rb +7 -5
- data/test/hexapdf/test_revision.rb +1 -1
- data/test/hexapdf/test_revisions.rb +90 -90
- data/test/hexapdf/test_serializer.rb +3 -2
- data/test/hexapdf/test_stream.rb +2 -4
- data/test/hexapdf/test_tokenizer.rb +2 -2
- data/test/hexapdf/test_writer.rb +80 -80
- data/test/hexapdf/test_xref_section.rb +1 -1
- data/test/hexapdf/type/annotations/test_link.rb +1 -1
- data/test/hexapdf/type/annotations/test_text.rb +3 -3
- data/test/hexapdf/type/test_font_descriptor.rb +1 -1
- data/test/hexapdf/type/test_font_simple.rb +2 -2
- data/test/hexapdf/type/test_font_type0.rb +0 -1
- data/test/hexapdf/type/test_image.rb +0 -3
- data/test/hexapdf/type/test_object_stream.rb +2 -1
- data/test/hexapdf/type/test_page.rb +5 -1
- data/test/hexapdf/type/test_page_tree_node.rb +4 -4
- data/test/hexapdf/type/test_trailer.rb +1 -1
- data/test/hexapdf/type/test_xref_stream.rb +4 -0
- data/test/hexapdf/utils/test_bit_field.rb +2 -0
- data/test/hexapdf/utils/test_bit_stream.rb +1 -1
- data/test/hexapdf/utils/test_lru_cache.rb +1 -1
- data/test/hexapdf/utils/test_sorted_tree_node.rb +10 -4
- data/test/test_helper.rb +3 -6
- metadata +3 -3
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -109,7 +109,6 @@ module HexaPDF
|
|
109
109
|
|
110
110
|
private_constant :Glyph
|
111
111
|
|
112
|
-
|
113
112
|
# Returns the wrapped TrueType font object.
|
114
113
|
attr_reader :wrapped_font
|
115
114
|
|
@@ -162,7 +161,7 @@ module HexaPDF
|
|
162
161
|
@id_to_glyph[id] ||=
|
163
162
|
begin
|
164
163
|
if id >= 0 && id < @wrapped_font[:maxp].num_glyphs
|
165
|
-
Glyph.new(@wrapped_font, id, str || ('' << (@cmap.gid_to_code(id) || 0xFFFD)))
|
164
|
+
Glyph.new(@wrapped_font, id, str || (+'' << (@cmap.gid_to_code(id) || 0xFFFD)))
|
166
165
|
else
|
167
166
|
@document.config['font.on_missing_glyph'].call("\u{FFFD}", font_type, @wrapped_font)
|
168
167
|
end
|
@@ -171,13 +170,13 @@ module HexaPDF
|
|
171
170
|
|
172
171
|
# Returns an array of glyph objects representing the characters in the UTF-8 encoded string.
|
173
172
|
def decode_utf8(str)
|
174
|
-
str.
|
173
|
+
str.codepoints.map! do |c|
|
175
174
|
@codepoint_to_glyph[c] ||=
|
176
175
|
begin
|
177
176
|
if (gid = @cmap[c])
|
178
|
-
glyph(gid, '' << c)
|
177
|
+
glyph(gid, +'' << c)
|
179
178
|
else
|
180
|
-
@document.config['font.on_missing_glyph'].call('' << c, font_type, @wrapped_font)
|
179
|
+
@document.config['font.on_missing_glyph'].call(+'' << c, font_type, @wrapped_font)
|
181
180
|
end
|
182
181
|
end
|
183
182
|
end
|
@@ -185,17 +184,17 @@ module HexaPDF
|
|
185
184
|
|
186
185
|
# Encodes the glyph and returns the code string.
|
187
186
|
def encode(glyph)
|
188
|
-
@encoded_glyphs[glyph] ||=
|
187
|
+
(@encoded_glyphs[glyph.id] ||=
|
189
188
|
begin
|
190
189
|
if glyph.kind_of?(InvalidGlyph)
|
191
190
|
raise HexaPDF::Error, "Glyph for #{glyph.str.inspect} missing"
|
192
191
|
end
|
193
192
|
if @subsetter
|
194
|
-
[@subsetter.use_glyph(glyph.id)].pack('n')
|
193
|
+
[[@subsetter.use_glyph(glyph.id)].pack('n'), glyph]
|
195
194
|
else
|
196
|
-
[glyph.id].pack('n')
|
195
|
+
[[glyph.id].pack('n'), glyph]
|
197
196
|
end
|
198
|
-
end
|
197
|
+
end)[0]
|
199
198
|
end
|
200
199
|
|
201
200
|
private
|
@@ -211,7 +210,7 @@ module HexaPDF
|
|
211
210
|
FontName: @wrapped_font.font_name.intern,
|
212
211
|
FontWeight: @wrapped_font.weight,
|
213
212
|
Flags: 0,
|
214
|
-
FontBBox: @wrapped_font.bounding_box.map {|m| m * scaling_factor},
|
213
|
+
FontBBox: @wrapped_font.bounding_box.map {|m| m * scaling_factor },
|
215
214
|
ItalicAngle: @wrapped_font.italic_angle || 0,
|
216
215
|
Ascent: @wrapped_font.ascender * scaling_factor,
|
217
216
|
Descent: @wrapped_font.descender * scaling_factor,
|
@@ -235,9 +234,9 @@ module HexaPDF
|
|
235
234
|
end
|
236
235
|
|
237
236
|
fd.flag(:fixed_pitch) if @wrapped_font[:post].is_fixed_pitch? ||
|
238
|
-
|
237
|
+
@wrapped_font[:hhea].num_of_long_hor_metrics == 1
|
239
238
|
fd.flag(:italic) if @wrapped_font[:'OS/2'].selection_include?(:italic) ||
|
240
|
-
|
239
|
+
@wrapped_font[:'OS/2'].selection_include?(:oblique)
|
241
240
|
fd.flag(:symbolic)
|
242
241
|
|
243
242
|
cid_font = @document.add(Type: :Font, Subtype: :CIDFontType2,
|
@@ -264,8 +263,8 @@ module HexaPDF
|
|
264
263
|
def update_font_name
|
265
264
|
return unless @subsetter
|
266
265
|
|
267
|
-
tag = ''
|
268
|
-
data = @encoded_glyphs.each_with_object(''.b) {|(
|
266
|
+
tag = +''
|
267
|
+
data = @encoded_glyphs.each_with_object(''.b) {|(id, v), s| s << id.to_s << v[0] }
|
269
268
|
hash = Digest::MD5.hexdigest(data << @wrapped_font.font_name).to_i(16)
|
270
269
|
while hash != 0 && tag.length < 6
|
271
270
|
hash, mod = hash.divmod(UPPERCASE_LETTERS.length)
|
@@ -295,8 +294,8 @@ module HexaPDF
|
|
295
294
|
# Adds the /DW and /W fields to the CIDFont dictionary.
|
296
295
|
def complete_width_information
|
297
296
|
default_width = glyph(3, " ").width.to_i
|
298
|
-
widths = @encoded_glyphs.
|
299
|
-
[(@subsetter ? @subsetter.subset_glyph_id(
|
297
|
+
widths = @encoded_glyphs.reject {|_, v| v[1].width == default_width }.map do |id, v|
|
298
|
+
[(@subsetter ? @subsetter.subset_glyph_id(id) : id), v[1].width]
|
300
299
|
end.sort!
|
301
300
|
@dict[:DescendantFonts].first.set_widths(widths, default_width: default_width)
|
302
301
|
end
|
@@ -305,11 +304,10 @@ module HexaPDF
|
|
305
304
|
# correctly.
|
306
305
|
def create_to_unicode_cmap
|
307
306
|
stream = HexaPDF::StreamData.new do
|
308
|
-
mapping = @encoded_glyphs.keys.map do |
|
307
|
+
mapping = @encoded_glyphs.keys.map! do |id|
|
309
308
|
# Using 0xFFFD as mentioned in Adobe #5411, last line before section 1.5
|
310
|
-
[(@subsetter ? @subsetter.subset_glyph_id(
|
311
|
-
|
312
|
-
end.sort_by(&:first)
|
309
|
+
[(@subsetter ? @subsetter.subset_glyph_id(id) : id), @cmap.gid_to_code(id) || 0xFFFD]
|
310
|
+
end.sort_by!(&:first)
|
313
311
|
HexaPDF::Font::CMap.create_to_unicode_cmap(mapping)
|
314
312
|
end
|
315
313
|
stream_obj = @document.add({}, stream: stream)
|
data/lib/hexapdf/font/type1.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -68,7 +68,7 @@ module HexaPDF
|
|
68
68
|
if source.respond_to?(:read)
|
69
69
|
new(source).parse
|
70
70
|
else
|
71
|
-
File.open(source) {|file| new(file).parse}
|
71
|
+
File.open(source) {|file| new(file).parse }
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -91,7 +91,7 @@ module HexaPDF
|
|
91
91
|
end
|
92
92
|
when /\AEnd/
|
93
93
|
sections.pop
|
94
|
-
break if sections.empty? && command == 'EndFontMetrics
|
94
|
+
break if sections.empty? && command == 'EndFontMetrics'
|
95
95
|
else
|
96
96
|
if sections.empty?
|
97
97
|
parse_global_font_information(command.to_sym)
|
@@ -180,7 +180,7 @@ module HexaPDF
|
|
180
180
|
# internal buffer.
|
181
181
|
def each_line
|
182
182
|
read_line
|
183
|
-
unless parse_name == 'StartFontMetrics'
|
183
|
+
unless parse_name == 'StartFontMetrics'
|
184
184
|
raise HexaPDF::Error, "The AFM file has to start with StartFontMetrics, not #{@line}"
|
185
185
|
end
|
186
186
|
until @io.eof?
|
@@ -197,7 +197,7 @@ module HexaPDF
|
|
197
197
|
# Parses and returns the name at the start of the line, with whitespace stripped.
|
198
198
|
def parse_name
|
199
199
|
result = @line[/\S+\s*/].to_s
|
200
|
-
@line[0, result.size] = ''
|
200
|
+
@line[0, result.size] = ''
|
201
201
|
result.strip!
|
202
202
|
result
|
203
203
|
end
|
@@ -221,7 +221,7 @@ module HexaPDF
|
|
221
221
|
|
222
222
|
# Parses the boolean at the start of the line.
|
223
223
|
def parse_boolean
|
224
|
-
parse_name == 'true'
|
224
|
+
parse_name == 'true'
|
225
225
|
end
|
226
226
|
|
227
227
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -87,7 +87,7 @@ module HexaPDF
|
|
87
87
|
def encoding
|
88
88
|
@encoding ||=
|
89
89
|
begin
|
90
|
-
if @metrics.encoding_scheme == 'AdobeStandardEncoding'
|
90
|
+
if @metrics.encoding_scheme == 'AdobeStandardEncoding'
|
91
91
|
Encoding.for_name(:StandardEncoding)
|
92
92
|
elsif font_name == 'ZapfDingbats' || font_name == 'Symbol'
|
93
93
|
Encoding.for_name((font_name + "Encoding").to_sym)
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -83,7 +83,6 @@ module HexaPDF
|
|
83
83
|
# Dominant width of vertical stems.
|
84
84
|
attr_accessor :dominant_vertical_stem_width
|
85
85
|
|
86
|
-
|
87
86
|
# Distance from the baseline for centering underlining strokes.
|
88
87
|
attr_accessor :underline_position
|
89
88
|
|
@@ -97,7 +96,6 @@ module HexaPDF
|
|
97
96
|
# Boolean specifying if the font is a fixed pitch (monospaced) font.
|
98
97
|
attr_accessor :is_fixed_pitch
|
99
98
|
|
100
|
-
|
101
99
|
# Mapping of character codes and names to CharacterMetrics objects.
|
102
100
|
attr_accessor :character_metrics
|
103
101
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -47,7 +47,7 @@ module HexaPDF
|
|
47
47
|
|
48
48
|
# The name of the glyph.
|
49
49
|
attr_reader :name
|
50
|
-
|
50
|
+
alias id name
|
51
51
|
|
52
52
|
# The string representation of the glyph.
|
53
53
|
attr_reader :str
|
@@ -98,7 +98,6 @@ module HexaPDF
|
|
98
98
|
|
99
99
|
private_constant :Glyph
|
100
100
|
|
101
|
-
|
102
101
|
# Returns the wrapped Type1 font object.
|
103
102
|
attr_reader :wrapped_font
|
104
103
|
|
@@ -155,11 +154,11 @@ module HexaPDF
|
|
155
154
|
|
156
155
|
# Returns an array of glyph objects representing the characters in the UTF-8 encoded string.
|
157
156
|
def decode_utf8(str)
|
158
|
-
str.
|
157
|
+
str.codepoints.map! do |c|
|
159
158
|
@codepoint_to_glyph[c] ||=
|
160
159
|
begin
|
161
|
-
name = Encoding::GlyphList.unicode_to_name('' << c, @zapf_dingbats_opt)
|
162
|
-
name = "u" << c.to_s(16).rjust(6, '0') if name == :'.notdef'
|
160
|
+
name = Encoding::GlyphList.unicode_to_name(+'' << c, @zapf_dingbats_opt)
|
161
|
+
name = +"u" << c.to_s(16).rjust(6, '0') if name == :'.notdef'
|
163
162
|
glyph(name)
|
164
163
|
end
|
165
164
|
end
|
@@ -221,13 +220,13 @@ module HexaPDF
|
|
221
220
|
min, max = @encoding.code_to_name.keys.minmax
|
222
221
|
@dict[:FirstChar] = min
|
223
222
|
@dict[:LastChar] = max
|
224
|
-
@dict[:Widths] = (min..max).map {|code| glyph(@encoding.name(code)).width}
|
223
|
+
@dict[:Widths] = (min..max).map {|code| glyph(@encoding.name(code)).width }
|
225
224
|
|
226
225
|
if VALID_ENCODING_NAMES.include?(@encoding.encoding_name)
|
227
226
|
@dict[:Encoding] = @encoding.encoding_name
|
228
227
|
else
|
229
228
|
differences = [min]
|
230
|
-
(min..max).each {|code| differences << @encoding.name(code)}
|
229
|
+
(min..max).each {|code| differences << @encoding.name(code) }
|
231
230
|
@dict[:Encoding] = {Differences: differences}
|
232
231
|
end
|
233
232
|
end
|
data/lib/hexapdf/font_loader.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
data/lib/hexapdf/image_loader.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|
@@ -49,7 +49,9 @@ module HexaPDF
|
|
49
49
|
# object.
|
50
50
|
#
|
51
51
|
# See: ITU T.81 B1.1.3
|
52
|
-
SOF_MARKERS = [
|
52
|
+
SOF_MARKERS = [
|
53
|
+
0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF
|
54
|
+
].freeze
|
53
55
|
|
54
56
|
# Adobe uses the marker 0xEE (APPE) for its purposes. We need to use it for determinig
|
55
57
|
# whether to invert the colors for CMYK/YCCK images or not (Adobe does this...).
|
@@ -87,7 +89,7 @@ module HexaPDF
|
|
87
89
|
# Creates a PDF image object from the JPEG file or IO stream.
|
88
90
|
def self.load(document, file_or_io)
|
89
91
|
dict = if file_or_io.kind_of?(String)
|
90
|
-
File.open(file_or_io, 'rb') {|io| image_data_from_io(io)}
|
92
|
+
File.open(file_or_io, 'rb') {|io| image_data_from_io(io) }
|
91
93
|
else
|
92
94
|
image_data_from_io(file_or_io)
|
93
95
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# -*- encoding: utf-8; frozen_string_literal: true -*-
|
2
2
|
#
|
3
3
|
#--
|
4
4
|
# This file is part of HexaPDF.
|
5
5
|
#
|
6
6
|
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
|
7
|
-
# Copyright (C) 2014-
|
7
|
+
# Copyright (C) 2014-2018 Thomas Leitner
|
8
8
|
#
|
9
9
|
# HexaPDF is free software: you can redistribute it and/or modify it
|
10
10
|
# under the terms of the GNU Affero General Public License version 3 as
|