public void ReadPatterns() { IOidCode oidCode = new TiptoiOidCode(); var codes = new DirectoryInfo(Path.Combine(PathUtil.GetDirectory(), @"..\test-data")).GetFiles("*.svg") .SelectMany(svg => { Console.WriteLine(svg); var d = new XmlDocument(); d.Load(svg.FullName); var manager = new XmlNamespaceManager(d.NameTable); manager.AddNamespace("svg", "http://www.w3.org/2000/svg"); var e = d.CreateNavigator() .Select("/svg:svg/svg:defs/svg:pattern", manager) .Cast<XPathNavigator>() .Select(_ => ReadCode(_, manager)); return e; }); var errors = 0; foreach (var c in codes ) { var calculated = oidCode.FromDigits(c.Digits); if (calculated != c.Oid) { Console.WriteLine("{0} {1} {2} {3}", calculated - c.Oid, c.Oid, calculated, String.Join(String.Empty, c.Digits)); ++errors; } if (!(c.Digits.SequenceEqual(oidCode.ToDigits(c.Oid)))) { Console.WriteLine("Actual : {0}", String.Join(String.Empty, c.Digits)); Console.WriteLine("Desire : {0}", String.Join(String.Empty, oidCode.ToDigits(c.Oid))); ++errors; } } Console.WriteLine("{0} errors", errors); Assert.AreEqual(80, errors); }
public static void CreatePrinterTestPage(string testPagePath) { var code = new TiptoiOidCode(); var mediaDir = Path.Combine(Path.GetDirectoryName(testPagePath), "media"); PathUtil.EnsureDirectoryExists(mediaDir); foreach (var mediaFile in new[] { "note_to_pen.png", "style.css" }) { PathUtil.CopyIfNewer( Path.Combine(PathUtil.GetDirectory(), "media", mediaFile), Path.Combine(mediaDir, mediaFile)); } using (var w = new StreamWriter(testPagePath)) { w.WriteLine(@" <!doctype html> <html moznomarginboxes mozdisallowselectionprint> <head> <meta charset=""utf-8""> <meta name=""viewport"" content=""width=device-width, initial-scale=1.0""> <title>ttaudio Printer Test Page</title> <link rel=""stylesheet"" href=""media/style.css"" /> <style> .oid-button { width: 4cm; } </style> </head> <body> <div class=""printInstructions""> <img src=""media/note_to_pen.png"" /> <p><a href=""javascript:window.print();"">Click here to print the test page with optical codes.</a> Use a printer with at least 600 dpi.</p> <p>This page was generated by <a href=""" + About.GithubUri.ToString() + @""">" + T(About.Product) + @"</a> on " + T(DateTime.Now.ToString()) + @".</p></div> <h1>ttaudio Printer Test Page</h1> "); var defaultOidWriter = new OidSvgWriter(code); var oid = 10250; var powBase = 1.1; w.Write("<table>"); w.Write("<tr>"); w.Write("<td/>"); for (int dotSize = -4; dotSize <= 4; ++dotSize) { var fDotSize = (float)Math.Pow(powBase, dotSize); w.Write("<td>"); w.Write(T(String.Format("Dot Size {0:F4} cm", defaultOidWriter.DotSize * fDotSize))); w.Write("</td>"); } w.Write("</tr>"); for (int gridSpacing = -4; gridSpacing <= 4; ++gridSpacing) { var fGridSpacing = (float)Math.Pow(powBase, gridSpacing); w.Write("<tr>"); w.Write("<td>"); w.Write(T(String.Format("Grid Spacing {0:F4} cm", defaultOidWriter.GridSpacing * fGridSpacing))); w.Write("</td>"); for (int dotSize = -4; dotSize <= 4; ++dotSize) { var fDotSize = (float)Math.Pow(powBase, dotSize); var oidWriter = new OidSvgWriter(code) { DotOffset = defaultOidWriter.DotOffset, DotSize = defaultOidWriter.DotSize * fDotSize, GridSpacing = defaultOidWriter.GridSpacing * fGridSpacing }; w.Write("<td>"); oidWriter.OidArea(w, oid++); // , String.Format("spacing: {0:F0}%, dot: {1:F0}%", fGridSpacing*100, fDotSize*100)); w.Write("</td>"); } w.Write("</tr>"); } w.Write("</table>"); w.WriteLine(@" </body> </html> "); } }
public static void CreatePrinterTestPage(string testPage) { var code = new TiptoiOidCode(); using (var w = new StreamWriter(testPage)) { w.WriteLine(@" <!doctype html> <html moznomarginboxes mozdisallowselectionprint> <head> <meta charset=""utf-8""> <meta name=""viewport"" content=""width=device-width, initial-scale=1.0""> <title>ttaudio Printer Test Page</title> <style> .printInstructions { font-size: 12px; border: solid; border-width: 1px; background-color: lightyellow; padding: 4px; margin: 4px; } @media print { .printInstructions { display: none; } } .oid-area { width: 0.5cm; height: 0.5cm; } .oid-button { border: solid; border-width: 1px; display: inline-block; padding: 4px; margin: 4px; width: 4cm; } </style> </head> <body> <div class=""printInstructions""> <img src=""media/note_to_pen.png"" /> <p><a href=""javascript:window.print();"">Click here to print the test page with optical codes.</a> Use a printer with at least 600 dpi.</p> <p>This page was generated by <a href=""" + About.GithubUri.ToString() + @""">" + T(About.Product) + @"</a> on " + T(DateTime.Now.ToString()) + @".</p></div>"); var defaultOidWriter = new OidSvgWriter(code); for (int gridSpacing = -3; gridSpacing <= 3; ++gridSpacing) { for (int dotSize = -3; dotSize <= 3; ++dotSize) { var oidWriter = new OidSvgWriter(code) { DotOffset = defaultOidWriter.DotOffset, DotSize = defaultOidWriter.DotSize * (float)Math.Pow(2.0, dotSize), GridSpacing = defaultOidWriter.GridSpacing * (float)Math.Pow(2.0, gridSpacing) }; oidWriter.OidButton(w, 10250, String.Format("spacing: {0}, dot: {1}", gridSpacing, dotSize)); } } w.WriteLine(@" </body> </html> "); } }