Skip to content

Commit 0da7ec2

Browse files
committed
Ensure fallback to font instead of fallback to typeface
1 parent 7028e6a commit 0da7ec2

14 files changed

Lines changed: 117 additions & 28 deletions

src/BinaryKits.Zpl.Viewer/ElementDrawers/Barcode128ElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
7777
{
7878
// TODO: use font 0, auto scale for Mode D
7979
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
80-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
80+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
8181
SKFont labelFont = new(labelTypeFace, labelFontSize);
8282
this.DrawInterpretationLine(interpretation, labelFont, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, barcode.PrintInterpretationLineAboveCode, options);
8383
}

src/BinaryKits.Zpl.Viewer/ElementDrawers/Barcode39ElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
5555
if (barcode.PrintInterpretationLine)
5656
{
5757
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
58-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
58+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
5959
SKFont labelFont = new(labelTypeFace, labelFontSize);
6060
this.DrawInterpretationLine(interpretation, labelFont, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, barcode.PrintInterpretationLineAboveCode, options);
6161
}

src/BinaryKits.Zpl.Viewer/ElementDrawers/Barcode93ElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
4747
if (barcode.PrintInterpretationLine)
4848
{
4949
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
50-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
50+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
5151
SKFont labelFont = new(labelTypeFace, labelFontSize);
5252
this.DrawInterpretationLine(content, labelFont, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, barcode.PrintInterpretationLineAboveCode, options);
5353
}

src/BinaryKits.Zpl.Viewer/ElementDrawers/BarcodeAnsiCodabarElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
5555
if (barcode.PrintInterpretationLine)
5656
{
5757
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
58-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
58+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
5959
SKFont labelFont = new(labelTypeFace, labelFontSize);
6060
this.DrawInterpretationLine(interpretation, labelFont, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, barcode.PrintInterpretationLineAboveCode, options);
6161
}

src/BinaryKits.Zpl.Viewer/ElementDrawers/BarcodeEAN13ElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
7171
if (barcode.PrintInterpretationLine)
7272
{
7373
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
74-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
74+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
7575
SKFont labelFont = new(labelTypeFace, labelFontSize);
7676
if (barcode.PrintInterpretationLineAboveCode)
7777
{

src/BinaryKits.Zpl.Viewer/ElementDrawers/BarcodeUpcAElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
8080
if (barcode.PrintInterpretationLine)
8181
{
8282
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
83-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
83+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
8484
SKFont labelFont = new(labelTypeFace, labelFontSize);
8585
if (barcode.PrintInterpretationLineAboveCode)
8686
{

src/BinaryKits.Zpl.Viewer/ElementDrawers/BarcodeUpcEElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
118118
if (barcode.PrintInterpretationLine)
119119
{
120120
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
121-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
121+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
122122
SKFont labelFont = new(labelTypeFace, labelFontSize);
123123
if (barcode.PrintInterpretationLineAboveCode)
124124
{

src/BinaryKits.Zpl.Viewer/ElementDrawers/BarcodeUpcExtensionElementDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
5858
if (barcode.PrintInterpretationLine)
5959
{
6060
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
61-
SKTypeface labelTypeFace = options.FontManager.FontLoader("A");
61+
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
6262
SKFont labelFont = new(labelTypeFace, labelFontSize);
6363
this.DrawInterpretationLine(interpretation, labelFont, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, barcode.PrintInterpretationLineAboveCode, options);
6464
}

src/BinaryKits.Zpl.Viewer/ElementDrawers/DrawerOptions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SkiaSharp;
1+
using SkiaSharp;
22

33
using System;
44

@@ -7,7 +7,10 @@ namespace BinaryKits.Zpl.Viewer.ElementDrawers
77
public class DrawerOptions
88
{
99
[Obsolete("Use FontManager.FontLoader instead.")]
10-
public Func<string, SKTypeface> FontLoader { get; set; }
10+
public Func<string, SKTypeface> FontLoader {
11+
get => FontManager.FontLoader;
12+
set => FontManager.FontLoader = value;
13+
}
1114

1215
/// <summary>
1316
/// Gets or sets the image format used when rendering output.
@@ -51,7 +54,6 @@ public DrawerOptions() : this(new FontManager()) { }
5154
public DrawerOptions(FontManager fontManager)
5255
{
5356
this.FontManager = fontManager;
54-
this.FontLoader = fontManager.FontLoader;
5557
}
5658
}
5759
}

src/BinaryKits.Zpl.Viewer/ElementDrawers/ElementDrawerBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ namespace BinaryKits.Zpl.Viewer.ElementDrawers
77
{
88
public abstract class ElementDrawerBase : IElementDrawer
99
{
10+
/// <summary>
11+
/// The font to use if the specified font is not found.
12+
/// </summary>
13+
protected const string FallbackFont = "A";
14+
1015
internal IPrinterStorage printerStorage;
1116
internal SKCanvas skCanvas;
1217

0 commit comments

Comments
 (0)