Example #1
0
 public SubSuperBase(EquationRow parent, Position position)
     : base(parent)
 {
     ApplySymbolGap = false;
     SubLevel++;
     Position = position;
 }
 public RowContainerAction(ISupportsUndo executor, int index, int childIndexInRow, int caretIndex, EquationRow equation)
     : base(executor)
 {
     Index = index;
     ChildIndexInRow = childIndexInRow;
     CaretIndex = caretIndex;
     Equation = equation;
 }
Example #3
0
 public RowContainer(EquationContainer parent, double lineSpaceFactor = 0)
     : base(parent)
 {
     EquationRow newLine = new EquationRow(this);
     AddLine(newLine);
     Height = newLine.Height;
     Width = newLine.Width;
     this.lineSpaceFactor = lineSpaceFactor;
 }
Example #4
0
 public Super(EquationRow parent, Position position)
     : base(parent, position)
 {
     ActiveChild = rowContainer = new RowContainer(this);
     childEquations.Add(rowContainer);
     if (SubLevel == 1)
     {
         rowContainer.FontFactor = SubFontFactor;
     }
     else if (SubLevel == 2)
     {
         rowContainer.FontFactor = SubSubFontFactor;
     }
 }
Example #5
0
 public SubAndSuper(EquationRow parent, Position position)
     : base(parent, position)
 {
     ActiveChild = superEquation = new RowContainer(this);
     subEquation = new RowContainer(this);
     childEquations.Add(superEquation);
     childEquations.Add(subEquation);
     if (SubLevel == 1)
     {
         superEquation.FontFactor = SubFontFactor;
         subEquation.FontFactor = SubFontFactor;
     }
     else if (SubLevel >= 2)
     {
         superEquation.FontFactor = SubSubFontFactor;
         subEquation.FontFactor = SubSubFontFactor;
     }
 }
Example #6
0
 void AddLine(EquationRow newRow)
 {
     int index = 0;
     if (childEquations.Count > 0)
     {
         index = childEquations.IndexOf((EquationRow)ActiveChild) + 1;
     }
     childEquations.Insert(index, newRow);
     ActiveChild = newRow;
     CalculateSize();
 }
Example #7
0
 public override void Paste(XElement xe)
 {
     if (((EquationRow)ActiveChild).ActiveChild.GetType() == typeof(TextEquation) && xe.Name.LocalName == GetType().Name)
     {
         XElement children = xe.Element("ChildRows");
         List<EquationRow> newRows = new List<EquationRow>();
         foreach (XElement xElement in children.Elements())
         {
             EquationRow row = new EquationRow(this);
             row.DeSerialize(xElement);
             newRows.Add(row);
             row.FontSize = FontSize;
         }
         if (newRows.Count > 0)
         {
             TextEquation activeText = (TextEquation)((EquationRow)ActiveChild).ActiveChild;
             RowContainerPasteAction action = new RowContainerPasteAction(this)
             {
                 ActiveEquation = ActiveChild,
                 ActiveEquationSelectedItems = ActiveChild.SelectedItems,
                 ActiveEquationSelectionIndex = ActiveChild.SelectionStartIndex,
                 ActiveTextInChildRow = activeText,
                 TextEquationDecorations = activeText.GetDecorations(),
                 CaretIndexOfActiveText = activeText.CaretIndex,
                 TextEquationContents = activeText.Text,
                 TextEquationFormats = activeText.GetFormats(),
                 TextEquationModes = activeText.GetModes(),
                 SelectedItems = SelectedItems,
                 SelectionStartIndex = SelectionStartIndex,
                 SelectedItemsOfTextEquation = activeText.SelectedItems,
                 SelectionStartIndexOfTextEquation = activeText.SelectionStartIndex,
                 HeadTextOfPastedRows = newRows[0].GetFirstTextEquation().Text,
                 TailTextOfPastedRows = newRows.Last().GetLastTextEquation().Text,
                 HeadFormatsOfPastedRows = newRows[0].GetFirstTextEquation().GetFormats(),
                 TailFormatsOfPastedRows = newRows.Last().GetLastTextEquation().GetFormats(),
                 HeadModeOfPastedRows = newRows[0].GetFirstTextEquation().GetModes(),
                 TailModesOfPastedRows = newRows.Last().GetLastTextEquation().GetModes(),
                 HeadDecorationsOfPastedRows = newRows[0].GetFirstTextEquation().GetDecorations(),
                 TailDecorationsOfPastedRows = newRows.Last().GetLastTextEquation().GetDecorations(),
                 Equations = newRows
             };
             EquationRow newRow = (EquationRow)ActiveChild.Split(this);
             ((EquationRow)ActiveChild).Merge(newRows[0]);
             int index = childEquations.IndexOf(ActiveChild) + 1;
             childEquations.InsertRange(index, newRows.Skip(1));
             newRows.Last().Merge(newRow);
             newRows.Add(newRow);
             ActiveChild = childEquations[index + newRows.Count - 3];
             UndoManager.AddUndoAction(action);
         }
         CalculateSize();
     }
     else
     {
         base.Paste(xe);
     }
 }
Example #8
0
 public override void DeSerialize(XElement xElement)
 {
     XElement children = xElement.Element("ChildRows");
     childEquations.Clear();
     foreach (XElement xe in children.Elements())
     {
         EquationRow row = new EquationRow(this);
         row.DeSerialize(xe);
         childEquations.Add(row);
     }
     if (childEquations.Count == 0)
     {
         childEquations.Add(new EquationRow(this));
     }
     ActiveChild = childEquations.First();
     CalculateSize();
 }
Example #9
0
        public override CopyDataObject Copy(bool removeSelection)
        {
            if (SelectedItems != 0)
            {
                int startIndex = SelectedItems > 0 ? SelectionStartIndex : SelectionStartIndex + SelectedItems;
                int count = (SelectedItems > 0 ? SelectionStartIndex + SelectedItems : SelectionStartIndex) - startIndex;
                EquationRow firstRow = (EquationRow)childEquations[startIndex];
                EquationRow lastRow = (EquationRow)childEquations[startIndex + count];
                List<EquationBase> firstRowSelectedItems = firstRow.GetSelectedEquations();
                List<EquationBase> lastRowSelectedItems = lastRow.GetSelectedEquations();

                EquationRow newFirstRow = new EquationRow(this);
                EquationRow newLastRow = new EquationRow(this);
                newFirstRow.GetFirstTextEquation().ConsumeFormattedText(firstRowSelectedItems.First().GetSelectedText(),
                                                                        ((TextEquation)firstRowSelectedItems.First()).GetSelectedFormats(),
                                                                        ((TextEquation)firstRowSelectedItems.First()).GetSelectedModes(),
                                                                        ((TextEquation)firstRowSelectedItems.First()).GetSelectedDecorations(), false);
                newLastRow.GetFirstTextEquation().ConsumeFormattedText(lastRowSelectedItems.Last().GetSelectedText(),
                                                                       ((TextEquation)lastRowSelectedItems.Last()).GetSelectedFormats(),
                                                                       ((TextEquation)lastRowSelectedItems.Last()).GetSelectedModes(),
                                                                       ((TextEquation)lastRowSelectedItems.First()).GetSelectedDecorations(),
                                                                       false);

                firstRowSelectedItems.RemoveAt(0);
                lastRowSelectedItems.RemoveAt(lastRowSelectedItems.Count - 1);
                newFirstRow.AddChildren(firstRowSelectedItems, false);
                newLastRow.AddChildren(lastRowSelectedItems, true);
                List<EquationBase> equations = new List<EquationBase>();
                for (int i = startIndex + 1; i < startIndex + count; i++)
                {
                    equations.Add(childEquations[i]);
                }
                equations.Add(newLastRow);
                foreach (EquationBase eb in equations)
                {
                    eb.Left = 1;
                }
                double left = firstRow.GetFirstSelectionText().Right - this.Left;
                Rect firstTextRect = firstRow.GetFirstSelectionText().GetSelectionBounds();
                if (!firstTextRect.IsEmpty)
                {
                    left = firstTextRect.Left - Left;
                }
                newFirstRow.Left = left + 1;
                equations.Insert(0, newFirstRow);
                double nextY = 1;
                double width = firstRow.Width;
                double height = 0;
                foreach (EquationBase eb in equations)
                {
                    eb.Top = nextY;
                    nextY += eb.Height + LineSpace;
                    width = eb.Width > width ? eb.Width : width;
                    height += eb.Height + LineSpace;
                }
                height -= LineSpace;
                RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(Math.Ceiling(width + 2)), (int)(Math.Ceiling(height + 2)), 96, 96, PixelFormats.Default);
                DrawingVisual dv = new DrawingVisual();
                IsSelecting = false;
                using (DrawingContext dc = dv.RenderOpen())
                {
                    dc.DrawRectangle(Brushes.White, null, new Rect(0, 0, bitmap.Width, bitmap.Height));
                    foreach (EquationBase eb in equations)
                    {
                        eb.DrawEquation(dc);
                    }
                }
                IsSelecting = true;
                bitmap.Render(dv);
                XElement thisElement = new XElement(GetType().Name);
                XElement children = new XElement("ChildRows");
                foreach (EquationBase eb in equations)
                {
                    eb.SelectAll();
                    children.Add(eb.Serialize());
                }
                thisElement.Add(children);
                foreach (EquationBase eb in equations)
                {
                    eb.DeSelect();
                }
                Left = Left;
                Top = Top;
                if (removeSelection)
                {
                    RemoveSelection(true);
                }
                return new CopyDataObject { Image = bitmap, Text = null, XElement = thisElement };
            }
            else
            {
                return base.Copy(removeSelection);
            }
        }
Example #10
0
 public override void ConsumeText(string text)
 {
     if (((EquationRow)ActiveChild).ActiveChild.GetType() == typeof(TextEquation))
     {
         List<string> lines = new List<string>();
         using (StringReader reader = new StringReader(text))
         {
             string s;
             while ((s = reader.ReadLine()) != null)
             {
                 lines.Add(s);
             }
         }
         if (lines.Count == 1)
         {
             ActiveChild.ConsumeText(lines[0]);
         }
         else if (lines.Count > 1)
         {
             List<EquationRow> newEquations = new List<EquationRow>();
             TextEquation activeText = (TextEquation)((EquationRow)ActiveChild).ActiveChild;
             RowContainerTextAction action = new RowContainerTextAction(this)
             {
                 ActiveEquation = ActiveChild,
                 SelectedItems = SelectedItems,
                 SelectionStartIndex = SelectionStartIndex,
                 ActiveEquationSelectedItems = ActiveChild.SelectedItems,
                 ActiveEquationSelectionIndex = ActiveChild.SelectionStartIndex,
                 ActiveTextInRow = activeText,
                 CaretIndexOfActiveText = activeText.CaretIndex,
                 SelectedItemsOfTextEquation = activeText.SelectedItems,
                 SelectionStartIndexOfTextEquation = activeText.SelectionStartIndex,
                 TextEquationContents = activeText.Text,
                 TextEquationFormats = activeText.GetFormats(),
                 FirstLineOfInsertedText = lines[0],
                 Equations = newEquations
             };
             UndoManager.DisableAddingActions = true;
             ActiveChild.ConsumeText(lines[0]);
             action.FirstFormatsOfInsertedText = activeText.GetFormats();
             EquationRow splitRow = (EquationRow)ActiveChild.Split(this);
             if (!splitRow.IsEmpty)
             {
                 childEquations.Add(splitRow);
             }
             int activeIndex = childEquations.IndexOf(ActiveChild);
             int i = 1;
             for (; i < lines.Count; i++)
             {
                 EquationRow row = new EquationRow(this);
                 row.ConsumeText(lines[i]);
                 childEquations.Insert(activeIndex + i, row);
                 newEquations.Add(row);
             }
             UndoManager.DisableAddingActions = false;
             newEquations.Add(splitRow);
             ActiveChild = childEquations[activeIndex + lines.Count - 1];
             ((TextEquation)((EquationRow)ActiveChild).ActiveChild).MoveToEnd();
             SelectedItems = 0;
             action.ActiveEquationAfterChange = ActiveChild;
             UndoManager.AddUndoAction(action);
         }
         CalculateSize();
     }
     else
     {
         base.ConsumeText(text);
     }
 }
Example #11
0
 public void Merge(EquationRow secondLine)
 {
     ((TextEquation)childEquations.Last()).Merge((TextEquation)secondLine.childEquations.First()); //first and last are always of tyep TextEquation
     for (int i = 1; i < secondLine.childEquations.Count; i++)
     {
         AddChild(secondLine.childEquations[i]);
     }
     CalculateSize();
 }
Example #12
0
        void SplitRow(EquationRow newRow)
        {
            int index = childEquations.IndexOf(ActiveChild) + 1;
            EquationBase newChild = ActiveChild.Split(newRow);

            if (newChild != null)
            {
                newRow.RemoveChild(newRow.ActiveChild);
                newRow.AddChild(newChild);
                int i = index;
                for (; i < childEquations.Count; i++)
                {
                    newRow.AddChild(childEquations[i]);
                }
                for (i = childEquations.Count - 1; i >= index; i--)
                {
                    RemoveChild(childEquations[i]);
                }
            }
        }
Example #13
0
 public override EquationBase Split(EquationContainer newParent)
 {
     deleteable = null;
     EquationRow newRow = null;
     if (ActiveChild.GetType() == typeof(TextEquation))
     {
         newRow = new EquationRow(newParent);
         SplitRow(newRow);
         newRow.CalculateSize();
     }
     else
     {
         ActiveChild.Split(this);
     }
     CalculateSize();
     return newRow;
 }