pdf_writing_tools 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pdf_writing_tools.rb +46 -17
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b86239df8011a50e9180eac3b9e61ca5dd3d479cfcda975c027bed0f920b8517
4
- data.tar.gz: f747087dfd3a4a483fb5611758d7b4501eb6377ac9ab04f9f3d5b11c4851553d
3
+ metadata.gz: 5689acbfbb2ea127782f06799e8dfeac843c86d7116f63f60a21caec2f4bcd8c
4
+ data.tar.gz: 986bdeb9b09545b0873478f2f024c15a8bc019e4a3dd231d45d37b4379f9f8b2
5
5
  SHA512:
6
- metadata.gz: 8d6750a12aaab5b59806a12f2150cf137483d0b0cb6398244584020ab56379492e1db7ff04d5fc53ee19e396ae10b02c0fd92443f207f02e1a2cd54bdb1b2864
7
- data.tar.gz: e466eecd65361c97f79254caf2ed651e499986c62538e89c53b7675ba9ceb33838b811d7318e96c17f0d9511f1f63f8d5e3f0858d54c7251f66c3f1ec76ba363
6
+ metadata.gz: bdea9aea430d42471a7b08509317bc3585a25c3782898f79727c386037e19bcd84357d628686e471b90626d414646c6e5d3da32ac2726a3156579fd8feea3e9d
7
+ data.tar.gz: 54b31a363356052fd7f902076e7a1fec6f7141e17fdbdd2da2ae7027ed9b0266ceb6c4b62ff0e0aabd17b30da75abccfe17642e48818a5478c1c5e2662467f7d
@@ -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
- pdf.stroke_color border_color
95
- pdf.stroke_rectangle([x, y_pos1], w, h)
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
@@ -235,7 +253,7 @@ module PdfWritingTools
235
253
  cell_opts[:pdf_width] = 21.cm
236
254
  cell_opts[:pdf_height] = 297.mm
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
@@ -302,8 +320,7 @@ module PdfWritingTools
302
320
  cell_opts[:pdf_height] = 297.mm
303
321
  cell_opts[:pdf_weigth] = 21.cm
304
322
 
305
- draw_simulation = true
306
- r = draw_cell_auto_height(pdf, draw_simulation, x+offset, y, width, texts[i], cell_opts, auto_y)
323
+ r = draw_cell_auto_height(pdf, true, x+offset, y, width, texts[i], cell_opts, auto_y)
307
324
 
308
325
 
309
326
  if r[:height] > max_cell_height
@@ -314,12 +331,25 @@ module PdfWritingTools
314
331
  end
315
332
 
316
333
 
317
- # Non voglio che la riga ecceda il margine di pagina, quindi se così fosse
318
- # cambio pagina
334
+ # Non voglio che la riga ecceda il margine di pagina...
319
335
  if (y + max_cell_height) > (pdf_height - pdf_margin_bottom)
320
- #max_cell_height = pdf_height - pdf_margin_bottom - y
321
- pdf.start_new_page
322
- y = pdf_margin_top
336
+ q = 1
337
+
338
+ # Se fino al margine di pagina, non ho almeno q cm... **
339
+ if (pdf_height - pdf_margin_bottom - y) < q.cm
340
+ # ...cambio pagina...
341
+ pdf.start_new_page
342
+ # ... e mi riposiziono all'inizio della pagina nuova
343
+ y = pdf_margin_top
344
+ else
345
+ # ... altrimenti, reimposto max_cell_height: la riga verrà spezzata su due pagine.
346
+ max_cell_height = pdf_height - pdf_margin_bottom - y
347
+ end
348
+
349
+ # ** non voglio imporre il vincolo "una riga deve stare in una pagina", ma contemporaneamente, voglio evitare che
350
+ # si creino delle righe "sottili" sul bordo inferiore della pagina; così sottili che non vi si possa disegnare testo
351
+ # e quindi appaiano vuote. Questo controllo non è risolutivo: x, dovrebbe dipendere dalla dimensione del carattere
352
+ # usato per il testo della riga, ma in questa fase, x.cm = 1.cm, mi pare una stima sufficiente
323
353
  end
324
354
 
325
355
  # A seguito della simulazione, ho ottenuto l'altezza di riga...
@@ -353,7 +383,7 @@ module PdfWritingTools
353
383
 
354
384
  # ...disegno le celle vere e proprie ad altezza fissa, con l'altezza
355
385
  # ricavata dal passo precedente.
356
- r = draw_cell_fixed_height(pdf, x+offset, y, width, max_cell_height, texts[i], cell_opts, auto_y)
386
+ r = draw_cell_fixed_height(pdf, draw_simulation, x+offset, y, width, max_cell_height, texts[i], cell_opts, auto_y)
357
387
 
358
388
  # Gli eventuali "testi residui" (es. raggiunto fine pagina) li raccolgo
359
389
  # nel seguente array
@@ -375,10 +405,9 @@ module PdfWritingTools
375
405
  y = pdf_margin_top # Posiziono il cursore ad inizio della nuova pagina
376
406
  end
377
407
  end
408
+
378
409
 
379
-
380
-
381
- pdf.y = (pdf_height - new_y)
410
+ #pdf.y = (pdf_height - new_y)
382
411
 
383
412
  return new_y
384
413
  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.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - JSalvo1978
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-09 00:00:00.000000000 Z
11
+ date: 2024-01-11 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: