Esempio n. 1
0
        private async void OptScale_Click(object sender, RoutedEventArgs e)
        {
            var ScaleItems = new ToggleMenuFlyoutItem[] {
                optScale100,
                optScale125, optScale133, optScale150,
                optScale200, optScale250,
                optScale300,
                optScale400
            };

            foreach (var item in ScaleItems)
            {
                if (item == sender)
                {
                    item.IsChecked = true;
                    var btnName = item.Name;
                    CURRENT_SCALE = int.Parse(btnName.Substring("optScale".Length));
                    var ret = await MathView.InvokeScriptAsync("ChangeScale", new string[] { $"{CURRENT_SCALE}" });
                }
                else
                {
                    item.IsChecked = false;
                }
            }
            Settings.Set("MathScale", CURRENT_SCALE);
        }
Esempio n. 2
0
        private async void OptColor_Click(object sender, RoutedEventArgs e)
        {
            var btn    = sender as MenuFlyoutItem;
            var C_NAME = btn.Name.Substring(3);

            switch (C_NAME)
            {
            case "ResetColor":
                CURRENT_BGCOLOR = Color.FromArgb(0, 255, 255, 255);
                CURRENT_FGCOLOR = Colors.Black;     // Color.FromArgb(255, 000, 000, 000);
                MathView.DefaultBackgroundColor = CURRENT_BGCOLOR;
                break;

            case "BgColor":
                CURRENT_BGCOLOR = await Utils.ShowColorDialog(CURRENT_BGCOLOR);

                MathView.DefaultBackgroundColor = CURRENT_BGCOLOR;
                break;

            case "FgColor":
                CURRENT_FGCOLOR = await Utils.ShowColorDialog(CURRENT_FGCOLOR);

                break;

            default:
                break;
            }
            var ret = await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), CURRENT_BGCOLOR.ToCssRGBA() });

            //await GetMathImage(true);
        }
Esempio n. 3
0
        private async Task <WriteableBitmap> GetMathCapture()
        {
            using (Windows.Storage.Streams.InMemoryRandomAccessStream rs = new Windows.Storage.Streams.InMemoryRandomAccessStream())
            {
                if (MathView.DefaultBackgroundColor.A == 0x00)
                {
                    await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), Colors.White.ToCssRGBA() });
                }

                await MathView.CapturePreviewToStreamAsync(rs);

                await rs.FlushAsync();

                var wb = await rs.ToWriteableBitmap();

                if (wb is WriteableBitmap)
                {
                    wb = wb.Crop(2);
                }

                if (MathView.DefaultBackgroundColor.A == 0x00)
                {
                    await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), CURRENT_BGCOLOR.ToCssRGBA() });
                }

                return(wb);
            }
        }
Esempio n. 4
0
        private async Task <WriteableBitmap> GetMathImage(bool force = false)
        {
            if (CURRENT_IMAGE == null || force)
            {
                var scale = await MathView.InvokeScriptAsync("GetPageZoomRatio", null);

                var ratio = 1.0;
                double.TryParse(scale, out ratio);
                if (ratio <= 0.0)
                {
                    ratio = 1.0;
                }
                //else ratio = Math.Ceiling(ratio);

                var wb = await MathView.ToWriteableBitmap();

                if (wb is WriteableBitmap)
                {
                    var space     = 2;
                    var tolerance = space * 2;

                    var size = await MathView.InvokeScriptAsync("GetEquationRect", null);

                    if (!string.IsNullOrEmpty(size))
                    {
                        try
                        {
                            var sv = size.Split(',');
                            var l  = (int)Math.Floor(double.Parse(sv[0].Trim()));
                            var t  = (int)Math.Floor(double.Parse(sv[1].Trim()));
                            var w  = (int)Math.Ceiling(double.Parse(sv[2].Trim()));
                            var h  = (int)Math.Ceiling(double.Parse(sv[3].Trim()));
                            l  = (int)Math.Min(l * ratio, Math.Max(0, l - tolerance));
                            t  = (int)Math.Min(t * ratio, Math.Max(0, t - tolerance));
                            w  = (int)Math.Max(w + tolerance * 2, Math.Min(wb.PixelWidth, w * Math.Ceiling(ratio) + tolerance * 2));
                            h  = (int)Math.Max(h + tolerance * 2, Math.Min(wb.PixelHeight, h * Math.Ceiling(ratio) + tolerance * 2));
                            wb = wb.Crop(l, t, w, h);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    wb = wb.Crop(space);
                }
                CURRENT_IMAGE = wb;
            }
            return(CURRENT_IMAGE);
        }
Esempio n. 5
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var ret = await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), CURRENT_BGCOLOR.ToCssRGBA() });

                //var ret = await mathView.InvokeScriptAsync("LoadMathJax", null);
                //if (ret.Equals("OK", StringComparison.CurrentCultureIgnoreCase))
                {
                    //edSrc.IsEnabled = true;
                }
            }
            catch
            {
            }
        }
Esempio n. 6
0
        private async Task <Size> GetMathSize()
        {
            Size result = Size.Empty;

            var scale = await MathView.InvokeScriptAsync("GetPageZoomRatio", null);

            var ratio = 1.0;

            double.TryParse(scale, out ratio);
            if (ratio == 0.0)
            {
                ratio = 1;
            }
            else
            {
                ratio = Math.Max(0, ratio);
            }

            var space     = 2;
            var tolerance = space * 2;

            var size = await MathView.InvokeScriptAsync("GetEquationRect", null);

            if (!string.IsNullOrEmpty(size))
            {
                try
                {
                    var sv = size.Split(',');
                    var l  = (int)Math.Floor(double.Parse(sv[0].Trim()));
                    var t  = (int)Math.Floor(double.Parse(sv[1].Trim()));
                    var w  = (int)Math.Ceiling(double.Parse(sv[2].Trim()));
                    var h  = (int)Math.Ceiling(double.Parse(sv[3].Trim()));
                    l             = Math.Max(0, l - tolerance);
                    t             = Math.Max(0, t - tolerance);
                    w             = Math.Max(w, (int)(w * ratio) + tolerance * 2);
                    h             = Math.Max(h, (int)(h * ratio) + tolerance * 2);
                    result.Width  = w;
                    result.Height = h;
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }
Esempio n. 7
0
        private async Task <bool> GeneratingMath()
        {
            bool result = false;

            var           lines = edSrc.Text.Trim().Split(new char[] { '\n', '\r' });
            StringBuilder sb    = new StringBuilder();

            foreach (var l in lines)
            {
                if (string.IsNullOrEmpty(l))
                {
                    continue;
                }
                var idx  = l.Replace("\\%", "\\\\").IndexOf("%");
                var line = idx >= 0 ? l.Substring(0, idx) : l;
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                //if (!line.EndsWith("\\\\")) line = $"{line} \\\\ ";
                line = await line.Decoder(TextCodecs.CODEC.HTML, Encoding.UTF8);

                sb.AppendLine(line);
            }
            var tex = string.Join(Environment.NewLine, sb);

            if (!string.IsNullOrEmpty(tex))
            {
                try
                {
                    ResetMathView();
                    var ret = await MathView.InvokeScriptAsync("ChangeEquation", new string[] { tex });

                    if (ret.Equals("OK", StringComparison.CurrentCultureIgnoreCase))
                    {
                        result = true;
                    }
                    SetMathView();

                    CURRENT_FORMULAR = tex;
                }
                catch (Exception) { }
            }
            return(result);
        }