hexapdf 0.34.0 → 0.34.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00aaef323df26b1a17c6e4ee39787c92037e8ae887713b28c3674962fcb6ac26
4
- data.tar.gz: a46ecda2514bc5c044d115370f66402fc22ad3f8c8dfa1741e057b6849a6b952
3
+ metadata.gz: 5f2aec69ce9d984994c40912cd86d4cd10c38f23d5b975288ab11cd9e967d28b
4
+ data.tar.gz: 3012460ef7ca03cf81d65ac4a507dd7e23f31292d60d6e101bc555eee60f66a0
5
5
  SHA512:
6
- metadata.gz: a15e468bdc852fd4c16286ba0e4829fcd3fb3be64aa48c429246216fbfe1c856cb8e155bfefa83c47b99246e7161f20a1de54769aa222dbcdfdb25f8be777643
7
- data.tar.gz: d75048ff9d77601d93893cceb0c73673410695e3ea381e17d27de8c92d7de3d29d2ed467e44df6362dd28d3ee374a8e5710e5f1323393ee2e4104cdcecef1112
6
+ metadata.gz: 10004ae421f4daefb3fa0a3672b56ff8cd208048ca61aaaa75de687af4ac0f9bad8470de011f4944828c4b530a61cd0f52d27dc74530af365f556bdbfcaf3373
7
+ data.tar.gz: 12c0e3dbca50e6dd05a8e2a211aa8459e7e085a30570769af4b98b85c46e36202275765ea64b2c5805ccca4bc8f28b3b5d1c1322085978b3e0ce5cfce6e9f6bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 0.34.1 - 2023-11-01
2
+
3
+ ### Added
4
+
5
+ * Setting of /SMask key in graphics state parameters operator
6
+
7
+ ### Fixed
8
+
9
+ * [HexaPDF::Composer#page_style] to set a page style when no attributes are
10
+ given but a block is
11
+ * [HexaPDF::Type::Page#each_annotation] and
12
+ [HexaPDF::Type::Page#flatten_annotations] to process certain invalid /Annot
13
+ keys without errors
14
+
15
+
1
16
  ## 0.34.0 - 2023-10-22
2
17
 
3
18
  ### Added
@@ -281,7 +281,7 @@ module HexaPDF
281
281
  #
282
282
  # See: HexaPDF::Layout::PageStyle
283
283
  def page_style(name, **attributes, &block)
284
- if attributes.empty?
284
+ if attributes.empty? && block.nil?
285
285
  @page_styles[name]
286
286
  else
287
287
  @page_styles[name] = HexaPDF::Layout::PageStyle.new(**attributes, &block)
@@ -326,7 +326,6 @@ module HexaPDF
326
326
  ops[:M].invoke(processor, dict[:ML]) if dict.key?(:ML)
327
327
  ops[:d].invoke(processor, *dict[:D]) if dict.key?(:D)
328
328
  ops[:ri].invoke(processor, dict[:RI]) if dict.key?(:RI)
329
- # TODO: dict[:SMask] works differently than operator!
330
329
 
331
330
  # No content operator exists for the following parameters
332
331
  gs = processor.graphics_state
@@ -335,6 +334,7 @@ module HexaPDF
335
334
  gs.stroke_alpha = dict[:CA] if dict.key?(:CA)
336
335
  gs.fill_alpha = dict[:ca] if dict.key?(:ca)
337
336
  gs.alpha_source = dict[:AIS] if dict.key?(:AIS)
337
+ gs.soft_mask = dict[:SMask] if dict.key?(:SMask)
338
338
  gs.text_knockout = dict[:TK] if dict.key?(:TK)
339
339
  if dict.key?(:Font)
340
340
  gs.font = processor.resources.document.deref(dict[:Font][0])
@@ -534,7 +534,7 @@ module HexaPDF
534
534
  def each_annotation
535
535
  return to_enum(__method__) unless block_given?
536
536
  Array(self[:Annots]).each do |annotation|
537
- next unless annotation&.key?(:Subtype) && annotation&.key?(:Rect)
537
+ next unless annotation?(annotation)
538
538
  yield(document.wrap(annotation, type: :Annot))
539
539
  end
540
540
  self
@@ -551,12 +551,14 @@ module HexaPDF
551
551
  # field itself.
552
552
  def flatten_annotations(annotations = self[:Annots])
553
553
  not_flattened = Array(annotations) || []
554
- return not_flattened unless key?(:Annots)
554
+ unless self[:Annots].kind_of?(PDFArray)
555
+ return (not_flattened == [annotations] ? [] : not_flattened)
556
+ end
555
557
 
556
558
  annotations = if annotations == self[:Annots]
557
559
  not_flattened
558
560
  else
559
- not_flattened & Array(self[:Annots])
561
+ not_flattened & self[:Annots]
560
562
  end
561
563
  return not_flattened if annotations.empty?
562
564
 
@@ -569,8 +571,8 @@ module HexaPDF
569
571
  to_delete = []
570
572
  not_flattened -= annotations
571
573
  annotations.each do |annotation|
572
- unless annotation&.key?(:Subtype) && annotation&.key?(:Rect)
573
- to_delete << annotation if annotation
574
+ unless annotation?(annotation)
575
+ self[:Annots].delete(annotation)
574
576
  next
575
577
  end
576
578
 
@@ -637,6 +639,12 @@ module HexaPDF
637
639
 
638
640
  private
639
641
 
642
+ # Returns +true+ if the given object seems to be an annotation.
643
+ def annotation?(obj)
644
+ (obj.kind_of?(Hash) || obj.kind_of?(Dictionary)) &&
645
+ obj&.key?(:Subtype) && obj&.key?(:Rect)
646
+ end
647
+
640
648
  # Ensures that the required inheritable fields are set.
641
649
  def perform_validation(&block)
642
650
  root_node = document.catalog.pages
@@ -37,6 +37,6 @@
37
37
  module HexaPDF
38
38
 
39
39
  # The version of HexaPDF.
40
- VERSION = '0.34.0'
40
+ VERSION = '0.34.1'
41
41
 
42
42
  end
@@ -195,7 +195,8 @@ describe_operator :SetGraphicsStateParameters, :gs do
195
195
  font.glyph_scaling_factor = 0.01
196
196
  @processor.resources[:ExtGState] = {Name: {LW: 10, LC: 2, LJ: 2, ML: 2, D: [[3, 5], 2],
197
197
  RI: 2, SA: true, BM: :Multiply, CA: 0.5, ca: 0.5,
198
- AIS: true, TK: false, Font: [font, 10]}}
198
+ AIS: true, TK: false, Font: [font, 10],
199
+ SMask: {Type: :Mask, S: :Luminosity}}}
199
200
  @processor.resources.define_singleton_method(:document) do
200
201
  Object.new.tap {|obj| obj.define_singleton_method(:deref) {|o| o } }
201
202
  end
@@ -213,6 +214,7 @@ describe_operator :SetGraphicsStateParameters, :gs do
213
214
  assert_equal(0.5, gs.stroke_alpha)
214
215
  assert_equal(0.5, gs.fill_alpha)
215
216
  assert(gs.alpha_source)
217
+ assert_equal({Type: :Mask, S: :Luminosity}, gs.soft_mask)
216
218
  assert_equal(font, gs.font)
217
219
  assert_equal(10, gs.font_size)
218
220
  refute(gs.text_knockout)
@@ -119,6 +119,26 @@ describe HexaPDF::Composer do
119
119
  end
120
120
  end
121
121
 
122
+ describe "page_style" do
123
+ it "returns the page style if no argument or block is given" do
124
+ page_style = @composer.page_style(:default)
125
+ assert_kind_of(HexaPDF::Layout::PageStyle, page_style)
126
+ assert_equal(:A4, page_style.page_size)
127
+ end
128
+
129
+ it "sets a page style using the given attributes" do
130
+ @composer.page_style(:other, page_size: :A3)
131
+ assert_equal(:A3, @composer.page_style(:other).page_size)
132
+ end
133
+
134
+ it "sets a page style using default attributes but with a block" do
135
+ @composer.page_style(:other) {|canvas, style| style.frame = :hallo }
136
+ style = @composer.page_style(:other)
137
+ style.create_page(@composer.document)
138
+ assert_equal(:hallo, style.frame)
139
+ end
140
+ end
141
+
122
142
  describe "text/formatted_text/image/box/method_missing" do
123
143
  before do
124
144
  test_self = self
@@ -40,7 +40,7 @@ describe HexaPDF::Writer do
40
40
  219
41
41
  %%EOF
42
42
  3 0 obj
43
- <</Producer(HexaPDF version 0.34.0)>>
43
+ <</Producer(HexaPDF version 0.34.1)>>
44
44
  endobj
45
45
  xref
46
46
  3 1
@@ -72,7 +72,7 @@ describe HexaPDF::Writer do
72
72
  141
73
73
  %%EOF
74
74
  6 0 obj
75
- <</Producer(HexaPDF version 0.34.0)>>
75
+ <</Producer(HexaPDF version 0.34.1)>>
76
76
  endobj
77
77
  2 0 obj
78
78
  <</Length 10>>stream
@@ -214,7 +214,7 @@ describe HexaPDF::Writer do
214
214
  <</Type/Page/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<<>>>>
215
215
  endobj
216
216
  5 0 obj
217
- <</Producer(HexaPDF version 0.34.0)>>
217
+ <</Producer(HexaPDF version 0.34.1)>>
218
218
  endobj
219
219
  4 0 obj
220
220
  <</Root 1 0 R/Info 5 0 R/Size 6/Type/XRef/W[1 1 2]/Index[0 6]/Filter/FlateDecode/DecodeParms<</Columns 4/Predictor 12>>/Length 33>>stream
@@ -592,11 +592,12 @@ describe HexaPDF::Type::Page do
592
592
  end
593
593
 
594
594
  it "gracefully handles invalid /Annot key values" do
595
- @page[:Annots] << nil << @doc.add({}, stream: '')
595
+ @page[:Annots] << nil << @doc.add({}, stream: '') << 543
596
596
  result = @page.flatten_annotations
597
597
  assert(result.empty?)
598
598
  assert(@annot1.null?)
599
599
  assert(@annot2.null?)
600
+ assert_equal([], @page[:Annots].value)
600
601
 
601
602
  @page[:Annots] = @doc.add({}, stream: '')
602
603
  result = @page.flatten_annotations
@@ -722,12 +723,13 @@ describe HexaPDF::Type::Page do
722
723
  annot1 = @doc.add({Type: :Annot, Subtype: :Text, Rect: [100, 100, 160, 125]})
723
724
  annot2 = @doc.add({Subtype: :Unknown, Rect: [10, 10, 70, 35]})
724
725
  not_an_annot = @doc.add({}, stream: '')
725
- page[:Annots] = [not_an_annot, annot1, nil, annot2]
726
+ page[:Annots] = [not_an_annot, annot1, nil, annot2, {Type: :Annot, Subtype: :Text, Rect: [0, 0, 0, 0]}]
726
727
 
727
728
  annotations = page.each_annotation.to_a
728
- assert_equal(2, annotations.size)
729
+ assert_equal(3, annotations.size)
729
730
  assert_equal([100, 100, 160, 125], annotations[0][:Rect])
730
731
  assert_equal(:Annot, annotations[0].type)
731
732
  assert_equal(:Annot, annotations[1].type)
733
+ assert_equal(:Annot, annotations[2].type)
732
734
  end
733
735
  end
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.34.0
4
+ version: 0.34.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Leitner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-22 00:00:00.000000000 Z
11
+ date: 2023-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmdparse