Skip to content

Commit

Permalink
Merge branch 'master' into support_base64_linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 authored Apr 17, 2024
2 parents c9b102b + 295730d commit dd49148
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
8 changes: 4 additions & 4 deletions QRCoder/ArtQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public Bitmap GetGraphic(Bitmap backgroundImage = null)
/// <param name="backgroundImageStyle">Style of the background image (if set). Fill=spanning complete graphic; DataAreaOnly=Don't paint background into quietzone</param>
/// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param>
/// <returns>QRCode graphic as bitmap</returns>
public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8,
public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, Bitmap backgroundImage = null, double pixelSizeFactor = 1,
bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Dotted,
BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null)
{
if (pixelSizeFactor > 1)
throw new Exception("The parameter pixelSize must be between 0 and 1. (0-100%)");
int pixelSize = (int)Math.Min(pixelsPerModule, Math.Floor(pixelsPerModule / pixelSizeFactor));
int pixelSize = (int)Math.Min(pixelsPerModule, Math.Floor(pixelsPerModule * pixelSizeFactor));

var numModules = QrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8);
var offset = (drawQuietZones ? 0 : 4);
Expand Down Expand Up @@ -283,7 +283,7 @@ public static class ArtQRCodeHelper
/// <param name="finderPatternImage">Optional image that should be used instead of the default finder patterns</param>
/// <returns>QRCode graphic as bitmap</returns>
public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, Color backgroundColor, ECCLevel eccLevel, bool forceUtf8 = false,
bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 0.8,
bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap backgroundImage = null, double pixelSizeFactor = 1.0,
bool drawQuietZones = true, QuietZoneStyle quietZoneRenderingStyle = QuietZoneStyle.Flat,
BackgroundImageStyle backgroundImageStyle = BackgroundImageStyle.DataAreaOnly, Bitmap finderPatternImage = null)
{
Expand All @@ -295,4 +295,4 @@ public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color dark
}
}

#endif
#endif
7 changes: 4 additions & 3 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
7 changes: 3 additions & 4 deletions QRCoderTests/ArtQRCodeRendererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public void should_throw_pixelfactor_oor_exception()
[Category("QRRenderer/ArtQRCode")]
public void can_instantate_parameterless()
{
var asciiCode = new ArtQRCode();
asciiCode.ShouldNotBeNull();
asciiCode.ShouldBeOfType<ArtQRCode>();
var artCode = new ArtQRCode();
artCode.ShouldNotBeNull();
artCode.ShouldBeOfType<ArtQRCode>();
}

[Fact]
Expand All @@ -94,7 +94,6 @@ public void can_render_artqrcode_from_helper()
{
//Create QR code
var bmp = ArtQRCodeHelper.GetQRCode("A", 10, Color.Black, Color.White, Color.Transparent, QRCodeGenerator.ECCLevel.L);

var result = HelperFunctions.BitmapToHash(bmp);
result.ShouldBe("57ecaa9bdeadcdcbeac8a19d734907ff");
}
Expand Down
25 changes: 25 additions & 0 deletions QRCoderTests/PayloadGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ public void wifi_should_build_wpa()
generator.ToString().ShouldBe($"WIFI:T:WPA;S:MyWiFiSSID;P:7heP4assw0rd;;");
}

[Fact]
[Category("PayloadGenerator/WiFi")]
public void wifi_should_build_wpa2()
{
var ssid = "MyWiFiSSID";
var password = "7heP4assw0rd";
var authmode = PayloadGenerator.WiFi.Authentication.WPA2;
var hideSSID = false;

var generator = new PayloadGenerator.WiFi(ssid, password, authmode, hideSSID);

generator.ToString().ShouldBe($"WIFI:T:WPA2;S:MyWiFiSSID;P:7heP4assw0rd;;");
}

[Fact]
[Category("PayloadGenerator/WiFi")]
Expand Down Expand Up @@ -744,6 +757,18 @@ public void url_should_build_https()
}


[Fact]
[Category("PayloadGenerator/Url")]
public void url_should_build_https_all_caps()
{
var url = "HTTPS://CODE-BUDE.NET";

var generator = new PayloadGenerator.Url(url);

generator.ToString().ShouldBe("HTTPS://CODE-BUDE.NET");
}


[Fact]
[Category("PayloadGenerator/Url")]
public void url_should_add_http()
Expand Down

0 comments on commit dd49148

Please sign in to comment.