Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
codebude committed Apr 17, 2024
2 parents 871e70a + a24c984 commit 33ae0c1
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 112 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/wf-build-release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
name: Checkout Code

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand All @@ -26,7 +26,7 @@ jobs:
uses: microsoft/setup-msbuild@v1

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.2
uses: NuGet/setup-nuget@v2

- name: Restore NuGet Packages
run: nuget restore QRCoder.sln
Expand All @@ -35,7 +35,7 @@ jobs:
run: msbuild QRCoder.sln /p:Configuration=Release /p:NoWarn="1182" /p:NoWarn="1701" /nr:false /t:Rebuild

- name: Upload artifacts
uses: actions/upload-artifact@v1.0.0
uses: actions/upload-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder
Expand All @@ -45,13 +45,13 @@ jobs:
runs-on: windows-2019
steps:
- name: Download artifacts
uses: actions/download-artifact@v1.0.0
uses: actions/download-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand Down Expand Up @@ -123,16 +123,16 @@ jobs:
needs: test
runs-on: windows-2019
env:
GH_PKG_SEC: ${{ secrets.GH_PKG_REPO }}
GH_PKG_SEC: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v1.0.0
uses: actions/download-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand Down Expand Up @@ -177,6 +177,6 @@ jobs:
runs-on: windows-2019
steps:
- name: Delete artifacts
uses: GeekyEggo/delete-artifact@v1.0.0
uses: GeekyEggo/delete-artifact@v5
with:
name: Compiled project
18 changes: 9 additions & 9 deletions .github/workflows/wf-build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
name: Checkout Code

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand All @@ -27,7 +27,7 @@ jobs:
uses: microsoft/setup-msbuild@v1

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.2
uses: NuGet/setup-nuget@v2

- name: Restore NuGet Packages
run: nuget restore QRCoder.sln
Expand All @@ -36,7 +36,7 @@ jobs:
run: msbuild QRCoder.sln /p:Configuration=Release /p:NoWarn="1182" /p:NoWarn="1701" /nr:false /t:Rebuild

- name: Upload artifacts
uses: actions/upload-artifact@v1.0.0
uses: actions/upload-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder
Expand All @@ -46,7 +46,7 @@ jobs:
runs-on: windows-2019
steps:
- name: Download artifacts
uses: actions/download-artifact@v1.0.0
uses: actions/download-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder
Expand Down Expand Up @@ -123,16 +123,16 @@ jobs:
needs: test
runs-on: windows-2019
env:
GH_PKG_SEC: ${{ secrets.GH_PKG_REPO }}
GH_PKG_SEC: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v1.0.0
uses: actions/download-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand Down Expand Up @@ -171,6 +171,6 @@ jobs:
runs-on: windows-2019
steps:
- name: Delete artifacts
uses: GeekyEggo/delete-artifact@v1.0.0
uses: GeekyEggo/delete-artifact@v5
with:
name: Compiled project
14 changes: 7 additions & 7 deletions .github/workflows/wf-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
name: Checkout Code

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand All @@ -26,7 +26,7 @@ jobs:
uses: microsoft/setup-msbuild@v1

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.2
uses: NuGet/setup-nuget@v2

- name: Restore NuGet Packages
run: nuget restore QRCoder.sln
Expand All @@ -35,7 +35,7 @@ jobs:
run: msbuild QRCoder.sln /p:Configuration=Release /p:NoWarn="1182" /p:NoWarn="1701" /nr:false /t:Rebuild

- name: Upload artifacts
uses: actions/upload-artifact@v1.0.0
uses: actions/upload-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder
Expand All @@ -45,13 +45,13 @@ jobs:
runs-on: windows-2019
steps:
- name: Download artifacts
uses: actions/download-artifact@v1.0.0
uses: actions/download-artifact@v4
with:
name: Compiled project
path: D:\a\qrcoder\qrcoder

- name: Install additional .NET SDKs
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
1.0.x
Expand Down Expand Up @@ -89,6 +89,6 @@ jobs:
runs-on: windows-2019
steps:
- name: Delete artifacts
uses: GeekyEggo/delete-artifact@v1.0.0
uses: GeekyEggo/delete-artifact@v5
with:
name: Compiled project
4 changes: 2 additions & 2 deletions QRCoder/ASCIIQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString
var lineBuilder = new StringBuilder();
for (var x = 0; x < QrCodeData.ModuleMatrix.Count - quietZonesModifier; x++)
{
var module = QrCodeData.ModuleMatrix[x + quietZonesOffset][((y + verticalNumberOfRepeats) / verticalNumberOfRepeats - 1)+quietZonesOffset];
var module = QrCodeData.ModuleMatrix[((y + verticalNumberOfRepeats) / verticalNumberOfRepeats - 1)+quietZonesOffset][x + quietZonesOffset];
for (var i = 0; i < repeatPerModule; i++)
{
lineBuilder.Append(module ? darkColorString : whiteSpaceString);
Expand All @@ -75,4 +75,4 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar
return qrCode.GetGraphic(pixelsPerModule, darkColorString, whiteSpaceString, drawQuietZones, endOfLine);
}
}
}
}
24 changes: 15 additions & 9 deletions QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public enum Authentication
{
WEP,
WPA,
nopass
nopass,
WPA2
}
}

Expand Down Expand Up @@ -311,7 +312,7 @@ public class Url : Payload
private readonly string url;

/// <summary>
/// Generates a link. If not given, http/https protocol will be added.
/// Generates a link. If the protocol is not specified, the http protocol will be added.
/// </summary>
/// <param name="url">Link url target</param>
public Url(string url)
Expand All @@ -321,7 +322,7 @@ public Url(string url)

public override string ToString()
{
return (!this.url.StartsWith("http") ? "http://" + this.url : this.url);
return (!this.url.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? "http://" + this.url : this.url);
}
}

Expand Down Expand Up @@ -2012,6 +2013,7 @@ private void ProcessCommonFields(StringBuilder sb)
}
string strippedSecret = Secret.Replace(" ", "");
string escapedIssuer = null;
string escapedLabel = null;
string label = null;

if (!String40Methods.IsNullOrWhiteSpace(Issuer))
Expand All @@ -2023,18 +2025,22 @@ private void ProcessCommonFields(StringBuilder sb)
escapedIssuer = Uri.EscapeDataString(Issuer);
}

if (!String40Methods.IsNullOrWhiteSpace(Label) && Label.Contains(":"))
if (!String40Methods.IsNullOrWhiteSpace(Label))
{
throw new Exception("Label must not have a ':'");
if (Label.Contains(":"))
{
throw new Exception("Label must not have a ':'");
}
escapedLabel = Uri.EscapeDataString(Label);
}

if (Label != null && Issuer != null)
if (escapedLabel != null && escapedIssuer != null)
{
label = Issuer + ":" + Label;
label = escapedIssuer + ":" + escapedLabel;
}
else if (Issuer != null)
else if (escapedIssuer != null)
{
label = Issuer;
label = escapedIssuer;
}

if (label != null)
Expand Down
9 changes: 1 addition & 8 deletions QRCoder/PostscriptQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
#if !NETSTANDARD1_3
using System;
using System.Drawing;
using static QRCoder.QRCodeGenerator;

namespace QRCoder
{

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public class PostscriptQRCode : AbstractQRCode, IDisposable
{
/// <summary>
Expand Down Expand Up @@ -143,9 +140,6 @@ sc sc scale
";
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class PostscriptQRCodeHelper
{
public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false)
Expand All @@ -157,5 +151,4 @@ public static string GetQRCode(string plainText, int pointsPerModule, string dar
}
}
}

#endif
32 changes: 23 additions & 9 deletions QRCoder/SvgQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0_OR_GREATER
using QRCoder.Extensions;
using System;
using System.Collections;
Expand All @@ -11,9 +11,6 @@

namespace QRCoder
{
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public class SvgQRCode : AbstractQRCode, IDisposable
{
/// <summary>
Expand Down Expand Up @@ -270,13 +267,16 @@ public class SvgLogo
private object _logoRaw;
private bool _isEmbedded;


#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
/// <summary>
/// Create a logo object to be used in SvgQRCode renderer
/// </summary>
/// <param name="iconRasterized">Logo to be rendered as Bitmap/rasterized graphic</param>
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
/// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)
{
_iconSizePercent = iconSizePercent;
Expand All @@ -285,14 +285,15 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac
using (var bitmap = new Bitmap(iconRasterized))
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
_logoData = Convert.ToBase64String(ms.GetBuffer(), Base64FormattingOptions.None);
_logoData = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length, Base64FormattingOptions.None);
}
}
_mediaType = MediaType.PNG;
_fillLogoBackground = fillLogoBackground;
_logoRaw = iconRasterized;
_isEmbedded = false;
}
#endif

/// <summary>
/// Create a logo object to be used in SvgQRCode renderer
Expand All @@ -311,6 +312,22 @@ public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBac
_isEmbedded = iconEmbedded;
}

/// <summary>
/// Create a logo object to be used in SvgQRCode renderer
/// </summary>
/// <param name="iconRasterized">Logo to be rendered as PNG</param>
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
/// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
public SvgLogo(byte[] iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)
{
_iconSizePercent = iconSizePercent;
_logoData = Convert.ToBase64String(iconRasterized, Base64FormattingOptions.None);
_mediaType = MediaType.PNG;
_fillLogoBackground = fillLogoBackground;
_logoRaw = iconRasterized;
_isEmbedded = false;
}

/// <summary>
/// Returns the raw logo's data
/// </summary>
Expand Down Expand Up @@ -379,9 +396,6 @@ public enum MediaType : int
}
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class SvgQRCodeHelper
{
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
Expand Down
Loading

0 comments on commit 33ae0c1

Please sign in to comment.