Ejemplo n.º 1
0
        /// <summary>
        /// Convert latex formula and render it.
        /// </summary>
        public void ConvertFormula()
        {
            if (IsRendering)
            {
                return;
            }

            PreConvert();

            var dump = outputMath.Source;

            outputMath.Source = null;

            // Get the formula latex.
            var tex = txtInputFomula.Text.Trim();

            if (Regex.IsMatch(tex, @"^\s*$"))
            {
                PostConvert("[ERROR] Empty formula.");
                return;
            }

            // Record last text for not converting.
            if (!IsForcing && currentLatexText == tex)
            {
                PostConvert($"[REJECT] Text not changed.\nTry angin in {ForceDelayTime / 1000.0}s to force to convert.");
                // Wait sometime for force converting.
                TaskCancel = new CancellationTokenSource();
                var x = new Thread(new ThreadStart(ForceConvertEnd));
                x.IsBackground = true;
                x.Start();
                outputMath.Source = dump;
                return;
            }
            // Stop wait for force converting.
            if (TaskCancel != null)
            {
                TaskCancel.Cancel();
            }
            currentLatexText = tex;
            IsForcing        = false;

            // Implement mathjax parser.
            string svgtext, mmltext;

            try {
                svgtext = MathjaxParser.GetInstance().Run(tex, out mmltext);
            } catch (Exception e) {
                PostConvert("[ERROR] Incorrect formula:\n" + e);
                return;
            }
            outpuMML.Text = mmltext;

            // Render SvgImage to ImageSource for showing
            // TODO: I still wonder how to use async well
            Render(svgtext);
        }
Ejemplo n.º 2
0
        public winMain(winSplash splash = null)
        {
            InitializeComponent();
            DataContext = this;

            if (splash != null)
            {
                splash.InvokeUpdate("Loading application settings ...");
            }
            _FormulaZoom = Settings.Default.FormulaScale;
            ClipBgColor.SelectedColor = Settings.Default.BgColorToClip;
            JpgBgColor.SelectedColor  = Settings.Default.BgColorToJpg;


            if (splash != null)
            {
                splash.InvokeUpdate("Loading V8 javascipt engine ...");
            }
            _ = MathjaxParser.GetInstance();

            if (splash != null)
            {
                splash.InvokeUpdate("Loading application resouces ...");
            }
            //InitializeFontSelector();
            //formulaFontName = ((FontFamily)eFontFamily.GetFirstCheckedItem().Tag).ToString();
            //formulaFontSize = (double)eFontSize.EditValue;
            DataObject.AddCopyingHandler(txtInputFomula, OnInputFomulaCopying);
            if (Clipboard.ContainsText())
            {
                myClipboard.Add(Clipboard.GetText());
            }

            if (splash != null)
            {
                splash.InvokeUpdate("Loading latex resources ...");
            }
            LoadSymbols();

            if (splash != null)
            {
                splash.InvokeUpdate("Show window ...");
            }
            AddNotifiactions();

            Application.Current.Exit += OnApplicationExit;
        }