powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / штрих коды , в частности ean128, есть у кого код или длл?
15 сообщений из 15, страница 1 из 1
штрих коды , в частности ean128, есть у кого код или длл?
    #37293229
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
штрих коды , в частности ean128, есть у кого код или длл под wpf.
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37294244
i
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
i
Гость
Не нужны никакие dll. Для вывода достаточно спец шрифтов, а считывание на автомате делает штрих-сканер
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37294778
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
i,

а можно ссылку на спецшрифты?
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37295626
i
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
i
Гость
Ссылку не дам на спецшрифты, но они есть. Не задавай глупых вопросов.
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37295727
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
не. я конечно же поискал . но индекс поисковика не возбудился от этих слов. и выдал списки коммерческих длл, где слово font приплетено косвенно.
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37295944
i
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
i
Гость
AlexeiKне. я конечно же поискал . но индекс поисковика не возбудился от этих слов. и выдал списки коммерческих длл, где слово font приплетено косвенно.

Муся тебе шрифты давать не захотел, а у меня их нет. Они должны идти в комплекте сканера. Если только для вывода, то на codeplex есть проект на SL. Cсылку не помню, если записал, то вышлю
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37295959
Вестник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
тут есть малёха
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37296039
i
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
i
Гость
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37296378
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вестник и i,
то есть вы полагает, что вам гугл дает другие ответы, на те же самые запросы? :))ыыы
ребят я все посмотрел это. вы хотя бы углубились на 3 ссылки вниз и поняли, что это хрень.
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37296698
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
короче я нашел код.влом мне его сча тут вставлять. как кому нито нужно будет, апните тему.
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37296799
Вестник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
про кашу из топора читали? это как раз ваш случай ;)
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #37297126
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
поскольку тему апнули.
вот код.
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
469.
470.
471.
472.
473.
474.
475.
476.
477.
478.
479.
480.
481.
482.
483.
484.
485.
486.
487.
488.
489.
490.
491.
492.
493.
494.
495.
496.
497.
498.
499.
500.
501.
502.
503.
504.
505.
506.
507.
508.
509.
510.
511.
512.
513.
514.
515.
516.
517.
518.
519.
520.
521.
522.
523.
524.
525.
526.
527.
528.
529.
530.
531.
532.
533.
534.
535.
536.
537.
538.
539.
540.
541.
542.
543.
544.
545.
546.
547.
548.
549.
550.
551.
552.
553.
554.
555.
556.
557.
558.
559.
560.
561.
562.
563.
564.
565.
566.
567.
568.
569.
570.
571.
572.
573.
574.
575.
576.
577.
578.
579.
580.
581.
582.
583.
584.
585.
586.
587.
588.
589.
590.
591.
592.
593.
594.
595.
596.
597.
598.
599.
600.
601.
602.
603.
604.
605.
606.
607.
608.
609.
610.
611.
612.
613.
614.
615.
616.
617.
618.
619.
620.
621.
622.
623.
624.
625.
626.
627.
628.
629.
630.
631.
632.
633.
634.
635.
636.
637.
638.
639.
640.
641.
642.
643.
644.
645.
646.
647.
648.
649.
650.
651.
652.
653.
654.
655.
656.
657.
658.
659.
660.
661.
662.
663.
664.
665.
666.
667.
668.
669.
670.
671.
672.
673.
674.
675.
676.
677.
678.
679.
680.
681.
682.
683.
684.
685.
686.
687.
688.
689.
690.
691.
692.
693.
694.
695.
696.
697.
698.
699.
700.
701.
702.
703.
704.
705.
706.
707.
708.
709.
710.
711.
712.
713.
714.
715.
716.
717.
718.
719.
720.
721.
722.
723.
724.
725.
726.
727.
728.
729.
730.
731.
732.
733.
734.
735.
736.
737.
738.
739.
740.
741.
742.
743.
744.
745.
746.
747.
748.
749.
750.
751.
752.
753.
754.
755.
756.
757.
758.
759.
760.
761.
762.
763.
764.
765.
766.
767.
768.
769.
770.
771.
772.
773.
774.
775.
776.
777.
778.
779.
780.
781.
782.
783.
784.
785.
786.
787.
788.
789.
790.
791.
792.
793.
794.
795.
796.
797.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfBarCode
{
    

        /// <summary>
        /// Base class for barcodes
        /// </summary>
        public class BarcodeBase : Canvas
        {
            /// <summary>
            /// Gets or sets the aggregate group
            /// </summary>
            public virtual string AggregateGroup
            {
                get { return (string)GetValue(AggregateGroupProperty); }
                set { SetValue(AggregateGroupProperty, value); }
            }

            // Using a DependencyProperty as the backing store for AggregateGroup.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty AggregateGroupProperty =
                DependencyProperty.Register("AggregateGroup", typeof(string), typeof(BarcodeBase), new UIPropertyMetadata(null));

            /// <summary>
            /// Gets or sets the brush which is to be uses to draw the bars
            /// </summary>
            public virtual Brush BrushBars
            {
                get { return (Brush)GetValue(BrushBarsProperty); }
                set { SetValue(BrushBarsProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for BrushBars.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty BrushBarsProperty =
                DependencyProperty.Register("BrushBars", typeof(Brush), typeof(BarcodeBase), new UIPropertyMetadata(Brushes.Black));

            /// <summary>
            /// Gets or sets the font family to be used to draw the barcode text
            /// </summary>
            public virtual FontFamily FontFamily
            {
                get { return (FontFamily)GetValue(FontFamilyProperty); }
                set { SetValue(FontFamilyProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for Font.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty FontFamilyProperty =
                DependencyProperty.Register("FontFamily", typeof(FontFamily), typeof(BarcodeBase), new UIPropertyMetadata(new FontFamily()));

            /// <summary>
            /// Gets or sets the font stretch property
            /// </summary>
            public virtual FontStretch FontStretch
            {
                get { return (FontStretch)GetValue(FontStretchProperty); }
                set { SetValue(FontStretchProperty, value); }
            }

            // Using a DependencyProperty as the backing store for FontStretch.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty FontStretchProperty =
                DependencyProperty.Register("FontStretch", typeof(FontStretch), typeof(BarcodeBase), new UIPropertyMetadata(new FontStretch()));

            /// <summary>
            /// Gets or sets the font style of the barcode text
            /// </summary>
            public virtual FontStyle FontStyle
            {
                get { return (FontStyle)GetValue(FontStyleProperty); }
                set { SetValue(FontStyleProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for FontStyle.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty FontStyleProperty =
                DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(BarcodeBase), new UIPropertyMetadata(new FontStyle()));

            /// <summary>
            /// Gets or sets the font weight of the barcode text
            /// </summary>
            public virtual FontWeight FontWeight
            {
                get { return (FontWeight)GetValue(FontWeightProperty); }
                set { SetValue(FontWeightProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for FontWeight.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty FontWeightProperty =
                DependencyProperty.Register("FontWeight", typeof(FontWeight), typeof(BarcodeBase), new UIPropertyMetadata(new FontWeight()));

            /// <summary>
            /// Gets or sets the value format
            /// </summary>
            public virtual string Format
            {
                get { return (string)GetValue(FormatProperty); }
                set { SetValue(FormatProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for Format.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty FormatProperty =
                DependencyProperty.Register("Format", typeof(string), typeof(BarcodeBase), new UIPropertyMetadata(null));

            /// <summary>
            /// Gets or sets the property name
            /// </summary>
            public virtual string PropertyName
            {
                get { return (string)GetValue(PropertyNameProperty); }
                set { SetValue(PropertyNameProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for PropertyName.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty PropertyNameProperty =
                DependencyProperty.Register("PropertyName", typeof(string), typeof(BarcodeBase), new UIPropertyMetadata(null));

            /// <summary>
            /// Enables or disables the option to show text below the barcode
            /// </summary>
            public virtual bool ShowText
            {
                get { return (bool)GetValue(ShowTextProperty); }
                set { SetValue(ShowTextProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for ShowText.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty ShowTextProperty =
                DependencyProperty.Register("ShowText", typeof(bool), typeof(BarcodeBase), new UIPropertyMetadata(true));

            /// <summary>
            /// Gets or sets the overridden text
            /// </summary>
            public virtual string Text
            {
                get { return (string)GetValue(TextProperty); }
                set { SetValue(TextProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty TextProperty =
                DependencyProperty.Register("Text", typeof(string), typeof(BarcodeBase), new UIPropertyMetadata(null));

            /// <summary>
            /// Gets or sets the object value
            /// </summary>
            public virtual object Value
            {
                get { return (object)GetValue(ValueProperty); }
                set { SetValue(ValueProperty, value); RedrawAll(); }
            }

            // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty ValueProperty =
                DependencyProperty.Register("Value", typeof(object), typeof(BarcodeBase), new UIPropertyMetadata(null));

            /// <summary>
            /// Identifies the ValueChanged routed event.
            /// </summary>
            public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent(
                "ValueChanged", RoutingStrategy.Bubble,
                typeof(RoutedPropertyChangedEventHandler<decimal>), typeof(BarcodeBase));

            /// <summary>
            /// Raises the ValueChanged event.
            /// </summary>
            /// <param name="args">Arguments associated with the ValueChanged event.</param>
            protected virtual void OnValueChanged(RoutedPropertyChangedEventArgs<decimal> args)
            {
                RaiseEvent(args);
            }

            /// <summary>
            /// Constructor
            /// </summary>
            public BarcodeBase()
            {
            }

            /// <summary>
            /// Render size has changed
            /// </summary>
            /// <param name="sizeInfo">size info</param>
            protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
            {
                base.OnRenderSizeChanged(sizeInfo);
                RedrawAll();
            }

            /// <summary>
            /// Redraws the whole barcode
            /// </summary>
            public virtual void RedrawAll()
            {
                Children.Clear();
            }
        }
        /// <summary>
        /// Creates a barcode C128 as a Canvas
        /// </summary>
        public class BarcodeC128 : BarcodeBase
        {
            /// <summary>
            /// Enumeration of all Code 128 sub-types
            /// </summary>
            public enum Code128SubType
            {
                /// <summary>
                /// Code 128 A
                /// </summary>
                A,
                /// <summary>
                /// Code 128 B
                /// </summary>
                B,
                /// <summary>
                /// Code 128 B and C mixed
                /// </summary>
                BC,
                /// <summary>
                /// Code 128 C
                /// </summary>
                C
            }

            private static char[] _keysA = new char[107];
            private static void GenerateKeysA()
            {
                for (int i = 0; i < 64; i++)
                {
                    _keysA[i] = (char)(32 + i);
                }
                for (int i = 64; i < 96; i++)
                {
                    _keysA[i] = (char)(i);
                }
                for (int i = 96; i < _keysA.Length; i++)
                {
                    _keysA[i] = '0';
                }
            }

            private static char[] _keysB = new char[107];
            private static void GenerateKeysB()
            {
                for (int i = 0; i < 96; i++)
                {
                    _keysB[i] = (char)(32 + i);
                }
                for (int i = 96; i < _keysB.Length; i++)
                {
                    _keysB[i] = '0';
                }
            }

            private static string[] _keysC = new string[107];
            private static void GenerateKeysC()
            {
                for (int i = 0; i < 100; i++)
                {
                    _keysC[i] = String.Format("{0:00}", i);
                }
                for (int i = 100; i < _keysC.Length; i++)
                {
                    _keysC[i] = "";
                }
            }

            /// <summary>
            /// Code table
            /// </summary>
            protected string[] _codeTable = new string[]
            {
                "101111", // 00
                "111011", // 01
                "111110", // 02
                "010112", // 03
                "010211", // 04
                "020111", // 05
                "011102", // 06
                "011201", // 07
                "021101", // 08
                "110102", // 09
                "110201", // 10
                "120101", // 11
                "001121", // 12
                "011021", // 13
                "011120", // 14
                "002111", // 15
                "012011", // 16
                "012110", // 17
                "112100", // 18
                "110021", // 19
                "110120", // 20
                "102101", // 21
                "112001", // 22
                "201020", // 23
                "200111", // 24
                "210011", // 25
                "210110", // 26
                "201101", // 27
                "211001", // 28
                "211100", // 29
                "101012", // 30
                "101210", // 31
                "121010", // 32
                "000212", // 33
                "020012", // 34
                "020210", // 35
                "001202", // 36
                "021002", // 37
                "021200", // 38
                "100202", // 39
                "120002", // 40
                "120200", // 41
                "001022", // 42
                "001220", // 43
                "021020", // 44
                "002012", // 45
                "002210", // 46
                "022010", // 47
                "202010", // 48
                "100220", // 49
                "120020", // 50
                "102002", // 51
                "102200", // 52
                "102020", // 53
                "200012", // 54
                "200210", // 55
                "220010", // 56
                "201002", // 57
                "201200", // 58
                "221000", // 59
                "203000", // 60
                "110300", // 61
                "320000", // 62
                "000113", // 63
                "000311", // 64
                "010013", // 65
                "010310", // 66
                "030011", // 67
                "030110", // 68
                "001103", // 69
                "001301", // 70
                "011003", // 71
                "011300", // 72
                "031001", // 73
                "031100", // 74
                "130100", // 75
                "110003", // 76
                "302000", // 77
                "130001", // 78
                "023000", // 79
                "000131", // 80
                "010031", // 81
                "010130", // 82
                "003101", // 83
                "013001", // 84
                "013100", // 85
                "300101", // 86
                "310001", // 87
                "310100", // 88
                "101030", // 89
                "103010", // 90
                "301010", // 91
                "000032", // 92
                "000230", // 93
                "020030", // 94
                "003002", // 95
                "003200", // 96
                "300002", // 97
                "300200", // 98
                "002030", // 99
                "003020", // 100
                "200030", // 101
                "300020", // 102
                "100301", // 103
                "100103", // 104
                "100121", // 105
                "1220001" // STOP
            };

            private Code128SubType _barcodeSubType = Code128SubType.BC;
            /// <summary>
            /// Gets or sets the barcode sub-type
            /// </summary>
            public Code128SubType BarcodeSubType
            {
                get { return _barcodeSubType; }
                set
                {
                    _barcodeSubType = value;
                    RedrawAll();
                }
            }

            /// <summary>
            /// Static constructor
            /// </summary>
            static BarcodeC128()
            {
                GenerateKeysA();
                GenerateKeysB();
                GenerateKeysC();
            }

            /// <summary>
            /// Constructor
            /// </summary>
            public BarcodeC128()
            {
                RedrawAll();
            }

            /// <summary>
            /// Gets the index of a char in a char array
            /// </summary>
            /// <param name="array">char array</param>
            /// <param name="ch">char</param>
            /// <returns>index or -1, if not found</returns>
            private static int IndexOfCharArray(char[] array, char ch)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] == ch) return i;
                }
                return -1;
            }

            /// <summary>
            /// Gets the index of a string in a string array
            /// </summary>
            /// <param name="array">string array</param>
            /// <param name="str">string</param>
            /// <returns>index or -1, if not found</returns>
            private static int IndexOfStringArray(string[] array, string str)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] == str) return i;
                }
                return -1;
            }

            private double DrawCharByIndex(Canvas canvas, double left, double top, double height, int charIndex)
            {
                string sequence = _codeTable[charIndex];

                double width = 0;
                for (int i = 0; i < sequence.Length; i++)
                {
                    double lineWidth = 0d;
                    switch (sequence[i])
                    {
                        case '0':
                            lineWidth = 1d;
                            break;
                        case '1':
                            lineWidth = 2d;
                            break;
                        case '2':
                            lineWidth = 3d;
                            break;
                        case '3':
                            lineWidth = 4d;
                            break;
                    }
                    if (lineWidth < 1d)
                    {
                        throw new ArgumentOutOfRangeException();
                    }

                    double charWidth = lineWidth; // *XRes;
                    //if (g != null)
                    //{
                    //    if ((i % 2) == 0)
                    //        g.FillRectangle(_foreColorBrush, (float)(left + width), _margin.Top, (float)charWidth, (float)height);
                    //}
                    if (canvas != null)
                    {
                        if ((i % 2) == 0)
                        {
                            Rectangle rect = new Rectangle();
                            rect.Fill = BrushBars;
                            rect.RenderTransform = new TranslateTransform(left + width, top);
                            rect.Width = charWidth;
                            rect.Height = height;
                            canvas.Children.Add(rect);
                        }
                    }

                    width += charWidth;
                }
                return width;
            }

            private List<int> GenerateCodeSequence(string code, out List<BarcodeCharInfo> charInfo)
            {
                List<int> res = new List<int>();
                charInfo = new List<BarcodeCharInfo>();
                bool isB = false;
                if (code == null) code = "";

                // start character first
                switch (_barcodeSubType)
                {
                    case Code128SubType.A:
                        res.Add(103);  // Start A
                        break;
                    case Code128SubType.B:
                        res.Add(104);  // Start B
                        break;
                    case Code128SubType.BC:
                        if ((code.Length >= 2) && (Char.IsDigit(code[0])) && (Char.IsDigit(code[1])))
                        {
                            res.Add(105); // Start C
                        }
                        else
                        {
                            isB = true;
                            res.Add(104); // Start B
                        }
                        break;
                    case Code128SubType.C:
                        res.Add(105);  // Start C
                        break;
                }

                // text
                string partC = "";
                for (int i = 0; i < code.Length; i++)
                {
                    int charIndex = -1;
                    switch (_barcodeSubType)
                    {
                        case Code128SubType.A:
                            charIndex = IndexOfCharArray(_keysA, code[i]);
                            charInfo.Add(new BarcodeCharInfo(i, -1, code[i].ToString()));
                            break;
                        case Code128SubType.B:
                            charIndex = IndexOfCharArray(_keysB, code[i]);
                            charInfo.Add(new BarcodeCharInfo(i, -1, code[i].ToString()));
                            break;
                        case Code128SubType.BC:
                            if (isB)
                            {
                                if ((i <= code.Length - 2) && (Char.IsDigit(code[i])) && (Char.IsDigit(code[i + 1])))
                                {
                                    isB = false;
                                    res.Add(99); // Code C
                                    charInfo.Add(new BarcodeCharInfo(i, -1, ""));

                                    partC += code[i];
                                    if (partC.Length == 2)
                                    {
                                        charIndex = IndexOfStringArray(_keysC, partC);
                                        charInfo.Add(new BarcodeCharInfo(i, -1, partC));
                                        partC = "";
                                    }
                                    else continue;
                                }
                                else
                                {
                                    charIndex = IndexOfCharArray(_keysB, code[i]);
                                    charInfo.Add(new BarcodeCharInfo(i, -1, code[i].ToString()));
                                }
                            }
                            else
                            {
                                if (partC.Length <= 0)
                                {
                                    if ((i >= code.Length - 1) || (!Char.IsDigit(code[i])) || (!Char.IsDigit(code[i + 1])))
                                    {
                                        isB = true;
                                        res.Add(100); // Code B
                                        charInfo.Add(new BarcodeCharInfo(i, -1, ""));

                                        charIndex = IndexOfCharArray(_keysB, code[i]);
                                        charInfo.Add(new BarcodeCharInfo(i, -1, code[i].ToString()));
                                        break;
                                    }
                                }

                                partC += code[i];
                                if (partC.Length == 2)
                                {
                                    charIndex = IndexOfStringArray(_keysC, partC);
                                    charInfo.Add(new BarcodeCharInfo(i, -1, partC));
                                    partC = "";
                                }
                                else continue;
                            }
                            break;
                        case Code128SubType.C:
                            partC += code[i];
                            if (partC.Length == 2)
                            {
                                charIndex = IndexOfStringArray(_keysC, partC);
                                charInfo.Add(new BarcodeCharInfo(i, -1, partC));
                                partC = "";
                            }
                            else continue;
                            break;
                    }

                    if (charIndex < 0) throw new ArgumentOutOfRangeException("code", "The barcode value contains an unsupported character \"" + code[i] + "\"");

                    res.Add(charIndex);
                }

                if (partC.Length > 0) throw new ArgumentException("Code 128C only supports a even number of characters", "code");
                return res;
            }

           
            public static string FormatValue(object value, string format)
            {
                if (value == null) return "";
                if (String.IsNullOrEmpty(format)) return value.ToString();

                Type type = value.GetType();
                if (type == typeof(DateTime)) return ((DateTime)value).ToString(format);
                if (type == typeof(decimal)) return ((decimal)value).ToString(format);
                if (type == typeof(double)) return ((double)value).ToString(format);
                if (type == typeof(float)) return ((float)value).ToString(format);
                if (type == typeof(int)) return ((int)value).ToString(format);
                if (type == typeof(long)) return ((long)value).ToString(format);
                if (type == typeof(short)) return ((short)value).ToString(format);
                if (type == typeof(uint)) return ((uint)value).ToString(format);
                if (type == typeof(ulong)) return ((ulong)value).ToString(format);
                if (type == typeof(ushort)) return ((ushort)value).ToString(format);

                return value.ToString();
            }
            public override void RedrawAll()
            {
                Children.Clear();

                double actualWidth = ActualWidth;
                double actualHeight = ActualHeight;
                if ((double.IsNaN(actualWidth)) || (actualWidth <= 0)) actualWidth = Width;
                if ((double.IsNaN(actualHeight)) || (actualHeight <= 0)) actualHeight = Height;
                if ((double.IsNaN(actualWidth)) || (actualWidth <= 0)) return;
                if ((double.IsNaN(actualHeight)) || (actualHeight <= 0)) return;

                Rect rectClient = new Rect(0, 0, actualWidth, actualHeight);

                if (Value == null) return;

                string text = FormatValue(Value, Format);
                if (String.IsNullOrEmpty(text)) return;

                List<BarcodeCharInfo> charInfo;
                List<int> codeSequence = GenerateCodeSequence(text, out charInfo);
                if (codeSequence.Count <= 0) return;

                // override shown text
                if ((Text != null) && (!String.IsNullOrEmpty(Text.ToString()))) text = Text.ToString();

                int checkSum = 0;
                double left = 0;

                // measure barcode first
                double startCharWidth = 0;
                for (int i = 0; i < codeSequence.Count; i++)
                {
                    double charWidth = DrawCharByIndex(null, left, 0, 1, codeSequence[i]);
                    if (i == 0) startCharWidth = charWidth;
                    left += charWidth;

                    if (i == 0) checkSum = codeSequence[0]; else checkSum += codeSequence[i] * i;
                }
                double barcodeDataWidth = left - startCharWidth;

                // draw check sum
                left += DrawCharByIndex(null, left, 0, 1, (checkSum % 103)); // Check Sum

                // draw stop char
                left += DrawCharByIndex(null, left, 0, 1, 106); // Stop

                double barcodeWidth = left;

                Canvas canvas = new Canvas();

                // show barcode text
                Label labelText = null;
                double textHeight = 0;
                decimal labelScale = 1;
                TransformGroup tgl = null;
                if (ShowText)
                {
                    labelText = new Label();
                    labelText.Content = text;
                    labelText.Padding = new Thickness(0.25); // HACK: something is not right here
                    labelText.FontFamily = FontFamily;
                    labelText.FontStretch = FontStretch;
                    labelText.FontStyle = FontStyle;
                    labelText.FontWeight = FontWeight;
                    labelText.FontSize = 1;
                    labelText.Measure(new Size(actualWidth, actualHeight));

                    labelScale = (decimal)rectClient.Width / (decimal)barcodeWidth * (decimal)barcodeDataWidth / (decimal)labelText.DesiredSize.Width;
                    textHeight = labelText.DesiredSize.Height * (double)labelScale;

                    // set new size of barcode text
                    tgl = new TransformGroup();
                    tgl.Children.Add(new ScaleTransform((double)labelScale, (double)labelScale));
                    labelText.RenderTransform = tgl;
                }

                // draw barcode now
                left = 0;
                for (int i = 0; i < codeSequence.Count; i++)
                {
                    double lineHeight = 1;
                    if ((ShowText) && (i > 0)) lineHeight = (rectClient.Height - (double)labelScale * labelText.DesiredSize.Height / 2) / rectClient.Height;

                    double charWidth = DrawCharByIndex(canvas, left, 0, lineHeight, codeSequence[i]);
                    left += charWidth;
                }

                // draw check sum
                left += DrawCharByIndex(canvas, left, 0, 1, (checkSum % 103)); // Check Sum

                // draw stop char
                left += DrawCharByIndex(canvas, left, 0, 1, 106); // Stop

                // move text to right place
                if (ShowText)
                {
                    tgl.Children.Add(new TranslateTransform(startCharWidth * rectClient.Width / left, rectClient.Height - textHeight));
                    Children.Add(labelText);
                }

                TransformGroup tg = new TransformGroup();
                tg.Children.Add(new ScaleTransform(rectClient.Width / left, rectClient.Height - textHeight / 2));
                tg.Children.Add(new TranslateTransform(rectClient.Left, rectClient.Top));
                canvas.RenderTransform = tg;
                Children.Add(canvas);
            }
        }
        public class BarcodeCharInfo
        {
            private int _index = -1;
            /// <summary>
            /// Index of the character
            /// </summary>
            public int Index
            {
                get { return _index; }
                set { _index = value; }
            }

            private double _left = -1;
            /// <summary>
            /// Character left position
            /// </summary>
            public double Left
            {
                get { return _left; }
                set { _left = value; }
            }

            private string _text = "";
            /// <summary>
            /// Text to be displayed
            /// </summary>
            public string Text
            {
                get { return _text; }
                set { _text = value; }
            }

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="index">Character index</param>
            /// <param name="left">Left position of character</param>
            /// <param name="text">Text to be displayed</param>
            public BarcodeCharInfo(int index, double left, string text)
            {
                _index = index;
                _left = left;
                _text = text;
            }
        }
    }



пример использования:

Код: c#
1.
<my1:BarcodeC128 Value="13423423424222"  PropertyName="EAN" Width="4cm" Height="1.0cm" BarcodeSubType="C" ShowText="False" />
...
Рейтинг: 0 / 0
Период между сообщениями больше года.
штрих коды , в частности ean128, есть у кого код или длл?
    #38035712
igara
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
На основании информации code128.narod.ru
переписал на SQL для CODE-128. Остальные элементарно переписать по аналогии
Код во вложении
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #38148350
Serge73
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
В спойлере конвертированный код C# для code_39
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
class Barcodeconverter
    {
        public static string Code_39(string A)
        {
            string S = "";
            string z = "";
        for (int I = 1; I <= A.Length;I++)
            {
                z = Code_Char(Code_39_Ch(A.Substring(I-1, 1)));
                S = S + z;
            }
        //Старт/стоп - символ *
        z = Code_Char(Code_39_Ch("*")) + S + Code_Char(Code_39_Ch("*"));
        return z;
        }

        private static string Code_39_Ch(string Ch)
        {
        string S;
        switch (Ch)
         {
            case "1":
                S = "3113111131";
                break;
            case "2":
                S = "1133111131";
                break;
            case "3":
                S = "3133111111";
                break;
            case "4":
                S = "1113311131";
                break;
            case "5":
                S = "3113311111";
                break;
            case "6":
                S = "1133311111";
                break;
            case "7":
                S = "1113113131";
                break;
            case "8":
                S = "3113113111";
                break;
            case "9":
                S = "1133113111";
                break;
            case "0":
                S = "1113313111";
                break;
            case "A":
                S = "3111131131";
                break;
            case "B":
                S = "1131131131";
                break;
            case "C":
                S = "3131131111";
                break;
            case "D":
                S = "1111331131";
                break;
            case "E":
                S = "3111331111";
                break;
            case "F":
                S = "1131331111";
                break;
            case "G":
                S = "1111133131";
                break;
            case "H":
                S = "3111133111";
                break;
            case "I":
                S = "1131133111";
                break;
            case "J":
                S = "1111333111";
                break;
            case "K":
                S = "3111111331";
                break;
            case "L":
                S = "1131111331";
                break;
            case "M":
                S = "3131111311";
                break;
            case "N":
                S = "1111311331";
                break;
            case "O":
                S = "3111311311";
                break;
            case "P":
                S = "1131311311";
                break;
            case "Q":
                S = "1111113331";
                break;
            case "R":
                S = "3111113311";
                break;
            case "S":
                S = "1131113311";
                break;
            case "T":
                S = "1111313311";
                break;
            case "U":
                S = "3311111131";
                break;
            case "V":
                S = "1331111131";
                break;
            case "W":
                S = "3331111111";
                break;
            case "X":
                S = "1311311131";
                break;
            case "Y":
                S = "3311311111";
                break;
            case "Z":
                S = "1331311111";
                break;
            case "-":
                S = "1311113131";
                break;
            case ".":
                S = "3311113111";
                break;
            case " ":
                S = "1331113111";
                break;
            case "*":
                S = "1311313111";
                break;
            case "$":
                S = "1313131111";
                break;
            case "/":
                S = "1313111311";
                break;
            case "+":
                S = "1311131311";
                break;
            case "%":
                S = "1113131311";
                break;
            default:
                S = "";
                break;
     }
        return S;
    }

        private static string Code_Char(string A)
        {
            string S;
            string B;
            switch (A)
            {
                case "211412":
                    S = "A";
                    break;
                case "211214":
                    S = "B";
                    break;
                case "211232":
                    S = "C";
                    break;
                case "2331112":
                    S = "@";
                    break;
                default:
                    S = "";
                    for (int I = 0; I <= A.Length / 2 - 1; I++)
                    {
                        switch (A.Substring(2 * I, 2))
                        {
                            case "11":
                                S = S + "0";
                                break;
                            case "21":
                                S = S + "1";
                                break;
                            case "31":
                                S = S + "2";
                                break;
                            case "41":
                                S = S + "3";
                                break;
                            case "12":
                                S = S + "4";
                                break;
                            case "22":
                                S = S + "5";
                                break;
                            case "32":
                                S = S + "6";
                                break;
                            case "42":
                                S = S + "7";
                                break;
                            case "13":
                                S = S + "8";
                                break;
                            case "23":
                                S = S + "9";
                                break;
                            case "33":
                                S = S + ":";
                                break;
                            case "43":
                                S = S + ";";
                                break;
                            case "14":
                                S = S + "<";
                                break;
                            case "24":
                                S = S + "=";
                                break;
                            case "34":
                                S = S + ">";
                                break;
                            case "44":
                                S = S + "?";
                                break;
                        }
                    }
                    break;
            }
            return S;
        }
    }


Вызывается например так:
Код: c#
1.
2.
3.
4.
5.
6.
        public string barcode 
        { get 
            {
                return Barcodeconverter.Code_39(billID);
            }
        }



Соответственно в XAML значение barcode нужно выводить шрифтом Barcode.ttf:

Код: xml
1.
<TextBlock Text="{Binding barcode}" FontFamily="Barcode"/>
...
Рейтинг: 0 / 0
штрих коды , в частности ean128, есть у кого код или длл?
    #38215847
igara
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Serge73
В спойлере конвертированный код C# для code_39
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
class Barcodeconverter
    {
        public static string Code_39(string A)
        {
            string S = "";
            string z = "";
        for (int I = 1; I <= A.Length;I++)
            {
                z = Code_Char(Code_39_Ch(A.Substring(I-1, 1)));
                S = S + z;
            }
        //Старт/стоп - символ *
        z = Code_Char(Code_39_Ch("*")) + S + Code_Char(Code_39_Ch("*"));
        return z;
        }

        private static string Code_39_Ch(string Ch)
        {
        string S;
        switch (Ch)
         {
            case "1":
                S = "3113111131";
                break;
            case "2":
                S = "1133111131";
                break;
            case "3":
                S = "3133111111";
                break;
            case "4":
                S = "1113311131";
                break;
            case "5":
                S = "3113311111";
                break;
            case "6":
                S = "1133311111";
                break;
            case "7":
                S = "1113113131";
                break;
            case "8":
                S = "3113113111";
                break;
            case "9":
                S = "1133113111";
                break;
            case "0":
                S = "1113313111";
                break;
            case "A":
                S = "3111131131";
                break;
            case "B":
                S = "1131131131";
                break;
            case "C":
                S = "3131131111";
                break;
            case "D":
                S = "1111331131";
                break;
            case "E":
                S = "3111331111";
                break;
            case "F":
                S = "1131331111";
                break;
            case "G":
                S = "1111133131";
                break;
            case "H":
                S = "3111133111";
                break;
            case "I":
                S = "1131133111";
                break;
            case "J":
                S = "1111333111";
                break;
            case "K":
                S = "3111111331";
                break;
            case "L":
                S = "1131111331";
                break;
            case "M":
                S = "3131111311";
                break;
            case "N":
                S = "1111311331";
                break;
            case "O":
                S = "3111311311";
                break;
            case "P":
                S = "1131311311";
                break;
            case "Q":
                S = "1111113331";
                break;
            case "R":
                S = "3111113311";
                break;
            case "S":
                S = "1131113311";
                break;
            case "T":
                S = "1111313311";
                break;
            case "U":
                S = "3311111131";
                break;
            case "V":
                S = "1331111131";
                break;
            case "W":
                S = "3331111111";
                break;
            case "X":
                S = "1311311131";
                break;
            case "Y":
                S = "3311311111";
                break;
            case "Z":
                S = "1331311111";
                break;
            case "-":
                S = "1311113131";
                break;
            case ".":
                S = "3311113111";
                break;
            case " ":
                S = "1331113111";
                break;
            case "*":
                S = "1311313111";
                break;
            case "$":
                S = "1313131111";
                break;
            case "/":
                S = "1313111311";
                break;
            case "+":
                S = "1311131311";
                break;
            case "%":
                S = "1113131311";
                break;
            default:
                S = "";
                break;
     }
        return S;
    }

        private static string Code_Char(string A)
        {
            string S;
            string B;
            switch (A)
            {
                case "211412":
                    S = "A";
                    break;
                case "211214":
                    S = "B";
                    break;
                case "211232":
                    S = "C";
                    break;
                case "2331112":
                    S = "@";
                    break;
                default:
                    S = "";
                    for (int I = 0; I <= A.Length / 2 - 1; I++)
                    {
                        switch (A.Substring(2 * I, 2))
                        {
                            case "11":
                                S = S + "0";
                                break;
                            case "21":
                                S = S + "1";
                                break;
                            case "31":
                                S = S + "2";
                                break;
                            case "41":
                                S = S + "3";
                                break;
                            case "12":
                                S = S + "4";
                                break;
                            case "22":
                                S = S + "5";
                                break;
                            case "32":
                                S = S + "6";
                                break;
                            case "42":
                                S = S + "7";
                                break;
                            case "13":
                                S = S + "8";
                                break;
                            case "23":
                                S = S + "9";
                                break;
                            case "33":
                                S = S + ":";
                                break;
                            case "43":
                                S = S + ";";
                                break;
                            case "14":
                                S = S + "<";
                                break;
                            case "24":
                                S = S + "=";
                                break;
                            case "34":
                                S = S + ">";
                                break;
                            case "44":
                                S = S + "?";
                                break;
                        }
                    }
                    break;
            }
            return S;
        }
    }


Вызывается например так:
Код: c#
1.
2.
3.
4.
5.
6.
        public string barcode 
        { get 
            {
                return Barcodeconverter.Code_39(billID);
            }
        }



Соответственно в XAML значение barcode нужно выводить шрифтом Barcode.ttf:

Код: xml
1.
<TextBlock Text="{Binding barcode}" FontFamily="Barcode"/>




Есть проще способ, входящюю строку с обоих сторон закрыть символом звёздочка '789456' -> '*789456*' и вывести штрифтом, который приложен в этом сообщении. Даже в ворде и экселе работает
...
Рейтинг: 0 / 0
15 сообщений из 15, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / штрих коды , в частности ean128, есть у кого код или длл?
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]