how in the world do i rotate text in ms paint

This commit is contained in:
Maff 2019-10-04 16:59:57 +01:00
parent 1afaea4f16
commit 8e55652567
4 changed files with 23 additions and 36 deletions

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using liblogtiny; using liblogtiny;
using libpaperang.Helpers; using libpaperang.Helpers;
using libpaperang.Interfaces; using libpaperang.Interfaces;
@ -49,26 +50,17 @@ namespace libpaperang.Main {
Feed(0); Feed(0);
NoOp(); NoOp();
} }
public bool HandshakeAsync() { public async Task HandshakeAsync() => await Task.Run(() => Handshake());
Handshake();
return true;
}
public void WriteBytes(byte[] packet) { public void WriteBytes(byte[] packet) {
logger?.Trace($"Writing packet with length {packet.Length} to printer"); logger?.Trace($"Writing packet with length {packet.Length} to printer");
_ = Printer.WriteBytes(packet); _ = Printer.WriteBytes(packet);
} }
public bool WriteBytesAsync(byte[] packet) { public async Task WriteBytesAsync(byte[] packet) => await Task.Run(() => WriteBytes(packet));
WriteBytes(packet);
return true;
}
public void WriteBytes(byte[] packet, int ms) { public void WriteBytes(byte[] packet, int ms) {
logger?.Trace($"Writing packet with length {packet.Length} to printer with delay of {ms}ms"); logger?.Trace($"Writing packet with length {packet.Length} to printer with delay of {ms}ms");
_ = Printer.WriteBytes(packet, ms); _ = Printer.WriteBytes(packet, ms);
} }
public bool WriteBytesAsync(byte[] packet, int ms) { public async Task WriteBytesAsync(byte[] packet, int ms) => await Task.Run(() => WriteBytes(packet, ms));
WriteBytes(packet, ms);
return true;
}
public void Feed(uint ms) { public void Feed(uint ms) {
logger?.Trace($"Feeding for {ms}ms"); logger?.Trace($"Feeding for {ms}ms");
WriteBytes( WriteBytes(
@ -76,21 +68,16 @@ namespace libpaperang.Main {
Transform.Arg(BaseTypes.Operations.LineFeed, ms), Transform.Arg(BaseTypes.Operations.LineFeed, ms),
Crc)); Crc));
} }
public bool FeedAsync(uint ms) { public async Task FeedAsync(uint ms) => await Task.Run(() => Feed(ms));
Feed(ms);
return true;
}
public void NoOp() => WriteBytes( public void NoOp() => WriteBytes(
Transform.Packet(BaseTypes.Operations.NoOp, new byte[] { 0, 0 }, Crc)); Transform.Packet(BaseTypes.Operations.NoOp, new byte[] { 0, 0 }, Crc));
public async Task NoOpAsync() => await Task.Run(() => NoOp());
public void Poll() { public void Poll() {
logger?.Trace("Polling attached printer"); logger?.Trace("Polling attached printer");
Feed(0); Feed(0);
NoOp(); NoOp();
} }
public bool PollAsync() { public async Task PollAsync() => await Task.Run(() => Poll());
Poll();
return true;
}
public void PrintBytes(byte[] data, bool autofeed = true) { public void PrintBytes(byte[] data, bool autofeed = true) {
logger?.Trace($"PrintBytes() invoked with data length of {data.Length}"); logger?.Trace($"PrintBytes() invoked with data length of {data.Length}");
List<byte[]> segments = data List<byte[]> segments = data
@ -108,9 +95,6 @@ namespace libpaperang.Main {
if(autofeed) if(autofeed)
Feed(185); Feed(185);
} }
public bool PrintBytesAsync(byte[] data, bool autofeed=true) { public async Task PrintBytesAsync(byte[] data, bool autofeed = true) => await Task.Run(() => PrintBytes(data, autofeed));
PrintBytes(data, autofeed);
return true;
}
} }
} }

View File

@ -47,7 +47,7 @@
</GroupBox> </GroupBox>
<Expander x:Name="expander" Header="Log" Margin="2,2,2,2" Grid.Row="1"> <Expander x:Name="expander" Header="Log" Margin="2,2,2,2" Grid.Row="1">
<Grid> <Grid>
<TextBox x:Name="tbLog" Margin="2,2,2,23" MaxHeight="280" TextWrapping="Wrap" AllowDrop="False" IsReadOnly="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" Text="{Binding Path=LogBuffer}" UseLayoutRounding="True"/> <TextBox x:Name="tbLog" Margin="2,2,2,23" MaxHeight="220" TextWrapping="Wrap" AllowDrop="False" IsReadOnly="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" Text="{Binding Path=LogBuffer}" UseLayoutRounding="True"/>
<Button x:Name="btClearLog" Content="Clear Log" MinWidth="75" Margin="2,0,2,0" Click="BtClearLog_Click" Height="21" VerticalAlignment="Bottom"/> <Button x:Name="btClearLog" Content="Clear Log" MinWidth="75" Margin="2,0,2,0" Click="BtClearLog_Click" Height="21" VerticalAlignment="Bottom"/>
</Grid> </Grid>
</Expander> </Expander>

View File

@ -13,6 +13,7 @@ using libpaperang.Main;
namespace paperangapp { namespace paperangapp {
public partial class MainWindow : Window { public partial class MainWindow : Window {
//TODO memory optimisation - this thing is a hongery boi
private ILogTiny logger; private ILogTiny logger;
private BaseTypes.Connection mmjcx=BaseTypes.Connection.USB; private BaseTypes.Connection mmjcx=BaseTypes.Connection.USB;
private BaseTypes.Model mmjmd=BaseTypes.Model.None; private BaseTypes.Model mmjmd=BaseTypes.Model.None;
@ -114,8 +115,7 @@ namespace paperangapp {
} catch(Exception) { } catch(Exception) {
} finally { } } finally { }
} }
private async void BtFeed_Click(object sender, RoutedEventArgs e) => await FeedAsync((uint)slFeedTime.Value); private async void BtFeed_Click(object sender, RoutedEventArgs e) => await mmj.FeedAsync((uint)slFeedTime.Value);
private async Task FeedAsync(uint time) => await Task.Run(() => mmj.Feed(time));
private async void BtPrintText_Click(object sender, RoutedEventArgs e) { private async void BtPrintText_Click(object sender, RoutedEventArgs e) {
if(!(txInput.Text.Length > 0)) { if(!(txInput.Text.Length > 0)) {
logger.Warn("PrintText event but nothing to print."); logger.Warn("PrintText event but nothing to print.");
@ -125,17 +125,20 @@ namespace paperangapp {
} }
private async Task PrintTextAsync(string text, string font, int szf) { private async Task PrintTextAsync(string text, string font, int szf) {
Font fnt=new Font(font, szf); Font fnt=new Font(font, szf);
Graphics g=Graphics.FromImage(new Bitmap(mmj.Printer.LineWidth*8, 1)); TextFormatFlags tf=
System.Drawing.Size szText = TextRenderer.MeasureText(g, text, fnt); TextFormatFlags.Left |
//SizeF szText=g.MeasureString(txInput.Text, fnt); TextFormatFlags.NoPadding |
g.Dispose(); TextFormatFlags.NoPrefix |
Bitmap b=new Bitmap(mmj.Printer.LineWidth*8, (int)szText.Height); TextFormatFlags.Top |
g = Graphics.FromImage(b); TextFormatFlags.WordBreak;
System.Drawing.Size szText = TextRenderer.MeasureText(text, fnt, new System.Drawing.Size(mmj.Printer.LineWidth*8,10000), tf);
Bitmap b=new Bitmap(mmj.Printer.LineWidth*8, szText.Height);
Graphics g = Graphics.FromImage(b);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
TextRenderer.DrawText(g, text, fnt, new System.Drawing.Point(0, 0), Color.Black); TextRenderer.DrawText(g, text, fnt, new System.Drawing.Point(0, 0), Color.Black, tf);
g.Flush(); g.Flush();
await Task.Run(() => PrintBitmap(b)); await Task.Run(() => PrintBitmap(b));
g.Dispose(); g.Dispose();
@ -194,7 +197,7 @@ namespace paperangapp {
} }
} }
logger.Debug($"Have {img.Length} bytes of print data ({mmj.Printer.LineWidth * 8}x{hSzImg}@1bpp)"); logger.Debug($"Have {img.Length} bytes of print data ({mmj.Printer.LineWidth * 8}x{hSzImg}@1bpp)");
await Task.Run(() => mmj.PrintBytes(iimg, false)); await mmj.PrintBytesAsync(iimg, false);
} }
#region GDIBitmap1bpp #region GDIBitmap1bpp
static Bitmap CopyToBpp(Bitmap b) { static Bitmap CopyToBpp(Bitmap b) {

View File

@ -28,7 +28,7 @@
<InstallUrl>https://swdist.ext.maff.scot/paperang/</InstallUrl> <InstallUrl>https://swdist.ext.maff.scot/paperang/</InstallUrl>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish> <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage> <WebPage>publish.htm</WebPage>
<ApplicationRevision>4</ApplicationRevision> <ApplicationRevision>5</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted> <PublishWizardCompleted>true</PublishWizardCompleted>