forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove GDI+ & new QRCode Impl & Add Skia
- Loading branch information
Showing
15 changed files
with
213 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule Titanium-Web-Proxy
updated
from 2bb9ad to 6dbddb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
src/ST.Client.Desktop/Services/Implementation/FontManagerImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/ST.Client/UI/QRCodeHelper.Net.Codecrete.QrCodeGenerator.SkiaSharp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* QR code generator library (.NET) | ||
* | ||
* Copyright (c) Manuel Bleichenbacher (MIT License) | ||
* https://github.com/manuelbl/QrCodeGenerator | ||
* | ||
*/ | ||
|
||
using SkiaSharp; | ||
using System; | ||
|
||
namespace Net.Codecrete.QrCodeGenerator | ||
{ | ||
public static class QrCodeBitmapExtensions | ||
{ | ||
/// <inheritdoc cref="ToBitmap(QrCode, int, int)"/> | ||
/// <param name="background">The background color.</param> | ||
/// <param name="foreground">The foreground color.</param> | ||
public static SKBitmap ToBitmap(this QrCode qrCode, int scale, int border, SKColor foreground, SKColor background) | ||
{ | ||
// check arguments | ||
if (scale <= 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(scale), "Value out of range"); | ||
} | ||
if (border < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(border), "Value out of range"); | ||
} | ||
|
||
int size = qrCode.Size; | ||
int dim = (size + border * 2) * scale; | ||
|
||
if (dim > short.MaxValue) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(scale), "Scale or border too large"); | ||
} | ||
|
||
// create bitmap | ||
SKBitmap bitmap = new SKBitmap(dim, dim, SKColorType.Argb4444, SKAlphaType.Premul); | ||
|
||
using (SKCanvas canvas = new SKCanvas(bitmap)) | ||
{ | ||
// draw background | ||
using (SKPaint paint = new SKPaint { Color = background }) | ||
{ | ||
canvas.DrawRect(0, 0, dim, dim, paint); | ||
} | ||
|
||
// draw modules | ||
using (SKPaint paint = new SKPaint { Color = foreground }) | ||
{ | ||
for (int y = 0; y < size; y++) | ||
{ | ||
for (int x = 0; x < size; x++) | ||
{ | ||
if (qrCode.GetModule(x, y)) | ||
{ | ||
canvas.DrawRect((x + border) * scale, (y + border) * scale, scale, scale, paint); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return bitmap; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/ST.Client/UI/QRCodeHelper.Net.Codecrete.QrCodeGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Net.Codecrete.QrCodeGenerator; | ||
using SkiaSharp; | ||
using System.IO; | ||
|
||
namespace System.Application.UI | ||
{ | ||
public static partial class QRCodeHelper | ||
{ | ||
public static (QRCodeCreateResult result, Stream? stream, Exception? exception) Create(byte[] bytes, QrCode.Ecc? level = null) | ||
{ | ||
level ??= QrCode.Ecc.Low; | ||
try | ||
{ | ||
var qrCode = QrCode.EncodeBinary(bytes, level); // Make the QR code symbol | ||
|
||
int scale = 10, border = 4; | ||
using SKBitmap bitmap = qrCode.ToBitmap(scale, border, SKColors.Black, SKColors.Transparent); | ||
SKData data = bitmap.Encode(SKEncodedImageFormat.Png, 90); | ||
|
||
return (QRCodeCreateResult.Success, data.AsStream(true), null); | ||
} | ||
catch (DataTooLongException e) | ||
{ | ||
return (QRCodeCreateResult.DataTooLong, null, e); | ||
} | ||
catch (Exception e) | ||
{ | ||
return (QRCodeCreateResult.Exception, null, e); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.