public override object OnPreRender()
 {
     // build SVG start tag including SVG font
     var buffer = new StringBuilder();
     buffer.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" class=\"alphaTabWrapperSvg\">");
     buffer.Append(SvgFontString.Value);
     return buffer.ToString();
 }
Exemple #2
0
        public override object OnPreRender()
        {
            // build SVG start tag including SVG font
            var buffer = new StringBuilder();

            buffer.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" class=\"alphaTabWrapperSvg\">");
            buffer.Append(SvgFontString.Value);
            return(buffer.ToString());
        }
Exemple #3
0
 public static string GetNodeValue(XmlNode n)
 {
     if (n.NodeType == XmlNodeType.Element || n.NodeType == XmlNodeType.Document)
     {
         var txt = new StringBuilder();
         foreach (XmlNode childNode in n.ChildNodes)
         {
             txt.Append(GetNodeValue(childNode));
         }
         return(txt.ToString().Trim());
     }
     return(n.Value);
 }
Exemple #4
0
        static void PlatformInit()
        {
            RenderEngines["svg"]     = () => new CssFontSvgCanvas();
            RenderEngines["default"] = () => new CssFontSvgCanvas();
            RenderEngines["html5"]   = () => new Platform.JavaScript.Html5Canvas();

            // check whether webfont is loaded
            CheckFontLoad();

            JsContext.JsCode("Math.log2 = Math.log2 || function(x) { return Math.log(x) * Math.LOG2E; };");

            // try to build the find the alphaTab script url in case we are not in the webworker already
            if (HtmlContext.self.document.As <bool>())
            {
                /**
                 * VB Loader For IE
                 * This code is based on the code of
                 *     http://nagoon97.com/reading-binary-files-using-ajax/
                 *     Copyright (c) 2008 Andy G.P. Na <*****@*****.**>
                 *     The source code is freely distributable under the terms of an MIT-style license.
                 */
                var vbAjaxLoader = new StringBuilder();
                vbAjaxLoader.AppendLine("<script type=\"text/vbscript\">");
                vbAjaxLoader.AppendLine("Function VbAjaxLoader(method, fileName)");
                vbAjaxLoader.AppendLine("    Dim xhr");
                vbAjaxLoader.AppendLine("    Set xhr = CreateObject(\"Microsoft.XMLHTTP\")");
                vbAjaxLoader.AppendLine("    xhr.Open method, fileName, False");
                vbAjaxLoader.AppendLine("    xhr.setRequestHeader \"Accept-Charset\", \"x-user-defined\"");
                vbAjaxLoader.AppendLine("    xhr.send");
                vbAjaxLoader.AppendLine("    Dim byteArray()");
                vbAjaxLoader.AppendLine("    if xhr.Status = 200 Then");
                vbAjaxLoader.AppendLine("        Dim byteString");
                vbAjaxLoader.AppendLine("        Dim i");
                vbAjaxLoader.AppendLine("        byteString=xhr.responseBody");
                vbAjaxLoader.AppendLine("        ReDim byteArray(LenB(byteString))");
                vbAjaxLoader.AppendLine("        For i = 1 To LenB(byteString)");
                vbAjaxLoader.AppendLine("            byteArray(i-1) = AscB(MidB(byteString, i, 1))");
                vbAjaxLoader.AppendLine("        Next");
                vbAjaxLoader.AppendLine("    End If");
                vbAjaxLoader.AppendLine("    VbAjaxLoader=byteArray");
                vbAjaxLoader.AppendLine("End Function");
                vbAjaxLoader.AppendLine("</script>");
                HtmlContext.document.write(vbAjaxLoader.ToString());

                var scriptElement = HtmlContext.document.Member("currentScript").As <HtmlScriptElement>();
                if (!scriptElement.As <bool>())
                {
                    // try to get javascript from exception stack
                    try
                    {
                        var error = new JsError();
                        var stack = error.Member("stack");
                        if (!stack.As <bool>())
                        {
                            throw error;
                        }

                        ScriptFile = ScriptFileFromStack(stack.As <JsString>());
                    }
                    catch (JsError e)
                    {
                        var stack = e.Member("stack");
                        if (!stack.As <bool>())
                        {
                            scriptElement =
                                HtmlContext.document.querySelector("script[data-alphatab]").As <HtmlScriptElement>();
                        }
                        else
                        {
                            ScriptFile = ScriptFileFromStack(stack.As <JsString>());
                        }
                    }
                }

                // failed to automatically resolve
                if (string.IsNullOrEmpty(ScriptFile))
                {
                    if (!scriptElement.As <bool>())
                    {
                        HtmlContext.console.warn(
                            "Could not automatically find alphaTab script file for worker, please add the data-alphatab attribute to the script tag that includes alphaTab or provide it when initializing alphaTab");
                    }
                    else
                    {
                        ScriptFile = scriptElement.src;
                    }
                }
            }
        }