diff --git a/src/BinaryKits.Zpl.Viewer/ElementDrawers/DrawerOptions.cs b/src/BinaryKits.Zpl.Viewer/ElementDrawers/DrawerOptions.cs index 38c0bbf..3544798 100644 --- a/src/BinaryKits.Zpl.Viewer/ElementDrawers/DrawerOptions.cs +++ b/src/BinaryKits.Zpl.Viewer/ElementDrawers/DrawerOptions.cs @@ -1,6 +1,7 @@ using SkiaSharp; using System; using System.Diagnostics; +using System.Linq; namespace BinaryKits.Zpl.Viewer.ElementDrawers { @@ -21,14 +22,97 @@ public class DrawerOptions public static Func DefaultFontLoader = fontName => { var typeface = SKTypeface.Default; + var skFontManager = SKFontManager.Default; + var fontFamilies = skFontManager.FontFamilies; + if (fontName == "0") { - //typeface = SKTypeface.FromFile(@"swiss-721-black-bt.ttf"); - typeface = SKTypeface.FromFamilyName("Helvetica", SKFontStyleWeight.Bold, SKFontStyleWidth.SemiCondensed, SKFontStyleSlant.Upright); + if (fontFamilies.Contains("Helvetica")) + { + typeface = SKTypeface.FromFamilyName( + "Helvetica", + SKFontStyleWeight.Bold, + SKFontStyleWidth.SemiCondensed, + SKFontStyleSlant.Upright + ); + } + else if (fontFamilies.Contains("Roboto Condensed")) + { + typeface = SKTypeface.FromFamilyName( + "Roboto Condensed", + SKFontStyleWeight.Bold, + SKFontStyleWidth.Normal, + SKFontStyleSlant.Upright + ); + } + else if (fontFamilies.Contains("Swis721 BT")) + { + //Note: Zebra Swis721 BT (tt0003m_.ttf) is not as bold and condensed as Labelary + //Note: swiss-721-bt-bold.ttf is not as condensed as Labelary + //typeface = SKTypeface.FromFile(@"swiss-721-black-bt.ttf"); + typeface = SKTypeface.FromFamilyName( + "Swis721 BT" + ); + } + else if (fontFamilies.Contains("Arial")) + { + typeface = SKTypeface.FromFamilyName( + "Arial", + SKFontStyleWeight.Bold, + SKFontStyleWidth.Condensed, + SKFontStyleSlant.Upright + ); + } + else + { + //let the system provide a fallback for Helvetica + typeface = SKTypeface.FromFamilyName( + "Helvetica", + SKFontStyleWeight.Bold, + SKFontStyleWidth.SemiCondensed, + SKFontStyleSlant.Upright + ); + } } else { - typeface = SKTypeface.FromFamilyName("DejaVu Sans Mono", SKFontStyleWeight.Normal, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright); + if (fontFamilies.Contains("DejaVu Sans Mono")) + { + typeface = SKTypeface.FromFamilyName( + "DejaVu Sans Mono", + SKFontStyleWeight.Normal, + SKFontStyleWidth.Normal, + SKFontStyleSlant.Upright + ); + } + else if (fontFamilies.Contains("Courier New")) + { + typeface = SKTypeface.FromFamilyName( + "Courier New", + SKFontStyleWeight.Medium, + SKFontStyleWidth.Normal, + SKFontStyleSlant.Upright + ); + } + else if (fontFamilies.Contains("Courier")) + { + typeface = SKTypeface.FromFamilyName( + "Courier", + SKFontStyleWeight.Medium, + SKFontStyleWidth.Normal, + SKFontStyleSlant.Upright + ); + } + else + { + //let the system provide a fallback for DejaVu + typeface = SKTypeface.FromFamilyName( + "DejaVu Sans Mono", + SKFontStyleWeight.Normal, + SKFontStyleWidth.Normal, + SKFontStyleSlant.Upright + ); + } } return typeface; diff --git a/src/Dockerfile b/src/Dockerfile index 00b5e99..03e874c 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -8,6 +8,7 @@ RUN apt-get update \ libc6-dev \ libgdiplus \ libx11-dev \ + fonts-roboto \ && rm -rf /var/lib/apt/lists/* WORKDIR /app