Skip to content

Commit 3fc14b7

Browse files
committed
Added code documentation/summary
1 parent 4ad5ea7 commit 3fc14b7

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

QRCoder/SvgQRCode.cs

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,27 @@ public class SvgQRCode : AbstractQRCode, IDisposable
1919
public SvgQRCode() { }
2020
public SvgQRCode(QRCodeData data) : base(data) { }
2121

22+
/// <summary>
23+
/// Returns a QR code as SVG string
24+
/// </summary>
25+
/// <param name="pixelsPerModule">The pixel size each b/w module is drawn</param>
26+
/// <returns>SVG as string</returns>
2227
public string GetGraphic(int pixelsPerModule)
2328
{
2429
var viewBox = new Size(pixelsPerModule*this.QrCodeData.ModuleMatrix.Count, pixelsPerModule * this.QrCodeData.ModuleMatrix.Count);
2530
return this.GetGraphic(viewBox, Color.Black, Color.White);
2631
}
32+
33+
/// <summary>
34+
/// Returns a QR code as SVG string with custom colors, optional quietzone and logo
35+
/// </summary>
36+
/// <param name="pixelsPerModule">The pixel size each b/w module is drawn</param>
37+
/// <param name="darkColor">Color of the dark modules</param>
38+
/// <param name="lightColor">Color of the light modules</param>
39+
/// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
40+
/// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
41+
/// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
42+
/// <returns>SVG as string</returns>
2743
public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
2844
{
2945
var offset = drawQuietZones ? 0 : 4;
@@ -32,6 +48,16 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
3248
return this.GetGraphic(viewBox, darkColor, lightColor, drawQuietZones, sizingMode, logo);
3349
}
3450

51+
/// <summary>
52+
/// Returns a QR code as SVG string with custom colors (in HEX syntax), optional quietzone and logo
53+
/// </summary>
54+
/// <param name="pixelsPerModule">The pixel size each b/w module is drawn</param>
55+
/// <param name="darkColorHex">The color of the dark/black modules in hex (e.g. #000000) representation</param>
56+
/// <param name="lightColorHex">The color of the light/white modules in hex (e.g. #ffffff) representation</param>
57+
/// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
58+
/// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
59+
/// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
60+
/// <returns>SVG as string</returns>
3561
public string GetGraphic(int pixelsPerModule, string darkColorHex, string lightColorHex, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
3662
{
3763
var offset = drawQuietZones ? 0 : 4;
@@ -40,16 +66,44 @@ public string GetGraphic(int pixelsPerModule, string darkColorHex, string lightC
4066
return this.GetGraphic(viewBox, darkColorHex, lightColorHex, drawQuietZones, sizingMode, logo);
4167
}
4268

69+
/// <summary>
70+
/// Returns a QR code as SVG string with optional quietzone and logo
71+
/// </summary>
72+
/// <param name="viewBox">The viewbox of the QR code graphic</param>
73+
/// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
74+
/// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
75+
/// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
76+
/// <returns>SVG as string</returns>
4377
public string GetGraphic(Size viewBox, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
4478
{
4579
return this.GetGraphic(viewBox, Color.Black, Color.White, drawQuietZones, sizingMode, logo);
4680
}
4781

82+
/// <summary>
83+
/// Returns a QR code as SVG string with custom colors and optional quietzone and logo
84+
/// </summary>
85+
/// <param name="viewBox">The viewbox of the QR code graphic</param>
86+
/// <param name="darkColor">Color of the dark modules</param>
87+
/// <param name="lightColor">Color of the light modules</param>
88+
/// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
89+
/// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
90+
/// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
91+
/// <returns>SVG as string</returns>
4892
public string GetGraphic(Size viewBox, Color darkColor, Color lightColor, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
4993
{
5094
return this.GetGraphic(viewBox, ColorTranslator.ToHtml(Color.FromArgb(darkColor.ToArgb())), ColorTranslator.ToHtml(Color.FromArgb(lightColor.ToArgb())), drawQuietZones, sizingMode, logo);
5195
}
5296

97+
/// <summary>
98+
/// Returns a QR code as SVG string with custom colors (in HEX syntax), optional quietzone and logo
99+
/// </summary>
100+
/// <param name="viewBox">The viewbox of the QR code graphic</param>
101+
/// <param name="darkColorHex">The color of the dark/black modules in hex (e.g. #000000) representation</param>
102+
/// <param name="lightColorHex">The color of the light/white modules in hex (e.g. #ffffff) representation</param>
103+
/// <param name="drawQuietZones">If true a white border is drawn around the whole QR Code</param>
104+
/// <param name="sizingMode">Defines if width/height or viewbox should be used for size definition</param>
105+
/// <param name="logo">A (optional) logo to be rendered on the code (either Bitmap or SVG)</param>
106+
/// <returns>SVG as string</returns>
53107
public string GetGraphic(Size viewBox, string darkColorHex, string lightColorHex, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
54108
{
55109
int offset = drawQuietZones ? 0 : 4;
@@ -194,26 +248,33 @@ private string CleanSvgVal(double input)
194248
return input.ToString(System.Globalization.CultureInfo.InvariantCulture);
195249
}
196250

251+
/// <summary>
252+
/// Mode of sizing attribution on svg root node
253+
/// </summary>
197254
public enum SizingMode
198255
{
199256
WidthHeightAttribute,
200257
ViewBoxAttribute
201258
}
202259

260+
/// <summary>
261+
/// Represents a logo graphic that can be rendered on a SvgQRCode
262+
/// </summary>
203263
public class SvgLogo
204264
{
205265
private string _logoData;
206266
private MediaType _mediaType;
207267
private int _iconSizePercent;
208268
private bool _fillLogoBackground;
209269
private object _logoRaw;
210-
211270

271+
212272
/// <summary>
213273
/// Create a logo object to be used in SvgQRCode renderer
214274
/// </summary>
215275
/// <param name="iconRasterized">Logo to be rendered as Bitmap/rasterized graphic</param>
216276
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
277+
/// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
217278
public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true)
218279
{
219280
_iconSizePercent = iconSizePercent;
@@ -235,6 +296,7 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac
235296
/// </summary>
236297
/// <param name="iconVectorized">Logo to be rendered as SVG/vectorized graphic/string</param>
237298
/// <param name="iconSizePercent">Degree of percentage coverage of the QR code by the logo</param>
299+
/// <param name="fillLogoBackground">If true, the background behind the logo will be cleaned</param>
238300
public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBackground = true)
239301
{
240302
_iconSizePercent = iconSizePercent;
@@ -244,30 +306,54 @@ public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBac
244306
_logoRaw = iconVectorized;
245307
}
246308

309+
/// <summary>
310+
/// Returns the raw logo's data
311+
/// </summary>
312+
/// <returns></returns>
247313
public object GetRawLogo()
248314
{
249315
return _logoRaw;
250316
}
251317

318+
/// <summary>
319+
/// Returns the media type of the logo
320+
/// </summary>
321+
/// <returns></returns>
252322
public MediaType GetMediaType()
253323
{
254324
return _mediaType;
255325
}
256326

327+
/// <summary>
328+
/// Returns the logo as data-uri
329+
/// </summary>
330+
/// <returns></returns>
257331
public string GetDataUri()
258332
{
259333
return $"data:{_mediaType.GetStringValue()};base64,{_logoData}";
260334
}
261335

336+
/// <summary>
337+
/// Returns how much of the QR code should be covered by the logo (in percent)
338+
/// </summary>
339+
/// <returns></returns>
262340
public int GetIconSizePercent()
263341
{
264342
return _iconSizePercent;
265343
}
344+
345+
/// <summary>
346+
/// Returns if the background of the logo should be cleaned (no QR modules will be rendered behind the logo)
347+
/// </summary>
348+
/// <returns></returns>
266349
public bool FillLogoBackground()
267350
{
268351
return _fillLogoBackground;
269352
}
270353

354+
/// <summary>
355+
/// Media types for SvgLogos
356+
/// </summary>
271357
public enum MediaType : int
272358
{
273359
[StringValue("image/png")]

0 commit comments

Comments
 (0)