hexapdf 0.5.0 → 0.6.0

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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +76 -2
  3. data/CONTRIBUTERS +1 -1
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/examples/boxes.rb +68 -0
  7. data/examples/graphics.rb +12 -12
  8. data/examples/{text_box_alignment.rb → text_layouter_alignment.rb} +14 -14
  9. data/examples/text_layouter_inline_boxes.rb +66 -0
  10. data/examples/{text_box_line_wrapping.rb → text_layouter_line_wrapping.rb} +9 -10
  11. data/examples/{text_box_shapes.rb → text_layouter_shapes.rb} +58 -54
  12. data/examples/text_layouter_styling.rb +125 -0
  13. data/examples/truetype.rb +5 -7
  14. data/lib/hexapdf/cli/command.rb +1 -0
  15. data/lib/hexapdf/configuration.rb +170 -106
  16. data/lib/hexapdf/content/canvas.rb +41 -36
  17. data/lib/hexapdf/content/graphics_state.rb +15 -0
  18. data/lib/hexapdf/content/operator.rb +1 -1
  19. data/lib/hexapdf/dictionary.rb +20 -8
  20. data/lib/hexapdf/dictionary_fields.rb +8 -6
  21. data/lib/hexapdf/document.rb +25 -26
  22. data/lib/hexapdf/document/fonts.rb +4 -4
  23. data/lib/hexapdf/document/images.rb +2 -2
  24. data/lib/hexapdf/document/pages.rb +16 -16
  25. data/lib/hexapdf/encryption/security_handler.rb +41 -9
  26. data/lib/hexapdf/filter/flate_decode.rb +1 -1
  27. data/lib/hexapdf/filter/lzw_decode.rb +1 -1
  28. data/lib/hexapdf/filter/predictor.rb +7 -1
  29. data/lib/hexapdf/font/true_type/font.rb +20 -0
  30. data/lib/hexapdf/font/type1/font.rb +23 -0
  31. data/lib/hexapdf/font_loader.rb +1 -0
  32. data/lib/hexapdf/font_loader/from_configuration.rb +2 -3
  33. data/lib/hexapdf/font_loader/from_file.rb +65 -0
  34. data/lib/hexapdf/image_loader/png.rb +2 -2
  35. data/lib/hexapdf/layout.rb +3 -2
  36. data/lib/hexapdf/layout/box.rb +146 -0
  37. data/lib/hexapdf/layout/inline_box.rb +40 -31
  38. data/lib/hexapdf/layout/{line_fragment.rb → line.rb} +12 -13
  39. data/lib/hexapdf/layout/style.rb +630 -41
  40. data/lib/hexapdf/layout/text_fragment.rb +80 -12
  41. data/lib/hexapdf/layout/{text_box.rb → text_layouter.rb} +164 -109
  42. data/lib/hexapdf/number_tree_node.rb +1 -1
  43. data/lib/hexapdf/parser.rb +4 -1
  44. data/lib/hexapdf/revisions.rb +11 -4
  45. data/lib/hexapdf/stream.rb +8 -9
  46. data/lib/hexapdf/tokenizer.rb +5 -3
  47. data/lib/hexapdf/type.rb +3 -0
  48. data/lib/hexapdf/type/action.rb +56 -0
  49. data/lib/hexapdf/type/actions.rb +52 -0
  50. data/lib/hexapdf/type/actions/go_to.rb +52 -0
  51. data/lib/hexapdf/type/actions/go_to_r.rb +54 -0
  52. data/lib/hexapdf/type/actions/launch.rb +73 -0
  53. data/lib/hexapdf/type/actions/uri.rb +65 -0
  54. data/lib/hexapdf/type/annotation.rb +85 -0
  55. data/lib/hexapdf/type/annotations.rb +51 -0
  56. data/lib/hexapdf/type/annotations/link.rb +70 -0
  57. data/lib/hexapdf/type/annotations/markup_annotation.rb +70 -0
  58. data/lib/hexapdf/type/annotations/text.rb +81 -0
  59. data/lib/hexapdf/type/catalog.rb +3 -1
  60. data/lib/hexapdf/type/embedded_file.rb +6 -11
  61. data/lib/hexapdf/type/file_specification.rb +4 -6
  62. data/lib/hexapdf/type/font.rb +3 -1
  63. data/lib/hexapdf/type/font_descriptor.rb +18 -16
  64. data/lib/hexapdf/type/form.rb +3 -1
  65. data/lib/hexapdf/type/graphics_state_parameter.rb +3 -1
  66. data/lib/hexapdf/type/image.rb +4 -2
  67. data/lib/hexapdf/type/info.rb +2 -5
  68. data/lib/hexapdf/type/names.rb +2 -5
  69. data/lib/hexapdf/type/object_stream.rb +2 -1
  70. data/lib/hexapdf/type/page.rb +14 -1
  71. data/lib/hexapdf/type/page_tree_node.rb +9 -6
  72. data/lib/hexapdf/type/resources.rb +2 -5
  73. data/lib/hexapdf/type/trailer.rb +2 -5
  74. data/lib/hexapdf/type/viewer_preferences.rb +2 -5
  75. data/lib/hexapdf/type/xref_stream.rb +3 -1
  76. data/lib/hexapdf/version.rb +1 -1
  77. data/test/hexapdf/common_tokenizer_tests.rb +3 -1
  78. data/test/hexapdf/content/test_canvas.rb +29 -3
  79. data/test/hexapdf/content/test_graphics_state.rb +11 -0
  80. data/test/hexapdf/content/test_operator.rb +3 -2
  81. data/test/hexapdf/document/test_fonts.rb +8 -8
  82. data/test/hexapdf/document/test_images.rb +4 -12
  83. data/test/hexapdf/document/test_pages.rb +7 -7
  84. data/test/hexapdf/encryption/test_security_handler.rb +1 -5
  85. data/test/hexapdf/filter/test_predictor.rb +40 -12
  86. data/test/hexapdf/font/true_type/test_font.rb +16 -0
  87. data/test/hexapdf/font/type1/test_font.rb +30 -0
  88. data/test/hexapdf/font_loader/test_from_file.rb +29 -0
  89. data/test/hexapdf/font_loader/test_standard14.rb +4 -3
  90. data/test/hexapdf/layout/test_box.rb +104 -0
  91. data/test/hexapdf/layout/test_inline_box.rb +24 -10
  92. data/test/hexapdf/layout/{test_line_fragment.rb → test_line.rb} +9 -9
  93. data/test/hexapdf/layout/test_style.rb +519 -31
  94. data/test/hexapdf/layout/test_text_fragment.rb +136 -15
  95. data/test/hexapdf/layout/{test_text_box.rb → test_text_layouter.rb} +224 -144
  96. data/test/hexapdf/layout/test_text_shaper.rb +1 -1
  97. data/test/hexapdf/test_configuration.rb +12 -6
  98. data/test/hexapdf/test_dictionary.rb +27 -2
  99. data/test/hexapdf/test_dictionary_fields.rb +10 -1
  100. data/test/hexapdf/test_document.rb +14 -13
  101. data/test/hexapdf/test_parser.rb +12 -0
  102. data/test/hexapdf/test_revisions.rb +34 -0
  103. data/test/hexapdf/test_stream.rb +1 -1
  104. data/test/hexapdf/test_type.rb +18 -0
  105. data/test/hexapdf/test_writer.rb +2 -2
  106. data/test/hexapdf/type/actions/test_launch.rb +24 -0
  107. data/test/hexapdf/type/actions/test_uri.rb +23 -0
  108. data/test/hexapdf/type/annotations/test_link.rb +19 -0
  109. data/test/hexapdf/type/annotations/test_markup_annotation.rb +22 -0
  110. data/test/hexapdf/type/annotations/test_text.rb +38 -0
  111. data/test/hexapdf/type/test_annotation.rb +38 -0
  112. data/test/hexapdf/type/test_file_specification.rb +0 -7
  113. data/test/hexapdf/type/test_info.rb +0 -5
  114. data/test/hexapdf/type/test_page.rb +14 -0
  115. data/test/hexapdf/type/test_page_tree_node.rb +4 -1
  116. data/test/hexapdf/type/test_trailer.rb +0 -4
  117. data/test/test_helper.rb +6 -3
  118. metadata +36 -15
  119. data/examples/text_box_inline_boxes.rb +0 -56
  120. data/examples/text_box_styling.rb +0 -72
  121. data/test/hexapdf/type/test_embedded_file.rb +0 -16
  122. data/test/hexapdf/type/test_names.rb +0 -9
@@ -6,13 +6,6 @@ require 'stringio'
6
6
  require 'hexapdf/type/file_specification'
7
7
  require 'hexapdf/document'
8
8
 
9
- describe HexaPDF::Type::FileSpecification::EFDictionary do
10
- it "uses a custom type" do
11
- obj = HexaPDF::Type::FileSpecification::EFDictionary.new({})
12
- assert_equal(:XXFilespecEFDictionary, obj.type)
13
- end
14
- end
15
-
16
9
  describe HexaPDF::Type::FileSpecification do
17
10
  before do
18
11
  @doc = HexaPDF::Document.new
@@ -6,9 +6,4 @@ describe HexaPDF::Type::Info do
6
6
  obj = HexaPDF::Type::Info.new({})
7
7
  assert(obj.must_be_indirect?)
8
8
  end
9
-
10
- it "uses a custom type" do
11
- obj = HexaPDF::Type::Info.new({})
12
- assert_equal(:XXInfo, obj.type)
13
- end
14
9
  end
@@ -11,6 +11,20 @@ describe HexaPDF::Type::Page do
11
11
  @doc = HexaPDF::Document.new
12
12
  end
13
13
 
14
+ describe "::media_box" do
15
+ it "returns the media box for a given paper size" do
16
+ assert_equal([0, 0, 595, 842], HexaPDF::Type::Page.media_box(:A4))
17
+ end
18
+
19
+ it "respects the orientation key" do
20
+ assert_equal([0, 0, 842, 595], HexaPDF::Type::Page.media_box(:A4, orientation: :landscape))
21
+ end
22
+
23
+ it "fails if the paper size is unknown" do
24
+ assert_raises(HexaPDF::Error) { HexaPDF::Type::Page.media_box(:Unknown) }
25
+ end
26
+ end
27
+
14
28
  # Asserts that the page's contents contains the operators.
15
29
  def assert_operators(page, operators)
16
30
  processor = TestHelper::OperatorRecorder.new
@@ -80,13 +80,16 @@ describe HexaPDF::Type::PageTreeNode do
80
80
  end
81
81
 
82
82
  describe "insert_page" do
83
- it "uses an empty new page when none is provided" do
83
+ it "uses an empty new page when none is provided, respecting the set configuration options" do
84
+ @doc.config['page.default_media_box'] = :A4
85
+ @doc.config['page.default_media_orientation'] = :landscape
84
86
  page = @root.insert_page(3)
85
87
  assert_equal([page], @root[:Kids])
86
88
  assert_equal(1, @root.page_count)
87
89
  assert_equal(:Page, page[:Type])
88
90
  assert_equal(@root, page[:Parent])
89
91
  assert_kind_of(HexaPDF::Rectangle, page[:MediaBox])
92
+ assert_equal([0, 0, 842, 595], page[:MediaBox].value)
90
93
  assert_equal({}, page[:Resources].value)
91
94
  refute(@root.value.key?(:Parent))
92
95
  end
@@ -16,10 +16,6 @@ describe HexaPDF::Type::Trailer do
16
16
  @obj = HexaPDF::Type::Trailer.new({Size: 10, Root: root}, document: @doc)
17
17
  end
18
18
 
19
- it "uses a custom type" do
20
- assert_equal(:XXTrailer, @obj.type)
21
- end
22
-
23
19
  it "returns the catalog object, creating it if needed" do
24
20
  doc = Minitest::Mock.new
25
21
  doc.expect(:add, :val, [{Type: :Catalog}])
@@ -1,8 +1,11 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require 'simplecov'
4
- SimpleCov.start do
5
- add_filter '/test/'
3
+ begin
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter '/test/'
7
+ end
8
+ rescue LoadError
6
9
  end
7
10
 
8
11
  gem 'minitest'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexapdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Leitner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-24 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse
@@ -155,6 +155,7 @@ files:
155
155
  - data/hexapdf/encoding/glyphlist.txt
156
156
  - data/hexapdf/encoding/zapfdingbats.txt
157
157
  - examples/arc.rb
158
+ - examples/boxes.rb
158
159
  - examples/emoji-smile.png
159
160
  - examples/emoji-wink.png
160
161
  - examples/graphics.rb
@@ -164,11 +165,11 @@ files:
164
165
  - examples/optimizing.rb
165
166
  - examples/show_char_bboxes.rb
166
167
  - examples/standard_pdf_fonts.rb
167
- - examples/text_box_alignment.rb
168
- - examples/text_box_inline_boxes.rb
169
- - examples/text_box_line_wrapping.rb
170
- - examples/text_box_shapes.rb
171
- - examples/text_box_styling.rb
168
+ - examples/text_layouter_alignment.rb
169
+ - examples/text_layouter_inline_boxes.rb
170
+ - examples/text_layouter_line_wrapping.rb
171
+ - examples/text_layouter_shapes.rb
172
+ - examples/text_layouter_styling.rb
172
173
  - examples/truetype.rb
173
174
  - lib/hexapdf.rb
174
175
  - lib/hexapdf/cli.rb
@@ -266,6 +267,7 @@ files:
266
267
  - lib/hexapdf/font/type1_wrapper.rb
267
268
  - lib/hexapdf/font_loader.rb
268
269
  - lib/hexapdf/font_loader/from_configuration.rb
270
+ - lib/hexapdf/font_loader/from_file.rb
269
271
  - lib/hexapdf/font_loader/standard14.rb
270
272
  - lib/hexapdf/image_loader.rb
271
273
  - lib/hexapdf/image_loader/jpeg.rb
@@ -273,12 +275,13 @@ files:
273
275
  - lib/hexapdf/image_loader/png.rb
274
276
  - lib/hexapdf/importer.rb
275
277
  - lib/hexapdf/layout.rb
278
+ - lib/hexapdf/layout/box.rb
276
279
  - lib/hexapdf/layout/inline_box.rb
277
- - lib/hexapdf/layout/line_fragment.rb
280
+ - lib/hexapdf/layout/line.rb
278
281
  - lib/hexapdf/layout/numeric_refinements.rb
279
282
  - lib/hexapdf/layout/style.rb
280
- - lib/hexapdf/layout/text_box.rb
281
283
  - lib/hexapdf/layout/text_fragment.rb
284
+ - lib/hexapdf/layout/text_layouter.rb
282
285
  - lib/hexapdf/layout/text_shaper.rb
283
286
  - lib/hexapdf/name_tree_node.rb
284
287
  - lib/hexapdf/number_tree_node.rb
@@ -295,6 +298,17 @@ files:
295
298
  - lib/hexapdf/task/optimize.rb
296
299
  - lib/hexapdf/tokenizer.rb
297
300
  - lib/hexapdf/type.rb
301
+ - lib/hexapdf/type/action.rb
302
+ - lib/hexapdf/type/actions.rb
303
+ - lib/hexapdf/type/actions/go_to.rb
304
+ - lib/hexapdf/type/actions/go_to_r.rb
305
+ - lib/hexapdf/type/actions/launch.rb
306
+ - lib/hexapdf/type/actions/uri.rb
307
+ - lib/hexapdf/type/annotation.rb
308
+ - lib/hexapdf/type/annotations.rb
309
+ - lib/hexapdf/type/annotations/link.rb
310
+ - lib/hexapdf/type/annotations/markup_annotation.rb
311
+ - lib/hexapdf/type/annotations/text.rb
298
312
  - lib/hexapdf/type/catalog.rb
299
313
  - lib/hexapdf/type/cid_font.rb
300
314
  - lib/hexapdf/type/embedded_file.rb
@@ -469,15 +483,17 @@ files:
469
483
  - test/hexapdf/font/type1/test_font_metrics.rb
470
484
  - test/hexapdf/font/type1/test_pfb_parser.rb
471
485
  - test/hexapdf/font_loader/test_from_configuration.rb
486
+ - test/hexapdf/font_loader/test_from_file.rb
472
487
  - test/hexapdf/font_loader/test_standard14.rb
473
488
  - test/hexapdf/image_loader/test_jpeg.rb
474
489
  - test/hexapdf/image_loader/test_pdf.rb
475
490
  - test/hexapdf/image_loader/test_png.rb
491
+ - test/hexapdf/layout/test_box.rb
476
492
  - test/hexapdf/layout/test_inline_box.rb
477
- - test/hexapdf/layout/test_line_fragment.rb
493
+ - test/hexapdf/layout/test_line.rb
478
494
  - test/hexapdf/layout/test_style.rb
479
- - test/hexapdf/layout/test_text_box.rb
480
495
  - test/hexapdf/layout/test_text_fragment.rb
496
+ - test/hexapdf/layout/test_text_layouter.rb
481
497
  - test/hexapdf/layout/test_text_shaper.rb
482
498
  - test/hexapdf/task/test_dereference.rb
483
499
  - test/hexapdf/task/test_optimize.rb
@@ -497,11 +513,17 @@ files:
497
513
  - test/hexapdf/test_serializer.rb
498
514
  - test/hexapdf/test_stream.rb
499
515
  - test/hexapdf/test_tokenizer.rb
516
+ - test/hexapdf/test_type.rb
500
517
  - test/hexapdf/test_writer.rb
501
518
  - test/hexapdf/test_xref_section.rb
519
+ - test/hexapdf/type/actions/test_launch.rb
520
+ - test/hexapdf/type/actions/test_uri.rb
521
+ - test/hexapdf/type/annotations/test_link.rb
522
+ - test/hexapdf/type/annotations/test_markup_annotation.rb
523
+ - test/hexapdf/type/annotations/test_text.rb
524
+ - test/hexapdf/type/test_annotation.rb
502
525
  - test/hexapdf/type/test_catalog.rb
503
526
  - test/hexapdf/type/test_cid_font.rb
504
- - test/hexapdf/type/test_embedded_file.rb
505
527
  - test/hexapdf/type/test_file_specification.rb
506
528
  - test/hexapdf/type/test_font.rb
507
529
  - test/hexapdf/type/test_font_descriptor.rb
@@ -511,7 +533,6 @@ files:
511
533
  - test/hexapdf/type/test_form.rb
512
534
  - test/hexapdf/type/test_image.rb
513
535
  - test/hexapdf/type/test_info.rb
514
- - test/hexapdf/type/test_names.rb
515
536
  - test/hexapdf/type/test_object_stream.rb
516
537
  - test/hexapdf/type/test_page.rb
517
538
  - test/hexapdf/type/test_page_tree_node.rb
@@ -538,7 +559,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
538
559
  requirements:
539
560
  - - ">="
540
561
  - !ruby/object:Gem::Version
541
- version: '2.3'
562
+ version: '2.4'
542
563
  required_rubygems_version: !ruby/object:Gem::Requirement
543
564
  requirements:
544
565
  - - ">="
@@ -546,7 +567,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
546
567
  version: '0'
547
568
  requirements: []
548
569
  rubyforge_project:
549
- rubygems_version: 2.6.8
570
+ rubygems_version: 2.6.14
550
571
  signing_key:
551
572
  specification_version: 4
552
573
  summary: HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
@@ -1,56 +0,0 @@
1
- # ## Text Box with Inline Boxes
2
- #
3
- # The [HexaPDF::Layout::TextBox] class can be used to easily lay out text mixed
4
- # with inline boxes.
5
- #
6
- # Inline boxes are used for showing graphics that follow the flow of the text.
7
- # This means that their horizontal and their general vertical position is
8
- # determined by the text layout functionality. However, inline boxes may be
9
- # vertically aligned to various positions, like the baseline, the top/bottom of
10
- # the text and the top/bottom of the line.
11
- #
12
- # This example shows some text containing emoticons that are replaced with their
13
- # graphical representation, with normal smileys being aligned to the baseline
14
- # and winking smileys to the top of the line.
15
- #
16
- # Usage:
17
- # : `ruby text_box_inline_boxes.rb`
18
- #
19
-
20
- require 'hexapdf'
21
-
22
- include HexaPDF::Layout
23
-
24
- sample_text = "Lorem ipsum :-) dolor sit amet, consectetur adipiscing
25
- ;-) elit, sed do eiusmod tempor incididunt :-) ut labore et dolore magna
26
- aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
27
- laboris nisi ut aliquip ex ea commodo consequat ;-). Duis aute irure
28
- dolor in reprehenderit in voluptate velit esse cillum :-) dolore eu
29
- fugiat nulla pariatur. ".tr("\n", ' ') * 4
30
-
31
- doc = HexaPDF::Document.new
32
- emoji_smile = doc.images.add(File.join(__dir__, "emoji-smile.png"))
33
- emoji_wink = doc.images.add(File.join(__dir__, "emoji-wink.png"))
34
- size = 10
35
-
36
- items = sample_text.split(/(:-\)|;-\))/).map do |part|
37
- case part
38
- when ':-)'
39
- InlineBox.new(size * 2, size * 2, valign: :baseline) do |box, canvas|
40
- canvas.image(emoji_smile, at: [0, 0], width: box.width)
41
- end
42
- when ';-)'
43
- InlineBox.new(size, size, valign: :top) do |box, canvas|
44
- canvas.image(emoji_wink, at: [0, 0], width: box.width)
45
- end
46
- else
47
- TextFragment.create(part, font: doc.fonts.load("Times"), font_size: 18)
48
- end
49
- end
50
-
51
- box = TextBox.new(items: items, width: 500, height: 700)
52
- box.style.align = :justify
53
- box.style.line_spacing(:proportional, 1.5)
54
- box.draw(doc.pages.add.canvas, 50, 800)
55
-
56
- doc.write("text_box_inline_boxes.pdf")
@@ -1,72 +0,0 @@
1
- # ## Text Box Styling
2
- #
3
- # The text used as part of a [HexaPDF::Layout::TextBox] class can be styled
4
- # using [HexaPDF::Layout::Style]. To do this [HexaPDF::Layout::TextFragment]
5
- # objects have to be created with the needed styling and then added to a text
6
- # box. In addition the style objects can be used for styling text boxes
7
- # themselves.
8
- #
9
- # This example shows how to do this and shows off the various styling option.
10
- #
11
- # Usage:
12
- # : `ruby text_box_styling.rb`
13
- #
14
-
15
- require 'hexapdf'
16
-
17
- # Wraps the text in a TextFragment using the given style.
18
- def fragment(text, style)
19
- HexaPDF::Layout::TextFragment.new(items: style.font.decode_utf8(text),
20
- style: style)
21
- end
22
-
23
- # Draws the text box at the given [x, y] position onto the canvas.
24
- def draw_box(box, canvas, x, y)
25
- rest, height = box.fit
26
- raise "Error" unless rest.empty?
27
- box.draw(canvas, x, y)
28
- y - height
29
- end
30
-
31
- sample_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,
32
- sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
33
- enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
34
- aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
35
- in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
36
- Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
37
- officia deserunt mollit anim id est laborum. ".tr("\n", ' ') * 3
38
-
39
- doc = HexaPDF::Document.new
40
-
41
- heading = HexaPDF::Layout::Style.new(font: doc.fonts.load("Helvetica", variant: :bold),
42
- font_size: 16, align: :center)
43
- body = HexaPDF::Layout::Style.new(font: doc.fonts.load("Times"),
44
- font_size: 10, align: :justify,
45
- text_indent: 20)
46
- body.line_spacing(:proportional, 1.5)
47
- standout = HexaPDF::Layout::Style.new(font: doc.fonts.load("Times", variant: :bold),
48
- font_size: 14)
49
-
50
- canvas = doc.pages.add.canvas
51
- y_base = 800
52
- left = 50
53
- width = 500
54
-
55
- box = HexaPDF::Layout::TextBox.new(items: [fragment("This is a header", heading)],
56
- width: width, style: heading)
57
- y_base = draw_box(box, canvas, left, y_base)
58
-
59
- box = HexaPDF::Layout::TextBox.new(items: [fragment(sample_text, body)],
60
- width: width, style: body)
61
- y_base = draw_box(box, canvas, left, y_base - 20)
62
-
63
- items = [
64
- fragment(sample_text[0, 50], body), fragment(sample_text[50, 15], standout),
65
- fragment(sample_text[65, 150], body), fragment(sample_text[215, 50], standout),
66
- fragment(sample_text[265...800], body), fragment(sample_text[800, 40], standout),
67
- fragment(sample_text[840..-1], body)
68
- ]
69
- box = HexaPDF::Layout::TextBox.new(items: items, width: width, style: body)
70
- draw_box(box, canvas, left, y_base - 20)
71
-
72
- doc.write("text_box_styling.pdf", optimize: true)
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
- require 'hexapdf/type/embedded_file'
3
-
4
- describe HexaPDF::Type::EmbeddedFile::MacInfo do
5
- it "uses a custom type" do
6
- obj = HexaPDF::Type::EmbeddedFile::MacInfo.new({})
7
- assert_equal(:XXEmbeddedFileParametersMacInfo, obj.type)
8
- end
9
- end
10
-
11
- describe HexaPDF::Type::EmbeddedFile::Parameters do
12
- it "uses a custom type" do
13
- obj = HexaPDF::Type::EmbeddedFile::Parameters.new({})
14
- assert_equal(:XXEmbeddedFileParameters, obj.type)
15
- end
16
- end
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
- require 'hexapdf/type/names'
3
-
4
- describe HexaPDF::Type::Names do
5
- it "uses a custom type" do
6
- obj = HexaPDF::Type::Names.new({})
7
- assert_equal(:XXNames, obj.type)
8
- end
9
- end