Skip to content

Commit

Permalink
float scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ccouliou committed Dec 14, 2023
1 parent 4a3efa2 commit ad6023c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/T2t.Barcode.Core/BarcodeMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected BarcodeMetrics()
/// When applied to a 2D barcode the scale adjusts both width and height
/// of barcode elements.
/// </remarks>
public int Scale
public float Scale
{
get;
set;
Expand Down
12 changes: 6 additions & 6 deletions src/T2t.Barcode.Drawing/BarCodeDrawBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/T2t.Barcode.Drawing/BarcodeDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Image Draw(string text, int maxBarHeight)
/// <returns>
/// An <see cref="Image"/> object containing the rendered barcode.
/// </returns>
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;
Expand Down
6 changes: 3 additions & 3 deletions src/T2t.Barcode.Drawing/CodeQr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -353,7 +353,7 @@ public QrEncodeMode EncodeMode
}
}

public int Scale
public float Scale
{
get
{
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/T2t.Barcode.Skia/BarcodeDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public SKBitmap Draw(string text, int maxBarHeight)
/// <returns>
/// An <see cref="SKImage"/> object containing the rendered barcode.
/// </returns>
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/T2t.Barcode.Skia/CodeQr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -353,7 +353,7 @@ public QrEncodeMode EncodeMode
}
}

public int Scale
public float Scale
{
get
{
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/T2t.Barcode.Svg/BarcodeDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public string Draw(string text, int maxBarHeight)
/// <returns>
/// An <see cref="SKImage"/> object containing the rendered barcode.
/// </returns>
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;
Expand Down Expand Up @@ -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<string> 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));
}
Expand Down
8 changes: 4 additions & 4 deletions src/T2t.Barcode.Svg/CodeQr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -353,7 +353,7 @@ public QrEncodeMode EncodeMode
}
}

public int Scale
public float Scale
{
get
{
Expand Down Expand Up @@ -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<string> rects = new()
{
Expand Down

0 comments on commit ad6023c

Please sign in to comment.