OidButton() public method

public OidButton ( TextWriter w, int oid, string innerHtml ) : void
w System.IO.TextWriter
oid int
innerHtml string
return void
Beispiel #1
0
        private void WriteHtml(CancellationToken cancellationToken)
        {
            var p = packageDirectoryStructure.Package;
            var htmlMediaFiles = new List<string>();

            AddStaticMediaFile(cancellationToken, "style.css");
            AddStaticMediaFile(cancellationToken, "power.svg");
            AddStaticMediaFile(cancellationToken, "stop.svg");

            var styles = new DirectoryInfo(Path.Combine(PathUtil.GetDirectory(), "media")).GetFiles("*.css")
                .Where(_ => !object.Equals(_.Name, "style.css")).ToList();

            foreach (var i in styles)
            {
                AddStaticMediaFile(cancellationToken, i.Name);
            }

            AddStaticMediaFile(cancellationToken, "note_to_pen.png");

            log.InfoFormat("Write {0}", packageDirectoryStructure.HtmlFile);

            var ow = new OidSvgWriter(new TiptoiOidCode());
            PathUtil.EnsureParentDirectoryExists(packageDirectoryStructure.HtmlFile);
            using (var w = new StreamWriter(packageDirectoryStructure.HtmlFile))
            {
                w.WriteLine(@"
<!doctype html>
<html moznomarginboxes mozdisallowselectionprint>
  <head>
    <meta charset=""utf-8"">
    <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
	<link rel=""stylesheet"" href=""media/style.css"" />
	<link rel=""stylesheet"" href=""media/default.css"" />
    <title>" + T(this.packageDirectoryStructure.Package.Title) + @"</title>
	<script>
	function changeCSS(cssFile) {
		var cssLinkIndex = 1;
		var oldlink = document.getElementsByTagName(""link"").item(cssLinkIndex);
		oldlink.setAttribute(""href"", cssFile);
	}
	</script>
  </head>
  <body>
    <div class=""printInstructions"">
        <img src=""media/note_to_pen.png"" />
        <p><a href=""javascript:window.print();"">Click here to print the page with optical codes to play your audio files.</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()) +
        @". Product ID = " + T(p.ProductId.ToString()) + @", GME file = " + T(packageDirectoryStructure.GmeFile) + @"</p>

Style: ");

                foreach (var i in styles)
                {
                    w.WriteLine(@"<a href=""#"" onclick=""changeCSS('media/{0}')"" >{1}</a>", i.Name, Path.GetFileNameWithoutExtension(i.Name));
                }

                w.WriteLine(@"</div>");
                w.WriteLine("<h1>");
                ow.OidButton(w, p.ProductId, "<img class=\"oid-area\" src=\"media/power.svg\" />");
                ow.OidButton(w, p.StopOid, "<img class=\"oid-area\" src=\"media/stop.svg\" />");
                w.WriteLine(T(p.Title));
                w.WriteLine("</h1>");

                foreach (var album in p.Albums)
                {
                    w.WriteLine(@"<div class=""album"">");
                    var pic = Extract(album.GetPicture());
                    htmlMediaFiles.Add(Path.GetFileName(pic));
                    w.WriteLine(@"<img src={0} class=""album-art"" />", ("media/" + Path.GetFileName(pic)).Quote());
                    w.WriteLine("<h2 class=\"album-title\" >{0} - {1}</h2>", T(album.Artist), T(album.Title));
                    w.WriteLine(@"<ul class={0}>", "track-list");
                    foreach (var track in album.Tracks)
                    {
                        w.WriteLine("<li>");
                        ow.OidArea(w, track.Oid);
                        w.WriteLine("</a>");
                        w.WriteLine("<span class={0}>{1}</span> ", "track-number".Quote(), T(track.TrackNumber.ToString()));
                        w.WriteLine("<span class={0}>{1}</span> ", "track-title".Quote(), T(track.Title));
                        w.WriteLine("<span class={0}>({1})</span> ", "track-duration".Quote(), T(track.Duration.ToString(@"mm\:ss")));
                        w.WriteLine("</li>");
                    }
                    w.WriteLine("</ul>");
                    w.WriteLine(@"<br class=""album-clear"" />");
                    w.WriteLine(@"</div>");
                }

                w.WriteLine(@"
  </body>
</html>
");
            }
        }
Beispiel #2
0
        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>
");
            }
        }