From ad6023ce40b843876d0832ea1481be35cdb991f9 Mon Sep 17 00:00:00 2001 From: ccouliou Date: Thu, 14 Dec 2023 15:06:45 +0100 Subject: [PATCH] float scale --- src/T2t.Barcode.Core/BarcodeMetrics.cs | 2 +- src/T2t.Barcode.Drawing/BarCodeDrawBase.cs | 12 ++++++------ src/T2t.Barcode.Drawing/BarcodeDraw.cs | 2 +- src/T2t.Barcode.Drawing/CodeQr.cs | 6 +++--- src/T2t.Barcode.Skia/BarcodeDraw.cs | 14 +++++++------- src/T2t.Barcode.Skia/CodeQr.cs | 6 +++--- src/T2t.Barcode.Svg/BarcodeDraw.cs | 14 +++++++------- src/T2t.Barcode.Svg/CodeQr.cs | 8 ++++---- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/T2t.Barcode.Core/BarcodeMetrics.cs b/src/T2t.Barcode.Core/BarcodeMetrics.cs index de2e936..8b85557 100644 --- a/src/T2t.Barcode.Core/BarcodeMetrics.cs +++ b/src/T2t.Barcode.Core/BarcodeMetrics.cs @@ -26,7 +26,7 @@ protected BarcodeMetrics() /// When applied to a 2D barcode the scale adjusts both width and height /// of barcode elements. /// - public int Scale + public float Scale { get; set; diff --git a/src/T2t.Barcode.Drawing/BarCodeDrawBase.cs b/src/T2t.Barcode.Drawing/BarCodeDrawBase.cs index 1f763b3..d08dbe8 100644 --- a/src/T2t.Barcode.Drawing/BarCodeDrawBase.cs +++ b/src/T2t.Barcode.Drawing/BarCodeDrawBase.cs @@ -187,9 +187,9 @@ protected virtual Image Draw1d(string text, BarcodeMetrics1d metrics) // Determine bar code length in pixels int totalImageWidth = GetBarcodeLength( barcode, - interGlyphSpace * metrics.Scale, - metrics.MinWidth * metrics.Scale, - metrics.MaxWidth * metrics.Scale); + (int)(interGlyphSpace * metrics.Scale), + (int)(metrics.MinWidth * metrics.Scale), + (int)(metrics.MaxWidth * metrics.Scale)); // Create image of correct size Bitmap image = new(totalImageWidth, metrics.MaxHeight); @@ -200,10 +200,10 @@ protected virtual Image Draw1d(string text, BarcodeMetrics1d metrics) barcode, dc, bounds, - interGlyphSpace * metrics.Scale, + (int)(interGlyphSpace * metrics.Scale), metrics.MinHeight, - metrics.MinWidth * metrics.Scale, - metrics.MaxWidth * metrics.Scale); + (int)(metrics.MinWidth * metrics.Scale), + (int)(metrics.MaxWidth * metrics.Scale)); } // Handle rotation of image as necessary diff --git a/src/T2t.Barcode.Drawing/BarcodeDraw.cs b/src/T2t.Barcode.Drawing/BarcodeDraw.cs index 1a2e338..55498f5 100644 --- a/src/T2t.Barcode.Drawing/BarcodeDraw.cs +++ b/src/T2t.Barcode.Drawing/BarcodeDraw.cs @@ -62,7 +62,7 @@ public Image Draw(string text, int maxBarHeight) /// /// An object containing the rendered barcode. /// - public Image Draw(string text, int maxBarHeight, int scale) + public Image Draw(string text, int maxBarHeight, float scale) { BarcodeMetrics defaultMetrics = GetDefaultMetrics(maxBarHeight); defaultMetrics.Scale = scale; diff --git a/src/T2t.Barcode.Drawing/CodeQr.cs b/src/T2t.Barcode.Drawing/CodeQr.cs index 2f200f3..88d1c2f 100644 --- a/src/T2t.Barcode.Drawing/CodeQr.cs +++ b/src/T2t.Barcode.Drawing/CodeQr.cs @@ -285,7 +285,7 @@ public static char[] ToCharArray(byte[] byteArray) private int _structureAppendParity; //private string _structureAppendOriginaldata; - private int _scale; + private float _scale; private Color _backgroundColor; private Color _foregroundColor; #endregion @@ -353,7 +353,7 @@ public QrEncodeMode EncodeMode } } - public int Scale + public float Scale { get { @@ -1190,7 +1190,7 @@ public virtual Bitmap Encode(string content, Encoding encoding) { bool[][] matrix = CalculateQrCode(encoding.GetBytes(content)); SolidBrush brush = new(_backgroundColor); - Bitmap image = new((matrix.Length * _scale) + 1, (matrix.Length * _scale) + 1); + Bitmap image = new((int)(matrix.Length * _scale) + 1, (int)(matrix.Length * _scale) + 1); Graphics g = Graphics.FromImage(image); g.FillRectangle(brush, new Rectangle(0, 0, image.Width, image.Height)); brush.Color = _foregroundColor; diff --git a/src/T2t.Barcode.Skia/BarcodeDraw.cs b/src/T2t.Barcode.Skia/BarcodeDraw.cs index b6d9a29..137523b 100644 --- a/src/T2t.Barcode.Skia/BarcodeDraw.cs +++ b/src/T2t.Barcode.Skia/BarcodeDraw.cs @@ -63,7 +63,7 @@ public SKBitmap Draw(string text, int maxBarHeight) /// /// An object containing the rendered barcode. /// - public SKBitmap Draw(string text, int maxBarHeight, int scale) + public SKBitmap Draw(string text, int maxBarHeight, float scale) { BarcodeMetrics defaultMetrics = GetDefaultMetrics(maxBarHeight); defaultMetrics.Scale = scale; @@ -276,9 +276,9 @@ protected virtual SKBitmap Draw1d(string text, BarcodeMetrics1d metrics) // Determine bar code length in pixels int totalImageWidth = GetBarcodeLength( barcode, - interGlyphSpace * metrics.Scale, - metrics.MinWidth * metrics.Scale, - metrics.MaxWidth * metrics.Scale); + (int)(interGlyphSpace * metrics.Scale), + (int)(metrics.MinWidth * metrics.Scale), + (int)(metrics.MaxWidth * metrics.Scale)); // Create image of correct size SKBitmap image = new(totalImageWidth, metrics.MaxHeight); @@ -288,10 +288,10 @@ protected virtual SKBitmap Draw1d(string text, BarcodeMetrics1d metrics) barcode, dc, bounds, - interGlyphSpace * metrics.Scale, + (int)(interGlyphSpace * metrics.Scale), metrics.MinHeight, - metrics.MinWidth * metrics.Scale, - metrics.MaxWidth * metrics.Scale); + (int)(metrics.MinWidth * metrics.Scale), + (int)(metrics.MaxWidth * metrics.Scale)); // Handle rotation of image as necessary if (metrics.RenderVertically) diff --git a/src/T2t.Barcode.Skia/CodeQr.cs b/src/T2t.Barcode.Skia/CodeQr.cs index d25acac..24aab67 100644 --- a/src/T2t.Barcode.Skia/CodeQr.cs +++ b/src/T2t.Barcode.Skia/CodeQr.cs @@ -285,7 +285,7 @@ public static char[] ToCharArray(byte[] byteArray) private int _structureAppendParity; //private string _structureAppendOriginaldata; - private int _scale; + private float _scale; private SKColor _backgroundColor; private SKColor _foregroundColor; #endregion @@ -353,7 +353,7 @@ public QrEncodeMode EncodeMode } } - public int Scale + public float Scale { get { @@ -1190,7 +1190,7 @@ public virtual SKBitmap Encode(string content, Encoding encoding) { bool[][] matrix = CalculateQrCode(encoding.GetBytes(content)); SKPaint brush = new() { Color = _backgroundColor }; - SKBitmap image = new(matrix.Length * _scale + 1, matrix.Length * _scale + 1); + SKBitmap image = new((int)(matrix.Length * _scale) + 1, (int)(matrix.Length * _scale) + 1); SKCanvas g = new(image); g.DrawRect(new SKRect(0, 0, image.Width, image.Height), brush); brush.Color = _foregroundColor; diff --git a/src/T2t.Barcode.Svg/BarcodeDraw.cs b/src/T2t.Barcode.Svg/BarcodeDraw.cs index ce9af3f..fa030d8 100644 --- a/src/T2t.Barcode.Svg/BarcodeDraw.cs +++ b/src/T2t.Barcode.Svg/BarcodeDraw.cs @@ -220,7 +220,7 @@ public string Draw(string text, int maxBarHeight) /// /// An object containing the rendered barcode. /// - public string Draw(string text, int maxBarHeight, int scale) + public string Draw(string text, int maxBarHeight, float scale) { BarcodeMetrics defaultMetrics = GetDefaultMetrics(maxBarHeight); defaultMetrics.Scale = scale; @@ -433,19 +433,19 @@ protected virtual string Draw1d(string text, BarcodeMetrics1d metrics) // Determine bar code length in pixels int totalImageWidth = GetBarcodeLength( barcode, - interGlyphSpace * metrics.Scale, - metrics.MinWidth * metrics.Scale, - metrics.MaxWidth * metrics.Scale); + (int)(interGlyphSpace * metrics.Scale), + (int)(metrics.MinWidth * metrics.Scale), + (int)(metrics.MaxWidth * metrics.Scale)); // Create image of correct size T2Rect bounds = new(0, 0, totalImageWidth, metrics.MaxHeight); List content = Render( barcode, bounds, - interGlyphSpace * metrics.Scale, + (int)(interGlyphSpace * metrics.Scale), metrics.MinHeight, - metrics.MinWidth * metrics.Scale, - metrics.MaxWidth * metrics.Scale); + (int)(metrics.MinWidth * metrics.Scale), + (int)(metrics.MaxWidth * metrics.Scale)); return string.Format(SvgTmpl, totalImageWidth, metrics.MaxHeight, string.Join('\n', content)); } diff --git a/src/T2t.Barcode.Svg/CodeQr.cs b/src/T2t.Barcode.Svg/CodeQr.cs index 7117e78..6dd1559 100644 --- a/src/T2t.Barcode.Svg/CodeQr.cs +++ b/src/T2t.Barcode.Svg/CodeQr.cs @@ -285,7 +285,7 @@ public static char[] ToCharArray(byte[] byteArray) private int _structureAppendParity; //private string _structureAppendOriginaldata; - private int _scale; + private float _scale; private string _backgroundColor; private string _foregroundColor; #endregion @@ -353,7 +353,7 @@ public QrEncodeMode EncodeMode } } - public int Scale + public float Scale { get { @@ -1189,8 +1189,8 @@ private static sbyte selectMask(sbyte[][] matrixContent, int maxCodewordsBitWith public virtual string Encode(string content, Encoding encoding) { bool[][] matrix = CalculateQrCode(encoding.GetBytes(content)); - int width = matrix.Length * _scale + 1; - int height = matrix.Length * _scale + 1; + int width = (int)(matrix.Length * _scale) + 1; + int height = (int)(matrix.Length * _scale) + 1; List rects = new() {