diff --git a/libpaperang/IPrinter.cs b/libpaperang/IPrinter.cs index e0913b1..641f0e9 100644 --- a/libpaperang/IPrinter.cs +++ b/libpaperang/IPrinter.cs @@ -14,10 +14,11 @@ namespace libpaperang { public byte End; } public enum Model { - P1, - T1, - P2, - P2S + P1, // Original model; 57mm feed, 48-byte lines (200DPI), LiPo battery (1Ah) + P1S,// Original "special edition" model; identical to P1 but in different colours + T1, // Label printer model; 15mm feed, unknown-byte lines, 4xAAA battery + P2, // Hi-DPI model; 57mm feed, 96-byte lines (300DPI), LiPo battery (1Ah) + P2S // Hi-DPI "special edition" model; identical to P2 but includes Pomodoro timer functionality } public enum State { Offline, @@ -36,6 +37,7 @@ namespace libpaperang { CrcTransmit, Print } + //I'm sure there are other opcodes available but these are the "core" ones implemented by the official MiaoMiaoJi chinese Windows and OSX apps public struct Opcodes { public byte[] NoOp; public byte[] LineFeed; diff --git a/paperangapp/MainWindow.xaml.cs b/paperangapp/MainWindow.xaml.cs index be7885d..281c4b3 100644 --- a/paperangapp/MainWindow.xaml.cs +++ b/paperangapp/MainWindow.xaml.cs @@ -46,7 +46,22 @@ namespace paperangapp { logger.Debug("PrinterInitialised? " + mmj.Printer.PrinterInitialised); logger.Debug("Printer initialised and ready"); } - private void BtTestLine_Click(object sender, RoutedEventArgs e) => mmj.Feed(200); + private void BtTestLine_Click(object sender, RoutedEventArgs e) { + string Font="Consolas"; + int FontSize=48; + + Bitmap b=new Bitmap(mmj.Printer.LineWidth*8, (FontSize+4)*10); + g=Graphics.FromImage(b); + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; + g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; + g.DrawString("hello", new Font(Font, FontSize), Brushes.Black, new RectangleF(0, 0, b.Width, b.Height)); + g.Flush(); + PrintBitmap(b); + g.Dispose(); + b.Dispose(); + } private void BtLoadImage_Click(object sender, RoutedEventArgs e) { logger.Debug("Loading image for print"); OpenFileDialog r = new OpenFileDialog { @@ -68,22 +83,25 @@ namespace paperangapp { logger.Debug("Loaded image as Bitmap"); _.Dispose(); logger.Debug("Disposed of Image"); - bimg=CopyToBpp(bimg); + PrintBitmap(bimg); + } + private void PrintBitmap(Bitmap bimg) { + bimg = CopyToBpp(bimg); logger.Debug("Converted Bitmap to Bitmap with 1-bit colour depth"); //BitArray img = new BitArray(bimg.Height*96*8); byte[] iimg = new byte[bimg.Height*mmj.Printer.LineWidth]; byte[] img; - using (MemoryStream s = new MemoryStream()) { + using(MemoryStream s = new MemoryStream()) { bimg.Save(s, ImageFormat.Bmp); - img=s.ToArray(); + img = s.ToArray(); } logger.Debug("Got bitmap's bytes"); int startoffset=img.Length-(bimg.Height*mmj.Printer.LineWidth); logger.Debug("Processing bytes with offset " + startoffset); - for(int h=0;h