dymo_render 0.0.2 → 0.0.3

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/dymo_render.rb +49 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 321b4f5fe3fb6cf45262f628d159b8bd64faf69c53e40e1363ddfed03b1540a1
4
- data.tar.gz: faee755ce995e3611e619e2a362f65656a194caf60b037f75560d682b0e1c1fc
3
+ metadata.gz: 6f1920c7d7a0f600191035481a970b58387f98113b8f6062a046378f5921bac2
4
+ data.tar.gz: d894c9e6b80f4fdeaa27b51e14d4502f0215470d0ba608b842ca457d432be69b
5
5
  SHA512:
6
- metadata.gz: '038ca7f11f823dfd44157da0b3dc5bea2987aa4b6cf753cf81b855bf1fdd86e1f504f45e5cb30870c2c3e484a402f6935e76468dd3108ad7192aecc649d9e401'
7
- data.tar.gz: a309930529d27e3fcc35fcb3c75e78963e71b02d6d053dfff8210b6648b05ec05dcdee36da80e5814b1fa855071cdcd2dd2c7338c685549446cd5e12e38759eb
6
+ metadata.gz: 7562dfefd8f15d5710a7db7f86ab00dcd8ec49018fbdfa997880b83c6f1138200c5e4a76c1419fc0285af0d3287d1d8882d1acd2ba860becbd4d357d3c56e260
7
+ data.tar.gz: a136d52bca03350aaf1fd5fd7a8b0eaff6bc208fef513ffeab5b166cbf7a9d62398a9f594b27187fa0fc04399309b2047fe4f9fb4d1da67a0e052a376d2e51f0
@@ -222,13 +222,20 @@ class DymoRender
222
222
  HORIZONTAL_LINE_VERTICAL_FUDGE_BY = -2.5
223
223
 
224
224
  def render_shape_object(shape_object, x, y, width, height)
225
- case shape_object.css('ShapeType').first.text
225
+ case shape_type = shape_object.css('ShapeType').first.text
226
226
  when 'HorizontalLine'
227
227
  pdf.line_width height
228
228
  pdf.horizontal_line x, x + width, at: y + HORIZONTAL_LINE_VERTICAL_FUDGE_BY
229
229
  pdf.stroke
230
+ when 'Rectangle'
231
+ top_left = [x, y]
232
+ line_width = shape_object.css("LineWidth").first.text.to_f / TWIP * PDF_POINT
233
+
234
+ pdf.line_width line_width
235
+ pdf.rectangle top_left, width, height
236
+ pdf.stroke
230
237
  else
231
- puts 'unknown shape type'
238
+ puts "unknown shape type #{shape_type}"
232
239
  end
233
240
  end
234
241
 
@@ -269,6 +276,44 @@ class DymoRender
269
276
  code = Barby::Code128.new(content, type)
270
277
  outputter = Barby::PrawnOutputter.new(code)
271
278
 
279
+ barcode_height = height
280
+ barcode_y = y
281
+
282
+ text_position = barcode_object.css("TextPosition").first&.text
283
+ if %w{Top Bottom}.include?(text_position)
284
+ font_element = barcode_object.css("TextFont").first
285
+ font_family = font_element.attribute("Family").value
286
+ font_size = font_element.attribute("Size").value.to_f
287
+ color = color_from_element(barcode_object.css("ForeColor").first)
288
+ valign = VALIGNS[text_position]
289
+
290
+ pdf.fill_color color
291
+ font_file = self.class.font_file_for_family(font_dirs, font_family)
292
+ pdf.font(font_file || raise("missing font #{font_family}"))
293
+ # horizontal padding of 1 point
294
+ x += 1
295
+ width -= 2
296
+ (box, actual_size) = text_box_with_font_size(
297
+ content,
298
+ size: font_size,
299
+ character_spacing: 0,
300
+ at: [x, y],
301
+ width: width,
302
+ height: height,
303
+ overflow: :truncate,
304
+ align: :center,
305
+ valign: valign,
306
+ disable_wrap_by_char: true,
307
+ single_line: true,
308
+ )
309
+ # on bottom-aligned boxes, Dymo counts the height of character descenders
310
+ box.at[1] += box.descender if valign == :bottom
311
+ box.render
312
+ code_offset = box.height * 1.25
313
+ barcode_height -= code_offset
314
+ barcode_y -= code_offset if valign == :top
315
+ end
316
+
272
317
  num_dots_x = outputter.full_width
273
318
  xdim = width.to_f / num_dots_x
274
319
  center_x = x + width.to_f / 2
@@ -283,8 +328,8 @@ class DymoRender
283
328
 
284
329
  # center in the x direction
285
330
  xpos = center_x - width.to_f / 2
286
- ypos = y - height
331
+ ypos = barcode_y - barcode_height
287
332
 
288
- outputter.annotate_pdf(pdf, { x: xpos, y: ypos, xdim: xdim, height: height });
333
+ outputter.annotate_pdf(pdf, { x: xpos, y: ypos, xdim: xdim, height: barcode_height });
289
334
  end
290
335
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dymo_render
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Gentry