mcc2 1.5.1 → 1.5.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.
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 +5 -10
  12. data/lib/mcc2/layout_file.rb +2 -33
  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 +2 -2
  25. data/lib/mcc2/printer/gdi_card_printer.rb +0 -3
  26. data/lib/mcc2/printer/gdi_printer.rb +0 -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 +0 -2
  31. data/lib/mcc2/printer/printer_epl.rb +2 -2
  32. data/lib/mcc2/printer/printer_ttp34x.rb +2 -2
  33. data/lib/mcc2/printer/printer_zebra.rb +0 -1
  34. data/lib/mcc2/printer/svg_drawer.rb +114 -110
  35. data/lib/mcc2/version.rb +1 -1
  36. data/lib/mcc2.rb +242 -7
  37. data/locales/en.yml +8 -7
  38. data/locales/rs.yml +7 -6
  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
@@ -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,7 +1,4 @@
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"
6
3
 
7
4
  Win32api4ruby::Base.unicode = true
@@ -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,7 +1,5 @@
1
1
  require "json"
2
2
  require "libcx320"
3
- require "mcc2/printer/card_printer"
4
- require "mcc2/printer/svg_drawer"
5
3
  require "rmagick"
6
4
 
7
5
  module Mcc2
@@ -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,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,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,11 +343,14 @@ 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)
351
350
  context = pango_font_map.create_context
352
- layout = Pango::Layout.new(context)
351
+ context.resolution = dpi
352
+ context.round_glyph_positions = false
353
+ layout = Pango::Layout.new(context)
353
354
 
354
355
  pango_font = get_pango_font(font_info, pt(fontsize))
355
356
  layout.font_description = pango_font
@@ -358,7 +359,8 @@ module Mcc2
358
359
  layout.wrap = Pango::WrapMode::WORD_CHAR
359
360
  layout.justify = just_block
360
361
  layout.alignment = pjust
361
- 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
362
364
  layout.text = data # set the text to render
363
365
 
364
366
  drawing.text_(fill: font_color,
@@ -477,102 +479,103 @@ module Mcc2
477
479
  }
478
480
 
479
481
  def draw_barcode(drawing, tra, go, go_width, go_height, data, barcode_dpi)
480
- return if data.nil? || data.empty?
482
+ unless data.nil? || data.empty?
481
483
 
482
- barcode_typ = go[GOA_BARCODE_TYP]
483
- option1 = go[GOA_BARCODE_OPTION_1].to_i
484
- option2 = go[GOA_BARCODE_OPTION_2].to_i
485
- option3 = go[GOA_BARCODE_OPTION_3].to_i
486
- font = go[GOA_FONT_TYP]
487
- if font == "from_file"
488
- font = go.layout_file.expand_path(go[GOA_FONT_FILE])
489
- end
490
- fontsize = go[GOA_FONT_HEIGHT].to_f
491
- 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
492
494
 
493
- font_info = get_font_info(font, go)
495
+ font_info = get_font_info(font, go)
494
496
 
495
- begin
496
- barcode = Zint.const_get(BARCODE_ALIAS[barcode_typ.to_sym] || barcode_typ).new(value: data)
497
- rescue => e
498
- raise Printer::Base::InvalidBarcodeData, I18n.t(:error_generating_barcode, default: "Fehler beim Generieren des Barcodes %{data}: %{e}", data: data.inspect, e: )
499
- else
500
- # TODO: bar_ratio wird nicht gesetzt
501
- # barcode.narrow_width = 1
502
- # barcode.wide_width = bar_ratio
503
- barcode.input_mode = Zint::DATA_MODE # Zint::UNICODE_MODE | Zint::ESCAPE_MODE
504
- # barcode.output_options = Zint::SMALL_TEXT
505
-
506
- # 50 is the default x-dimension for most of the 1D barcodes:
507
- barcode.height = go[GOA_BARCODE_HEIGHT].to_f if go[GOA_BARCODE_HEIGHT].to_f.round(3) != 0
508
- barcode.show_hrt = 0 if fontsize == 0
509
- barcode.option_1 = option1
510
- barcode.option_2 = option2
511
- barcode.option_3 = option3
512
- # barcode.fontsize = fontsize # not used in zint
513
- # p [go_height, go_width, barcode.height]
514
- barcode.whitespace_width = 0
515
497
  begin
516
- bcvector = barcode.to_vector
517
- rescue Zint::ErrorInvalidData => err
518
- raise err, "#{err.message} Barcode text: #{data.inspect}"
519
- 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
520
522
 
521
- %w[EAN13 EAN8].include?(barcode_typ)
522
-
523
- # bcvector values are always a multiple of 2 or more, but we need a multiple of 1 for to_i below.
524
- # So all bcvector measurements are divided by 2 or more.
525
- xgran = bcvector.width.round / barcode.width
526
- ygran = bcvector.height.round / barcode.rows
527
- xbars, ybars = bcvector.width / xgran, bcvector.height / ygran
528
- # p vector_width: bcvector.width, vector_height: bcvector.height
529
-
530
- optimized = (go[GOA_BARCODE_OPTIMIZED] || true).to_s == "true"
531
- px_width, px_height = barcode_mm_to_px(go_width, barcode_dpi), barcode_mm_to_px(go_height, barcode_dpi)
532
- xdim, ydim = px_width / xbars, px_height / ybars
533
- if optimized
534
- xdim = xdim.to_i
535
- ydim = ydim.to_i if barcode.rows > 1 # optimize y dimension only on 2D codes
536
- end
537
- go_width, go_height = barcode_px_to_mm(xdim * xbars, barcode_dpi), barcode_px_to_mm(ydim * ybars, barcode_dpi)
538
- px_width, px_height = mm(go_width), mm(go_height)
539
- xdim = px_width / xbars / xgran
540
- ydim = px_height / ybars / ygran
541
-
542
- pathd = +""
543
- bcvector.each_rectangle do |bar|
544
- # p [bar.x, bar.y, bar.width, bar.height]
545
- # p [xdim*bar.width, ydim*bar.height, xdim*bar.x, ydim*bar.y]
546
- x = tra.x + xdim * bar.x
547
- y = tra.y + ydim * bar.y
548
- # drawing.rectangle(
549
- # x,
550
- # y,
551
- # x + [xdim * bar.width - 1, 0].max,
552
- # y + [ydim * bar.height - 1, 0].max
553
- # )
554
- # drawing.rect(x: x, y: y, width: xdim * bar.width, height: ydim * bar.height, fill: font_color, stroke: "none")
555
- # body.rect([xdim * bar.width / 2 - 1, 0].max, [ydim * bar.height / 2 - 1, 0].max, xdim * bar.x / 2, ydim * bar.y / 2)
556
- w = xdim * bar.width
557
- h = ydim * bar.height
558
- pathd << "M#{x} #{y}h#{w}v#{h}h-#{w}Z"
559
- end
560
- drawing.path(d: pathd, stroke: "none", fill: font_color)
561
- bcvector.each_string do |str|
562
- # p [str.x, str.y, str.text, str.halign, str.fsize]
563
- # drawing.text_anchor(HALIGNMENT[str.halign])
564
- # apos = tra.translate(xdim * str.x / xgran, )
565
- # drawing.text(tra.x + xdim * str.x, tra.y + ydim * str.y, str.text)
566
- # body.text(xdim * str.x / 2, ydim * str.y / 2, str.text).styles(text_anchor: HALIGNMENT[str.halign])
567
- drawing.text_(str.text, x: tra.x + xdim * str.x, y: tra.y + ydim * str.y,
568
- 'text-anchor': HALIGNMENT[str.halign],
569
- fill: font_color,
570
- 'font-size': pt(fontsize),
571
- 'font-family': font_info.font_family,
572
- 'font-weight': font_info.font_weight,
573
- 'font-style': font_info.font_style,
574
- 'font-stretch': font_info.font_stretch,
575
- '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
576
579
  end
577
580
  end
578
581
  return go_width, go_height
@@ -695,4 +698,5 @@ module Mcc2
695
698
  desc
696
699
  end
697
700
  end
701
+ end
698
702
  end
data/lib/mcc2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mcc2
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.3"
3
3
  end