mcc2 1.5.2 → 1.5.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +5 -3
  4. data/lib/mcc2/dataman/base.rb +0 -44
  5. data/lib/mcc2/dataman/csv.rb +0 -1
  6. data/lib/mcc2/dataman/database.rb +0 -2
  7. data/lib/mcc2/dataman/dbf.rb +0 -1
  8. data/lib/mcc2/dataman/none.rb +0 -2
  9. data/lib/mcc2/{cc_dialogbox.rb → fxselection_dialog.rb} +2 -2
  10. data/lib/mcc2/gui/layoutview_dlg.pp +1067 -1146
  11. data/lib/mcc2/layout.rb +0 -7
  12. data/lib/mcc2/layout_file.rb +1 -30
  13. data/lib/mcc2/layout_object/barcode.rb +0 -2
  14. data/lib/mcc2/layout_object/box.rb +0 -2
  15. data/lib/mcc2/layout_object/chip.rb +0 -3
  16. data/lib/mcc2/layout_object/embed.rb +0 -2
  17. data/lib/mcc2/layout_object/graphic.rb +0 -2
  18. data/lib/mcc2/layout_object/picture.rb +0 -2
  19. data/lib/mcc2/layout_object/text.rb +1 -3
  20. data/lib/mcc2/layoutview.rb +5 -3
  21. data/lib/mcc2/layoutview_dlg.rb +573 -607
  22. data/lib/mcc2/mcc2gui.rb +2 -8
  23. data/lib/mcc2/printer/card_printer.rb +0 -2
  24. data/lib/mcc2/printer/file_printer.rb +3 -3
  25. data/lib/mcc2/printer/gdi_card_printer.rb +0 -3
  26. data/lib/mcc2/printer/gdi_printer.rb +2 -3
  27. data/lib/mcc2/printer/linux_cups_printer.rb +2 -2
  28. data/lib/mcc2/printer/preview.rb +2 -9
  29. data/lib/mcc2/printer/printer_cab.rb +2 -2
  30. data/lib/mcc2/printer/printer_cx320_direct.rb +2 -2
  31. data/lib/mcc2/printer/printer_epl.rb +2 -3
  32. data/lib/mcc2/printer/printer_ttp34x.rb +2 -3
  33. data/lib/mcc2/printer/printer_zebra.rb +0 -1
  34. data/lib/mcc2/printer/svg_drawer.rb +111 -109
  35. data/lib/mcc2/version.rb +1 -1
  36. data/lib/mcc2.rb +242 -7
  37. data/locales/en.yml +5 -0
  38. data/locales/rs.yml +5 -0
  39. data/mcc2.gemspec +1 -0
  40. data.tar.gz.sig +0 -0
  41. metadata +16 -3
  42. metadata.gz.sig +0 -0
  43. data/lib/mcc2/constants.rb +0 -154
data/lib/mcc2/mcc2gui.rb CHANGED
@@ -8,6 +8,7 @@ require "fox16/responder"
8
8
  require "libguib16"
9
9
  require "optparse"
10
10
  require "i18n"
11
+ require "tempfile"
11
12
 
12
13
  # convert relative image file path to absolute one
13
14
  # based on dir of this file.
@@ -20,14 +21,7 @@ def loadImage(file)
20
21
  i
21
22
  end
22
23
 
23
- # die GUI's, alle mit FoxGUI-Builder erstellt
24
- require "mcc2/mcc2_mainwin" # das Main-GUI
25
- require "mcc2/cc_dialogbox"
26
-
27
- require "mcc2/layout" # das Kartenlayout
28
- require "mcc2/debug_tools"
29
-
30
- require "tempfile"
24
+ require "mcc2/mcc2_mainwin"
31
25
 
32
26
  # *****************************************************************************
33
27
  module Mcc2
@@ -1,5 +1,3 @@
1
- require "mcc2/printer/base" # die Basisklasse für die Printer
2
-
3
1
  module Mcc2
4
2
  module Printer
5
3
  module CardPrinting
@@ -1,5 +1,5 @@
1
- require "mcc2/printer/card_printer"
2
- require "mcc2/printer/svg_drawer"
1
+ require 'rsvg2'
2
+ require 'cairo'
3
3
 
4
4
  module Mcc2
5
5
  module Printer
@@ -117,7 +117,7 @@ module Mcc2
117
117
  # TODO where comes the factor 0.8 from?
118
118
  svg_attrs = {width: "#{page_width*0.8}mm", height: "#{page_height*0.8}mm"}
119
119
  end
120
- svg_data = svg_builder(viewBox: "0 0 #{image_width} #{image_height}", **svg_attrs) do |svg|
120
+ svg_data = svg_builder(viewBox: "0 0 #{image_width} #{image_height}", **(svg_attrs || {})) do |svg|
121
121
  tra = Transformation.new
122
122
  draw(svg, tra.translate(mm(draw_pos_x).round, mm(draw_pos_y).round), layout_file, false, nil, row, page_nr)
123
123
  end
@@ -1,6 +1,3 @@
1
- require "mcc2/printer/gdi_printer"
2
- require "mcc2/printer/card_printer"
3
-
4
1
  module Mcc2
5
2
  module Printer
6
3
  class GdiCardPrinter < GdiPrinter
@@ -1,8 +1,7 @@
1
- gem "win32api4ruby", ">= 0.2.1"
2
1
  require "win32api4ruby"
3
- require "mcc2/printer/card_printer"
4
- require "mcc2/printer/svg_drawer"
5
2
  require "mcc2_c_helper"
3
+ require 'rsvg2'
4
+ require 'cairo'
6
5
 
7
6
  Win32api4ruby::Base.unicode = true
8
7
 
@@ -1,6 +1,6 @@
1
- require "mcc2/printer/card_printer"
2
- require "mcc2/printer/svg_drawer"
3
1
  require "ffi-cups"
2
+ require 'rsvg2'
3
+ require 'cairo'
4
4
 
5
5
  module Mcc2
6
6
  module Printer
@@ -1,7 +1,5 @@
1
- require "mcc2/printer/base" # die Basisklasse für die Printer
2
- require "mcc2/printer/card_printer"
3
- require "mcc2/printer/svg_drawer"
4
- require 'nokogiri'
1
+ require 'rsvg2'
2
+ require 'cairo'
5
3
 
6
4
  module Mcc2
7
5
  module Printer
@@ -195,11 +193,6 @@ module Mcc2
195
193
  attr_reader :font_map
196
194
 
197
195
  def draw_preview_now(row = nil)
198
- require 'rsvg2'
199
- require 'cairo'
200
- require 'pango'
201
- require 'ttfunk'
202
-
203
196
  @font_map = {}
204
197
 
205
198
  # allgemeine Einstellungen des Image vornehmen
@@ -1,7 +1,7 @@
1
- require "mcc2/printer/card_printer"
2
- require "mcc2/printer/svg_drawer"
3
1
  require "socket"
4
2
  require "rmagick"
3
+ require 'rsvg2'
4
+ require 'cairo'
5
5
 
6
6
  module Mcc2
7
7
  module Printer
@@ -1,8 +1,8 @@
1
1
  require "json"
2
2
  require "libcx320"
3
- require "mcc2/printer/card_printer"
4
- require "mcc2/printer/svg_drawer"
5
3
  require "rmagick"
4
+ require 'rsvg2'
5
+ require 'cairo'
6
6
 
7
7
  module Mcc2
8
8
  module Printer
@@ -1,7 +1,6 @@
1
- require "mcc2/printer/card_printer"
2
- require "mcc2/printer/svg_drawer"
3
- require "socket"
4
1
  require "rmagick"
2
+ require 'rsvg2'
3
+ require 'cairo'
5
4
 
6
5
  module Mcc2
7
6
  module Printer
@@ -1,7 +1,6 @@
1
- require "mcc2/printer/card_printer"
2
- require "mcc2/printer/svg_drawer"
3
- require "socket"
4
1
  require "rmagick"
2
+ require 'rsvg2'
3
+ require 'cairo'
5
4
 
6
5
  module Mcc2
7
6
  module Printer
@@ -1,6 +1,5 @@
1
1
  require "win32api4ruby"
2
2
  require "zebra_dll"
3
- require "mcc2/printer/gdi_card_printer" # die Basisklasse für alle CardPrinter
4
3
 
5
4
  module Mcc2
6
5
  module Printer
@@ -1,9 +1,9 @@
1
- require "mcc2/dataman/base"
2
1
  require "i18n"
3
2
  require "ttfunk"
4
3
  require "pango"
5
4
 
6
5
  module Mcc2
6
+ module Printer
7
7
  module SvgDrawer
8
8
  class ObjRectangle
9
9
  def initialize(v1, v2, v3, v4, obj_id)
@@ -250,22 +250,18 @@ module Mcc2
250
250
  drawing.g transform: "rotate(#{rec.a})" do
251
251
  opos = rec.inverse
252
252
 
253
- begin
254
- # die Objekt-spezifischen Attribute ermitteln
255
- go_width, go_height = if typ == TEXTOBJECT
256
- draw_textobject(drawing, opos, go, go_width, go_height, data.empty? ? data_nosub : data)
257
- elsif typ == PICTUREOBJECT
258
- draw_pictureobject(drawing, opos, go, go_width, go_height, data)
259
- elsif typ == BARCODEOBJECT
260
- data = data.gsub(/\\x([0-9a-f][0-9a-f])/i) { [$1.hex].pack("C") }
261
- draw_barcode(drawing, opos, go, go_width, go_height, data, barcode_dpi)
262
- elsif typ == BOXOBJECT
263
- draw_boxobject(drawing, opos, go, go_width, go_height)
264
- elsif typ == EMBEDOBJECT
265
- draw_embedobject(drawing, opos, go, go_width, go_height, data, row ? row["row_number"] : "1", barcode_dpi)
266
- end
267
- rescue => err
268
- raise err, "#{go[GOA_NAME]}: #{err}"
253
+ # die Objekt-spezifischen Attribute ermitteln
254
+ go_width, go_height = if typ == TEXTOBJECT
255
+ draw_textobject(drawing, opos, go, go_width, go_height, data.empty? ? data_nosub : data)
256
+ elsif typ == PICTUREOBJECT
257
+ draw_pictureobject(drawing, opos, go, go_width, go_height, data)
258
+ elsif typ == BARCODEOBJECT
259
+ data = data.gsub(/\\x([0-9a-f][0-9a-f])/i) { [$1.hex].pack("C") }
260
+ draw_barcode(drawing, opos, go, go_width, go_height, data, barcode_dpi)
261
+ elsif typ == BOXOBJECT
262
+ draw_boxobject(drawing, opos, go, go_width, go_height)
263
+ elsif typ == EMBEDOBJECT
264
+ draw_embedobject(drawing, opos, go, go_width, go_height, data, row ? row["row_number"] : "1", barcode_dpi)
269
265
  end
270
266
 
271
267
  rec2 = rec.translate(mm(go_width), 0)
@@ -286,6 +282,8 @@ module Mcc2
286
282
  end
287
283
  end
288
284
  end
285
+ rescue => err
286
+ raise err, "#{go[GOA_NAME] if go}: #{err}"
289
287
  end
290
288
 
291
289
  if preview
@@ -345,6 +343,7 @@ module Mcc2
345
343
  pjust = Pango::Alignment::LEFT
346
344
  end
347
345
  just_block = go[GOA_JUSTIFICATION_BLOCK] == "true"
346
+ line_spacing = go[GOA_LINE_SPACING]
348
347
 
349
348
  if data && !data.empty?
350
349
  font_info = get_font_info(font, go)
@@ -360,7 +359,8 @@ module Mcc2
360
359
  layout.wrap = Pango::WrapMode::WORD_CHAR
361
360
  layout.justify = just_block
362
361
  layout.alignment = pjust
363
- layout.ellipsize = Pango::EllipsizeMode::END
362
+ layout.line_spacing = line_spacing.to_f unless line_spacing.to_s.empty?
363
+ layout.ellipsize = Pango::EllipsizeMode::END if go_width && go_height
364
364
  layout.text = data # set the text to render
365
365
 
366
366
  drawing.text_(fill: font_color,
@@ -479,102 +479,103 @@ module Mcc2
479
479
  }
480
480
 
481
481
  def draw_barcode(drawing, tra, go, go_width, go_height, data, barcode_dpi)
482
- return if data.nil? || data.empty?
482
+ unless data.nil? || data.empty?
483
483
 
484
- barcode_typ = go[GOA_BARCODE_TYP]
485
- option1 = go[GOA_BARCODE_OPTION_1].to_i
486
- option2 = go[GOA_BARCODE_OPTION_2].to_i
487
- option3 = go[GOA_BARCODE_OPTION_3].to_i
488
- font = go[GOA_FONT_TYP]
489
- if font == "from_file"
490
- font = go.layout_file.expand_path(go[GOA_FONT_FILE])
491
- end
492
- fontsize = go[GOA_FONT_HEIGHT].to_f
493
- font_color = ["#", go[GOA_FONT_COLOR]].join
484
+ barcode_typ = go[GOA_BARCODE_TYP]
485
+ option1 = go[GOA_BARCODE_OPTION_1].to_i
486
+ option2 = go[GOA_BARCODE_OPTION_2].to_i
487
+ option3 = go[GOA_BARCODE_OPTION_3].to_i
488
+ font = go[GOA_FONT_TYP]
489
+ if font == "from_file"
490
+ font = go.layout_file.expand_path(go[GOA_FONT_FILE])
491
+ end
492
+ fontsize = go[GOA_FONT_HEIGHT].to_f
493
+ font_color = ["#", go[GOA_FONT_COLOR]].join
494
494
 
495
- font_info = get_font_info(font, go)
495
+ font_info = get_font_info(font, go)
496
496
 
497
- begin
498
- barcode = Zint.const_get(BARCODE_ALIAS[barcode_typ.to_sym] || barcode_typ).new(value: data)
499
- rescue => e
500
- raise Printer::Base::InvalidBarcodeData, I18n.t(:error_generating_barcode, default: "Fehler beim Generieren des Barcodes %{data}: %{e}", data: data.inspect, e: )
501
- else
502
- # TODO: bar_ratio wird nicht gesetzt
503
- # barcode.narrow_width = 1
504
- # barcode.wide_width = bar_ratio
505
- barcode.input_mode = Zint::DATA_MODE # Zint::UNICODE_MODE | Zint::ESCAPE_MODE
506
- # barcode.output_options = Zint::SMALL_TEXT
507
-
508
- # 50 is the default x-dimension for most of the 1D barcodes:
509
- barcode.height = go[GOA_BARCODE_HEIGHT].to_f if go[GOA_BARCODE_HEIGHT].to_f.round(3) != 0
510
- barcode.show_hrt = 0 if fontsize == 0
511
- barcode.option_1 = option1
512
- barcode.option_2 = option2
513
- barcode.option_3 = option3
514
- # barcode.fontsize = fontsize # not used in zint
515
- # p [go_height, go_width, barcode.height]
516
- barcode.whitespace_width = 0
517
497
  begin
518
- bcvector = barcode.to_vector
519
- rescue Zint::ErrorInvalidData => err
520
- raise err, "#{err.message} Barcode text: #{data.inspect}"
521
- end
498
+ barcode = Zint.const_get(BARCODE_ALIAS[barcode_typ.to_sym] || barcode_typ).new(value: data)
499
+ rescue => e
500
+ raise Printer::Base::InvalidBarcodeData, I18n.t(:error_generating_barcode, default: "Fehler beim Generieren des Barcodes %{data}: %{e}", data: data.inspect, e: )
501
+ else
502
+ # TODO: bar_ratio wird nicht gesetzt
503
+ # barcode.narrow_width = 1
504
+ # barcode.wide_width = bar_ratio
505
+ barcode.input_mode = Zint::DATA_MODE # Zint::UNICODE_MODE | Zint::ESCAPE_MODE
506
+ # barcode.output_options = Zint::SMALL_TEXT
507
+
508
+ # 50 is the default x-dimension for most of the 1D barcodes:
509
+ barcode.height = go[GOA_BARCODE_HEIGHT].to_f if go[GOA_BARCODE_HEIGHT].to_f.round(3) != 0
510
+ barcode.show_hrt = 0 if fontsize == 0
511
+ barcode.option_1 = option1
512
+ barcode.option_2 = option2
513
+ barcode.option_3 = option3
514
+ # barcode.fontsize = fontsize # not used in zint
515
+ # p [go_height, go_width, barcode.height]
516
+ barcode.whitespace_width = 0
517
+ begin
518
+ bcvector = barcode.to_vector
519
+ rescue Zint::ErrorInvalidData => err
520
+ raise err, "#{err.message} Barcode text: #{data.inspect}"
521
+ end
522
522
 
523
- %w[EAN13 EAN8].include?(barcode_typ)
524
-
525
- # bcvector values are always a multiple of 2 or more, but we need a multiple of 1 for to_i below.
526
- # So all bcvector measurements are divided by 2 or more.
527
- xgran = bcvector.width.round / barcode.width
528
- ygran = bcvector.height.round / barcode.rows
529
- xbars, ybars = bcvector.width / xgran, bcvector.height / ygran
530
- # p vector_width: bcvector.width, vector_height: bcvector.height
531
-
532
- optimized = (go[GOA_BARCODE_OPTIMIZED] || true).to_s == "true"
533
- px_width, px_height = barcode_mm_to_px(go_width, barcode_dpi), barcode_mm_to_px(go_height, barcode_dpi)
534
- xdim, ydim = px_width / xbars, px_height / ybars
535
- if optimized
536
- xdim = xdim.to_i
537
- ydim = ydim.to_i if barcode.rows > 1 # optimize y dimension only on 2D codes
538
- end
539
- go_width, go_height = barcode_px_to_mm(xdim * xbars, barcode_dpi), barcode_px_to_mm(ydim * ybars, barcode_dpi)
540
- px_width, px_height = mm(go_width), mm(go_height)
541
- xdim = px_width / xbars / xgran
542
- ydim = px_height / ybars / ygran
543
-
544
- pathd = +""
545
- bcvector.each_rectangle do |bar|
546
- # p [bar.x, bar.y, bar.width, bar.height]
547
- # p [xdim*bar.width, ydim*bar.height, xdim*bar.x, ydim*bar.y]
548
- x = tra.x + xdim * bar.x
549
- y = tra.y + ydim * bar.y
550
- # drawing.rectangle(
551
- # x,
552
- # y,
553
- # x + [xdim * bar.width - 1, 0].max,
554
- # y + [ydim * bar.height - 1, 0].max
555
- # )
556
- # drawing.rect(x: x, y: y, width: xdim * bar.width, height: ydim * bar.height, fill: font_color, stroke: "none")
557
- # body.rect([xdim * bar.width / 2 - 1, 0].max, [ydim * bar.height / 2 - 1, 0].max, xdim * bar.x / 2, ydim * bar.y / 2)
558
- w = xdim * bar.width
559
- h = ydim * bar.height
560
- pathd << "M#{x} #{y}h#{w}v#{h}h-#{w}Z"
561
- end
562
- drawing.path(d: pathd, stroke: "none", fill: font_color)
563
- bcvector.each_string do |str|
564
- # p [str.x, str.y, str.text, str.halign, str.fsize]
565
- # drawing.text_anchor(HALIGNMENT[str.halign])
566
- # apos = tra.translate(xdim * str.x / xgran, )
567
- # drawing.text(tra.x + xdim * str.x, tra.y + ydim * str.y, str.text)
568
- # body.text(xdim * str.x / 2, ydim * str.y / 2, str.text).styles(text_anchor: HALIGNMENT[str.halign])
569
- drawing.text_(str.text, x: tra.x + xdim * str.x, y: tra.y + ydim * str.y,
570
- 'text-anchor': HALIGNMENT[str.halign],
571
- fill: font_color,
572
- 'font-size': pt(fontsize),
573
- 'font-family': font_info.font_family,
574
- 'font-weight': font_info.font_weight,
575
- 'font-style': font_info.font_style,
576
- 'font-stretch': font_info.font_stretch,
577
- 'xml:space': "preserve")
523
+ %w[EAN13 EAN8].include?(barcode_typ)
524
+
525
+ # bcvector values are always a multiple of 2 or more, but we need a multiple of 1 for to_i below.
526
+ # So all bcvector measurements are divided by 2 or more.
527
+ xgran = bcvector.width.round / barcode.width
528
+ ygran = bcvector.height.round / barcode.rows
529
+ xbars, ybars = bcvector.width / xgran, bcvector.height / ygran
530
+ # p vector_width: bcvector.width, vector_height: bcvector.height
531
+
532
+ optimized = (go[GOA_BARCODE_OPTIMIZED] || true).to_s == "true"
533
+ px_width, px_height = barcode_mm_to_px(go_width, barcode_dpi), barcode_mm_to_px(go_height, barcode_dpi)
534
+ xdim, ydim = px_width / xbars, px_height / ybars
535
+ if optimized
536
+ xdim = xdim.to_i
537
+ ydim = ydim.to_i if barcode.rows > 1 # optimize y dimension only on 2D codes
538
+ end
539
+ go_width, go_height = barcode_px_to_mm(xdim * xbars, barcode_dpi), barcode_px_to_mm(ydim * ybars, barcode_dpi)
540
+ px_width, px_height = mm(go_width), mm(go_height)
541
+ xdim = px_width / xbars / xgran
542
+ ydim = px_height / ybars / ygran
543
+
544
+ pathd = +""
545
+ bcvector.each_rectangle do |bar|
546
+ # p [bar.x, bar.y, bar.width, bar.height]
547
+ # p [xdim*bar.width, ydim*bar.height, xdim*bar.x, ydim*bar.y]
548
+ x = tra.x + xdim * bar.x
549
+ y = tra.y + ydim * bar.y
550
+ # drawing.rectangle(
551
+ # x,
552
+ # y,
553
+ # x + [xdim * bar.width - 1, 0].max,
554
+ # y + [ydim * bar.height - 1, 0].max
555
+ # )
556
+ # drawing.rect(x: x, y: y, width: xdim * bar.width, height: ydim * bar.height, fill: font_color, stroke: "none")
557
+ # body.rect([xdim * bar.width / 2 - 1, 0].max, [ydim * bar.height / 2 - 1, 0].max, xdim * bar.x / 2, ydim * bar.y / 2)
558
+ w = xdim * bar.width
559
+ h = ydim * bar.height
560
+ pathd << "M#{x} #{y}h#{w}v#{h}h-#{w}Z"
561
+ end
562
+ drawing.path(d: pathd, stroke: "none", fill: font_color)
563
+ bcvector.each_string do |str|
564
+ # p [str.x, str.y, str.text, str.halign, str.fsize]
565
+ # drawing.text_anchor(HALIGNMENT[str.halign])
566
+ # apos = tra.translate(xdim * str.x / xgran, )
567
+ # drawing.text(tra.x + xdim * str.x, tra.y + ydim * str.y, str.text)
568
+ # body.text(xdim * str.x / 2, ydim * str.y / 2, str.text).styles(text_anchor: HALIGNMENT[str.halign])
569
+ drawing.text_(str.text, x: tra.x + xdim * str.x, y: tra.y + ydim * str.y,
570
+ 'text-anchor': HALIGNMENT[str.halign],
571
+ fill: font_color,
572
+ 'font-size': pt(fontsize),
573
+ 'font-family': font_info.font_family,
574
+ 'font-weight': font_info.font_weight,
575
+ 'font-style': font_info.font_style,
576
+ 'font-stretch': font_info.font_stretch,
577
+ 'xml:space': "preserve")
578
+ end
578
579
  end
579
580
  end
580
581
  return go_width, go_height
@@ -697,4 +698,5 @@ module Mcc2
697
698
  desc
698
699
  end
699
700
  end
701
+ end
700
702
  end
data/lib/mcc2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mcc2
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.4"
3
3
  end