예제 #1
0
 public async Task <Stream> CreateBitmapAsync(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
 {
     return(await Task.Run(() =>
     {
         return CreateBitmap(text, languageIndex, paperSizeIndex);
     }));
 }
예제 #2
0
    private LanguageIndex GetLanguageIndexByName(LanguagesNames name)
    {
        LanguageIndex index = LanguageIndex.PT;

        switch (name)
        {
        case LanguagesNames.Português: index = LanguageIndex.PT; break;

        case LanguagesNames.English: index = LanguageIndex.EN; break;

        case LanguagesNames.Español: index = LanguageIndex.ES; break;

        case LanguagesNames.Frainçais: index = LanguageIndex.FR; break;
        }
        return(index);
    }
예제 #3
0
    private LanguagesNames GetLanguageNameByIndex(LanguageIndex index)
    {
        LanguagesNames name = LanguagesNames.Português;

        switch (index)
        {
        case LanguageIndex.PT: name = LanguagesNames.Português; break;

        case LanguageIndex.EN: name = LanguagesNames.English; break;

        case LanguageIndex.ES: name = LanguagesNames.Español; break;

        case LanguageIndex.FR: name = LanguagesNames.Frainçais; break;
        }
        return(name);
    }
        public LocalizeReceipts(LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
        {
            switch (languageIndex)
            {
            default:
//              case LanguageIndex.English :
                this.localizeReceiptsComponent = new EnglishReceiptsComponent();
                break;

            case LanguageIndex.Japanese:
                this.localizeReceiptsComponent = new JapaneseReceiptsComponent();
                break;

            case LanguageIndex.French:
                this.localizeReceiptsComponent = new FrenchReceiptsComponent();
                break;

            case LanguageIndex.Portuguese:
                this.localizeReceiptsComponent = new PortugueseReceiptsComponent();
                break;

            case LanguageIndex.Spanish:
                this.localizeReceiptsComponent = new SpanishReceiptsComponent();
                break;

            case LanguageIndex.German:
                this.localizeReceiptsComponent = new GermanReceiptsComponent();
                break;

            case LanguageIndex.Russian:
                this.localizeReceiptsComponent = new RussianReceiptsComponent();
                break;

            case LanguageIndex.SimplifiedChinese:
                this.localizeReceiptsComponent = new SimplifiedChineseReceiptsComponent();
                break;

            case LanguageIndex.TraditionalChinese:
                this.localizeReceiptsComponent = new TraditionalChineseReceiptsComponent();
                break;
            }

            this.languageIndex  = languageIndex;
            this.paperSizeIndex = paperSizeIndex;
        }
예제 #5
0
        public async Task <Stream> CreateBitmapAsync(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
        {
            Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> > sizeDictionary = new Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> >()
            {
                { LanguageIndex.English, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 26 }, { PaperSizeIndex.ThreeInch, 30 }, { PaperSizeIndex.FourInch, 29 }, { PaperSizeIndex.EscPosThreeInch, 28 }
                  } },
                { LanguageIndex.Japanese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 26 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.French, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 29 }, { PaperSizeIndex.ThreeInch, 30 }, { PaperSizeIndex.FourInch, 30 }, { PaperSizeIndex.EscPosThreeInch, 28 }
                  } },
                { LanguageIndex.Portuguese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 29 }, { PaperSizeIndex.ThreeInch, 29 }, { PaperSizeIndex.FourInch, 29 }, { PaperSizeIndex.EscPosThreeInch, 29 }
                  } },
                { LanguageIndex.Spanish, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 29 }, { PaperSizeIndex.ThreeInch, 30 }, { PaperSizeIndex.FourInch, 29 }, { PaperSizeIndex.EscPosThreeInch, 29 }
                  } },
                { LanguageIndex.German, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 29 }, { PaperSizeIndex.ThreeInch, 30 }, { PaperSizeIndex.FourInch, 29 }, { PaperSizeIndex.EscPosThreeInch, 29 }
                  } },
                { LanguageIndex.Russian, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 26 }, { PaperSizeIndex.EscPosThreeInch, 23 }
                  } },
                { LanguageIndex.SimplifiedChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 28 }, { PaperSizeIndex.FourInch, 29 }, { PaperSizeIndex.EscPosThreeInch, 27 }
                  } },
                { LanguageIndex.TraditionalChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 29 }, { PaperSizeIndex.FourInch, 29 }, { PaperSizeIndex.EscPosThreeInch, 29 }
                  } }
            };

            Dictionary <LanguageIndex, FontFamily> fontDictionary = new Dictionary <LanguageIndex, FontFamily>()
            {
                { LanguageIndex.English, new FontFamily("MS Gothic") },
                { LanguageIndex.Japanese, new FontFamily("MS Gothic") },
                { LanguageIndex.French, new FontFamily("MS Gothic") },
                { LanguageIndex.Portuguese, new FontFamily("MS Gothic") },
                { LanguageIndex.Spanish, new FontFamily("MS Gothic") },
                { LanguageIndex.German, new FontFamily("MS Gothic") },
                { LanguageIndex.Russian, new FontFamily("Courier New") },
                { LanguageIndex.SimplifiedChinese, new FontFamily("MS Gothic") },
                { LanguageIndex.TraditionalChinese, new FontFamily("MS Gothic") }
            };

            Windows.UI.Xaml.Controls.Grid grid = new Windows.UI.Xaml.Controls.Grid();

            Windows.UI.Xaml.Controls.RowDefinition rowDefinition = new Windows.UI.Xaml.Controls.RowDefinition();
            grid.RowDefinitions.Add(rowDefinition);

            TextBlock textdata = new TextBlock();

            textdata.Text         = text;
            textdata.FontSize     = sizeDictionary[languageIndex][paperSizeIndex];
            textdata.FontFamily   = fontDictionary[languageIndex];
            textdata.Width        = (uint)paperSizeIndex;
            textdata.TextWrapping = TextWrapping.Wrap;

            Windows.UI.Xaml.Controls.Grid.SetRow(textdata, 0);

            grid.Children.Add(textdata);

            StackPanel panel = new StackPanel();

            panel.Background        = new SolidColorBrush(Colors.White);
            panel.VerticalAlignment = VerticalAlignment.Top;
            panel.Orientation       = Orientation.Horizontal;
            panel.Children.Add(grid);

            Popup popup = new Popup();

            double h = Window.Current.Bounds.Height;
            double w = Window.Current.Bounds.Width;

            popup.HorizontalOffset = -h * 2;
            popup.VerticalOffset   = -w * 2;
            popup.Child            = panel;
            popup.IsOpen           = true;

            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(panel);

            popup.IsOpen = false;
            IBuffer pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

            byte[] pixels = pixelBuffer.ToArray();

            InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
            BitmapEncoder encoder             = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

            encoder.SetPixelData(
                BitmapPixelFormat.Bgra8,
                BitmapAlphaMode.Ignore,
                (uint)renderTargetBitmap.PixelWidth,
                (uint)renderTargetBitmap.PixelHeight,
                72,
                72,
                pixels);

            encoder.BitmapTransform.Rotation          = BitmapRotation.None;
            encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Cubic;
            await encoder.FlushAsync();

            return(stream.AsStream());
        }
예제 #6
0
 public DefinitionsData(LanguageIndex languageDefined, int languageIndexer)
 {
     LanguageDefined = languageDefined;
     LanguageIndexer = languageIndexer;
 }
예제 #7
0
 public Task <Stream> CreateBitmapAsync(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
 {
     return(DependencyService.Get <IPlatformDepends>().CreateBitmapAsync(text, languageIndex, paperSizeIndex));
 }
예제 #8
0
 public static Sprite GetFlag(LanguageIndex language) => GetSprite(FLAGS + language.ToString());
        public Stream CreateBitmap(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
        {
            Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> > sizeDictionary = new Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> >()
            {
                { LanguageIndex.English, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 10 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.Japanese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 11 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.French, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 12 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.Portuguese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 12 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.Spanish, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 12 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.German, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 12 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.Russian, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 11 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.SimplifiedChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 11 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } },
                { LanguageIndex.TraditionalChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 11 * 2 }, { PaperSizeIndex.ThreeInch, 12 * 2 }, { PaperSizeIndex.FourInch, 12 * 2 }, { PaperSizeIndex.EscPosThreeInch, 12 * 2 }
                  } }
            };

            NSString nativeText = new NSString(text);

            UIFont font = UIFont.FromName("Menlo", sizeDictionary[languageIndex][paperSizeIndex]);

            UIStringAttributes stringAttributes = new UIStringAttributes
            {
                Font            = font,
                ForegroundColor = UIColor.Black
            };

            CGSize size = NSExtendedStringDrawing.GetBoundingRect(nativeText,
                                                                  new CGSize((int)paperSizeIndex, 10000),
                                                                  NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.TruncatesLastVisibleLine,
                                                                  stringAttributes,
                                                                  null).Size;

            if (UIScreen.MainScreen.RespondsToSelector(new ObjCRuntime.Selector("scale")))
            {
                if (UIScreen.MainScreen.Scale == 2.0)
                {
                    UIGraphics.BeginImageContextWithOptions(size, false, 1.0f);
                }
                else
                {
                    UIGraphics.BeginImageContext(size);
                }
            }
            else
            {
                UIGraphics.BeginImageContext(size);
            }

            CGContext context = UIGraphics.GetCurrentContext();

            UIColor.White.SetColor();

            CGRect rect = new CGRect(0, 0, size.Width + 1, size.Height + 1);

            context.FillRect(rect);

            NSDictionary attributes = new NSDictionary("NSForegroundColorAttributeName", UIColor.Black, "NSFontAttributeName", font);

            (new NSAttributedString(nativeText, stringAttributes)).DrawString(rect);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image.AsPNG().AsStream());
        }
예제 #10
0
        private Stream CreateBitmap(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex)
        {
            Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> > sizeDictionary = new Dictionary <LanguageIndex, Dictionary <PaperSizeIndex, int> >()
            {
                { LanguageIndex.English, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 23 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Japanese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.French, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 25 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Portuguese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Spanish, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.German, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 24 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.Russian, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 25 }, { PaperSizeIndex.FourInch, 25 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.SimplifiedChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } },
                { LanguageIndex.TraditionalChinese, new Dictionary <PaperSizeIndex, int>()
                  {
                      { PaperSizeIndex.TwoInch, 22 }, { PaperSizeIndex.ThreeInch, 24 }, { PaperSizeIndex.FourInch, 24 }, { PaperSizeIndex.EscPosThreeInch, 24 }
                  } }
            };

            Paint paint = new Paint();

            paint.TextSize = sizeDictionary[languageIndex][paperSizeIndex];

            Typeface typeface = Typeface.Create(Typeface.Monospace, TypefaceStyle.Normal);

            paint.SetTypeface(typeface);

            paint.GetTextBounds(text, 0, text.Length, new Rect());

            TextPaint textPaint = new TextPaint(paint);

            StaticLayout staticLayout = new StaticLayout(text, textPaint, (int)paperSizeIndex, Android.Text.Layout.Alignment.AlignNormal, 1, 0, false);

            Bitmap bitmap = Bitmap.CreateBitmap(staticLayout.Width, staticLayout.Height, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(bitmap);

            canvas.DrawColor(Android.Graphics.Color.White);

            canvas.Translate(0, 0);

            staticLayout.Draw(canvas);

            MemoryStream memoryStream = new MemoryStream();

            bitmap.Compress(Bitmap.CompressFormat.Png, 100, memoryStream);

            memoryStream.Seek(0, SeekOrigin.Begin);

            return(memoryStream);
        }