1
1
#if ! NETSTANDARD1_3
2
2
using System ;
3
- using System . Collections ;
4
- using System . Collections . Generic ;
5
3
using System . Drawing ;
6
4
using System . Text ;
7
- using System . Text . RegularExpressions ;
8
5
using QRCoder . Extensions ;
9
6
using static QRCoder . QRCodeGenerator ;
10
7
using static QRCoder . SvgQRCode ;
@@ -84,9 +81,7 @@ public string GetGraphic(int pixelsPerModule, string darkColorHex, string lightC
84
81
/// <param name="logo">An optional logo to be rendered on the code (either Bitmap or SVG).</param>
85
82
/// <returns>Returns the QR code graphic as an SVG string.</returns>
86
83
public string GetGraphic ( Size viewBox , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo ? logo = null )
87
- {
88
- return GetGraphic ( viewBox , Color . Black , Color . White , drawQuietZones , sizingMode , logo ) ;
89
- }
84
+ => GetGraphic ( viewBox , Color . Black , Color . White , drawQuietZones , sizingMode , logo ) ;
90
85
91
86
/// <summary>
92
87
/// Returns a QR code as an SVG string with custom colors and optional quiet zones and an optional logo.
@@ -99,9 +94,7 @@ public string GetGraphic(Size viewBox, bool drawQuietZones = true, SizingMode si
99
94
/// <param name="logo">An optional logo to be rendered on the code (either Bitmap or SVG).</param>
100
95
/// <returns>Returns the QR code graphic as an SVG string.</returns>
101
96
public string GetGraphic ( Size viewBox , Color darkColor , Color lightColor , bool drawQuietZones = true , SizingMode sizingMode = SizingMode . WidthHeightAttribute , SvgLogo ? logo = null )
102
- {
103
- return GetGraphic ( viewBox , ColorTranslator . ToHtml ( Color . FromArgb ( darkColor . ToArgb ( ) ) ) , ColorTranslator . ToHtml ( Color . FromArgb ( lightColor . ToArgb ( ) ) ) , drawQuietZones , sizingMode , logo ) ;
104
- }
97
+ => GetGraphic ( viewBox , ColorTranslator . ToHtml ( Color . FromArgb ( darkColor . ToArgb ( ) ) ) , ColorTranslator . ToHtml ( Color . FromArgb ( lightColor . ToArgb ( ) ) ) , drawQuietZones , sizingMode , logo ) ;
105
98
106
99
/// <summary>
107
100
/// Returns a QR code as an SVG string with custom colors (in HEX syntax), optional quiet zones, and an optional logo.
@@ -220,9 +213,7 @@ public string GetGraphic(Size viewBox, string darkColorHex, string lightColorHex
220
213
}
221
214
222
215
private bool IsBlockedByLogo(double x, double y, ImageAttributes attr, double pixelPerModule)
223
- {
224
- return x + pixelPerModule >= attr.X && x <= attr.X + attr.Width && y + pixelPerModule >= attr.Y && y <= attr.Y + attr.Height;
225
- }
216
+ => x + pixelPerModule >= attr.X && x <= attr.X + attr.Width && y + pixelPerModule >= attr.Y && y <= attr.Y + attr.Height;
226
217
227
218
private ImageAttributes GetLogoAttributes(SvgLogo logo, Size viewBox)
228
219
{
@@ -247,13 +238,11 @@ private struct ImageAttributes
247
238
public double Y;
248
239
}
249
240
241
+ //Clean double values for international use/formats
242
+ //We use explicitly "G15" to avoid differences between .NET full and Core platforms
243
+ //https://stackoverflow.com/questions/64898117/tostring-has-a-different-behavior-between-net-462-and-net-core-3-1
250
244
private string CleanSvgVal(double input)
251
- {
252
- //Clean double values for international use/formats
253
- //We use explicitly "G15" to avoid differences between .NET full and Core platforms
254
- //https://stackoverflow.com/questions/64898117/tostring-has-a-different-behavior-between-net-462-and-net-core-3-1
255
- return input.ToString("G15", System.Globalization.CultureInfo.InvariantCulture);
256
- }
245
+ => input.ToString("G15", System.Globalization.CultureInfo.InvariantCulture);
257
246
258
247
/// <summary>
259
248
/// Mode of sizing attribution on svg root node
@@ -338,52 +327,35 @@ public SvgLogo(byte[] iconRasterized, int iconSizePercent = 15, bool fillLogoBac
338
327
/// <summary>
339
328
/// Returns the raw logo's data
340
329
/// </summary>
341
- public object GetRawLogo()
342
- {
343
- return _logoRaw;
344
- }
330
+ public object GetRawLogo() => _logoRaw;
345
331
346
332
/// <summary>
347
333
/// Defines, if the logo shall be natively embedded.
348
334
/// true=native svg embedding, false=embedding via image-tag
349
335
/// </summary>
350
- public bool IsEmbedded()
351
- {
352
- return _isEmbedded;
353
- }
336
+ public bool IsEmbedded() => _isEmbedded;
354
337
355
338
/// <summary>
356
339
/// Returns the media type of the logo
357
340
/// </summary>
358
341
/// <returns></returns>
359
- public MediaType GetMediaType()
360
- {
361
- return _mediaType;
362
- }
342
+ public MediaType GetMediaType() => _mediaType;
363
343
364
344
/// <summary>
365
345
/// Returns the logo as data-uri
366
346
/// </summary>
367
347
public string GetDataUri()
368
- {
369
- return $"data:{GetMimeType(_mediaType)};base64,{_logoData}";
370
- }
348
+ => $"data:{GetMimeType(_mediaType)};base64,{_logoData}";
371
349
372
350
/// <summary>
373
351
/// Returns how much of the QR code should be covered by the logo (in percent)
374
352
/// </summary>
375
- public int GetIconSizePercent()
376
- {
377
- return _iconSizePercent;
378
- }
353
+ public int GetIconSizePercent() => _iconSizePercent;
379
354
380
355
/// <summary>
381
356
/// Returns if the background of the logo should be cleaned (no QR modules will be rendered behind the logo)
382
357
/// </summary>
383
- public bool FillLogoBackground()
384
- {
385
- return _fillLogoBackground;
386
- }
358
+ public bool FillLogoBackground() => _fillLogoBackground;
387
359
388
360
/// <summary>
389
361
/// Media types for SvgLogos
@@ -400,15 +372,12 @@ public enum MediaType : int
400
372
SVG = 1
401
373
}
402
374
403
- private string GetMimeType(MediaType type)
375
+ private string GetMimeType(MediaType type) => type switch
404
376
{
405
- return type switch
406
- {
407
- MediaType.PNG => "image/png",
408
- MediaType.SVG => "image/svg+xml",
409
- _ => throw new ArgumentOutOfRangeException(nameof(type)),
410
- };
411
- }
377
+ MediaType.PNG => "image/png",
378
+ MediaType.SVG => "image/svg+xml",
379
+ _ => throw new ArgumentOutOfRangeException(nameof(type)),
380
+ };
412
381
413
382
}
414
383
}
0 commit comments