standard-procedure-consolidate 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cbb574bced054ba32f67038b7f91eed28836470eb0d40e7bbbbcaefdca41142
4
- data.tar.gz: 64438e3b31ea879c4c10d42afa08873a44528ec89ba60d3e248c07baf1bd028b
3
+ metadata.gz: f54b1e9134c3e9ec1a9a87ba47dd0a0842e430f9bc2ad2801fdaaecb6d4784c1
4
+ data.tar.gz: 881e583371a1cc58b7742ea74cb90e47b934198d03a6d76d538a7c48330378cf
5
5
  SHA512:
6
- metadata.gz: 947a488ad5d98514589cbaa9495cd7970e7821832a05f74719821d9423785fc9e04f2563b7c4c4c34e5c5c25c32c6a1fd175cbd862e247cdfc2e8612663412b4
7
- data.tar.gz: cc6e12303d7abea0be365df9c443d868d18bc658f3696488a6826ce83b93cfd17e588aecc6f3af94a9ac46e9621bc483800effd44e37b550dc752767757fe9fc
6
+ metadata.gz: a48b68b17ba644b23b4bd81ff30a195260a00343aeba22cfcfd77151e1d22f4d13dff7b54409d87737b9610f888fd574b624a4aac5bcd3c114500be3626f9267
7
+ data.tar.gz: 14acf38a2067475f7a5cd25e2783aed5f2299d764b051906c833dba4d1ae4f515ab2929606990bdb87da74a139aa587ef23682d5297d896a6f9293d6c16dcdd1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.4.3] - 2025-02-24
2
+
3
+ Use wp:anchor tags instead of wp:inline tags for embedding images
4
+
1
5
  # [0.4.1] - 2024-12-18
2
6
 
3
7
  Replace image merge fields with blanks if the image data is not provided
@@ -0,0 +1 @@
1
+ 646e5a14ad25738c476cb587c9012fff12687fc7e26e555b6d17a61d69ae1477bdf1a55326b952bbc05dde988d945c3a9504ebeb58b2ff6598c10be5be26c6cb
@@ -0,0 +1 @@
1
+ c1a13d3d2b2c50741b839e2ca20c730b2689fac090e9c67660950a506ce83b3b9e07e31f3de205ec67dcbf4b1eff462f8fc507468fdb378e864e9a5952b9decf
@@ -18,15 +18,16 @@ module Consolidate
18
18
  # Convert height from pixels to EMU
19
19
  def height = super * emu_per_height_pixel
20
20
 
21
- # Get the width of this image in EMU up to a maximum page width (also in EMU)
22
- def clamped_width(maximum = 7_772_400) = [width, maximum].min
21
+ def emu_per_width_pixel = EMU_PER_PIXEL * 72 / dpi[:x]
23
22
 
24
- # Get the height of this image in EMU adjusted for a maximum page width (also in EMU)
25
- def clamped_height(maximum = 7_772_400) = (height * clamped_width(maximum).to_f / width.to_f).to_i
23
+ def emu_per_height_pixel = EMU_PER_PIXEL * 72 / dpi[:y]
26
24
 
27
- def emu_per_width_pixel = 914_400 / dpi[:x]
28
-
29
- def emu_per_height_pixel = 914_400 / dpi[:y]
25
+ DEFAULT_PAGE_WIDTH = 12_240
26
+ TWENTIETHS_OF_A_POINT_TO_EMU = 635
27
+ DEFAULT_PAGE_WIDTH_IN_EMU = DEFAULT_PAGE_WIDTH * TWENTIETHS_OF_A_POINT_TO_EMU
28
+ EMU_PER_PIXEL = 9525
29
+ DEFAULT_PAGE_HEIGHT = DEFAULT_PAGE_WIDTH * 11 / 8.5 # Assuming US Letter size
30
+ DEFAULT_PAGE_HEIGHT_IN_EMU = DEFAULT_PAGE_HEIGHT * TWENTIETHS_OF_A_POINT_TO_EMU
30
31
  end
31
32
  end
32
33
  end
@@ -12,27 +12,58 @@ module Consolidate
12
12
 
13
13
  Nokogiri::XML::Node.new("w:drawing", document).tap do |drawing|
14
14
  drawing["xmlns:a"] = "http://schemas.openxmlformats.org/drawingml/2006/main"
15
- drawing << Nokogiri::XML::Node.new("wp:inline", document).tap do |inline|
16
- inline["distT"] = "0"
17
- inline["distB"] = "0"
18
- inline["distL"] = "0"
19
- inline["distR"] = "0"
20
- inline << Nokogiri::XML::Node.new("wp:extent", document).tap do |extent|
15
+ drawing << Nokogiri::XML::Node.new("wp:anchor", document).tap do |anchor|
16
+ anchor["behindDoc"] = "0"
17
+ anchor["distT"] = "0"
18
+ anchor["distB"] = "0"
19
+ anchor["distL"] = "0"
20
+ anchor["distR"] = "0"
21
+ anchor["simplePos"] = "0"
22
+ anchor["locked"] = "0"
23
+ anchor["layoutInCell"] = "0"
24
+ anchor["allowOverlap"] = "1"
25
+ anchor["relativeHeight"] = "2"
26
+ anchor << Nokogiri::XML::Node.new("wp:simplePos", document).tap do |pos|
27
+ pos["x"] = "0"
28
+ pos["y"] = "0"
29
+ end
30
+ anchor << Nokogiri::XML::Node.new("wp:positionH", document).tap do |posh|
31
+ posh["relativeFrom"] = "column"
32
+ posh << Nokogiri::XML::Node.new("wp:align", document).tap do |align|
33
+ align.content = "center"
34
+ end
35
+ end
36
+ anchor << Nokogiri::XML::Node.new("wp:positionV", document).tap do |posv|
37
+ posv["relativeFrom"] = "paragraph"
38
+ posv << Nokogiri::XML::Node.new("wp:posOffset", document).tap do |offset|
39
+ offset.content = "635"
40
+ end
41
+ end
42
+ anchor << Nokogiri::XML::Node.new("wp:extent", document).tap do |extent|
21
43
  extent["cx"] = scaled_width
22
44
  extent["cy"] = scaled_height
23
45
  end
24
- inline << Nokogiri::XML::Node.new("wp:effectExtent", document).tap do |effect_extent|
46
+ anchor << Nokogiri::XML::Node.new("wp:effectExtent", document).tap do |effect_extent|
25
47
  effect_extent["l"] = "0"
26
48
  effect_extent["t"] = "0"
27
49
  effect_extent["r"] = "0"
28
50
  effect_extent["b"] = "0"
29
51
  end
30
- inline << Nokogiri::XML::Node.new("wp:cNvGraphicFramePr", document).tap do |c_nv_graphic_frame_pr|
52
+ anchor << Nokogiri::XML::Node.new("wp:wrapSquare", document).tap do |wrap_square|
53
+ wrap_square["wrapText"] = "largest"
54
+ end
55
+ anchor << Nokogiri::XML::Node.new("wp:docPr", document).tap do |doc_pr|
56
+ doc_pr["id"] = image_number
57
+ doc_pr["name"] = image.name
58
+ doc_pr["descr"] = ""
59
+ doc_pr["title"] = ""
60
+ end
61
+ anchor << Nokogiri::XML::Node.new("wp:cNvGraphicFramePr", document).tap do |c_nv_graphic_frame_pr|
31
62
  c_nv_graphic_frame_pr << Nokogiri::XML::Node.new("a:graphicFrameLocks", document).tap do |graphic_frame_locks|
32
63
  graphic_frame_locks["noChangeAspect"] = true
33
64
  end
34
65
  end
35
- inline << Nokogiri::XML::Node.new("a:graphic", document).tap do |graphic|
66
+ anchor << Nokogiri::XML::Node.new("a:graphic", document).tap do |graphic|
36
67
  graphic["xmlns:a"] = "http://schemas.openxmlformats.org/drawingml/2006/main"
37
68
  graphic << Nokogiri::XML::Node.new("a:graphicData", document).tap do |graphic_data|
38
69
  graphic_data["uri"] = "http://schemas.openxmlformats.org/drawingml/2006/picture"
@@ -44,7 +75,12 @@ module Consolidate
44
75
  c_nv_pr["name"] = image.name
45
76
  c_nv_pr["descr"] = image.name
46
77
  c_nv_pr["hidden"] = false
47
- c_nv_pr << Nokogiri::XML::Node.new("pic:cNvPicPr", document)
78
+ c_nv_pr << Nokogiri::XML::Node.new("pic:cNvPicPr", document).tap do |c_nv_pic_pr|
79
+ c_nv_pic_pr << Nokogiri::XML::Node.new("a:picLocks", document).tap do |pic_locks|
80
+ pic_locks["noChangeAspect"] = "1"
81
+ pic_locks["noChangeArrowheads"] = "1"
82
+ end
83
+ end
48
84
  end
49
85
  end
50
86
  pic << Nokogiri::XML::Node.new("pic:blipFill", document).tap do |blip_fill|
@@ -56,6 +92,7 @@ module Consolidate
56
92
  end
57
93
  end
58
94
  pic << Nokogiri::XML::Node.new("pic:spPr", document).tap do |sp_pr|
95
+ sp_pr["bwMode"] = "auto"
59
96
  sp_pr << Nokogiri::XML::Node.new("a:xfrm", document).tap do |xfrm|
60
97
  xfrm << Nokogiri::XML::Node.new("a:off", document).tap do |off|
61
98
  off["x"] = "0"
@@ -70,6 +107,7 @@ module Consolidate
70
107
  prst_geom["prst"] = "rect"
71
108
  prst_geom << Nokogiri::XML::Node.new("a:avLst", document)
72
109
  end
110
+ sp_pr << Nokogiri::XML::Node.new("a:noFill", document)
73
111
  end
74
112
  end
75
113
  end
@@ -78,24 +116,17 @@ module Consolidate
78
116
  end
79
117
  end
80
118
 
81
- DEFAULT_PAGE_WIDTH = 12_240
82
- TWENTIETHS_OF_A_POINT_TO_EMU = 635
83
- DEFAULT_PAGE_WIDTH_IN_EMU = DEFAULT_PAGE_WIDTH * TWENTIETHS_OF_A_POINT_TO_EMU
84
- EMU_PER_PIXEL = 9525
85
- DEFAULT_PAGE_HEIGHT = DEFAULT_PAGE_WIDTH * 11 / 8.5 # Assuming standard page ratio
86
- DEFAULT_PAGE_HEIGHT_IN_EMU = DEFAULT_PAGE_HEIGHT * TWENTIETHS_OF_A_POINT_TO_EMU
87
-
88
119
  private def max_width_from document
89
- page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || DEFAULT_PAGE_WIDTH).to_i
90
- page_width * TWENTIETHS_OF_A_POINT_TO_EMU
120
+ page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || Image::DEFAULT_PAGE_WIDTH).to_i
121
+ page_width * Image::TWENTIETHS_OF_A_POINT_TO_EMU
91
122
  end
92
123
 
93
124
  private def max_dimensions_from(document)
94
- page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || DEFAULT_PAGE_WIDTH).to_i
95
- page_height = (document.at_xpath("//w:sectPr/w:pgSz/@w:h")&.value || DEFAULT_PAGE_HEIGHT).to_i
125
+ page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || Image::DEFAULT_PAGE_WIDTH).to_i
126
+ page_height = (document.at_xpath("//w:sectPr/w:pgSz/@w:h")&.value || Image::DEFAULT_PAGE_HEIGHT).to_i
96
127
 
97
- width_emu = page_width * TWENTIETHS_OF_A_POINT_TO_EMU
98
- height_emu = page_height * TWENTIETHS_OF_A_POINT_TO_EMU
128
+ width_emu = page_width * Image::TWENTIETHS_OF_A_POINT_TO_EMU
129
+ height_emu = page_height * Image::TWENTIETHS_OF_A_POINT_TO_EMU
99
130
 
100
131
  [width_emu, height_emu]
101
132
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Consolidate
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.4"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard-procedure-consolidate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahoul Baruah
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-20 00:00:00.000000000 Z
10
+ date: 2025-02-24 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rubyzip
@@ -66,6 +66,8 @@ files:
66
66
  - checksums/standard-procedure-consolidate-0.4.0.gem.sha512
67
67
  - checksums/standard-procedure-consolidate-0.4.1.gem.sha512
68
68
  - checksums/standard-procedure-consolidate-0.4.2.gem.sha512
69
+ - checksums/standard-procedure-consolidate-0.4.3.gem.sha512
70
+ - checksums/standard-procedure-consolidate-0.4.4.gem.sha512
69
71
  - exe/consolidate
70
72
  - exe/examine
71
73
  - lib/consolidate.rb