Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Read HP-GL plot files (.plt, #410)
cre8ive-marketing25a8ca1da780
diff --git a/docs/ENGINES.md b/docs/ENGINES.mdindex 482c302e..d10eed97 100644--- a/docs/ENGINES.md+++ b/docs/ENGINES.md@@ -7,7 +7,7 @@ Filee chooses engines automatically. Settings → *Engines* shows their status,|---|---|---|| ImageMagick (Magick.NET) | built in (library) | JPG, PNG, WEBP, TIFF, BMP, GIF, ICO, AVIF, JPEG XL, JPEG 2000, PSD/PSB, TGA, PPM, MNG, QOI, DDS, PCX, CUR, XPM, XBM, WBMP, PAM, PFM, SGI, Sun Raster, MIFF ↔ each other, and **APNG** (Filee's own reader and writer); HEIC (written with FFmpeg), XCF, camera RAW (LibRaw), DICOM (uncompressed ones by Filee's own reader), Photo CD, OpenEXR, Radiance HDR, EMF/WMF (Windows) and the photo of an iPhone LIVP read || Windows Imaging Component | part of Windows (Windows only) | **JPEG XR** (JXR, WDP, HDP; HDR screenshots of Windows) → the images ImageMagick writes, and PDF, ICNS, HEIC and SVG through PNG; HDR tone-mapped to SDR |-| Vector graphics | built in (Svg.Skia, SkiaSharp, ACadSharp) | **SVG/SVGZ → PDF (vector) and images**, SVG ↔ SVGZ, **SVG → DXF** (→ DWG with the CAD engine), **raster images → SVG (tracing)**, PDF-compatible AI → PDF |+| Vector graphics | built in (Svg.Skia, SkiaSharp, ACadSharp) | **SVG/SVGZ → PDF (vector) and images**, SVG ↔ SVGZ, **SVG → DXF** (→ DWG with the CAD engine), **raster images → SVG (tracing)**, PDF-compatible AI → PDF, **HP-GL / HP-GL/2 plot files (PLT) → SVG**, PDF and images (pen moves, packed PE polylines, arcs and filled polygons; text labels are not drawn) || ICNS | built in | images → ICNS (16–1024 px), ICNS → images || PDFsharp | built in (library) | images → PDF, merge, split, page ranges, **compression** (smaller PDFs, see below) || PDFium | built in (library) | PDF → images (multi-page TIFF/GIF supported) |diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.csindex 1ec46736..0f754505 100644--- a/src/Filee.Core/Formats/FormatRegistry.cs+++ b/src/Filee.Core/Formats/FormatRegistry.cs@@ -66,6 +66,7 @@ public static class FormatRegistrynew("wmf", "WMF", FormatCategory.Vector, ["wmf"]),new("cdr", "CDR", FormatCategory.Vector, ["cdr"], Writable: false),new("cgm", "CGM", FormatCategory.Vector, ["cgm"], Writable: false),+ new("plt", "PLT", FormatCategory.Vector, ["plt", "hpgl", "hpg", "hgl"], Writable: false),new("vsd", "VSD", FormatCategory.Vector, ["vsd", "vsdx"], Writable: false),new("odg", "ODG", FormatCategory.Vector, ["odg"]),new("fodg", "FODG", FormatCategory.Vector, ["fodg"], Writable: false),diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.csindex 4f488dcb..3df95d28 100644--- a/src/Filee.Core/Settings/AppSettings.cs+++ b/src/Filee.Core/Settings/AppSettings.cs@@ -112,7 +112,7 @@ public sealed class DonutSettingspublic sealed class AppSettings{/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>- public const int CurrentSchemaVersion = 32;+ public const int CurrentSchemaVersion = 33;public int SchemaVersion { get; set; } = CurrentSchemaVersion;diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.csindex 7aff0c84..e1e89185 100644--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@ -750,6 +750,9 @@ internal static class SettingsMigrations// v32: logs and script source, Video CD DAT and Workbench archives learn their donuts; custom claims stay put.if (from < 32)changed |= LearnExtensions(profiles, out _, ["log", "py", "pac", "bat", "command", "dat", "wbpz"]);+ // v33: HP-GL plot files learn their donut; custom claims stay put.+ if (from < 33)+ changed |= LearnExtensions(profiles, out _, ["plt", "hpgl", "hpg", "hgl"]);return changed;}diff --git a/src/Filee.Engines/Vector/HpglPlot.cs b/src/Filee.Engines/Vector/HpglPlot.csnew file mode 100644index 00000000..7808aab4--- /dev/null+++ b/src/Filee.Engines/Vector/HpglPlot.cs@@ -0,0 +1,384 @@+// HP-GL and HP-GL/2 plot files (.plt, issue #410): what AutoCAD and other programs "plot to file" for pen plotters+// and large-format printers, also cutting plotters. The pen moves become SVG polylines at the plot's real size (40+// plotter units per millimetre), and the vector engine renders PDF, PNG, … from there.+//+// Read: IN, SP / PC / NP / PW (pens and their colours and widths), PU / PD / PA / PR, CI, AA / AR (arcs as short+// lines), PE (HP-GL/2 encoded polylines, the bulk of a printer driver's plot), PM / EP / FP (polygons, filled with+// FP). A PJL / PCL wrapper around HP-GL/2 is skipped up to "enter HP-GL/2 mode" (ESC % … B). Not drawn: text (LB),+// fill patterns, raster data; user scaling (SC) is ignored, so a scaled plot keeps its shape but not its size.+// The PE decoding follows ezdxf's hpgl2 add-on (MIT).++using System.Globalization;+using System.Text;++namespace Filee.Engines.Vector;++internal static class HpglPlot+{+ /// <summary>Plotter units per millimetre.</summary>+ private const double UnitsPerMm = 40;++ /// <summary>HP-GL/2's default pen colours: 0 white (paper), 1 black, 2 red, 3 green, 4 yellow, 5 blue, 6 magenta, 7 cyan.</summary>+ private static readonly string[] DefaultColors = ["#FFFFFF", "#000000", "#FF0000", "#00A000", "#E0C000", "#0000FF", "#FF00FF", "#00B0B0"];++ /// <summary>A line or a filled polygon, in plotter units, Y up.</summary>+ internal sealed record Stroke(string Color, double Width, List<(double X, double Y)> Points, bool Filled);++ /// <summary>Reads the drawing of a plot file. Fails with a reason when it holds no HP-GL.</summary>+ internal static List<Stroke> Read(byte[] data)+ {+ var plotter = new Plotter();+ foreach (var (name, args) in Commands(data))+ plotter.Run(name, args);+ plotter.EndLine();+ if (plotter.Strokes.Count == 0)+ throw new InvalidDataException("No HP-GL drawing found: the plot file has no pen moves (it may be PostScript or PCL raster output).");+ return plotter.Strokes;+ }++ /// <summary>The drawing as SVG at its real size, with a small margin and white paper.</summary>+ internal static string ToSvg(byte[] data)+ {+ var strokes = Read(data);+ var points = strokes.SelectMany(s => s.Points).ToList();+ var margin = 2 * UnitsPerMm;+ double left = points.Min(p => p.X) - margin, right = points.Max(p => p.X) + margin;+ double bottom = points.Min(p => p.Y) - margin, top = points.Max(p => p.Y) + margin;+ double width = right - left, height = top - bottom;+ string N(double v) => v.ToString("0.##", CultureInfo.InvariantCulture);++ var svg = new StringBuilder();+ svg.Append(CultureInfo.InvariantCulture,+ $"""<svg xmlns="http://www.w3.org/2000/svg" width="{N(width / UnitsPerMm)}mm" height="{N(height / UnitsPerMm)}mm" viewBox="0 0 {N(width)} {N(height)}">""");+ svg.Append(CultureInfo.InvariantCulture, $"""<rect width="{N(width)}" height="{N(height)}" fill="#FFFFFF"/>""");+ foreach (var stroke in strokes)+ {+ var path = string.Join(' ', stroke.Points.Select(p => $"{N(p.X - left)},{N(top - p.Y)}"));+ svg.Append(stroke.Filled+ ? $"""<polygon points="{path}" fill="{stroke.Color}"/>"""+ : $"""<polyline points="{path}" fill="none" stroke="{stroke.Color}" stroke-width="{N(stroke.Width)}" stroke-linecap="round" stroke-linejoin="round"/>""");+ }+ svg.Append("</svg>");+ return svg.ToString();+ }++ // ───────────────────────── Commands ─────────────────────────++ /// <summary>+ /// Splits the plot into commands: two letters and their arguments up to ';' or the next command. PE's arguments+ /// are its encoded bytes; LB's run to the label terminator (ETX).+ /// </summary>+ internal static IEnumerable<(string Name, string Args)> Commands(byte[] s)+ {+ var i = StartsWithHpgl(s) ? 0 : EntryPoint(s, 0);+ while (i < s.Length)+ {+ var c = s[i];+ if (c == 27)+ {+ // An escape sequence leaves HP-GL/2 (PCL, PJL): go on where the plot enters it again.+ i = EntryPoint(s, i + 1);+ continue;+ }+ if (c <= 32 || c == ';' || !char.IsAsciiLetterUpper((char)c) && !char.IsAsciiLetterLower((char)c))+ {+ i++;+ continue;+ }+ if (i + 1 >= s.Length)+ yield break;+ var name = Encoding.ASCII.GetString(s, i, 2).ToUpperInvariant();+ var start = i + 2;+ var end = start;+ if (name == "PE")+ while (end < s.Length && s[end] != ';' && s[end] != 27) end++;+ else if (name == "LB")+ while (end < s.Length && s[end] != 3) end++;+ else+ while (end < s.Length && s[end] != ';' && s[end] != 27 && !char.IsAsciiLetter((char)s[end])) end++;+ yield return (name, Encoding.Latin1.GetString(s, start, end - start));+ i = end < s.Length && s[end] is (byte)';' or 3 ? end + 1 : end;+ }+ }++ private static bool StartsWithHpgl(byte[] s)+ {+ var head = Encoding.ASCII.GetString(s, 0, Math.Min(s.Length, 16)).TrimStart();+ return head.StartsWith("IN", StringComparison.OrdinalIgnoreCase) || head.StartsWith("BP", StringComparison.Ordinal)+ || head.StartsWith("SP", StringComparison.Ordinal) || head.StartsWith("PU", StringComparison.Ordinal)+ || head.StartsWith("PA", StringComparison.Ordinal) || head.StartsWith("DF", StringComparison.Ordinal);+ }++ /// <summary>Index after the next "enter HP-GL/2 mode" (ESC % 0-3 B, also ESC % -1 B), or the end.</summary>+ private static int EntryPoint(byte[] s, int from)+ {+ for (var i = from; i + 3 < s.Length; i++)+ {+ if (s[i] != 27 || s[i + 1] != '%')+ continue;+ var j = s[i + 2] == '-' ? i + 3 : i + 2;+ if (j + 1 < s.Length && s[j] is >= (byte)'0' and <= (byte)'3' && s[j + 1] == 'B')+ return j + 2;+ }+ return s.Length;+ }++ private static List<double> Numbers(string args) =>+ [.. args.Split([',', ' '], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)+ .Select(a => double.TryParse(a, NumberStyles.Float, CultureInfo.InvariantCulture, out var v) ? v : double.NaN)+ .Where(v => !double.IsNaN(v))];++ /// <summary>+ /// The numbers of a PE command from <paramref name="start"/> until a flag or the end. Base 64 (or base 32 in+ /// 7-bit mode): digits 63.. are followed by a terminating digit (191.. or 95..), least significant first; the+ /// lowest bit is the sign.+ /// </summary>+ internal static List<double> DecodeNumbers(string data, ref int start, int fractionBits, int numberBase)+ {+ var terminator = numberBase == 64 ? 191 : 95;+ var values = new List<double>();+ long value = 0, scale = 1;+ for (; start < data.Length; start++)+ {+ int c = data[start];+ if (c < 63)+ break;+ if (c >= terminator)+ {+ value += (c - terminator) * scale;+ var signed = (value & 1) == 1 ? -(value >> 1) : value >> 1;+ values.Add(signed / (double)(1L << fractionBits));+ value = 0;+ scale = 1;+ }+ else+ {+ value += (c - 63) * scale;+ scale *= numberBase;+ }+ }+ return values;+ }++ // ───────────────────────── Plotter ─────────────────────────++ private sealed class Plotter+ {+ private readonly Dictionary<int, string> _colors = [];+ private readonly Dictionary<int, double> _widths = [];+ private List<(double X, double Y)>? _line;+ private bool _penDown;+ private bool _relative;+ private int _pen = 1;+ private (double X, double Y) _at;+ private List<List<(double X, double Y)>>? _polygon;+ private bool _inPolygon;++ public List<Stroke> Strokes { get; } = [];++ /// <summary>The pen's colour; pens past the default eight draw black.</summary>+ private string Color => _colors.TryGetValue(_pen, out var c) ? c : DefaultColors[_pen is > 0 and < 8 ? _pen : 1];++ /// <summary>Pen width in plotter units (default 0.35 mm).</summary>+ private double Width => _widths.TryGetValue(_pen, out var w) ? w : 0.35 * UnitsPerMm;++ public void Run(string name, string args)+ {+ switch (name)+ {+ case "IN":+ EndLine();+ _penDown = _relative = false;+ _pen = 1;+ _at = (0, 0);+ break;+ case "SP":+ EndLine();+ _pen = Numbers(args) is [var pen, ..] ? (int)pen : 0;+ break;+ case "PC":+ if (Numbers(args) is [var p, var r, var g, var b, ..])+ _colors[(int)p] = $"#{Channel(r)}{Channel(g)}{Channel(b)}";+ break;+ case "PW":+ // Width in millimetres, for one pen or all of them.+ var width = Numbers(args);+ if (width is [var mm, var forPen, ..])+ _widths[(int)forPen] = Math.Max(0.05, mm) * UnitsPerMm;+ else if (width is [var all])+ foreach (var any in Enumerable.Range(0, 256))+ _widths[any] = Math.Max(0.05, all) * UnitsPerMm;+ EndLine();+ break;+ case "PU" or "PD":+ EndLine(keepPolygon: true);+ _penDown = name == "PD";+ MoveAll(Numbers(args));+ break;+ case "PA" or "PR":+ _relative = name == "PR";+ MoveAll(Numbers(args));+ break;+ case "CI":+ if (Numbers(args) is [var radius, ..])+ Circle(radius);+ break;+ case "AA" or "AR":+ if (Numbers(args) is [var cx, var cy, var sweep, ..])+ Arc(name == "AR" ? (_at.X + cx, _at.Y + cy) : (cx, cy), sweep);+ break;+ case "PE":+ Encoded(args);+ break;+ case "PM":+ // PM0 starts a polygon (its buffer is cleared), PM1 closes an outline of it, PM2 ends it.+ EndLine(keepPolygon: true);+ var mode = Numbers(args) is [var m, ..] ? (int)m : 0;+ if (mode == 0)+ _polygon = [];+ _polygon ??= [];+ _inPolygon = mode != 2;+ break;+ case "EP" or "FP":+ EndLine();+ foreach (var outline in _polygon ?? [])+ if (outline.Count > 1)+ Strokes.Add(new Stroke(Color, Width, outline, Filled: name == "FP"));+ break;+ }+ }++ private static string Channel(double value) => ((int)Math.Clamp(value, 0, 255)).ToString("X2", CultureInfo.InvariantCulture);++ private void MoveAll(List<double> coordinates)+ {+ for (var i = 0; i + 1 < coordinates.Count; i += 2)+ MoveTo(_relative ? (_at.X + coordinates[i], _at.Y + coordinates[i + 1]) : (coordinates[i], coordinates[i + 1]), _penDown);+ }++ private void MoveTo((double X, double Y) to, bool draw)+ {+ if (draw)+ {+ _line ??= [_at];+ _line.Add(to);+ }+ else+ {+ EndLine(keepPolygon: true);+ }+ _at = to;+ }++ /// <summary>+ /// Ends the line being drawn. In polygon mode it becomes an outline of the polygon (drawn by EP / FP), else a+ /// stroke.+ /// </summary>+ public void EndLine(bool keepPolygon = false)+ {+ if (_line is { Count: > 1 } line)+ {+ if (_inPolygon && keepPolygon)+ _polygon!.Add(line);+ else if (_pen != 0)+ Strokes.Add(new Stroke(Color, Width, line, Filled: false));+ }+ _line = null;+ }++ private void Circle(double radius)+ {+ EndLine(keepPolygon: true);+ var center = _at;+ var points = Enumerable.Range(0, 73)+ .Select(i => (center.X + radius * Math.Cos(i * Math.PI / 36), center.Y + radius * Math.Sin(i * Math.PI / 36))).ToList();+ if (_inPolygon)+ _polygon!.Add(points);+ else if (_pen != 0)+ Strokes.Add(new Stroke(Color, Width, points, Filled: false));+ }++ private void Arc((double X, double Y) center, double sweepDegrees)+ {+ var radius = Math.Sqrt(Math.Pow(_at.X - center.X, 2) + Math.Pow(_at.Y - center.Y, 2));+ var start = Math.Atan2(_at.Y - center.Y, _at.X - center.X);+ var steps = Math.Max(2, (int)Math.Ceiling(Math.Abs(sweepDegrees) / 5));+ for (var i = 1; i <= steps; i++)+ {+ var angle = start + sweepDegrees * Math.PI / 180 * i / steps;+ MoveTo((center.X + radius * Math.Cos(angle), center.Y + radius * Math.Sin(angle)), _penDown);+ }+ }++ /// <summary>+ /// PE: flags ':' (select pen), '<' (the next point is a move), '>' (fraction bits), '=' (the next point is+ /// absolute), '7' (7-bit mode, base 32); points are relative and drawn otherwise. The pen stays down after it.+ /// </summary>+ private void Encoded(string data)+ {+ var penUp = false;+ var absolute = false;+ var fractionBits = 0;+ var numberBase = 64;+ var queue = new List<double>();+ var i = 0;+ while (i < data.Length)+ {+ var flag = data[i];+ if (flag is ':' or '<' or '>' or '=' or '7')+ {+ i++;+ switch (flag)+ {+ case ':':+ var pen = DecodeNumbers(data, ref i, 0, numberBase);+ if (pen.Count > 0)+ {+ EndLine();+ _pen = (int)pen[0];+ queue.AddRange(pen.Skip(1));+ }+ break;+ case '<':+ penUp = true;+ break;+ case '>':+ var bits = DecodeNumbers(data, ref i, 0, numberBase);+ if (bits.Count > 0)+ {+ fractionBits = (int)bits[0];+ queue.AddRange(bits.Skip(1));+ }+ break;+ case '=':+ absolute = true;+ break;+ case '7':+ numberBase = 32;+ break;+ }+ }+ else if (data[i] < 63)+ {+ i++; // not part of PE+ }+ else+ {+ queue.AddRange(DecodeNumbers(data, ref i, fractionBits, numberBase));+ }++ for (var k = 0; k + 1 < queue.Count; k += 2)+ {+ var to = absolute ? (queue[k], queue[k + 1]) : (_at.X + queue[k], _at.Y + queue[k + 1]);+ MoveTo(to, draw: !penUp);+ penUp = absolute = false;+ }+ if (queue.Count % 2 == 0)+ queue.Clear();+ else+ queue.RemoveRange(0, queue.Count - 1);+ }+ _penDown = true;+ }+ }+}diff --git a/src/Filee.Engines/Vector/VectorConverter.cs b/src/Filee.Engines/Vector/VectorConverter.csindex d23f0fdb..d7ab9dbe 100644--- a/src/Filee.Engines/Vector/VectorConverter.cs+++ b/src/Filee.Engines/Vector/VectorConverter.cs@@ -41,6 +41,8 @@ public sealed class VectorConverter : IConverter, IImageTransformernew("svgz", "dxf"),// Illustrator files are PDF inside (or PostScript, see ConvertIllustratorAsync).new("ai", "pdf"),+ // HP-GL plot files: their pen moves as lines (HpglPlot), PDF / PNG / ... from there.+ new("plt", "svg"),// Raster images are traced (other raster formats through PNG, e.g. ICNS; never vector files or documents)... ImageEncoder.Readable.Select(source => new ConversionEdge(source, "svg", TraceCost, ImageSourcesOnly: true)),];@@ -54,6 +56,7 @@ public sealed class VectorConverter : IConverter, IImageTransformer("ai", "pdf") => await ConvertIllustratorAsync(step, progress, cancellationToken),("svg", "svgz") => await Task.Run(() => Compress(step), cancellationToken),("svgz", "svg") => await Task.Run(() => Decompress(step), cancellationToken),+ ("plt", "svg") => await Task.Run(() => Plot(step), cancellationToken),(_, "svg") => await Task.Run(() => RasterTracing.Run(step, progress, cancellationToken), cancellationToken),(_, "dxf") => await Task.Run(() => ToDxf(step, cancellationToken), cancellationToken),(_, "pdf") => await Task.Run(() => ToPdf(step, cancellationToken), cancellationToken),@@ -63,6 +66,16 @@ public sealed class VectorConverter : IConverter, IImageTransformerreturn written;}+ private static IReadOnlyList<string> Plot(ConversionStep step)+ {+ var svg = HpglPlot.ToSvg(File.ReadAllBytes(step.InputPath));+ var output = step.Output.Allocate("svg");+ if (output is null)+ return [];+ File.WriteAllText(output, svg, new System.Text.UTF8Encoding(false));+ return [output];+ }+private static IReadOnlyList<string> ToPdf(ConversionStep step, CancellationToken ct){using var drawing = SvgRenderer.Load(step.InputPath);diff --git a/tests/Filee.Core.Tests/PltFormatTests.cs b/tests/Filee.Core.Tests/PltFormatTests.csnew file mode 100644index 00000000..13601c2d--- /dev/null+++ b/tests/Filee.Core.Tests/PltFormatTests.cs@@ -0,0 +1,32 @@+// HP-GL plot files (.plt, issue #410) are a read-only vector format, learnt by existing vector donuts.++using Filee.Core.Formats;+using Filee.Core.Presets;+using Filee.Core.Settings;++namespace Filee.Core.Tests;++public class PltFormatTests+{+ [Theory]+ [InlineData("floor.plt")]+ [InlineData("cut.hpgl")]+ public void Plot_files_are_a_read_only_vector_format(string name)+ {+ var format = FormatRegistry.Detect(name)!;+ Assert.Equal(("plt", FormatCategory.Vector, false), (format.Id, format.Category, format.Writable));+ }++ [Fact]+ public void Version_32_vector_donuts_learn_them()+ {+ var presets = BuiltInData.CreatePresets();+ var profiles = BuiltInData.CreateProfiles();+ foreach (var profile in profiles)+ profile.Extensions.RemoveAll(e => e is "plt" or "hpgl" or "hpg" or "hgl");++ Assert.True(SettingsMigrations.ApplyToLibrary(32, presets, profiles));++ Assert.Contains("plt", profiles.Single(p => p.Id == "vector").Extensions);+ }+}diff --git a/tests/Filee.Engines.Tests/HpglPlotTests.cs b/tests/Filee.Engines.Tests/HpglPlotTests.csnew file mode 100644index 00000000..887b13e5--- /dev/null+++ b/tests/Filee.Engines.Tests/HpglPlotTests.cs@@ -0,0 +1,93 @@+// HP-GL plot files (.plt, issue #410): pen moves read as lines, drawn as SVG and rendered through the vector engine.+// The packed HP-GL/2 sample (PE) was encoded with ezdxf's hpgl2 add-on, not with Filee's own decoder.++using System.Text;+using Filee.Core.Conversion;+using Filee.Core.Formats;+using Filee.Core.Presets;+using Filee.Engines.Vector;+using ImageMagick;++namespace Filee.Engines.Tests;++public class HpglPlotTests(EngineFixture fx) : IClassFixture<EngineFixture>+{+ /// <summary>+ /// Pen 1: a square of 400 units (10 mm) from (400, 400), drawn relative; pen 2: a move of (800, 0), then a line+ /// of (-120, -120). Wrapped in PJL / PCL like a printer driver's plot, with pen 2 at 0.5 mm.+ /// </summary>+ private static byte[] DriverPlot() => Encoding.Latin1.GetBytes(+ "\u001B%-12345X@PJL ENTER LANGUAGE=HPGL2\r\n\u001BE\u001B%0BIN;PW0.5,2;PE" ++ ":Á<=_Ë_Ë_Ë¿¿_Ë`Ë¿¿`Ë:Ã<?Ø¿pÂpÂ" ++ ";\u001B%0A\u001BE\u001B%-12345X");++ [Fact]+ public void Plain_hpgl_pen_moves_become_lines()+ {+ var strokes = HpglPlot.Read(Encoding.ASCII.GetBytes("IN;SP1;PU0,0;PD400,0,400,400;PU;SP2;PA800,0;PD;PR0,400;SP0;"));++ Assert.Equal(2, strokes.Count);+ Assert.Equal([(0, 0), (400, 0), (400, 400)], strokes[0].Points);+ Assert.Equal("#000000", strokes[0].Color);+ Assert.Equal([(800, 0), (800, 400)], strokes[1].Points);+ Assert.Equal("#FF0000", strokes[1].Color);+ }++ [Fact]+ public void Encoded_polylines_of_a_printer_driver_are_read()+ {+ var strokes = HpglPlot.Read(DriverPlot());++ Assert.Equal(2, strokes.Count);+ Assert.Equal([(400, 400), (800, 400), (800, 800), (400, 800), (400, 400)], strokes[0].Points);+ Assert.Equal([(1200, 400), (1080, 280)], strokes[1].Points);+ Assert.Equal(("#FF0000", 20.0), (strokes[1].Color, strokes[1].Width)); // 0.5 mm+ }++ [Fact]+ public void Arcs_circles_and_filled_polygons_are_drawn()+ {+ var strokes = HpglPlot.Read(Encoding.ASCII.GetBytes(+ "IN;SP1;PA1000,1000;CI200;PA0,0;PD;AA0,400,90;PU;PC3,0,128,255;SP3;PA2000,0;PM0;PD2400,0,2400,400;PU;PM2;FP;"));++ Assert.Equal(3, strokes.Count);+ Assert.All(strokes[0].Points, p => Assert.Equal(200, Math.Sqrt(Math.Pow(p.X - 1000, 2) + Math.Pow(p.Y - 1000, 2)), 6));+ Assert.Equal(400, strokes[1].Points[^1].X, 6); // a quarter turn around (0, 400) ends at (400, 400)+ Assert.Equal(400, strokes[1].Points[^1].Y, 6);+ Assert.True(strokes[2].Filled);+ Assert.Equal("#0080FF", strokes[2].Color);+ }++ [Fact]+ public async Task A_plot_becomes_an_svg_a_png_and_a_pdf()+ {+ var path = Path.Combine(fx.NewFolder(), "floor.plt");+ await File.WriteAllBytesAsync(path, DriverPlot(), TestContext.Current.CancellationToken);+ Assert.Equal("plt", FormatRegistry.Detect(path)?.Id);++ var svg = await fx.ConvertAsync([path], new Preset { TargetFormat = "svg" });+ Assert.True(svg.State == JobState.Completed, string.Join("; ", svg.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ var text = await File.ReadAllTextAsync(svg.Outputs.Single(), TestContext.Current.CancellationToken);+ Assert.Contains("width=\"24mm\"", text); // 20 mm of drawing (400 → 1200) and 2 mm on each side++ var png = await fx.ConvertAsync([path], new Preset { TargetFormat = "png" });+ Assert.True(png.State == JobState.Completed, string.Join("; ", png.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ using (var image = new MagickImage(png.Outputs.Single()))+ Assert.True(image.Histogram().Count > 2, "the lines are drawn");++ var pdf = await fx.ConvertAsync([path], new Preset { TargetFormat = "pdf" });+ Assert.Equal(JobState.Completed, pdf.State);+ }++ [Fact]+ public async Task A_plot_file_without_hpgl_fails_with_a_reason()+ {+ var path = Path.Combine(fx.NewFolder(), "postscript.plt");+ await File.WriteAllTextAsync(path, "%!PS-Adobe-3.0\nnewpath 0 0 moveto showpage\n", TestContext.Current.CancellationToken);++ var job = await fx.ConvertAsync([path], new Preset { TargetFormat = "png" });++ Assert.Equal(JobState.Failed, job.State);+ Assert.Contains("HP-GL", job.Files[0].ErrorDetail);+ }+}diff --git a/tests/Filee.Engines.Tests/TracingTests.cs b/tests/Filee.Engines.Tests/TracingTests.csindex 831e64f0..82d265b1 100644--- a/tests/Filee.Engines.Tests/TracingTests.cs+++ b/tests/Filee.Engines.Tests/TracingTests.cs@@ -465,7 +465,8 @@ public class TracingTests(EngineFixture fx) : IClassFixture<EngineFixture>Assert.True(checkedRoutes > 1000);}- private static bool IsTracing(RouteStep step) => step.Converter is VectorConverter && step.To == "svg" && step.From is not "svgz";+ // SVGZ is unpacked and a plot file's pen moves are drawn (HpglPlot): neither is tracing.+ private static bool IsTracing(RouteStep step) => step.Converter is VectorConverter && step.To == "svg" && step.From is not ("svgz" or "plt");/// <summary>The vector engine without its tracing edges.</summary>private sealed class WithoutTracing(IConverter inner) : IConverter