standard-procedure-consolidate 0.4.1 → 0.4.3

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: 0ffce925315399bd4432936d929e995114acc2dea081f3835eb437fe2787f612
4
- data.tar.gz: b64ae5181ae92d5e66be79e5861787c3355fe08870dbb4ee3ab8355ef4ce149d
3
+ metadata.gz: c3a7f02d5159a44a47af30100fe1743b2b5bff5ab845a0da2170ffaf44302f03
4
+ data.tar.gz: b041806b3d682a4c5ccc0011025a1d3d5b25a7c1a65fda56e9b3fcce34b364a9
5
5
  SHA512:
6
- metadata.gz: e56547c32223cf66f807c804cdfff2897f63887729dcf1ff80d51c35a0615115f47b16347b582d58a6ae128c3ecad91a67ca128e0d7c89b6e55a3e88b2d5a6c9
7
- data.tar.gz: 4b351ad3a367dd4382abc18e18fbc978095fec92aa8b258a90feb82f2e0a65ffbcca26a8177383d75fab07d711a170b10b541e48c195c4b8b7db0eea2cfd1b26
6
+ metadata.gz: 2bc84355758ef68cd525c684fe1ef6973858eb3ba360f4a37a026cc54a11c9eb143cc364bd034cdd4452bec75a91a768b7f96ccbb727039da5e6ba727fb643bd
7
+ data.tar.gz: b8061eb3ff1a61deb3c1b153be11d9c5b416be6a576d559c0846236a1e8dabdf9dcf339f33479e39589d3c247930cb28d437a360becbe5e498e90b99eb26ffea
@@ -2,7 +2,7 @@
2
2
  // README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
3
  {
4
4
  "name": "Ruby",
5
- "image": "mcr.microsoft.com/devcontainers/ruby:1-3.2-bullseye",
5
+ "image": "ghcr.io/rails/devcontainer/images/ruby:3.3.5",
6
6
  "postCreateCommand": "bundle install",
7
7
  "customizations": {
8
8
  "vscode": {
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.5
1
+ 3.3.5
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
+ 391a0d85024adf2a5866f0dabab3d601e6865c482e4fff5e780af0a6dc6ca36aade243a9e97cdb68552b00fce51d763ed94e89a701ce466428a64df9f4d574a0
@@ -0,0 +1 @@
1
+ 646e5a14ad25738c476cb587c9012fff12687fc7e26e555b6d17a61d69ae1477bdf1a55326b952bbc05dde988d945c3a9504ebeb58b2ff6598c10be5be26c6cb
@@ -7,29 +7,63 @@ module Consolidate
7
7
  module Docx
8
8
  class ImageReferenceNodeBuilder < Data.define(:field_name, :image, :node_id, :image_number, :document)
9
9
  def call
10
+ max_width, max_height = max_dimensions_from(document)
11
+ scaled_width, scaled_height = scale_dimensions(image.width, image.height, max_width, max_height)
12
+
10
13
  Nokogiri::XML::Node.new("w:drawing", document).tap do |drawing|
11
14
  drawing["xmlns:a"] = "http://schemas.openxmlformats.org/drawingml/2006/main"
12
- drawing << Nokogiri::XML::Node.new("wp:inline", document).tap do |inline|
13
- inline["distT"] = "0"
14
- inline["distB"] = "0"
15
- inline["distL"] = "0"
16
- inline["distR"] = "0"
17
- inline << Nokogiri::XML::Node.new("wp:extent", document).tap do |extent|
18
- extent["cx"] = image.clamped_width(max_width_from(document))
19
- extent["cy"] = image.clamped_height(max_width_from(document))
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
20
41
  end
21
- inline << Nokogiri::XML::Node.new("wp:effectExtent", document).tap do |effect_extent|
42
+ anchor << Nokogiri::XML::Node.new("wp:extent", document).tap do |extent|
43
+ extent["cx"] = scaled_width
44
+ extent["cy"] = scaled_height
45
+ end
46
+ anchor << Nokogiri::XML::Node.new("wp:effectExtent", document).tap do |effect_extent|
22
47
  effect_extent["l"] = "0"
23
48
  effect_extent["t"] = "0"
24
49
  effect_extent["r"] = "0"
25
50
  effect_extent["b"] = "0"
26
51
  end
27
- 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|
28
62
  c_nv_graphic_frame_pr << Nokogiri::XML::Node.new("a:graphicFrameLocks", document).tap do |graphic_frame_locks|
29
63
  graphic_frame_locks["noChangeAspect"] = true
30
64
  end
31
65
  end
32
- inline << Nokogiri::XML::Node.new("a:graphic", document).tap do |graphic|
66
+ anchor << Nokogiri::XML::Node.new("a:graphic", document).tap do |graphic|
33
67
  graphic["xmlns:a"] = "http://schemas.openxmlformats.org/drawingml/2006/main"
34
68
  graphic << Nokogiri::XML::Node.new("a:graphicData", document).tap do |graphic_data|
35
69
  graphic_data["uri"] = "http://schemas.openxmlformats.org/drawingml/2006/picture"
@@ -41,7 +75,12 @@ module Consolidate
41
75
  c_nv_pr["name"] = image.name
42
76
  c_nv_pr["descr"] = image.name
43
77
  c_nv_pr["hidden"] = false
44
- 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
45
84
  end
46
85
  end
47
86
  pic << Nokogiri::XML::Node.new("pic:blipFill", document).tap do |blip_fill|
@@ -53,20 +92,22 @@ module Consolidate
53
92
  end
54
93
  end
55
94
  pic << Nokogiri::XML::Node.new("pic:spPr", document).tap do |sp_pr|
95
+ sp_pr["bwMode"] = "auto"
56
96
  sp_pr << Nokogiri::XML::Node.new("a:xfrm", document).tap do |xfrm|
57
97
  xfrm << Nokogiri::XML::Node.new("a:off", document).tap do |off|
58
98
  off["x"] = "0"
59
99
  off["y"] = "0"
60
100
  end
61
101
  xfrm << Nokogiri::XML::Node.new("a:ext", document).tap do |ext|
62
- ext["cx"] = image.clamped_width(max_width_from(document))
63
- ext["cy"] = image.clamped_height(max_width_from(document))
102
+ ext["cx"] = scaled_width
103
+ ext["cy"] = scaled_height
64
104
  end
65
105
  end
66
106
  sp_pr << Nokogiri::XML::Node.new("a:prstGeom", document).tap do |prst_geom|
67
107
  prst_geom["prst"] = "rect"
68
108
  prst_geom << Nokogiri::XML::Node.new("a:avLst", document)
69
109
  end
110
+ sp_pr << Nokogiri::XML::Node.new("a:noFill", document)
70
111
  end
71
112
  end
72
113
  end
@@ -78,11 +119,32 @@ module Consolidate
78
119
  DEFAULT_PAGE_WIDTH = 12_240
79
120
  TWENTIETHS_OF_A_POINT_TO_EMU = 635
80
121
  DEFAULT_PAGE_WIDTH_IN_EMU = DEFAULT_PAGE_WIDTH * TWENTIETHS_OF_A_POINT_TO_EMU
122
+ EMU_PER_PIXEL = 9525
123
+ DEFAULT_PAGE_HEIGHT = DEFAULT_PAGE_WIDTH * 11 / 8.5 # Assuming standard page ratio
124
+ DEFAULT_PAGE_HEIGHT_IN_EMU = DEFAULT_PAGE_HEIGHT * TWENTIETHS_OF_A_POINT_TO_EMU
81
125
 
82
126
  private def max_width_from document
83
127
  page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || DEFAULT_PAGE_WIDTH).to_i
84
128
  page_width * TWENTIETHS_OF_A_POINT_TO_EMU
85
129
  end
130
+
131
+ private def max_dimensions_from(document)
132
+ page_width = (document.at_xpath("//w:sectPr/w:pgSz/@w:w")&.value || DEFAULT_PAGE_WIDTH).to_i
133
+ page_height = (document.at_xpath("//w:sectPr/w:pgSz/@w:h")&.value || DEFAULT_PAGE_HEIGHT).to_i
134
+
135
+ width_emu = page_width * TWENTIETHS_OF_A_POINT_TO_EMU
136
+ height_emu = page_height * TWENTIETHS_OF_A_POINT_TO_EMU
137
+
138
+ [width_emu, height_emu]
139
+ end
140
+
141
+ private def scale_dimensions(width, height, max_width, max_height)
142
+ width_ratio = max_width.to_f / width
143
+ height_ratio = max_height.to_f / height
144
+ scale = [width_ratio, height_ratio, 1.0].min # Never scale up
145
+
146
+ [(width * scale).to_i, (height * scale).to_i]
147
+ end
86
148
  end
87
149
  end
88
150
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Consolidate
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.3"
5
5
  end
metadata CHANGED
@@ -1,14 +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.1
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahoul Baruah
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-18 00:00:00.000000000 Z
10
+ date: 2025-02-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rubyzip
@@ -66,6 +65,8 @@ files:
66
65
  - checksums/standard-procedure-consolidate-0.3.9.gem.sha512
67
66
  - checksums/standard-procedure-consolidate-0.4.0.gem.sha512
68
67
  - checksums/standard-procedure-consolidate-0.4.1.gem.sha512
68
+ - checksums/standard-procedure-consolidate-0.4.2.gem.sha512
69
+ - checksums/standard-procedure-consolidate-0.4.3.gem.sha512
69
70
  - exe/consolidate
70
71
  - exe/examine
71
72
  - lib/consolidate.rb
@@ -84,7 +85,6 @@ metadata:
84
85
  homepage_uri: https://github.com/standard-procedure/standard-procedure-consolidate
85
86
  source_code_uri: https://github.com/standard-procedure/standard-procedure-consolidate
86
87
  changelog_uri: https://github.com/standard-procedure/standard-procedure-consolidate/blob/main/CHANGELOG.md
87
- post_install_message:
88
88
  rdoc_options: []
89
89
  require_paths:
90
90
  - lib
@@ -99,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.4.19
103
- signing_key:
102
+ rubygems_version: 3.6.2
104
103
  specification_version: 4
105
104
  summary: Simple ruby mailmerge for Microsoft Word .docx files.
106
105
  test_files: []