상속: JsApiBase
예제 #1
0
 public WorkerScoreRenderer(JsApi api, Settings settings)
 {
     _api = api;
     try
     {
         _worker = new Worker(settings.ScriptFile);
     }
     catch
     {
         // fallback to blob worker
         try
         {
             var script = "importScripts('" + settings.ScriptFile + "')";
             var blob   = new Blob(new[] { script });
             _worker = new Worker(window.URL.createObjectURL(blob));
         }
         catch (Exception e)
         {
             Logger.Error("Rendering", "Failed to create WebWorker: " + e);
             // TODO: fallback to synchronous mode
         }
     }
     _worker.postMessage(new { cmd = "alphaTab.initialize", settings = settings.ToJson() });
     _worker.addEventListener("message", HandleWorkerMessage, false);
 }
예제 #2
0
        public WorkerScoreRenderer(JsApi api, Settings settings)
        {
            _api = api;

            // Bug #172: FireFox silently does not start the worker when script is on a different domain
            // we use blob workers always since they seem to work always
            try
            {
                var script = "importScripts('" + settings.ScriptFile + "')";
                var blob   = new Blob(new[] { script });
                _worker = new Worker(window.URL.createObjectURL(blob));
            }
            catch (Exception e)
            {
                Logger.Error("Rendering", "Failed to create WebWorker: " + e);
                // TODO: fallback to synchronous mode
            }

            _worker.postMessage(new { cmd = "alphaTab.initialize", settings = settings.ToJson() });
            _worker.addEventListener("message", HandleWorkerMessage, false);
        }
예제 #3
0
        public void Print(string width)
        {
            // prepare a popup window for printing (a4 width, window height, centered)

            var preview = window.open("", "", "width=0,height=0");
            var a4      = (HtmlDivElement)preview.document.createElement("div");

            if (!string.IsNullOrEmpty(width))
            {
                a4.style.width = width;
            }
            else
            {
                a4.style.width = "210mm";
            }
            preview.document.As <HtmlDocument>().write("<!DOCTYPE html><html></head><body></body></html>");
            preview.document.body.appendChild(a4);

            var dualScreenLeft = JsTypeOf(window.screenLeft) != JsTypes.undefined
                ? window.screenLeft
                : screen.Member("left").As <int>();
            var dualScreenTop = JsTypeOf(window.screenTop) != JsTypes.undefined
                ? window.screenTop
                : screen.Member("top").As <int>();
            var screenWidth = JsTypeOf(window.innerWidth) != JsTypes.undefined
                ? window.innerWidth
                : JsTypeOf(document.documentElement.clientWidth) != JsTypes.undefined
                    ? document.documentElement.clientWidth
                    : screen.width;
            var screenHeight = JsTypeOf(window.innerHeight) != JsTypes.undefined
                ? window.innerHeight
                : JsTypeOf(document.documentElement.clientHeight) != JsTypes.undefined
                    ? document.documentElement.clientHeight
                    : screen.height;

            var w    = a4.offsetWidth + 50;
            var h    = window.innerHeight;
            var left = ((screenWidth / 2) - (w / 2)) + dualScreenLeft;
            var top  = ((screenHeight / 2) - (h / 2)) + dualScreenTop;

            preview.resizeTo(w, h);
            preview.moveTo(left, top);

            preview.focus();

            // render alphaTab
            var settings = Settings.Defaults;

            settings.ScriptFile         = Settings.ScriptFile;
            settings.FontDirectory      = Settings.FontDirectory;
            settings.Scale              = 0.8f;
            settings.StretchForce       = 0.8f;
            settings.DisableLazyLoading = true;
            settings.UseWebWorker       = false;

            var alphaTab = new JsApi(a4, settings);

            alphaTab.Renderer.PostRenderFinished += () =>
            {
                alphaTab.CanvasElement.style.height = "100%";
                preview.window.print();
            };
            alphaTab.SetTracks(Tracks);
        }