Skip to content

Commit

Permalink
change qr lib; bump serilog #53
Browse files Browse the repository at this point in the history
  • Loading branch information
mrerro committed Jul 16, 2023
1 parent 021b972 commit fa06a40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions PrinterApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
<Rectangle Style="{DynamicResource Flake3}" Canvas.Left="{Binding FlakesCanvasLeft[11]}"
Canvas.Top="{Binding FlakesCanvasTop[11]}" />
</Canvas>
<Image Width="212" Height="212" Source="{Binding PrintQr}" HorizontalAlignment="Left"
<Path Width="212" Height="212" Data="{Binding PrintQr}" HorizontalAlignment="Left"
VerticalAlignment="Top" Canvas.Left="219" Canvas.Top="485"
Visibility="{Binding PrintQrVisibility}" Focusable="False" Stretch="Fill"
RenderOptions.EdgeMode="Aliased" />
RenderOptions.EdgeMode="Aliased" Fill="White" />
<Rectangle Width="3" Height="590" Canvas.Left="684" Canvas.Top="155"
Fill="{DynamicResource Labels.Foreground}" Focusable="False" />
<TextBlock FontSize="24" Width="641" Height="449" Canvas.Left="814" Canvas.Top="57" TextWrapping="Wrap"
Expand Down
6 changes: 3 additions & 3 deletions PrinterApp/PrinterApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="QRCoder" Version="1.4.3" />
<PackageReference Include="QRCoder.Xaml" Version="1.4.3" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="ZXing.Net" Version="0.16.9" />
<PackageReference Include="ZXing.Net.Bindings.Windows.Compatibility" Version="0.16.12" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 14 additions & 10 deletions PrinterApp/PrinterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using QRCoder;
using QRCoder.Xaml;
using System.Collections.Generic;
using System.Windows.Documents;
using ZXing;
using ZXing.Windows.Compatibility;

namespace PrinterApp;

Expand Down Expand Up @@ -44,7 +43,6 @@ public class PrinterModel

public PrinterViewModel PrinterViewModel { get; } = new();

private readonly QRCodeGenerator _qrGenerator = new();
private readonly ConfigFile _configFile;
private readonly AutoUpdater _autoUpdater;
private readonly HttpClient _httpClient;
Expand Down Expand Up @@ -108,7 +106,6 @@ public PrinterModel(ConfigFile configFile, AutoUpdater autoUpdater)
~PrinterModel()
{
_httpClient.Dispose();
_qrGenerator?.Dispose();
}

private static string SearchSumatraPdf()
Expand Down Expand Up @@ -458,11 +455,18 @@ private void GenerateQr(string value)
$"{GetType().Name} {MethodBase.GetCurrentMethod()?.Name}: new qr code {value}");
try
{
var qrCodeData = _qrGenerator.CreateQrCode(value, QRCodeGenerator.ECCLevel.Q);
var qrCode = new XamlQRCode(qrCodeData);
var qrCodeImage = qrCode.GetGraphic(20, "#FFFFFFFF", "#00FFFFFF", false);
qrCodeImage.Freeze();
PrinterViewModel.PrintQr = qrCodeImage;
var writer = new BarcodeWriterGeometry
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 212,
Width = 212
}
};
var image = writer.Write(value);
image.Freeze();
PrinterViewModel.PrintQr = image;
}
catch (Exception exception)
{
Expand Down
5 changes: 2 additions & 3 deletions PrinterApp/PrinterViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace PrinterApp;

Expand All @@ -11,7 +10,7 @@ public class PrinterViewModel : NotifyPropertyChangeBase
private string _codeTextBoxText = "";
private string _errorTextBlockText = "";
private Visibility _errorTextBlockVisibility = Visibility.Collapsed;
private ImageSource _printQr = new BitmapImage();
private Geometry _printQr = Geometry.Empty;
private Visibility _printQrVisibility = Visibility.Visible;
private string _compliment = "";
private Visibility _flakesVisibility = Visibility.Collapsed;
Expand Down Expand Up @@ -62,7 +61,7 @@ public Visibility ErrorTextBlockVisibility
}
}

public ImageSource PrintQr
public Geometry PrintQr
{
get => _printQr;
set
Expand Down

0 comments on commit fa06a40

Please sign in to comment.