public static FontFamily GetGDIFontFamily(Text text) { string[] textArray1; string text1 = text.FontName; if (((text1 == "") || (text1 == null)) || (text1 == string.Empty)) { string[] textArray2 = new string[1] { "Arial" } ; textArray1 = textArray2; } else { char[] chArray1 = new char[1] { ',' } ; textArray1 = text1.Split(chArray1); } string[] textArray3 = textArray1; for (int num1 = 0; num1 < textArray3.Length; num1++) { FontFamily family2=new FontFamily("Arial"); string text2 = textArray3[num1]; try { FontFamily family1; char[] chArray2 = new char[2] { ' ', '\'' } ; string text3 = text2.Trim(chArray2).ToLower(); if (text3 == "serif") { family1 = FontFamily.GenericSerif; } else if (text3 == "sans-serif") { family1 = FontFamily.GenericSansSerif; } else if (text3 == "monospace") { family1 = FontFamily.GenericMonospace; } else { family1 = new FontFamily(text3); } family2 = family1; } catch { } return family2; } return new FontFamily("Arial"); }
// 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; }
public override XmlElement CreateElement(string prefix, string localName, string ns) { XmlElement element1; if (this.firstload) { // SvgElement element2 = null; if (this.preelement != null) { // if (this.preelement.ParentNode == null) // { // if (this.groups.Count > 0) // { // element2 = (SvgElement) this.groups[this.groups.Count - 1]; // if ((element2 is ContainerElement) && ((ContainerElement) element2).IsValidChild(this.preelement)) // { // ((ContainerElement) element2).ChildList.Add(this.preelement); // } // } // this.groups.Add(this.preelement); // } // else if (this.groups.Count > 0) // { // if(this.preelement.ParentNode is ContainerElement && ((ContainerElement) this.preelement.ParentNode).IsValidChild(this.preelement)) // { // ((ContainerElement)this.preelement.ParentNode).ChildList.Add(this.preelement); // } // // } } } switch (localName) { case "clipPath": { element1 = new ClipPath(prefix, localName, ns, this); break; } case "rect": { element1 = new RectangleElement(prefix, localName, ns, this); break; } case "path": { element1 = new GraphPath(prefix, localName, ns, this); break; } case "polyline": { element1 = new Polyline(prefix, localName, ns, this); break; } case "polygon": { element1 = new Polygon(prefix, localName, ns, this); break; } case "circle": { element1 = new Circle(prefix, localName, ns, this); break; } case "ellipse": { element1 = new Ellips(prefix, localName, ns, this); break; } case "script": { element1 = new SvgScript(prefix, localName, ns, this); break; } case "line": { element1 = new Line(prefix, localName, ns, this); break; } case "connectline": case "connect": { element1 = new ConnectLine(prefix, localName, ns, this); break; } case "g": { element1 = new Group(prefix, localName, ns, this); break; } case "svg": { element1 = new SVG(prefix, localName, ns, this); break; } case "text": { element1 = new Text(prefix, localName, ns, this); break; } case "tspan": { element1 = new TSpan(prefix, localName, ns, this); break; } case "tref": { element1 = new TRef(prefix, localName, ns, this); break; } case "linearGradient": { element1 = new LinearGradient(prefix, localName, ns, this); break; } case "radialGradient": { element1 = new RadialGradients(prefix, localName, ns, this); break; } case "stop": { element1 = new GradientStop(prefix, localName, ns, this); break; } case "symbol": { element1 = new ItopVector.Core.Figure.Symbol(prefix, localName, ns, this); break; } case "marker": { element1 = new ItopVector.Core.Figure.Marker(prefix, localName, ns, this); break; } case "defs": { element1 = new ItopVector.Core.Figure.Defs(prefix, localName, ns, this); break; } case "image": { element1 = new ItopVector.Core.Figure.Image(prefix, localName, ns, this); break; } case "a": { element1 = new ItopVector.Core.Figure.Link(prefix, localName, ns, this); break; } case "use": { element1 = new ItopVector.Core.Figure.Use(prefix, localName, ns, this); break; } case "animate": { element1 = new ItopVector.Core.Animate.Animate(prefix, localName, ns, this); break; } case "set": { element1 = new SetAnimate(prefix, localName, ns, this); break; } case "animateColor": { element1 = new ColorAnimate(prefix, localName, ns, this); break; } case "animateMotion": { element1 = new MotionAnimate(prefix, localName, ns, this); break; } case "animateTransform": { element1 = new TransformAnimate(prefix, localName, ns, this); break; } case "pattern": { element1 = new Pattern(prefix, localName, ns, this); break; } case "audio3d": case "audio": { element1 = new AudioAnimate(prefix, localName, ns, this); break; } case "state"://״̬ { element1 =new State(prefix, localName, ns, this); break; } case "layer": { element1 =new Layer(prefix, localName, ns, this); break; } default: { element1 = base.CreateElement(prefix, localName, ns); break; } } if (element1 is SvgElement) { ((SvgElement) element1).ShowParticular = this.AutoShowAnim; } if ((element1 is SvgElement) && this.firstload) { this.preelement = (SvgElement) element1; } else { this.preelement = null; } if (this.xmlreader != null) { int num3 = this.xmlreader.LineNumber; int num4 = this.xmlreader.LinePosition; } // if ((element1 is SVG) && (this.DocumentType == null)) // { // XmlDocumentType type1 = this.CreateDocumentType("svg", "-/W3C/DTD SVG 1.1/EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null); // this.AppendChild(type1); // this.AppendChild(this.CreateWhitespace("\r\n")); // } return element1; }
public static float GetComputedFontSize(Text text) { return text.Size; }
public static string TrimText(string val, Text text) { Regex regex1 = new Regex(@"[\n\f\t]"); if (text.XmlSpace != "preserve") { val = val.Replace("\n", ""); } val = regex1.Replace(val, " "); if (text.XmlSpace == "preserve") { return val; } return val.Trim(); }
public static int GetGDIStyle(Text text) { int num1 = 0; string text1 = AttributeFunc.ParseAttribute("font-weight", text, false).ToString().Trim(); if ((((text1 == "bold") || (text1 == "bolder")) || ((text1 == "600") || (text1 == "700"))) || ((text1 == "800") || (text1 == "900"))) { num1 |= 1; } if (AttributeFunc.ParseAttribute("font-style", text, false).ToString().Trim() == "italic") { num1 |= 2; } string text2 = AttributeFunc.ParseAttribute("text-decoration", text, false).ToString().Trim(); if (text2 == "line-through") { return (num1 | 8); } if (text2 == "underline") { num1 |= 4; } return num1; }
public static StringFormat GetGDIStringFormat(Text text) { StringFormat format1 = new StringFormat(StringFormat.GenericTypographic); format1.LineAlignment = StringAlignment.Near; bool flag1 = true; if (text is TSpan) { flag1 = text.doalign; } if (flag1) { string text1 = AttributeFunc.ParseAttribute("text-anchor", text, false).ToString().Trim(); if (text1 == "middle") { format1.Alignment = StringAlignment.Center; } if (text1 == "end") { format1.Alignment = StringAlignment.Far; } } string text2 = AttributeFunc.ParseAttribute("direction", text, false).ToString().Trim(); if (text2 == "rtl") { if (format1.Alignment == StringAlignment.Far) { format1.Alignment = StringAlignment.Near; } else if (format1.Alignment == StringAlignment.Near) { format1.Alignment = StringAlignment.Far; } format1.FormatFlags = StringFormatFlags.DirectionRightToLeft; } text2 = AttributeFunc.ParseAttribute("writing-mode", text, false).ToString().Trim(); if (text2 == "tb") { format1.FormatFlags |= StringFormatFlags.DirectionVertical; } format1.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; return format1; }
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--; } } } }
public void PostElement() { int num1; int num2; bool flag1 = this.doc.AcceptChanges; if (this.chars.Count == 0) { this.doc.AcceptChanges = true; if (this.preText != null) { this.preText.ParentNode.RemoveChild(this.preText); } this.currrentText = null; } if (this.currrentText != null) { this.doc.AcceptChanges = false; this.currrentText.Normalize(); this.currrentText.EditMode = false; this.doc.AcceptChanges = true; this.chars.Clear(); this.mouseAreaControl.SVGDocument.ClearSelects(); this.currrentText.pretime=-1; if (this.currrentText.ParentNode == null) { this.mouseAreaControl.PicturePanel.AddElement(this.currrentText); } } this.preText = null; this.caretindex = num1 = 0; this.selectionlength = num2 = num1; this.selectionstart = num2; this.currrentText = null; this.doc.AcceptChanges = flag1; this.editmode = false; this.mouseAreaControl.Invalidate(); this.mouseAreaControl.SVGDocument.RecordAnim = true; this.undostack.ClearAll(); if (this.enterUpdate) { this.mouseAreaControl.PicturePanel.Operation = ToolOperation.Select; } }
public void OnPaint(PaintEventArgs e) { if (this.mouseAreaControl.SVGDocument.RecordAnim && this.editmode) { this.mouseAreaControl.SVGDocument.RecordAnim = false; } if ((this.currrentText != null) && this.editmode) { if (this.activeText == null) { this.activeText = this.currrentText; } this.scaleMatrix = this.mouseAreaControl.PicturePanel.CoordTransform.Clone(); this.scaleMatrix.Multiply(this.currrentText.Transform.Matrix); FontFamily family1 = this.font.FontFamily; float single1 = (((float) family1.GetCellAscent(FontStyle.Regular)) / ((float) family1.GetEmHeight(FontStyle.Regular))) * this.currrentText.Size; this.scaleMatrix.Translate(this.currrentText.X, this.currrentText.Y - single1); e.Graphics.Transform = this.scaleMatrix; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; this.PaintSelect(e.Graphics); GraphicsPath path1 = this.PaintText(e.Graphics); this.PaintCaret(e.Graphics); } }
public void OnMouseMove(MouseEventArgs e) { if ((e.Button == MouseButtons.None) && !this.editmode) { this.preText = null; /*SvgElementCollection.ISvgElementEnumerator enumerator1 = this.mouseAreaControl.PicturePanel.ElementList.GetEnumerator(); while (enumerator1.MoveNext()) { IGraph graph1 = (IGraph) enumerator1.Current; if (graph1 is Text) { Text text1 = (Text) graph1; PointF tf1 = this.mouseAreaControl.PicturePanel.PointToView(new PointF((float) e.X, (float) e.Y)); GraphicsPath path1 = (GraphicsPath) text1.GPath.Clone(); path1.Transform(text1.GraphTransform.Matrix); RectangleF ef1 = path1.GetBounds(); if (ef1.Contains(new PointF((float) e.X, (float) e.Y))) { this.preText = text1; return; } } } */ } if (e.Button == MouseButtons.Left) { int num1 = this.GetIndexForPoint(this.PointToView(new PointF((float) e.X, (float) e.Y))); if (num1 > this.startindex) { this.selectionstart = this.startindex; this.selectionlength = num1 - this.startindex; } else { this.selectionstart = num1; this.selectionlength = this.startindex - num1; } this.CaretIndex = num1; this.mouseAreaControl.Invalidate(); } }