public PrinterSelectorDialogViewModel() { printingProvider = Main.PrintingProvider; PrinterSelector = printingProvider.PrinterSelector; SelectedPrinterIndex = PrinterSelector.ObserveProperty(p => p.SelectedPrinter) .Select(x => PrinterSelector.Printers.IndexOf(x)).ToReactiveProperty(); PaperSizes = PrintingProvider.PaperSizes; PaperOrientations = PrintingProvider.PaperOrientations; PaperSizeIndex = printingProvider.ObserveProperty(p => p.PaperSize) .Select(x => PrintingProvider.PaperSizes.IndexOf(x)).ToReactiveProperty(); PaperOrientationIndex = printingProvider.ObserveProperty(p => p.PaperOrientation) .Select(x => PrintingProvider.PaperOrientations.IndexOf(x)).ToReactiveProperty(); PaperSizeIndex.ObserveProperty(x => x.Value) .Subscribe(i => printingProvider.PaperSize = PrintingProvider.PaperSizes[i]); PaperOrientationIndex.ObserveProperty(x => x.Value).Subscribe(i => printingProvider.PaperOrientation = PrintingProvider.PaperOrientations[i]); PrintCommand = new ReactiveCommand(); PrintCommand.Subscribe(Print); CancelCommand = new ReactiveCommand(); CancelCommand.Subscribe(() => IsShowDialog = false); ShowDialogCommand = new ReactiveCommand(); ShowDialogCommand.Subscribe(() => IsShowDialog = true); }
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; }
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()); }
public Task <Stream> CreateBitmapAsync(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex) { return(DependencyService.Get <IPlatformDepends>().CreateBitmapAsync(text, languageIndex, paperSizeIndex)); }
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()); }
public async Task <Stream> CreateBitmapAsync(string text, LanguageIndex languageIndex, PaperSizeIndex paperSizeIndex) { Stream bitmap = CreateBitmap(text, languageIndex, paperSizeIndex); return(await Task.Run(() => { return bitmap; })); }
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); }