// Methods public TextOperation(MouseArea mc) { this.currrentText = null; this.caretvisible = true; this.selectionstart = 0; this.selectionlength = 0; this.hmargin = 5; this.vmargin = 5; this.doc = null; this.activeText = null; this.sf = StringFormat.GenericTypographic; this.paint = Color.Black; this.stroke = Color.Black; this.font = new Font("Arial", 12f); this.caretChar = null; this.caretRect = RectangleF.Empty; this.startindex = 0; this.scale = 1f; this.scaleMatrix = new Matrix(); this.mouseAreaControl = null; this.editmode = false; this.preText = null; this.recordanim = true; this.undostack = new UndoStack(); this.enterUpdate = false; this.chars = new ArrayList(0x10); this.caretindex = 0; this.mouseAreaControl = mc; mc.Focus(); this.caretthread = new Thread(new ThreadStart(this.CaretMethod)); this.caretthread.IsBackground = true; this.caretthread.Start(); this.mouseAreaControl.Cursor = Cursors.IBeam; this.mouseAreaControl.KeyPress += new KeyPressEventHandler(this.OnKeyPress); this.sf.LineAlignment = StringAlignment.Near; }
private void ParseText(Text text) { if (text != null) { if (this.chars == null) { this.chars = new ArrayList(0x10); } Color color1 = Color.Black; Color color2 = Color.Black; Font font1 = new Font("Arial", 20f); StringFormat format1 = TextFunc.GetGDIStringFormat(text); format1.LineAlignment = StringAlignment.Near; FontFamily family1 = TextFunc.GetGDIFontFamily(text); int num1 = TextFunc.GetGDIStyle(text); font1 = new Font(family1.Name, text.Size, (FontStyle) num1); float single1 = text.Dx; float single2 = text.Dy; ISvgBrush brush1 = text.GraphBrush; if (brush1 is SolidColor) { color1 = ((SolidColor) brush1).Color; } bool flag1 = true; this.doc.AcceptChanges = false; for (int num2 = 0; num2 < text.ChildNodes.Count; num2++) { XmlNode node1 = text.ChildNodes[num2]; if (node1 is Text) { this.ParseText((Text) node1); } else if (node1 is XmlText) { string text1 = TextFunc.TrimText(node1.Value, text); CharEnumerator enumerator1 = text1.GetEnumerator(); while (enumerator1.MoveNext()) { char ch1 = enumerator1.Current; XmlText text2 = this.doc.CreateTextNode(ch1.ToString()); ItopVector.DrawArea.CharInfo info1 = new ItopVector.DrawArea.CharInfo(); info1.TextNode = text2; info1.TextSvgElement = text; info1.Paint = color1; info1.StringFormat = format1; info1.StringFormat.LineAlignment = StringAlignment.Near; info1.Font = font1; if (flag1 && (text.ChildNodes[0] == node1)) { info1.Dx = single1; info1.Dy = single2; info1.firstChild = true; } this.chars.Add(info1); text.InsertBefore(text2, node1); num2++; } text.RemoveChild(node1); num2--; } } } }
private void PaintCaret(Graphics g) { if (((this.doc != null) && this.caretvisible) && (this.currrentText != null)) { this.caretChar = null; FontFamily family1 = this.font.FontFamily; float single1 = (((float) family1.GetLineSpacing(FontStyle.Regular)) / ((float) family1.GetEmHeight(FontStyle.Regular))) * this.font.Size; PointF tf1 = PointF.Empty; if (this.chars.Count > 0) { if (this.caretindex >= this.chars.Count) { ItopVector.DrawArea.CharInfo info1 = (ItopVector.DrawArea.CharInfo) this.chars[this.chars.Count - 1]; tf1 = new PointF(info1.Position.X + info1.CharSize.Width, info1.Position.Y); single1 = info1.CharSize.Height; } else { int num1 = Math.Max(0, Math.Min(this.caretindex, (int) (this.chars.Count - 1))); ItopVector.DrawArea.CharInfo info2 = (ItopVector.DrawArea.CharInfo) this.chars[num1]; tf1 = info2.Position; single1 = info2.CharSize.Height; this.caretChar = info2; } } this.caretRect = new RectangleF(tf1.X, tf1.Y, 1f, single1); GraphicsPath path1=new GraphicsPath(); // Matrix matrix1=g.Transform.Clone(); // Matrix matrix2=new Matrix(); // matrix2.Translate(g.Transform.OffsetX,g.Transform.OffsetY); // matrix1.Invert(); // matrix1.Translate(-matrix1.OffsetX,-matrix1.OffsetY); path1.AddRectangle(caretRect); // path1.Transform(matrix2); GraphicsContainer container1=g.BeginContainer(); // g.Transform=matrix1; g.FillPath(new SolidBrush(ControlPaint.Light(Color.Black)), path1); g.EndContainer(container1); } }
private void InsertChar(char ch) { if (((this.doc != null) && (this.activeText != null)) && ((ch >= ' ') || (ch == '\t'))) { ItopVector.DrawArea.CharInfo[] infoArray1 = this.RemoveSelection(); TextUndoOperation operation1 = null; if (infoArray1 != null) { operation1 = new TextUndoOperation(TextAction.Delete, this.selectionstart, infoArray1, this); } bool flag1 = this.doc.AcceptChanges; this.doc.AcceptChanges = false; string text1 = ch.ToString(); XmlText text2 = this.doc.CreateTextNode(text1); this.doc.AcceptChanges = false; ItopVector.DrawArea.CharInfo info1 = new ItopVector.DrawArea.CharInfo(); info1.Font = this.font; info1.TextSvgElement = this.activeText; info1.TextNode = text2; info1.StringFormat = this.sf; info1.StringFormat.LineAlignment = StringAlignment.Near; info1.Paint = this.paint; info1.Stroke = this.stroke; if (this.caretindex >= this.chars.Count) { this.activeText.AppendChild(text2); this.chars.Add(info1); } else if ((this.caretindex >= 0) && (this.caretindex < this.chars.Count)) { this.chars.Insert(this.caretindex, info1); XmlNode node1 = this.activeText.ChildNodes[this.caretindex]; this.activeText.InsertBefore(text2, node1); } ItopVector.DrawArea.CharInfo[] infoArray2 = new ItopVector.DrawArea.CharInfo[1] { info1 } ; TextUndoOperation operation2 = new TextUndoOperation(TextAction.Insert, this.chars.IndexOf(info1), infoArray2, this); info1.PreSibling = info1.TextNode.PreviousSibling; bool flag2 = this.undostack.AcceptChanges; this.undostack.AcceptChanges = true; if (operation1 != null) { TextUndoOperation[] operationArray1 = new TextUndoOperation[2] { operation1, operation2 } ; this.undostack.Push(operationArray1); } else { TextUndoOperation[] operationArray2 = new TextUndoOperation[1] { operation2 } ; this.undostack.Push(operationArray2); } this.undostack.AcceptChanges = flag2; this.caretindex++; this.mouseAreaControl.Invalidate(); this.doc.AcceptChanges = flag1; } }
private ItopVector.DrawArea.CharInfo[] RemoveSelection() { ArrayList list1 = new ArrayList(0x10); if (this.doc == null) { return null; } bool flag1 = this.doc.AcceptChanges; this.doc.AcceptChanges = false; for (int num1 = this.selectionstart; num1 < (this.selectionstart + this.selectionlength); num1++) { if (this.selectionstart >= this.chars.Count) { break; } ItopVector.DrawArea.CharInfo info1 = (ItopVector.DrawArea.CharInfo) this.chars[this.selectionstart]; list1.Add(info1); info1.TextSvgElement.RemoveChild(info1.TextNode); this.chars.Remove(info1); this.caretindex = this.selectionstart; } this.selectionlength = 0; this.doc.AcceptChanges = flag1; if (list1.Count == 0) { return null; } ItopVector.DrawArea.CharInfo[] infoArray1 = new ItopVector.DrawArea.CharInfo[list1.Count]; list1.CopyTo(infoArray1); return infoArray1; }
private void Remove(int index) { bool flag1 = this.doc.AcceptChanges; this.doc.AcceptChanges = false; if ((index >= 0) && (index < this.chars.Count)) { ItopVector.DrawArea.CharInfo info1 = (ItopVector.DrawArea.CharInfo) this.chars[index]; XmlNode node1 = info1.TextNode.PreviousSibling; info1.TextNode.ParentNode.RemoveChild(info1.TextNode); if ((info1.firstChild && (info1.TextSvgElement != this.currrentText)) && (((info1.Dx != 0f) || (info1.Dy != 0f)) || ((info1.X != 0f) || (info1.Y != 0f)))) { for (Text text1 = info1.TextSvgElement; text1 != this.currrentText; text1 = (Text) text1.ParentNode) { float single1; float single2; float single3; text1.Y = single1 = 0f; text1.X = single2 = single1; text1.Dy = single3 = single2; text1.Dx = single3; if ((text1.Dx == info1.Dx) && (info1.Dy == info1.Dy)) { break; } } if ((index + 1) < this.chars.Count) { ((ItopVector.DrawArea.CharInfo) this.chars[index + 1]).firstChild = true; } } this.chars.Remove(info1); ItopVector.DrawArea.CharInfo[] infoArray1 = new ItopVector.DrawArea.CharInfo[1] { info1 } ; TextUndoOperation operation1 = new TextUndoOperation(TextAction.Delete, index, infoArray1, this); info1.PreSibling = node1; bool flag2 = this.undostack.AcceptChanges; this.undostack.AcceptChanges = true; TextUndoOperation[] operationArray1 = new TextUndoOperation[1] { operation1 } ; this.undostack.Push(operationArray1); this.undostack.AcceptChanges = flag2; } this.doc.AcceptChanges = flag1; }