pdf_writing_tools 0.0.20 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pdf_writing_tools.rb +62 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d2bb105508a3b9d4530fc61ee7e069ff809e834f2d67e3b1868d358bc4dd0c8
|
4
|
+
data.tar.gz: 728a3eaf9c32d7a056095c0b65bb4a97938773a326d0db0bd41b032819461e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f17b5557e4a7eb58a60e01fe7d3f7792c83e5329164afd5e25b0183f48475b37a5ab7925b0f3049e29f22661d3e40aec52f9c44e132f1695a988c22ff53d056e
|
7
|
+
data.tar.gz: bb2a5b0c0fd1b3d5089ac562286d548b10774faeb6abe6159e0e76787e19eb025db0b819a9f204b05dac95dae3e34bcbaf70f12f95de9b402fbaecdfcbdcc0bf
|
data/lib/pdf_writing_tools.rb
CHANGED
@@ -59,7 +59,7 @@ module PdfWritingTools
|
|
59
59
|
# quello basso della pagina).
|
60
60
|
# Bisogna pertanto prestare attenzione quando si dovessero mischiare primitive prawn
|
61
61
|
# con queste funzioni.
|
62
|
-
def self.draw_cell_fixed_height(pdf, x, y, w, h, t, opts={}, auto_y=false, no_background=false)
|
62
|
+
def self.draw_cell_fixed_height(pdf, draw_simulation, x, y, w, h, t, opts={}, auto_y=false, no_background=false)
|
63
63
|
t = (t.class == String ? [{text: t}] : t)
|
64
64
|
font_size = opts[:font_size] || 10
|
65
65
|
style = opts[:style] || :normal
|
@@ -86,13 +86,15 @@ module PdfWritingTools
|
|
86
86
|
pdf.fill_color(background_color)
|
87
87
|
|
88
88
|
# Disegna lo sfondo della cella
|
89
|
-
if no_background
|
89
|
+
if no_background or draw_simulation
|
90
90
|
else
|
91
91
|
pdf.fill_rectangle([x, y_pos1], w, h)
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
if not draw_simulation
|
95
|
+
pdf.stroke_color border_color
|
96
|
+
pdf.stroke_rectangle([x, y_pos1], w, h)
|
97
|
+
end
|
96
98
|
|
97
99
|
# Colore del testo nella cella
|
98
100
|
pdf.fill_color(font_color)
|
@@ -100,7 +102,23 @@ module PdfWritingTools
|
|
100
102
|
at = [x + left_padding, y_pos2]
|
101
103
|
width = w - left_padding - right_padding
|
102
104
|
height = h - top_padding - bottom_padding + 1.cm
|
103
|
-
result = pdf.formatted_text_box(t, width: width, height: height, at: at, size: font_size, style: style, align: align, valign: valign)
|
105
|
+
#result = pdf.formatted_text_box(t, width: width, height: height, at: at, size: font_size, style: style, align: align, valign: valign)
|
106
|
+
|
107
|
+
b = Prawn::Text::Formatted::Box.new(
|
108
|
+
t,
|
109
|
+
{
|
110
|
+
width: width,
|
111
|
+
height: height,
|
112
|
+
at: at,
|
113
|
+
size: font_size,
|
114
|
+
style: style,
|
115
|
+
align: align,
|
116
|
+
valign: valign,
|
117
|
+
document: pdf
|
118
|
+
}
|
119
|
+
)
|
120
|
+
|
121
|
+
result = b.render(:dry_run => draw_simulation)
|
104
122
|
end
|
105
123
|
|
106
124
|
result
|
@@ -179,7 +197,7 @@ module PdfWritingTools
|
|
179
197
|
|
180
198
|
if no_background
|
181
199
|
else
|
182
|
-
pdf.fill_and_stroke_rectangle([x, y_pos2],
|
200
|
+
pdf.fill_and_stroke_rectangle([x, y_pos2], w, h+top_padding+bottom_padding)
|
183
201
|
end
|
184
202
|
# ... e infine, sopra lo sfondo disegno il testo
|
185
203
|
pdf.fill_color(font_color) # colore del testo
|
@@ -232,10 +250,10 @@ module PdfWritingTools
|
|
232
250
|
cell_opts[:right_padding] = padding[:right_padding]
|
233
251
|
cell_opts[:top_padding] = padding[:top_padding]
|
234
252
|
cell_opts[:bottom_padding] = padding[:bottom_padding]
|
235
|
-
cell_opts[:pdf_width] =
|
236
|
-
cell_opts[:pdf_height] =
|
253
|
+
cell_opts[:pdf_width] = pdf_width
|
254
|
+
cell_opts[:pdf_height] = pdf_height
|
237
255
|
|
238
|
-
draw_cell_fixed_height( pdf, x+offset, y, width, height, texts[i], cell_opts, auto_y)
|
256
|
+
draw_cell_fixed_height( pdf, false, x+offset, y, width, height, texts[i], cell_opts, auto_y)
|
239
257
|
|
240
258
|
offset += width
|
241
259
|
end
|
@@ -299,11 +317,14 @@ module PdfWritingTools
|
|
299
317
|
cell_opts[:right_padding] = padding[:right_padding]
|
300
318
|
cell_opts[:top_padding] = padding[:top_padding]
|
301
319
|
cell_opts[:bottom_padding] = padding[:bottom_padding]
|
302
|
-
cell_opts[:pdf_height] =
|
303
|
-
cell_opts[:
|
320
|
+
cell_opts[:pdf_height] = pdf_height
|
321
|
+
cell_opts[:pdf_width] = pdf_width
|
322
|
+
cell_opts[:pdf_margin_top] = pdf_margin_top
|
323
|
+
cell_opts[:pdf_margin_bottom] = pdf_margin_bottom
|
324
|
+
cell_opts[:pdf_margin_left] = pdf_margin_left
|
325
|
+
cell_opts[:pdf_margin_right] = pdf_margin_right
|
304
326
|
|
305
|
-
|
306
|
-
r = draw_cell_auto_height(pdf, draw_simulation, x+offset, y, width, texts[i], cell_opts, auto_y)
|
327
|
+
r = draw_cell_auto_height(pdf, true, x+offset, y, width, texts[i], cell_opts, auto_y)
|
307
328
|
|
308
329
|
|
309
330
|
if r[:height] > max_cell_height
|
@@ -314,12 +335,25 @@ module PdfWritingTools
|
|
314
335
|
end
|
315
336
|
|
316
337
|
|
317
|
-
# Non voglio che la riga ecceda il margine di pagina
|
318
|
-
# cambio pagina
|
338
|
+
# Non voglio che la riga ecceda il margine di pagina...
|
319
339
|
if (y + max_cell_height) > (pdf_height - pdf_margin_bottom)
|
320
|
-
|
321
|
-
|
322
|
-
|
340
|
+
q = 1
|
341
|
+
|
342
|
+
# Se fino al margine di pagina, non ho almeno q cm... **
|
343
|
+
if (pdf_height - pdf_margin_bottom - y) < q.cm
|
344
|
+
# ...cambio pagina...
|
345
|
+
pdf.start_new_page
|
346
|
+
# ... e mi riposiziono all'inizio della pagina nuova
|
347
|
+
y = pdf_margin_top
|
348
|
+
else
|
349
|
+
# ... altrimenti, reimposto max_cell_height: la riga verrà spezzata su due pagine.
|
350
|
+
max_cell_height = pdf_height - pdf_margin_bottom - y
|
351
|
+
end
|
352
|
+
|
353
|
+
# ** non voglio imporre il vincolo "una riga deve stare in una pagina", ma contemporaneamente, voglio evitare che
|
354
|
+
# si creino delle righe "sottili" sul bordo inferiore della pagina; così sottili che non vi si possa disegnare testo
|
355
|
+
# e quindi appaiano vuote. Questo controllo non è risolutivo: x, dovrebbe dipendere dalla dimensione del carattere
|
356
|
+
# usato per il testo della riga, ma in questa fase, x.cm = 1.cm, mi pare una stima sufficiente
|
323
357
|
end
|
324
358
|
|
325
359
|
# A seguito della simulazione, ho ottenuto l'altezza di riga...
|
@@ -348,12 +382,16 @@ module PdfWritingTools
|
|
348
382
|
cell_opts[:right_padding] = padding[:right_padding]
|
349
383
|
cell_opts[:top_padding] = padding[:top_padding]
|
350
384
|
cell_opts[:bottom_padding] = padding[:bottom_padding]
|
351
|
-
cell_opts[:pdf_height] =
|
352
|
-
cell_opts[:
|
353
|
-
|
385
|
+
cell_opts[:pdf_height] = pdf_height
|
386
|
+
cell_opts[:pdf_width] = pdf_width
|
387
|
+
cell_opts[:pdf_margin_top] = pdf_margin_top
|
388
|
+
cell_opts[:pdf_margin_bottom] = pdf_margin_bottom
|
389
|
+
cell_opts[:pdf_margin_left] = pdf_margin_left
|
390
|
+
cell_opts[:pdf_margin_right] = pdf_margin_right
|
391
|
+
|
354
392
|
# ...disegno le celle vere e proprie ad altezza fissa, con l'altezza
|
355
393
|
# ricavata dal passo precedente.
|
356
|
-
r = draw_cell_fixed_height(pdf, x+offset, y, width, max_cell_height, texts[i], cell_opts, auto_y)
|
394
|
+
r = draw_cell_fixed_height(pdf, draw_simulation, x+offset, y, width, max_cell_height, texts[i], cell_opts, auto_y)
|
357
395
|
|
358
396
|
# Gli eventuali "testi residui" (es. raggiunto fine pagina) li raccolgo
|
359
397
|
# nel seguente array
|
@@ -375,10 +413,9 @@ module PdfWritingTools
|
|
375
413
|
y = pdf_margin_top # Posiziono il cursore ad inizio della nuova pagina
|
376
414
|
end
|
377
415
|
end
|
416
|
+
|
378
417
|
|
379
|
-
|
380
|
-
|
381
|
-
pdf.y = (pdf_height - new_y)
|
418
|
+
#pdf.y = (pdf_height - new_y)
|
382
419
|
|
383
420
|
return new_y
|
384
421
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf_writing_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JSalvo1978
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Plugin for write pdf in a simplified manner, using prawn as backend
|
14
14
|
email:
|