コード例 #1
0
 public TextAction(ISupportsUndo executor, int index, string text, int[] formats, EditorMode[] modes, CharacterDecorationInfo[] decorations)
     : base(executor)
 {
     Index = index;
     Text = text;
     Formats = formats;
     Modes = modes;
     Decorations = decorations;
 }
コード例 #2
0
        //void DrawDecorations(DrawingContext dc, List<CharacterDecorationInfo> decorationList, FormattedText ft, int index, double hCenter)
        //{
        //    double offset = FontSize * .05;
        //    //character metrics
        //    double topPixel = ft.Height + ft.OverhangAfter - ft.Extent; //ft.Baseline - ft.Extent + descent;
        //    double descent = ft.Height - ft.Baseline + ft.OverhangAfter;
        //    double halfCharWidth = ft.GetFullWidth() / 2;
        //    double right = hCenter + halfCharWidth + offset;
        //    double left = hCenter - halfCharWidth - offset;
        //    double top = Top + topPixel - offset;
        //    double bottom = Top + ft.Baseline + descent + offset;
        //}

        //private void DrawTopDecorations(DrawingContext dc, FormattedText ft, List<CharacterDecorationInfo> cdiList, double center, int formatId)
        //{
        //    var topDecorations = (from x in cdiList where x.Position == Position.Top select x).ToList();
        //    if (topDecorations.Count > 0)
        //    {
        //        double top = Top + ft.Height + ft.OverhangAfter - ft.Extent - FontSize * .1;
        //        foreach (var d in topDecorations)
        //        {
        //            string text = d.UnicodeString;
        //            var sign = textManager.GetFormattedText(text, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal));
        //            sign.DrawTextBottomCenterAligned(dc, new Point(center, top));
        //            top -= sign.Extent + FontSize * .08;
        //        }
        //    }
        //}

        //private void DrawBottomDecorations(DrawingContext dc, FormattedText ft, List<CharacterDecorationInfo> cdiList, double hCenter, int formatId)
        //{
        //    var bottomDecorations = (from x in cdiList where x.Position == Position.Bottom select x).ToList();
        //    if (bottomDecorations.Count > 0)
        //    {
        //        double bottom = Top + ft.Height + ft.OverhangAfter + FontSize * .2;
        //        foreach (var d in bottomDecorations)
        //        {
        //            string text = d.UnicodeString;
        //            var sign = textManager.GetFormattedText(text, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal));
        //            sign.DrawTextBottomCenterAligned(dc, new Point(hCenter, bottom));
        //            bottom += sign.Extent + FontSize * .08;
        //        }
        //    }
        //}

        //private void DrawLeftDecorations(DrawingContext dc, List<CharacterDecorationInfo> cdiList, double left, int formatId)
        //{
        //    var leftDecorations = (from x in cdiList where x.Position == Position.TopLeft select x).ToList();
        //    if (leftDecorations.Count > 0)
        //    {
        //        string s = "";
        //        foreach (var d in leftDecorations)
        //        {
        //            s = s + d.UnicodeString;
        //        }
        //        var formattedText = textManager.GetFormattedText(s, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal));
        //        formattedText.DrawTextRightAligned(dc, new Point(left, Top));
        //    }
        //}

        //private void DrawRightDecorations(DrawingContext dc, List<CharacterDecorationInfo> cdiList, double right, int formatId)
        //{
        //    var rightDecorations = (from x in cdiList where x.Position == Position.TopRight select x).ToList();
        //    if (rightDecorations.Count > 0)
        //    {
        //        string s = "";
        //        foreach (var d in rightDecorations)
        //        {
        //            s = s + d.UnicodeString;
        //        }
        //        dc.DrawText(textManager.GetFormattedText(s, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal)), new Point(right, Top));
        //    }
        //}

        ////index = index of the decorated character in this.textData
        //private void DrawFaceDecorations(DrawingContext dc, FormattedText charText, List<CharacterDecorationInfo> cdiList, double hCenter)
        //{
        //    var decorations = (from x in cdiList where x.Position == Position.Over select x).ToList();
        //    if (decorations.Count > 0)
        //    {
        //        double offset = FontSize * .05;
        //        double top = Top + charText.Height + charText.OverhangAfter - charText.Extent; //ft.Baseline - ft.Extent + descent;
        //        double bottom = top + charText.Extent; //charText.Height - charText.Baseline + charText.OverhangAfter;
        //        double vCenter = top + charText.Extent / 2;
        //        double left = hCenter - charText.GetFullWidth() / 2 - offset;
        //        double right = hCenter + charText.GetFullWidth() / 2 + offset;

        //        Pen pen = PenManager.GetPen(FontSize * .035);
        //        foreach (var d in decorations)
        //        {
        //            switch (d.DecorationType)
        //            {
        //                case CharacterDecorationType.Cross:
        //                    dc.DrawLine(pen, new Point(left, top), new Point(right, bottom));
        //                    dc.DrawLine(pen, new Point(left, bottom), new Point(right, top));
        //                    break;
        //                case CharacterDecorationType.LeftCross:
        //                    dc.DrawLine(pen, new Point(left, top), new Point(right, bottom));
        //                    break;
        //                case CharacterDecorationType.RightCross:
        //                    dc.DrawLine(pen, new Point(left, bottom), new Point(right, top));
        //                    break;
        //                case CharacterDecorationType.LeftUprightCross:
        //                    dc.DrawLine(pen, new Point(hCenter - FontSize * .08, top - FontSize * 0.04), new Point(hCenter + FontSize * .08, bottom + FontSize * 0.04));
        //                    break;
        //                case CharacterDecorationType.RightUprightCross:
        //                    dc.DrawLine(pen, new Point(hCenter + FontSize * .08, top - FontSize * 0.04), new Point(hCenter - FontSize * .08, bottom + FontSize * 0.04));
        //                    break;
        //                case CharacterDecorationType.StrikeThrough:
        //                    dc.DrawLine(pen, new Point(left, vCenter), new Point(right, vCenter));
        //                    break;
        //                case CharacterDecorationType.DoubleStrikeThrough:
        //                    dc.DrawLine(pen, new Point(left, vCenter - FontSize * .05), new Point(right, vCenter - FontSize * .05));
        //                    dc.DrawLine(pen, new Point(left, vCenter + FontSize * .05), new Point(right, vCenter + FontSize * .05));
        //                    break;
        //                case CharacterDecorationType.VStrikeThrough:
        //                    dc.DrawLine(pen, new Point(hCenter, top - FontSize * .05), new Point(hCenter, bottom + FontSize * .05));
        //                    break;
        //                case CharacterDecorationType.VDoubleStrikeThrough:
        //                    dc.DrawLine(pen, new Point(hCenter - FontSize * .05, top - FontSize * .05), new Point(hCenter - FontSize * .05, bottom + FontSize * .05));
        //                    dc.DrawLine(pen, new Point(hCenter + FontSize * .05, top - FontSize * .05), new Point(hCenter + FontSize * .05, bottom + FontSize * .05));
        //                    break;
        //            }
        //        }
        //    }
        //}


        public void AddDecoration(CharacterDecorationInfo cdi)
        {
            //if (cdi.DecorationType == CharacterDecorationType.None)
            //{
            //    decorations.RemoveAll(x => x.Index == caretIndex - 1);
            //}
            //else if (!char.IsWhiteSpace(textData[caretIndex - 1]))
            //{
            //    cdi.Index = caretIndex - 1;
            //    decorations.Add(cdi);
            //}
            //FormatText();
        }
コード例 #3
0
 public TextRemoveAction(ISupportsUndo executor, int index, string text, int selectionStartIndex,
                         int selectionCout, int parentSelectionStartIndex, int[] formats, EditorMode[] modes, 
                         CharacterDecorationInfo[] decorations)
     : base(executor)
 {
     Index = index;
     Text = text;
     Formats = formats;
     Modes = modes;
     Decorations = decorations;
     SelectionStartIndex = selectionStartIndex;
     SelectionCount = selectionCout;
     ParentSelectionStartIndex = parentSelectionStartIndex;
 }
コード例 #4
0
 void RemoveDecoration(CharacterDecorationInfo cdi)
 {
     decorations.Remove(cdi);
     UndoManager.AddUndoAction(new DecorationAction(this, new[] { cdi }) { UndoFlag = false });
 }
コード例 #5
0
 public override void ConsumeFormattedText(string text, int[] formats, EditorMode[] modes, CharacterDecorationInfo[] decorations, bool addUndo)
 {
     //this.decorations.AddRange(decorations);
     textData.Insert(caretIndex, text);
     this.formats.InsertRange(caretIndex, formats);
     this.modes.InsertRange(caretIndex, modes);
     if (decorations != null)
     {
         foreach (var d in decorations)
         {
             d.Index = d.Index + caretIndex;
         }
         this.decorations.AddRange(decorations);
     }
     if (addUndo)
     {
         UndoManager.AddUndoAction(new TextAction(this, caretIndex, text, formats, modes, decorations ?? new CharacterDecorationInfo[0]) { UndoFlag = false });
     }
     SetCaretIndex(caretIndex + text.Length);
     FormatText();
 }
コード例 #6
0
 public override void DeSerialize(XElement xElement)
 {
     textData.Append(xElement.Element("Text").Value);
     try
     {
         string[] formatStrings = xElement.Element("Formats").Value.Split(',');
         string[] modeStrings = xElement.Element("Modes").Value.Split(',');
         for (int i = 0; i < formatStrings.Length; i++)
         {
             formats.Add(int.Parse(formatStrings[i]));
             modes.Add((EditorMode)Enum.Parse(typeof(EditorMode), modeStrings[i]));
         }
         var decos = xElement.Elements().FirstOrDefault(x => x.Name == "Decorations");
         if (decos != null)
         {
             var children = decos.Elements("d").ToList();
             for (int i = 0; i < children.Count; i++)
             {
                 string[] list = children[i].Value.Split(',');
                 var d = new CharacterDecorationInfo();
                 d.DecorationType = (CharacterDecorationType)Enum.Parse(typeof(CharacterDecorationType), list[0]);
                 d.Index = int.Parse(list[1]);
                 d.Position = (Position)Enum.Parse(typeof(Position), list[2]);
                 d.UnicodeString = list[3];
                 decorations.Add(d);
             }
         }
     }
     catch
     {
         formats.Clear();
         modes.Clear();
         decorations.Clear();
         int formatId = textManager.GetFormatId(FontSize, fontType, FontStyles.Normal, FontWeights.Normal, Brushes.Black, false);
         for (int i = 0; i < textData.Length; i++)
         {
             formats.Add(formatId);
             modes.Add(Editor.EditorMode.Math);
         }
     }
     FormatText();
 }
コード例 #7
0
 public override void Paste(XElement xElement)
 {
     if (xElement.Name.LocalName == GetType().Name)
     {
         //textData.Insert(caretIndex, xElement.Element("Text").Value);
         string text = xElement.Element("Text").Value;
         string[] formatStrings = xElement.Element("Formats").Value.Split(',');
         string[] modeStrings = xElement.Element("Modes").Value.Split(',');
         int[] formats = new int[text.Length];
         EditorMode[] modes = new EditorMode[text.Length];
         var decos = xElement.Elements().FirstOrDefault(x => x.Name == "Decorations");
         CharacterDecorationInfo[] decorations = null;
         if (decos != null)
         {
             var children = decos.Elements("d").ToList();
             decorations = new CharacterDecorationInfo[children.Count];
             for (int i = 0; i < children.Count; i++)
             {
                 string[] list = children[i].Value.Split(',');
                 decorations[i] = new CharacterDecorationInfo();
                 decorations[i].DecorationType = (CharacterDecorationType)Enum.Parse(typeof(CharacterDecorationType), list[0]);
                 decorations[i].Index = int.Parse(list[1]);
                 decorations[i].Position = (Position)Enum.Parse(typeof(Position), list[2]);
                 decorations[i].UnicodeString = list[3];
             }
         }
         try
         {
             for (int i = 0; i < text.Length; i++)
             {
                 formats[i] = int.Parse(formatStrings[i]);
                 modes[i] = (EditorMode)Enum.Parse(typeof(EditorMode), modeStrings[i]);
             }
         }
         catch
         {
             int formatId = textManager.GetFormatId(FontSize, fontType, FontStyles.Normal, FontWeights.Normal, Brushes.Black, false);
             for (int i = 0; i < text.Length; i++)
             {
                 formats[i] = formatId;
                 modes[i] = Editor.EditorMode.Math;
             }
         }
         ConsumeFormattedText(text, formats, modes, decorations, true);
     }
 }
コード例 #8
0
 public void ResetTextEquation(int caretIndex, int selectionStartIndex, int selectedItems, string text, int[] formats,
                               EditorMode[] modes, CharacterDecorationInfo[] cdiList)
 {
     textData.Clear();
     textData.Append(text);
     this.caretIndex = caretIndex;
     this.SelectionStartIndex = selectionStartIndex;
     this.SelectedItems = selectedItems;
     this.formats.Clear();
     this.formats.AddRange(formats);
     this.modes.Clear();
     this.modes.AddRange(modes);
     this.decorations.Clear();
     decorations.AddRange(cdiList);
     FormatText();
 }
コード例 #9
0
 public void AddDecoration(CharacterDecorationType cdt, Position position, string sign)
 {
     if (cdt == CharacterDecorationType.None)
     {
         var decoArray = (from d in decorations where d.Index == caretIndex - 1 select d).ToArray();
         UndoManager.AddUndoAction(new DecorationAction(this, decoArray) { UndoFlag = false });
         decorations.RemoveAll(x => x.Index == caretIndex - 1);
     }
     else if (!char.IsWhiteSpace(textData[caretIndex - 1]))
     {
         CharacterDecorationInfo cdi = new CharacterDecorationInfo();
         cdi.DecorationType = cdt;
         cdi.Position = position;
         cdi.UnicodeString = sign;
         cdi.Index = caretIndex - 1;
         decorations.Add(cdi);
         UndoManager.AddUndoAction(new DecorationAction(this, new[] { cdi }));
     }
     FormatText();
 }
コード例 #10
0
 //void DrawDecorations(DrawingContext dc, List<CharacterDecorationInfo> decorationList, FormattedText ft, int index, double hCenter)
 //{
 //    double offset = FontSize * .05;
 //    //character metrics
 //    double topPixel = ft.Height + ft.OverhangAfter - ft.Extent; //ft.Baseline - ft.Extent + descent;
 //    double descent = ft.Height - ft.Baseline + ft.OverhangAfter;
 //    double halfCharWidth = ft.GetFullWidth() / 2;
 //    double right = hCenter + halfCharWidth + offset;
 //    double left = hCenter - halfCharWidth - offset;
 //    double top = Top + topPixel - offset;
 //    double bottom = Top + ft.Baseline + descent + offset;
 //}
 //private void DrawTopDecorations(DrawingContext dc, FormattedText ft, List<CharacterDecorationInfo> cdiList, double center, int formatId)
 //{
 //    var topDecorations = (from x in cdiList where x.Position == Position.Top select x).ToList();
 //    if (topDecorations.Count > 0)
 //    {
 //        double top = Top + ft.Height + ft.OverhangAfter - ft.Extent - FontSize * .1;
 //        foreach (var d in topDecorations)
 //        {
 //            string text = d.UnicodeString;
 //            var sign = textManager.GetFormattedText(text, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal));
 //            sign.DrawTextBottomCenterAligned(dc, new Point(center, top));
 //            top -= sign.Extent + FontSize * .08;
 //        }
 //    }
 //}
 //private void DrawBottomDecorations(DrawingContext dc, FormattedText ft, List<CharacterDecorationInfo> cdiList, double hCenter, int formatId)
 //{
 //    var bottomDecorations = (from x in cdiList where x.Position == Position.Bottom select x).ToList();
 //    if (bottomDecorations.Count > 0)
 //    {
 //        double bottom = Top + ft.Height + ft.OverhangAfter + FontSize * .2;
 //        foreach (var d in bottomDecorations)
 //        {
 //            string text = d.UnicodeString;
 //            var sign = textManager.GetFormattedText(text, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal));
 //            sign.DrawTextBottomCenterAligned(dc, new Point(hCenter, bottom));
 //            bottom += sign.Extent + FontSize * .08;
 //        }
 //    }
 //}
 //private void DrawLeftDecorations(DrawingContext dc, List<CharacterDecorationInfo> cdiList, double left, int formatId)
 //{
 //    var leftDecorations = (from x in cdiList where x.Position == Position.TopLeft select x).ToList();
 //    if (leftDecorations.Count > 0)
 //    {
 //        string s = "";
 //        foreach (var d in leftDecorations)
 //        {
 //            s = s + d.UnicodeString;
 //        }
 //        var formattedText = textManager.GetFormattedText(s, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal));
 //        formattedText.DrawTextRightAligned(dc, new Point(left, Top));
 //    }
 //}
 //private void DrawRightDecorations(DrawingContext dc, List<CharacterDecorationInfo> cdiList, double right, int formatId)
 //{
 //    var rightDecorations = (from x in cdiList where x.Position == Position.TopRight select x).ToList();
 //    if (rightDecorations.Count > 0)
 //    {
 //        string s = "";
 //        foreach (var d in rightDecorations)
 //        {
 //            s = s + d.UnicodeString;
 //        }
 //        dc.DrawText(textManager.GetFormattedText(s, textManager.GetFormatIdForNewStyle(formatId, FontStyles.Normal)), new Point(right, Top));
 //    }
 //}
 ////index = index of the decorated character in this.textData
 //private void DrawFaceDecorations(DrawingContext dc, FormattedText charText, List<CharacterDecorationInfo> cdiList, double hCenter)
 //{
 //    var decorations = (from x in cdiList where x.Position == Position.Over select x).ToList();
 //    if (decorations.Count > 0)
 //    {
 //        double offset = FontSize * .05;
 //        double top = Top + charText.Height + charText.OverhangAfter - charText.Extent; //ft.Baseline - ft.Extent + descent;
 //        double bottom = top + charText.Extent; //charText.Height - charText.Baseline + charText.OverhangAfter;
 //        double vCenter = top + charText.Extent / 2;
 //        double left = hCenter - charText.GetFullWidth() / 2 - offset;
 //        double right = hCenter + charText.GetFullWidth() / 2 + offset;
 //        Pen pen = PenManager.GetPen(FontSize * .035);
 //        foreach (var d in decorations)
 //        {
 //            switch (d.DecorationType)
 //            {
 //                case CharacterDecorationType.Cross:
 //                    dc.DrawLine(pen, new Point(left, top), new Point(right, bottom));
 //                    dc.DrawLine(pen, new Point(left, bottom), new Point(right, top));
 //                    break;
 //                case CharacterDecorationType.LeftCross:
 //                    dc.DrawLine(pen, new Point(left, top), new Point(right, bottom));
 //                    break;
 //                case CharacterDecorationType.RightCross:
 //                    dc.DrawLine(pen, new Point(left, bottom), new Point(right, top));
 //                    break;
 //                case CharacterDecorationType.LeftUprightCross:
 //                    dc.DrawLine(pen, new Point(hCenter - FontSize * .08, top - FontSize * 0.04), new Point(hCenter + FontSize * .08, bottom + FontSize * 0.04));
 //                    break;
 //                case CharacterDecorationType.RightUprightCross:
 //                    dc.DrawLine(pen, new Point(hCenter + FontSize * .08, top - FontSize * 0.04), new Point(hCenter - FontSize * .08, bottom + FontSize * 0.04));
 //                    break;
 //                case CharacterDecorationType.StrikeThrough:
 //                    dc.DrawLine(pen, new Point(left, vCenter), new Point(right, vCenter));
 //                    break;
 //                case CharacterDecorationType.DoubleStrikeThrough:
 //                    dc.DrawLine(pen, new Point(left, vCenter - FontSize * .05), new Point(right, vCenter - FontSize * .05));
 //                    dc.DrawLine(pen, new Point(left, vCenter + FontSize * .05), new Point(right, vCenter + FontSize * .05));
 //                    break;
 //                case CharacterDecorationType.VStrikeThrough:
 //                    dc.DrawLine(pen, new Point(hCenter, top - FontSize * .05), new Point(hCenter, bottom + FontSize * .05));
 //                    break;
 //                case CharacterDecorationType.VDoubleStrikeThrough:
 //                    dc.DrawLine(pen, new Point(hCenter - FontSize * .05, top - FontSize * .05), new Point(hCenter - FontSize * .05, bottom + FontSize * .05));
 //                    dc.DrawLine(pen, new Point(hCenter + FontSize * .05, top - FontSize * .05), new Point(hCenter + FontSize * .05, bottom + FontSize * .05));
 //                    break;
 //            }
 //        }
 //    }
 //}
 public void AddDecoration(CharacterDecorationInfo cdi)
 {
     //if (cdi.DecorationType == CharacterDecorationType.None)
     //{
     //    decorations.RemoveAll(x => x.Index == caretIndex - 1);
     //}
     //else if (!char.IsWhiteSpace(textData[caretIndex - 1]))
     //{
     //    cdi.Index = caretIndex - 1;
     //    decorations.Add(cdi);
     //}
     //FormatText();
 }
コード例 #11
0
 public virtual void ConsumeFormattedText(string text, int[] formats, EditorMode[] modes, CharacterDecorationInfo[] decorations, bool addUndo)
 {
 }
コード例 #12
0
 public DecorationAction(ISupportsUndo executor, CharacterDecorationInfo [] cdi, bool added)
     : base(executor)
 {
     Added = added;
     CharacterDecorations = cdi;
 }
コード例 #13
0
 public DecorationAction(ISupportsUndo executor, CharacterDecorationInfo [] cdi)
     : base(executor)
 {
     CharacterDecorations = cdi;
 }
コード例 #14
0
 public override void ConsumeFormattedText(string text, int[] formats, EditorMode[] modes, CharacterDecorationInfo[] decorations, bool addUndo)
 {
     ActiveChild.ConsumeFormattedText(text, formats, modes, decorations, addUndo);
     CalculateSize();
 }