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

View File

@ -47,7 +47,7 @@
</GroupBox>
<Expander x:Name="expander" Header="Log" Margin="2,2,2,2" Grid.Row="1">
<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"/>
</Grid>
</Expander>

View File

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

View File

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