31 lines
785 B
C#
31 lines
785 B
C#
using System.Globalization;
|
|||
|
|
using System.Text;
|
||
|
|
|
||
|
|
using Avalonia.Media;
|
||
|
|
|
||
|
|
using QRCoder;
|
||
|
|
|
||
|
|
namespace MeWeb.App.Services;
|
||
|
|
|
||
|
|
public static class QrCodes
|
||
|
|
{
|
||
|
|
public static Geometry For(string text)
|
||
|
|
{
|
||
|
|
using var generator = new QRCodeGenerator();
|
||
|
|
using var data = generator.CreateQrCode(text, QRCodeGenerator.ECCLevel.M);
|
||
|
|
var path = new StringBuilder();
|
||
|
|
for (var y = 0; y < data.ModuleMatrix.Count; y++)
|
||
|
|
{
|
||
|
|
var row = data.ModuleMatrix[y];
|
||
|
|
for (var x = 0; x < row.Length; x++)
|
||
|
|
{
|
||
|
|
if (!row[x]) continue;
|
||
|
|
var run = 1;
|
||
|
|
while (x + run < row.Length && row[x + run]) run++;
|
||
|
|
path.Append(CultureInfo.InvariantCulture, $"M{x},{y}h{run}v1h-{run}z");
|
||
|
|
x += run - 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return Geometry.Parse(path.ToString());
|
||
|
|
}
|
||
|
|
}
|