Skip to content

Commit

Permalink
fix scale
Browse files Browse the repository at this point in the history
  • Loading branch information
ccouliou committed Dec 15, 2023
1 parent ad6023c commit a88064f
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 111 deletions.
132 changes: 65 additions & 67 deletions src/T2t.Barcode.Svg/BarcodeDraw.cs

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/T2t.Barcode.Svg/BarcodeDrawFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class BarcodeDrawFactory
/// Gets an agent capable of rendering a Code39 barcode without
/// adding a checksum glyph.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code39BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code39BarcodeDraw"/> object.</value>
public static Code39BarcodeDraw Code39WithoutChecksum
{
get
Expand All @@ -49,7 +49,7 @@ public static Code39BarcodeDraw Code39WithoutChecksum
/// Gets an agent capable of rendering a Code39 barcode with an
/// added checksum glyph.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code39BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code39BarcodeDraw"/> object.</value>
public static Code39BarcodeDraw Code39WithChecksum
{
get
Expand All @@ -64,7 +64,7 @@ public static Code39BarcodeDraw Code39WithChecksum
/// Gets an agent capable of rendering a Code93 barcode with added
/// checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code93BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code93BarcodeDraw"/> object.</value>
public static Code93BarcodeDraw Code93WithChecksum
{
get
Expand All @@ -79,7 +79,7 @@ public static Code93BarcodeDraw Code93WithChecksum
/// Gets an agent capable of rendering a Code128 barcode with added
/// checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code128BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code128BarcodeDraw"/> object.</value>
public static Code128BarcodeDraw Code128WithChecksum
{
get
Expand All @@ -93,7 +93,7 @@ public static Code128BarcodeDraw Code128WithChecksum
/// <summary>
/// Gets an agent capable of rendering a Code11 barcode.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code11BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code11BarcodeDraw"/> object.</value>
public static Code11BarcodeDraw Code11WithoutChecksum
{
get
Expand All @@ -108,7 +108,7 @@ public static Code11BarcodeDraw Code11WithoutChecksum
/// Gets an agent capable of rendering a Code11 barcode with added
/// checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code11BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code11BarcodeDraw"/> object.</value>
public static Code11BarcodeDraw Code11WithChecksum
{
get
Expand All @@ -123,7 +123,7 @@ public static Code11BarcodeDraw Code11WithChecksum
/// Gets an agent capable of rendering a Code EAN-13 barcode with
/// added checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.CodeEan13BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.CodeEan13BarcodeDraw"/> object.</value>
public static CodeEan13BarcodeDraw CodeEan13WithChecksum
{
get
Expand All @@ -138,7 +138,7 @@ public static CodeEan13BarcodeDraw CodeEan13WithChecksum
/// Gets an agent capable of rendering a Code EAN-8 barcode with
/// added checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.CodeEan8BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.CodeEan8BarcodeDraw"/> object.</value>
public static CodeEan8BarcodeDraw CodeEan8WithChecksum
{
get
Expand All @@ -153,7 +153,7 @@ public static CodeEan8BarcodeDraw CodeEan8WithChecksum
/// Gets an agent capable of rendering a Code 25 barcode without
/// checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code25BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code25BarcodeDraw"/> object.</value>
public static Code25BarcodeDraw Code25StandardWithoutChecksum
{
get
Expand All @@ -168,7 +168,7 @@ public static Code25BarcodeDraw Code25StandardWithoutChecksum
/// Gets an agent capable of rendering a Code 25 barcode with
/// added checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code25BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code25BarcodeDraw"/> object.</value>
public static Code25BarcodeDraw Code25StandardWithChecksum
{
get
Expand All @@ -183,7 +183,7 @@ public static Code25BarcodeDraw Code25StandardWithChecksum
/// Gets an agent capable of rendering a Code 25 barcode without
/// checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code25BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code25BarcodeDraw"/> object.</value>
public static Code25BarcodeDraw Code25InterleavedWithoutChecksum
{
get
Expand All @@ -198,7 +198,7 @@ public static Code25BarcodeDraw Code25InterleavedWithoutChecksum
/// Gets an agent capable of rendering a Code 25 barcode with
/// added checksum glyphs.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.Code25BarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.Code25BarcodeDraw"/> object.</value>
public static Code25BarcodeDraw Code25InterleavedWithChecksum
{
get
Expand All @@ -212,7 +212,7 @@ public static Code25BarcodeDraw Code25InterleavedWithChecksum
/// <summary>
/// Gets an agent capable of rendering a Code QR barcode.
/// </summary>
/// <value>A <see cref="T:T2t.Barcode.Skia.CodeQrBarcodeDraw"/> object.</value>
/// <value>A <see cref="T:T2t.Barcode.Svg.CodeQrBarcodeDraw"/> object.</value>
public static CodeQrBarcodeDraw CodeQr
{
get
Expand All @@ -232,7 +232,7 @@ public static CodeQrBarcodeDraw CodeQr
/// A value from the <see cref="T:T2t.Barcode.Core.BarcodeSymbology"/> enumeration.
/// </param>
/// <returns>
/// A class derived from <see cref="T:T2t.Barcode.Skia.BarcodeDraw"/>.
/// A class derived from <see cref="T:T2t.Barcode.Svg.BarcodeDraw"/>.
/// </returns>
/// <exception cref="T:System.ArgumentException">
/// Thrown if the specified symbology is invalid or unknown.
Expand Down
13 changes: 6 additions & 7 deletions src/T2t.Barcode.Svg/BinaryPitchBarcodeDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ protected BinaryPitchBarcodeDraw(TGlyphFactory factory, TChecksum checksum,
/// <param name="barMinWidth">Minimum barcode width.</param>
/// <param name="barMaxWidth">Maximum barcode width.</param>
/// <returns></returns>
protected override int GetBarcodeLength(Glyph[] barcode,
int interGlyphSpace, int barMinWidth, int barMaxWidth)
protected override float GetBarcodeLength(Glyph[] barcode,
float interGlyphSpace, float barMinWidth, float barMaxWidth)
{
// Sanity check
if (barMinWidth == barMaxWidth)
Expand All @@ -100,7 +100,7 @@ protected override int GetBarcodeLength(Glyph[] barcode,
}

// Determine bar code length in pixels
int totalImageWidth = GetBarcodeInterGlyphLength(barcode, interGlyphSpace);
float totalImageWidth = GetBarcodeInterGlyphLength(barcode, interGlyphSpace);
foreach (BinaryPitchGlyph glyph in barcode)
{
// Determine encoding bit-width for this character
Expand Down Expand Up @@ -158,7 +158,6 @@ protected virtual int GetGlyphEncodingBitCount(Glyph glyph)
/// </summary>
/// <param name="glyphIndex">Index of the glyph.</param>
/// <param name="glyph">A <see cref="T:Glyph"/> to be rendered.</param>
/// <param name="dc">A <see cref="T:SKCanvas"/> representing the device context.</param>
/// <param name="bounds">The bounding rectangle.</param>
/// <param name="barOffset">The bar offset in pixels.</param>
/// <param name="barMinHeight">Minimum bar height in pixels.</param>
Expand All @@ -169,8 +168,8 @@ protected virtual int GetGlyphEncodingBitCount(Glyph glyph)
/// bar rendering is attempted.
/// </exception>
protected override List<string> RenderBar(int glyphIndex, BarGlyph glyph,
T2Rect bounds, ref int barOffset, int barMinHeight,
int barMinWidth, int barMaxWidth)
T2Rect bounds, ref float barOffset, float barMinHeight,
float barMinWidth, float barMaxWidth)
{
List<string> res = new();
// Sanity check
Expand All @@ -196,7 +195,7 @@ protected override List<string> RenderBar(int glyphIndex, BarGlyph glyph,
for (int bitIndex = encodingBitCount - 1; bitIndex >= 0; --bitIndex)
{
int bitMask = 1 << bitIndex;
int barWidth = barMinWidth;
float barWidth = barMinWidth;

bool currentBitState = false;
if ((bitMask & binGlyph.BitEncoding) != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/T2t.Barcode.Svg/Code11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ protected override Glyph[] GetFullBarcode(string text)
/// <param name="barMinWidth"></param>
/// <param name="barMaxWidth"></param>
/// <returns></returns>
protected override int GetDefaultInterGlyphSpace(int barMinWidth, int barMaxWidth)
protected override float GetDefaultInterGlyphSpace(float barMinWidth, float barMaxWidth)
{
return barMinWidth;
}
Expand Down
4 changes: 2 additions & 2 deletions src/T2t.Barcode.Svg/Code128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,8 @@ protected override Glyph[] GetFullBarcode(string text)
/// <param name="barMinWidth">Minimum bar width.</param>
/// <param name="barMaxWidth">Maximum bar width.</param>
/// <returns></returns>
protected override int GetBarcodeLength(Glyph[] barcode,
int interGlyphSpace, int barMinWidth, int barMaxWidth)
protected override float GetBarcodeLength(Glyph[] barcode,
float interGlyphSpace, float barMinWidth, float barMaxWidth)
{
return base.GetBarcodeLength(barcode, interGlyphSpace,
barMinWidth, barMaxWidth) - (9 * barMinWidth);
Expand Down
13 changes: 6 additions & 7 deletions src/T2t.Barcode.Svg/Code25.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ protected override Glyph[] GetFullBarcode(string text)
/// <param name="barMinWidth"></param>
/// <param name="barMaxWidth"></param>
/// <returns></returns>
protected override int GetDefaultInterGlyphSpace(int barMinWidth, int barMaxWidth)
protected override float GetDefaultInterGlyphSpace(float barMinWidth, float barMaxWidth)
{
if (Factory is Code25StandardGlyphFactory)
{
Expand All @@ -424,8 +424,8 @@ protected override int GetDefaultInterGlyphSpace(int barMinWidth, int barMaxWidt
/// Currently this method does not account for any "quiet space"
/// around the barcode as dictated by each symbology standard.
/// </remarks>
protected override int GetBarcodeLength(
Glyph[] barcode, int interGlyphSpace, int barMinWidth, int barMaxWidth)
protected override float GetBarcodeLength(
Glyph[] barcode, float interGlyphSpace, float barMinWidth, float barMaxWidth)
{
if (Factory is not Code25InterleavedGlyphFactory)
{
Expand All @@ -438,9 +438,8 @@ protected override int GetBarcodeLength(
/// <summary>
/// Renders the barcode bars.
/// </summary>
/// <param name="barcode">A collection of <see cref="T:T2t.Barcode.Skia.Glyph"/> objects representing the
/// <param name="barcode">A collection of <see cref="T:T2t.Barcode.Core.Glyph"/> objects representing the
/// barcode to be rendered.</param>
/// <param name="dc">A <see cref="T:System.Drawing.SKCanvas"/> representing the draw context.</param>
/// <param name="bounds">The bounding rectangle.</param>
/// <param name="interGlyphSpace">The inter glyph space in pixels.</param>
/// <param name="barMinHeight">Minimum bar height in pixels.</param>
Expand All @@ -451,7 +450,7 @@ protected override int GetBarcodeLength(
/// <see cref="M:RenderBar"/> method, applying the specified
/// inter-glyph spacing as necessary.
/// </remarks>
protected override List<string> RenderBars(Glyph[] barcode, T2Rect bounds, int interGlyphSpace, int barMinHeight, int barMinWidth, int barMaxWidth)
protected override List<string> RenderBars(Glyph[] barcode, T2Rect bounds, float interGlyphSpace, float barMinHeight, float barMinWidth, float barMaxWidth)
{
List<string> res = new();
// Standard Code 2 of 5 can be rendered via base class
Expand All @@ -462,7 +461,7 @@ protected override List<string> RenderBars(Glyph[] barcode, T2Rect bounds, int i

// Interleaved version needs custom rendering support

int barOffset = 0;
float barOffset = 0;
for (int index = 0; index < barcode.Length;)
{
BarGlyph glyph = (BarGlyph)barcode[index];
Expand Down
2 changes: 1 addition & 1 deletion src/T2t.Barcode.Svg/Code39.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ protected override Glyph[] GetFullBarcode(string text)
/// <param name="barMinWidth"></param>
/// <param name="barMaxWidth"></param>
/// <returns></returns>
protected override int GetDefaultInterGlyphSpace(int barMinWidth, int barMaxWidth)
protected override float GetDefaultInterGlyphSpace(float barMinWidth, float barMaxWidth)
{
return barMinWidth;
}
Expand Down
4 changes: 2 additions & 2 deletions src/T2t.Barcode.Svg/Code93.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ protected override Glyph[] GetFullBarcode(string text)
/// Currently this method does not account for any "quiet space"
/// around the barcode as dictated by each symbology standard.
/// </remarks>
protected override int GetBarcodeLength(Glyph[] barcode,
int interGlyphSpace, int barMinWidth, int barMaxWidth)
protected override float GetBarcodeLength(Glyph[] barcode,
float interGlyphSpace, float barMinWidth, float barMaxWidth)
{
return base.GetBarcodeLength(barcode, interGlyphSpace,
barMinWidth, barMaxWidth) - (8 * barMinWidth);
Expand Down
8 changes: 4 additions & 4 deletions src/T2t.Barcode.Svg/CodeEan13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public CodeEan13BarcodeDraw(CodeEan13Checksum checksum)
public override BarcodeMetrics GetDefaultMetrics(int maxHeight)
{
// TODO: Min bar height should be percentage of max height
return new BarcodeMetrics1d(1, 1, maxHeight - 5, maxHeight);
return new BarcodeMetrics1d(1, 1, (int)(maxHeight * .9), maxHeight);
}

/// <summary>
Expand Down Expand Up @@ -414,7 +414,7 @@ protected override Glyph[] GetFullBarcode(string text)
/// For EAN 13 the only full height glyphs are start/stop/seperator
/// glyphs.
/// </remarks>
protected override int GetGlyphHeight(Glyph glyph, int barMinHeight, int barMaxHeight)
protected override float GetGlyphHeight(Glyph glyph, float barMinHeight, float barMaxHeight)
{
if (glyph.Character == '*' || glyph.Character == '|')
{
Expand All @@ -429,9 +429,9 @@ protected override int GetGlyphHeight(Glyph glyph, int barMinHeight, int barMaxH
/// <param name="barMinWidth"></param>
/// <param name="barMaxWidth"></param>
/// <returns></returns>
protected override int GetDefaultInterGlyphSpace(int barMinWidth, int barMaxWidth)
protected override float GetDefaultInterGlyphSpace(float barMinWidth, float barMaxWidth)
{
return 0;
return 0f;
}
#endregion
}
4 changes: 2 additions & 2 deletions src/T2t.Barcode.Svg/CodeEan8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ protected override Glyph[] GetFullBarcode(string text)
/// For EAN 13 the only full height glyphs are start/stop/seperator
/// glyphs.
/// </remarks>
protected override int GetGlyphHeight(Glyph glyph, int barMinHeight, int barMaxHeight)
protected override float GetGlyphHeight(Glyph glyph, float barMinHeight, float barMaxHeight)
{
if (glyph.Character == '*' || glyph.Character == '|')
{
Expand All @@ -387,7 +387,7 @@ protected override int GetGlyphHeight(Glyph glyph, int barMinHeight, int barMaxH
/// <param name="barMinWidth"></param>
/// <param name="barMaxWidth"></param>
/// <returns></returns>
protected override int GetDefaultInterGlyphSpace(int barMinWidth, int barMaxWidth)
protected override float GetDefaultInterGlyphSpace(float barMinWidth, float barMaxWidth)
{
return 0;
}
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 @@ -1238,20 +1238,20 @@ public virtual string Encode(string content)
/// Draws the specified text using the supplied barcode metrics.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="metrics">A <see cref="T:T2t.Barcode.Skia.BarcodeMetrics"/> object.</param>
/// <param name="metrics">A <see cref="T:T2t.Barcode.Svg.BarcodeMetrics"/> object.</param>
/// <returns></returns>
public override sealed string Draw(string text, BarcodeMetrics metrics)
{
return DrawQr(text, (BarcodeMetricsQr)metrics);
}

/// <summary>
/// Gets a <see cref="T:T2t.Barcode.Skia.BarcodeMetrics"/> object containing default
/// Gets a <see cref="T:T2t.Barcode.Svg.BarcodeMetrics"/> object containing default
/// settings for the specified maximum bar height.
/// </summary>
/// <param name="maxHeight">The maximum barcode height.</param>
/// <returns>
/// A <see cref="T:T2t.Barcode.Skia.BarcodeMetrics"/> object.
/// A <see cref="T:T2t.Barcode.Svg.BarcodeMetrics"/> object.
/// </returns>
public override BarcodeMetrics GetDefaultMetrics(int maxHeight)
{
Expand All @@ -1276,7 +1276,7 @@ public override BarcodeMetrics GetDefaultMetrics(int maxHeight)
/// <param name="printResolution">The print resolution in pixels per inch.</param>
/// <param name="barcodeCharLength">Length of the barcode in characters.</param>
/// <returns>
/// A <see cref="T:T2t.Barcode.Skia.BarcodeMetrics"/> object.
/// A <see cref="T:T2t.Barcode.Svg.BarcodeMetrics"/> object.
/// </returns>
public override BarcodeMetrics GetPrintMetrics(
T2Size desiredBarcodeDimensions, T2Size printResolution, int barcodeCharLength)
Expand Down

0 comments on commit a88064f

Please sign in to comment.