Exemplo n.º 1
0
        /// <summary>
        /// Shows moved symbol
        /// </summary>
        /// <param name="s">the symbol</param>
        protected void ShowSybmol(MathSymbol s)
        {
            if (s == null)
            {
                return;
            }
            Graphics        g  = Graphics.FromImage(iTemp);
            IDrawableSymbol ds = s as IDrawableSymbol;
            Rectangle       r  = ds.PureDrawable.RectForShow;

            sRect.X      = r.X;
            sRect.Y      = r.Y;
            sRect.Width  = r.Width;
            sRect.Height = r.Height;
            g.DrawImage(iBkgnd, sRect, sRect, GraphicsUnit.Pixel);
            g.Dispose();
            g = virtualControl.Graphics;
            Point p = transPoint;

            dRect.X      = r.X + p.X;
            dRect.Y      = r.Y + p.Y;
            dRect.Width  = r.Width;
            dRect.Height = r.Height;
            sRect.X      = r.X;
            sRect.Y      = r.Y;
            sRect.Width  = r.Width;
            sRect.Height = r.Height;
            g.DrawImage(iBkgnd, dRect, sRect, GraphicsUnit.Pixel);
            g.Dispose();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Preparation
        /// </summary>
        /// <param name="iBkgnd">The background image</param>
        public void Prepare(Image iBkgnd)
        {
            this.iBkgnd = iBkgnd;
            Graphics g = Graphics.FromImage(iBkgnd);

            for (int i = 0; i < Count; i++)
            {
                IDrawableSymbol symbol = this[i];
                DrawSymbol(symbol as MathSymbol, true);
                symbol.Prepare(this);
            }
            Rectangle r = formulaRectangle;

            pointFormula.X = r.X + 20;
            pointFormula.Y = r.Y + r.Height / 2;
            iTemp          = new Bitmap(iBkgnd.Width, iBkgnd.Height);
            g = Graphics.FromImage(iTemp);
            g.DrawImage(iBkgnd, 0, 0);
            DrawFormula();
            Bitmap   im    = new Bitmap(iBkgnd.Width, iBkgnd.Height);
            Brush    brush = new SolidBrush(Color.FromArgb(120, 50, 50, 50));
            Graphics gI    = Graphics.FromImage(im);

            gI.FillRectangle(brush, 0, 0, im.Width, im.Height);
            cursorImage = im;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates full relative rectangle of the formula
        /// </summary>
        public virtual void CalculateFullRelativeRectangle()
        {
            IDrawableSymbol symbol = null;
            int             up = 0, down = 0, width = 0;

            for (int i = 0; i < Count; i++)
            {
                symbol = this[i] as IDrawableSymbol;
                symbol.CalculateFullRelativeRectangle();
                Rectangle r = symbol.PureDrawable.FullRelativeRectangle;
                int       w = r.Width;
                if (r.Y < up)
                {
                    up = r.Y;
                }
                if (r.X + r.Height > down)
                {
                    down = r.X + r.Height;
                }
                width += w;
            }
            if (symbol == null)
            {
                fullRelativeRectangle.X      = 0;
                fullRelativeRectangle.Y      = -PureDrawableSymbol.GetHeight(level) / 2;
                fullRelativeRectangle.Width  = PureDrawableSymbol.GetWidth(level);
                fullRelativeRectangle.Height = PureDrawableSymbol.GetHeight(level);
                return;
            }
            fullRelativeRectangle.X      = 0;
            fullRelativeRectangle.Y      = up;
            fullRelativeRectangle.Width  = width;
            fullRelativeRectangle.Height = down - up;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Draws itself
 /// </summary>
 /// <param name="g">graphics for drawing</param>
 public void Draw(Graphics g)
 {
     for (int i = 0; i < Count; i++)
     {
         IDrawableSymbol sym = this[i] as IDrawableSymbol;
         MathSymbolDrawable.Draw(sym as MathSymbol, g);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Calculates relative rectangle with its children
        /// </summary>
        public static void CalculateFullRelativeRectangle(IDrawableSymbol symbol)
        {
            SimpleSymbolDrawable.CalculateFullRelativeRectangle(symbol);
            //SimpleSymbolDrawable.C
            symbol.CalculateRelativeRectangle();
            if (symbol is RootSymbol | symbol is FractionSymbol | symbol is BinaryFunctionSymbol)
            {
                return;
            }
            if (!(symbol is BracketsSymbolDrawable))
            {
                return;
            }
            BracketsSymbolDrawable sym = symbol as BracketsSymbolDrawable;
            Rectangle           rr     = symbol.PureDrawable.RelativeRectangle;
            int                 w      = rr.Width;
            int                 up     = rr.Y;
            MathSymbol          ms     = symbol as MathSymbol;
            MathFormulaDrawable df     = ms[0] as MathFormulaDrawable;
            Rectangle           r1     = df.FullRelativeRectangle;
            Rectangle           r2     = new Rectangle();

            if (ms.Children != null)
            {
                if (ms.Count > 1)
                {
                    if (ms[1] != null)
                    {
                        if (!ms[1].IsEmpty)
                        {
                            MathFormulaDrawable dr = ms[1] as MathFormulaDrawable;
                            r2 = dr.FullRelativeRectangle;
                        }
                    }
                }
            }
            sym.h    = (int)((double)sym.down / Math.Sin(40.0 * 3.1415926 / 180.0));
            sym.warc = (int)((double)sym.h * (1 - Math.Cos(40.0 * 3.1415926 / 180.0)));
            int wpow = 0, hpow = 0;

            if (sym.Count > 1)
            {
                sym.h    = (int)((double)sym.down / Math.Sin(40.0 * 3.1415926 / 180.0));
                sym.warc = (int)((double)sym.h * (1 - Math.Cos(40.0 * 3.1415926 / 180.0)));
                if (ms.Count > 1)
                {
                    wpow = r2.Width;
                    hpow = -r2.Y;
                }
            }
            PureDrawableSymbol pDrawable = symbol.PureDrawable;

            pDrawable.FullRelativeRectangleX      = 0;
            pDrawable.FullRelativeRectangleY      = -sym.down - hpow;
            pDrawable.FullRelativeRectangleWidth  = r1.Width + 2 * sym.warc + 4 + wpow;
            pDrawable.FullRelativeRectangleHeight = 2 * sym.down + sym.hpow;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calculates its and its children positions
        /// </summary>
        public static void CalculatePositions(IDrawableSymbol symbol)
        {
            SimpleSymbolDrawable.CalculatePositions(symbol);
            PureDrawableSymbol pDrawable = symbol.PureDrawable;

            pDrawable.InsertedRectX      = pDrawable.Rectangle.X;
            pDrawable.InsertedRectY      = pDrawable.Rectangle.Y;
            pDrawable.InsertedRectHeight = pDrawable.Rectangle.Height;
            pDrawable.InsertedRectWidth  = pDrawable.WidthInsert;
            pDrawable.InsertedRectX      = pDrawable.InsertedRect.X - pDrawable.WidthInsert / 2;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets location on toolbar
        /// </summary>
        /// <param name="x">the x position</param>
        /// <param name="y">the y position</param>

        /*public void SetLocationOnTable(int x, int y)
         * {
         *  pDrawable.RectForShow.Location = new Point(x, y);
         * }*/


        public void CalculatePositions()
        {
            SimpleSymbolDrawable.CalculatePositions(this);
            IDrawableSymbol    ds        = this;
            PureDrawableSymbol pDrawable = ds.PureDrawable;

            pDrawable.InsertedRectX      = pDrawable.Rectangle.X;
            pDrawable.InsertedRectY      = pDrawable.Rectangle.Y;
            pDrawable.InsertedRectHeight = pDrawable.Rectangle.Height;
            pDrawable.InsertedRectWidth  = pDrawable.WidthInsert;
            pDrawable.InsertedRectX      = pDrawable.InsertedRect.X - pDrawable.WidthInsert / 2;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets the symbol for removing by mouse click
 /// </summary>
 /// <param name="p">the mouse position</param>
 /// <returns>the symbol for removing by mouse click</returns>
 public IDrawableSymbol GetRemovedSymbol(Point p)
 {
     for (int i = 0; i < Count; i++)
     {
         MathSymbol      symbol = this[i];
         IDrawableSymbol ret    = MathSymbolDrawable.GetRemovedSymbol(symbol, p);
         if (ret != null)
         {
             return(ret);
         }
     }
     return(null);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Prepares for polynom editing
        /// </summary>
        /// <param name="sizes">Sizes of symbols</param>
        /// <param name="arg">Argument of polynon</param>
        /// <param name="letters">Variable letters</param>
        public void PreparePoly(int[] sizes, char arg, string[] letters)
        {
            this.sizes = sizes;
            BeforePrepare();
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(arg)));
            for (int i = 0; i < letters.Length; i++)
            {
                string let = letters[i];
                for (int j = 0; j < let.Length; j++)
                {
                    performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(let[j])));
                }
            }

            string numbers = "0123456789";

            for (int i = 0; i < numbers.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(numbers[i], false, (byte)5)));
            }
            string binary = ".+-*";

            for (int i = 0; i < binary.Length; i++)
            {
                performer.Add(new BinarySymbolDrawable(new BinarySymbol(binary[i])));
            }

            performer.Add(new BracketsSymbolDrawable(new BracketsSymbol()));
            performer.Add(new AbsSymbolDrawable(new AbsSymbol()));
            performer.Add(new FractionSymbolDrawable(new FractionSymbol()));
            performer.Add(new BinarySymbolDrawable(MathSymbol.Bra as BinarySymbol));
            performer.Add(new SimpleSymbolDrawable(MathSymbol.Ket as SimpleSymbol));

            int             y      = 3;
            IDrawableSymbol symbol = null;
            int             n      = 0;

            Set(1, ref n, ref symbol, ref y);
            for (int i = 0; i < letters.Length; i++)
            {
                Set(letters[i].Length, ref n, ref symbol, ref y);
            }

            int[] np = new int[] { numbers.Length, binary.Length, 4 };
            for (int i = 0; i < np.Length; i++)
            {
                Set(np[i], ref n, ref symbol, ref y);
            }
            AfrerPrepare(y);
            Resize += OnResize;
        }
Exemplo n.º 10
0
        private void Set(int n, ref int k, ref IDrawableSymbol symbol, ref int y)
        {
            int x = 0;

            for (int i = k; i < k + n; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            y += symbol.PureDrawable.RectForShow.Height;
            k += n;
        }
Exemplo n.º 11
0
        /// <summary>
        ///Draws symbol on tool box
        /// </summary>
        /// <param name="s">the symbol</param>
        /// <param name="mode">the on/off mode</param>
        protected void DrawSymbol(MathSymbol s, bool mode)
        {
            if (s == null)
            {
                return;
            }
            IDrawableSymbol ds = s as IDrawableSymbol;
            Graphics        g = Graphics.FromImage(iBkgnd);
            Color           cb, cs;
            Brush           bb, bs;

            if (mode)
            {
                cb = backgroundColor;
                cs = symbolColor;
                bb = this.backgroundBrush;
                bs = this.symbolBrush;
            }
            else
            {
                cs = backgroundColor;
                cb = symbolColor;
                bs = this.backgroundBrush;
                bb = this.symbolBrush;
            }
            Rectangle r = ds.PureDrawable.RectForShow;

            g.FillRectangle(bb, r.X, r.Y, r.Width, r.Height);

            Pen linePen = new Pen(Color.Black);

            ds.DrawOnComponent(g, bs, PureDrawableSymbol.LinePen);
            g.DrawLine(linePen, r.X, r.Y, r.X + r.Width - 1, r.Y);
            g.DrawLine(linePen, r.X + r.Width - 1, r.Y, r.X + r.Width - 1, r.Y + r.Height - 1);
            g.DrawLine(linePen, r.X, r.Y + r.Height - 1, r.X + r.Width - 1, r.Y + r.Height - 1);
            g.DrawLine(linePen, r.X, r.Y, r.X, r.Y + r.Height - 1);
            g.Dispose();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Calculates positions of formula symbols
        /// </summary>
        public void CalculatePositions()
        {
            tempPosition.X = position.X;
            tempPosition.Y = position.Y;
            IDrawableSymbol symbol = null;

            //int up = 0, down = 0, width = 0;
            for (int i = 0; i < Count; i++)
            {
                symbol = this[i] as IDrawableSymbol;
                symbol.PureDrawable.X = tempPosition.X;
                symbol.PureDrawable.Y = tempPosition.Y;
                symbol.CalculatePositions();
                Rectangle r = symbol.PureDrawable.FullRelativeRectangle;
                int       w = r.Width;
                tempPosition.X += w;
            }
            if (symbol == null)
            {
                endRectangle.X = position.X;
                int h = PureDrawableSymbol.GetHeight(level);
                endRectangle.Y      = position.Y - h / 2;
                endRectangle.Height = h;
                int w = (int)(((float)h) * RELATION);
                endRectangle.Width = w;
                return;
            }
            endRectangle.Width  = symbol.PureDrawable.FullRectangle.Width;
            endRectangle.Height = symbol.PureDrawable.FullRectangle.Height;
            endRectangle.X      = tempPosition.X;
            int H = symbol.PureDrawable.RelativeRectangle.Height;
            int W = (int)(((float)H) * RELATION);

            endRectangle.Width = W;
            endRectangle.Y     = tempPosition.Y - H / 2;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Preparation
        /// </summary>
        /// <param name="sx">Variable symbols</param>
        /// <param name="n">Level</param>
        /// <param name="sSubscript">Subscripted symbols</param>
        /// <param name="symbols">Text symbols</param>
        public void Prepare(string sx, int n, string[,] sSubscript, string[] symbols)

        {
            string[] all = symbols;

            Hashtable table = new Hashtable();

            string[,] el = new string[, ] {
                { "=", "=" }, { "&", "AND" }, { "\u2216", "AND" }, { "\u2217", "OR" }, { "|", "OR" }, { "\u8835", "=>" }, { "l", "LIKE" }, { "p", "=>" },
                { "¬", "NOT" }, { "(", "(" }, { ".", "." }, { ":", ":" }, { "?", "?" }, { "<", "<" }, { ">", ">" }, { "+", "+" },
                { "-", "-" }, { "*", "*" }, { "/", "/" }, { "﹪", "%" }, { "=", "=" }, { "A", "atan2" }, { "'", "d/dt" }
            };
            for (int i = 0; i < el.GetLength(0); i++)
            {
                table[el[i, 0]] = el[i, 1];
            }
            // MathFormula.Resources = table;


            int[] sizes = MathSymbolFactory.Sizes;
            int   sub   = (sSubscript == null) ? 0 : sSubscript.GetLength(0);
            MathFormulaDrawable formula = new MathFormulaDrawable(new MathFormula((byte)0, sizes), DrawableConverter.Object);
            Control             control = this;

            performer = new FormulaEditor.FormulaEditorPerformer(control, formula);
            Color[] cols = new Color[] { Color.FromArgb(216, 203, 187), Color.Black };
            performer.SetColors(cols[0], cols[1]);
            Graphics g = Graphics.FromHwnd(control.Handle);

            SimpleSymbolDrawable.Prepare(sizes, g);
            BracketsSymbolDrawable.Prepare(sizes, g);
            AbsSymbolDrawable.Prepare(sizes, g);
            if (all != null)
            {
                foreach (string str in all)
                {
                    foreach (char c in str)
                    {
                        performer.Add(new SimpleSymbolDrawable(
                                          new SimpleSymbol(c, 0x0, false, false)));
                    }
                }
            }

            string ss = sx;

            for (int i = 0; i < sub; i++)
            {
                performer.Add(new SubscriptedSymbolDrawable(new SubscriptedSymbol(sSubscript[i, 0], sSubscript[i, 1])));
            }
            for (int i = 0; i < ss.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(ss[i])));
            }
            string elem = "scletqabjkfgw'\u2211\u03B4\u0442";

            for (int i = 0; i < elem.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(elem[i], false, (byte)4)));
            }
            string integerSym = "ABCDEFGH";

            performer.Add(new BinaryFunctionSymbolDrawable(new BinaryFunctionSymbol('A', "atan2")));
            for (int i = 0; i < integerSym.Length; i++)
            {
                char c = integerSym[i];
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(c, (byte)4, false, ElementaryIntegerOperation.GetString(c))));
            }
            string numbers = "x0123456789ABCDEF";

            for (int i = 0; i < numbers.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(numbers[i], false, (byte)5)));
            }
            string binary = ".+-*×=><\u2264\u2265\u2260?:&|^\u2266\u2267\u2216\u2217\u8835l\u2270";

            //string[,] el = new string[,] {{"\u2216", "AND"}, {"\u2217", "OR"}};
            //string binary = ".+-*=><?:&|^\u2217l";
            for (int i = 0; i < binary.Length; i++)
            {
                performer.Add(new BinarySymbolDrawable(new BinarySymbol(binary[i])));
            }
            string unary = "¬~";

            for (int i = 0; i < unary.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(unary[i], false, (byte)4)));
            }
            performer.Add(new BracketsSymbolDrawable(new BracketsSymbol()));
            performer.Add(new AbsSymbolDrawable(new AbsSymbol()));
            performer.Add(new RootSymbolDrawable(new RootSymbol()));
            performer.Add(new FractionSymbolDrawable(new FractionSymbol()));
            performer.Add(new BinarySymbolDrawable(MathSymbol.Bra as BinarySymbol));
            performer.Add(new SimpleSymbolDrawable(MathSymbol.Ket as SimpleSymbol));
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('e')));
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('%', (byte)FormulaConstants.Variable, true, "\u03c0")));
            for (int i = 0; i < n; i++)
            {
                performer.Add(new SeriesSymbolDrawable(new SeriesSymbol(i)));
            }
            int             x = 10, y = 10;
            int             bottom = 0;
            IDrawableSymbol symbol = null;
            int             ns     = 0;

            if (all != null)
            {
                foreach (string str in all)
                {
                    foreach (char c in str)
                    {
                        symbol = performer[ns];
                        Point p = new Point(x, y);
                        MathSymbolDrawable.SetComponentPosition(symbol, p);
                        symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20));
                        x += symbol.PureDrawable.RectForShow.Width;
                        ++ns;
                    }
                    bottom = y + symbol.PureDrawable.RectForShow.Height;
                    y      = bottom;
                    x      = 10;
                }
            }

            if (sub != 0)
            {
                for (int i = ns; i < sub + ns; i++)
                {
                    symbol = performer[i];
                    Point p = new Point(x, y);
                    MathSymbolDrawable.SetComponentPosition(symbol, p);
                    symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20));
                    x += symbol.PureDrawable.RectForShow.Width;
                }

                bottom = y + symbol.PureDrawable.RectForShow.Height;
                y      = bottom;
                x      = 10;
            }
            for (int i = sub + ns; i < sub + ns + ss.Length; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, 30, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }

            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;
            for (int i = ss.Length + ns + sub; i < ss.Length + elem.Length + 2 + sub + ns; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;

            for (int i = sub + ns + ss.Length + elem.Length + 1; i < sub + ns + ss.Length + elem.Length + integerSym.Length + 1; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }

            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;
            for (int i = sub + ns + ss.Length + elem.Length + integerSym.Length + 1;
                 i < sub + ns + ss.Length + elem.Length + numbers.Length + integerSym.Length + 2; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;
            for (int i = sub + ns + ss.Length + elem.Length + integerSym.Length + numbers.Length + 1; i < sub + ns + ss.Length +
                 elem.Length + numbers.Length + integerSym.Length + binary.Length + unary.Length + 8 + n; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            Rectangle r = new Rectangle(80, bottom, 1100, control.Height - bottom - 20);

            performer.FormulaRectangle = r;
            Image back = new Bitmap(1200, r.Y + r.Height + 10);

            g = Graphics.FromImage(back);
            g.FillRectangle(new SolidBrush(Color.LightGray), 0, 0, back.Width, back.Height);
            g.DrawRectangle(new Pen(Color.Black), 0, 0, back.Width - 1, back.Height - 1);
            Font  f      = new Font("Serif", sizes[0], FontStyle.Bold | FontStyle.Italic);
            int   delta  = 15;
            Brush bBrush = new SolidBrush(Color.Black);

            g.DrawString("f = ", f, bBrush, 10, r.Y + r.Height / 2 + delta);
            g.Dispose();
            performer.Prepare(back);
            formula           = new MathFormulaDrawable(new MathFormula((byte)0, sizes), DrawableConverter.Object);
            performer.Formula = formula;
            performer.InitEventHandlers();
            performer.DrawFormula();
        }
Exemplo n.º 14
0
 /// <summary>
 /// Adds symbol to toolbox
 /// </summary>
 /// <param name="symbol">symbol</param>
 public void Add(IDrawableSymbol symbol)
 {
     symbols.Add(symbol);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Preparation
        /// </summary>
        /// <param name="sx">Variable symbols</param>
        /// <param name="n">Level</param>
        /// <param name="sSubscript">Subscripted symbols</param>
        /// <param name="symbols">Text symbols</param>
        public void Prepare(string sx, int n, string[,] sSubscript, string[] symbols)
        {
            int[] sizes = MathSymbolFactory.Sizes;
            this.sizes = sizes;
            BeforePrepare();
            string[] all = symbols;

            Hashtable table = new Hashtable();

            string[,] el = new string[, ] {
                { "=", "=" }, { "&", "AND" }, { "\u2216", "AND" }, { "\u2217", "OR" }, { "|", "OR" }, { "\u8835", "=>" }, { "l", "LIKE" }, { "p", "=>" },
                { "¬", "NOT" }, { "(", "(" }, { ".", "." }, { ":", ":" }, { "?", "?" }, { "<", "<" }, { ">", ">" }, { "+", "+" },
                { "-", "-" }, { "*", "*" }, { "=", "=" }, { "/", "/" }, { "﹪", "%" }, { "A", "atan2" }, { "'", "d/dt" }
            };
            for (int i = 0; i < el.GetLength(0); i++)
            {
                table[el[i, 0]] = el[i, 1];
            }
            // MathFormula.Resources = table;


            int sub = (sSubscript == null) ? 0 : sSubscript.GetLength(0);

            //BinaryFunctionSymbolDrawable.Prepare(sizes, g);
            if (all != null)
            {
                foreach (string str in all)
                {
                    foreach (char c in str)
                    {
                        performer.Add(new SimpleSymbolDrawable(
                                          new SimpleSymbol(c, 0x0, false, false)));
                    }
                }
            }

            string ss = sx;

            for (int i = 0; i < sub; i++)
            {
                performer.Add(new SubscriptedSymbolDrawable(new SubscriptedSymbol(sSubscript[i, 0], sSubscript[i, 1])));
            }
            for (int i = 0; i < ss.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(ss[i])));
            }
            string elem = "scletqabjkfgwo'\u2211\u03B4\u0442";

            for (int i = 0; i < elem.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(elem[i], false, (byte)4)));
            }
            string integerSym = "ABCDEFGHI";

            performer.Add(new BinaryFunctionSymbolDrawable(new BinaryFunctionSymbol('A', "atan2")));
            for (int i = 0; i < integerSym.Length; i++)
            {
                char c = integerSym[i];
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(c, (byte)4, false, ElementaryIntegerOperation.GetString(c))));
            }
            string numbers = "x0123456789ABCDEF";

            for (int i = 0; i < numbers.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(numbers[i], false, (byte)5)));
            }
            string binary = ".+-*×/﹪=><\u2264\u2265\u2260?:&|^\u2266\u2267\u2216\u2217\u8835l\u2270";

            //string[,] el = new string[,] {{"\u2216", "AND"}, {"\u2217", "OR"}};
            //string binary = ".+-*=><?:&|^\u2217l";
            for (int i = 0; i < binary.Length; i++)
            {
                performer.Add(new BinarySymbolDrawable(new BinarySymbol(binary[i])));
            }
            string unary = "¬~";

            for (int i = 0; i < unary.Length; i++)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(unary[i], false, (byte)4)));
            }
            performer.Add(new BracketsSymbolDrawable(new BracketsSymbol()));
            performer.Add(new AbsSymbolDrawable(new AbsSymbol()));
            performer.Add(new BinaryFunctionSymbolDrawable(new BinaryFunctionSymbol('2', "(,)")));
            performer.Add(new TernaryFunctionSymbolDrawable(new TernaryFunctionSymbol('3', "(,,)")));
            performer.Add(new RootSymbolDrawable(new RootSymbol()));
            performer.Add(new FractionSymbolDrawable(new FractionSymbol()));
            performer.Add(new BinarySymbolDrawable(MathSymbol.Bra as BinarySymbol));
            performer.Add(new SimpleSymbolDrawable(MathSymbol.Ket as SimpleSymbol));
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('e')));
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('%', (byte)FormulaConstants.Variable, true, "\u03c0")));
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(true)));
            performer.Add(new SimpleSymbolDrawable(new SimpleSymbol(false)));
            for (int i = 0; i < n; i++)
            {
                performer.Add(new SeriesSymbolDrawable(new SeriesSymbol(i)));
            }
            List <string> ls = StaticExtensionFormulaEditor.AdditionalFormulas;

            foreach (string str in ls)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('@', 0x0, false, true, str)));
            }
            List <string> lp = StaticExtensionFormulaEditor.Properties;

            foreach (string str in lp)
            {
                performer.Add(new SimpleSymbolDrawable(new SimpleSymbol('.', 0x0, true, false, str)));
            }
            int             x = 10, y = 10;
            int             bottom = 0;
            IDrawableSymbol symbol = null;
            int             ns     = 0;

            if (all != null)
            {
                foreach (string str in all)
                {
                    foreach (char c in str)
                    {
                        symbol = performer[ns];
                        Point p = new Point(x, y);
                        MathSymbolDrawable.SetComponentPosition(symbol, p);
                        symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20));
                        x += symbol.PureDrawable.RectForShow.Width;
                        ++ns;
                    }
                    bottom = y + symbol.PureDrawable.RectForShow.Height;
                    y      = bottom;
                    x      = 10;
                }
            }

            if (sub != 0)
            {
                for (int i = ns; i < sub + ns; i++)
                {
                    symbol = performer[i];
                    Point p = new Point(x, y);
                    MathSymbolDrawable.SetComponentPosition(symbol, p);
                    symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth, (int)(1.5 * 20));
                    x += symbol.PureDrawable.RectForShow.Width;
                }
                bottom = y + symbol.PureDrawable.RectForShow.Height;
                y      = bottom;
                x      = 10;
            }
            for (int i = sub + ns; i < sub + ns + ss.Length; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, 30, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;
            for (int i = ss.Length + ns + sub; i < ss.Length + elem.Length + 1 + sub + ns; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;

            for (int i = sub + ns + ss.Length + elem.Length + 1; i < sub + ns + ss.Length + elem.Length + integerSym.Length + 1; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }

            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;
            for (int i = sub + ns + ss.Length + elem.Length + integerSym.Length + 1;
                 i < sub + ns + ss.Length + elem.Length + numbers.Length + integerSym.Length + 1; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            x      = 10;
            int k = sub + ns + ss.Length +
                    elem.Length + numbers.Length + integerSym.Length + binary.Length + unary.Length + 13 + n;

            for (int i = sub + ns + ss.Length + elem.Length + integerSym.Length + numbers.Length + 1; i < k; i++)
            {
                symbol = performer[i];
                Point p = new Point(x, y);
                MathSymbolDrawable.SetComponentPosition(symbol, p);
                symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                x += symbol.PureDrawable.RectForShow.Width;
            }
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            x      = 10;
            y      = bottom;
            if (ls.Count > 0)
            {
                for (int i = k; i < k + ls.Count; i++)
                {
                    symbol = performer[i];
                    Point p = new Point(x, y);
                    MathSymbolDrawable.SetComponentPosition(symbol, p);
                    symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                    x += symbol.PureDrawable.RectForShow.Width;
                }
                bottom = y + symbol.PureDrawable.RectForShow.Height;
            }
            k     += ls.Count;
            x      = 10;
            bottom = y + symbol.PureDrawable.RectForShow.Height;
            y      = bottom;
            if (lp.Count > 0)
            {
                for (int i = k; i < k + lp.Count; i++)
                {
                    symbol = performer[i];
                    Point p = new Point(x, y);
                    MathSymbolDrawable.SetComponentPosition(symbol, p);
                    symbol.PureDrawable.RectForShow = new Rectangle(x, y, symbol.StandardWidth + 10, (int)(1.5 * 20));
                    x += symbol.PureDrawable.RectForShow.Width;
                }
                bottom = y + symbol.PureDrawable.RectForShow.Height;
            }
            AfrerPrepare(bottom);
            Resize += OnResize;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Draws itself on component
        /// </summary>
        /// <param name="g">The graphics to draw</param>
        /// <param name="brush">The drawing brush</param>
        /// <param name="pen">The drawing pen</param>
        public static void DrawOnComponent(IDrawableSymbol sym, Graphics g, Brush brush, Pen pen)
        {
            MathSymbol ms = sym as MathSymbol;
            char       ch = ms.Symbol;

            if ((ch != '\u2216') & (ch != '\u2217') & (ch != '\u8835') & (ch != '\u2295') & (ch != '\u2297')
                | MathFormula.Resources.ContainsKey(ms.Symbol + ""))
            {
                SimpleSymbolDrawable.DrawOnComponent(sym, g, brush, pen);
                return;
            }

            PureDrawableSymbol pDrawable = sym.PureDrawable;

            int    shift = 8;
            string ss    = ms.String;

            if (ss == null)
            {
                ss = "" + ch;
            }
            if (ss.Length == 0)
            {
                ss += ch;
            }
            int w = (int)g.MeasureString(ss, BracketsSymbolDrawable.FontB).Width;
            int h = pDrawable.RectForShow.Height;
            int s = (w < h) ? w : h;

            s = (int)(0.6 * (float)s);
            int x = pDrawable.RectForShow.X + w / 2;
            int y = pDrawable.RectForShow.Y + h / 2;

            if (ch == '\u2216')
            {
                g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + shift, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift,
                           pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + shift);
                g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + shift,
                           pDrawable.RectForShow.X + pDrawable.RectForShow.Width - shift, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift);
            }
            else if (ch == '\u2217')
            {
                g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + shift, pDrawable.RectForShow.Y + shift,
                           pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift);
                g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift,
                           pDrawable.RectForShow.X + pDrawable.RectForShow.Width - shift, pDrawable.RectForShow.Y + shift);
            }
            else if (ch == '\u8835')
            {
                g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + shift, pDrawable.RectForShow.Y + shift,
                           pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift);
                g.DrawLine(PureDrawableSymbol.WidePen, pDrawable.RectForShow.X + pDrawable.RectForShow.Width / 2, pDrawable.RectForShow.Y + pDrawable.RectForShow.Height - shift,
                           pDrawable.RectForShow.X + pDrawable.RectForShow.Width - shift, pDrawable.RectForShow.Y + shift);
            }
            else if (ch == '\u2295')
            {
                DrawCircledPlus(g, PureDrawableSymbol.LinePen, x, y, s);
            }
            else if (ch == '\u2297')
            {
                DrawCircledProduct(g, PureDrawableSymbol.LinePen, x, y, s);
            }
        }
Exemplo n.º 17
0
        void IDrawableSymbol.CalculateFullRelativeRectangle()
        {
            IDrawableSymbol ds = this;

            ds.CalculateRelativeRectangle();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Draws moved cursor
        /// </summary>
        protected void DrawCursor()
        {
            int   minX, minY, maxX, maxY;
            Point p = imagePoint;

            if (oldX < p.X)
            {
                minX = oldX;
                maxX = p.X;
            }
            else
            {
                maxX = oldX;
                minX = p.X;
            }
            if (oldY < p.Y)
            {
                minY = oldY;
                maxY = p.Y;
            }
            else
            {
                maxY = oldY;
                minY = p.Y;
            }
            oldX = p.X;
            oldY = p.Y;
            int left   = minX - 100;
            int top    = minY - 60 - wImage;
            int right  = maxX + 100;
            int bottom = maxY + 60 + hImage;

            if (left < 0)
            {
                left = 0;
            }
            if (top < 0)
            {
                top = 0;
            }
            Graphics g = Graphics.FromImage(iTemp);

            sRect.X      = left;
            sRect.Y      = top;
            sRect.Width  = right - left;
            sRect.Height = bottom - top;
            g.DrawImage(iBkgnd, sRect, sRect, GraphicsUnit.Pixel);

            if (movedSymbol != null)
            {
                IDrawableSymbol ds = movedSymbol as IDrawableSymbol;
                Image           im = ds.PureDrawable.SymbolImage;
                g.DrawImage(im, p.X - im.Width / 2,
                            p.Y - im.Height - 20);
            }
            g.Dispose();
            Graphics gr = virtualControl.Graphics;
            Point    tP = transPoint;

            sRect.X     += tP.X;
            sRect.Y     += tP.Y;
            dRect.Width  = sRect.Width;
            dRect.Height = sRect.Height;
            dRect.X      = left + tP.X;
            dRect.Y      = top + tP.Y;
            gr.DrawImage(iTemp, dRect, sRect, GraphicsUnit.Pixel);
            gr.Dispose();
        }
Exemplo n.º 19
0
 /// <summary>
 /// The "on click" event handler
 /// </summary>
 /// <param name="sender">The sender</param>
 /// <param name="e">The event arguments</param>
 private void onMouseClicked(object sender, MouseEventArgs e)
 {
     translate(e);
     if (movedSymbol == null)
     {
         movedSymbol = newSymbol;
         if (movedSymbol != null)
         {
             if (movedSymbol is DateTimeSymbol)
             {
                 DateTimeSymbol dts = movedSymbol as DateTimeSymbol;
                 dts.DateTime = dateTime.DateTime;
             }
             IDrawableSymbol ds = movedSymbol as IDrawableSymbol;
             wImage         = ds.PureDrawable.SymbolImage.Width;
             hImage         = ds.PureDrawable.SymbolImage.Height;
             control.Cursor = CURSOR_MOVE;
             oldX           = imagePoint.X;
             oldY           = imagePoint.Y;
             DrawCursor();
             if (newCursor != null)
             {
                 DrawCursor(newCursor, true, true);
             }
         }
         if (newRemoveCursor != null)
         {
             MathSymbol s = (MathSymbol)newRemoveCursor;
             if (s.Contains(newCursor))
             {
                 newCursor = null;
                 oldCursor = null;
             }
             s.Remove();
             newRemoveCursor = null;
             oldRemoveCursor = null;
             DrawFormulaOnComponent();
         }
     }
     else
     {
         if (newCursor == null)
         {
             movedSymbol = null;
             DrawCursor();
             newCursor      = null;
             oldCursor      = null;
             control.Cursor = CURSOR_EDIT;
         }
         else
         {
             if (newCursor is MathSymbol)
             {
                 MathSymbol ds = newCursor as MathSymbol;
                 newCursor = MathSymbolDrawable.InsertObject(ds, movedSymbol) as IInsertedObject;
             }
             else if (newCursor is MathFormulaDrawable)
             {
                 MathFormulaDrawable mf = newCursor as MathFormulaDrawable;
                 newCursor = mf.InsertObject(movedSymbol) as IInsertedObject;
             }
             //newCursor = newCursor.InsertObject(movedSymbol);
             movedSymbol = null;
             DrawCursor();
             DrawFormulaOnComponent();
             oldCursor      = movedSymbol as IInsertedObject;
             control.Cursor = CURSOR_EDIT;
         }
     }
 }