private static void WriteMText() { DxfDocument dxf = new DxfDocument(); //xData sample XData xdata = new XData(new ApplicationRegistry("netDxf")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf")); xdata.XDataRecord.Add(XDataRecord.OpenControlString); xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0)); xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0)); xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0)); xdata.XDataRecord.Add(XDataRecord.CloseControlString); //text TextStyle style = new TextStyle("Times.ttf"); //TextStyle style = TextStyle.Default; MText mText = new MText(new Vector3(3,2,0), 1.0f, 100.0f, style); mText.Layer = new Layer("Multiline Text"); //mText.Layer.Color.Index = 8; mText.Rotation = 0; mText.LineSpacingFactor = 1.0; mText.ParagraphHeightFactor = 1.0; //mText.AttachmentPoint = MTextAttachmentPoint.TopCenter; //mText.Write("Hello World!"); //mText.Write(" we keep writting on the same line."); //mText.WriteLine("This text is in a new line"); //mText.Write("Hello World! "); //for (int i = 0; i < 50; i++) //{ // mText.Write("1234567890"); //} //mText.Write(" This text is over the limit of the 250 character chunk"); //mText.NewParagraph(); //mText.Write("This is a text in a new paragraph"); //mText.Write(" and we continue writing in the previous paragraph"); //mText.NewParagraph(); MTextFormattingOptions options = new MTextFormattingOptions(mText.Style); options.Bold = true; mText.Write("Bold text in mText.Style", options); mText.EndParagraph(); options.Italic = true; mText.Write("Bold and italic text in mText.Style", options); mText.EndParagraph(); options.Bold = false; options.FontName = "Arial"; options.Color = AciColor.Blue; mText.ParagraphHeightFactor = 2; mText.Write("Italic text in Arial", options); mText.EndParagraph(); options.Italic = false; options.Color = null; // back to the default text color mText.Write("Normal text in Arial with the default paragraph height factor", options); mText.EndParagraph(); mText.ParagraphHeightFactor = 1; mText.Write("No formatted text uses mText.Style"); mText.Write(" and the text continues in the same paragraph."); mText.EndParagraph(); //options.HeightPercentage = 2.5; //options.Color = AciColor.Red; //options.Overstrike = true; //options.Underline = true; //options.FontFile = "times.ttf"; //options.ObliqueAngle = 15; //options.CharacterSpacePercentage = 2.35; //options.WidthFactor = 1.8; //for unknown reasons the aligment doesn't seem to change anything //mText.Write("Formatted text", options); //options.Aligment = MTextFormattingOptions.TextAligment.Center; //mText.Write("Center", options); //options.Aligment = MTextFormattingOptions.TextAligment.Top; //mText.Write("Top", options); //options.Aligment = MTextFormattingOptions.TextAligment.Bottom; //mText.Write("Bottom", options); mText.XData.Add(xdata); dxf.AddEntity(mText); dxf.Save("MText sample.dxf"); }
private static void MTextEntity() { TextStyle style = new TextStyle("Arial"); MText text1 = new MText(Vector2.Zero, 10, 0, style); // you can set manually the text value with all available formatting commands text1.Value = "{\\C71;\\c10938556;Text} with true color\\P{\\C140;Text} with indexed color"; MText text2 = new MText(new Vector2(0, 30), 10, 0, style); // or use the Write() method MTextFormattingOptions op = new MTextFormattingOptions(text2.Style); op.Color = new AciColor(188, 232, 166); // using true color text2.Write("Text", op); op.Color = null; // set color to the default defined in text2.Style text2.Write(" with true color"); text2.EndParagraph(); op.Color = new AciColor(140); // using index color text2.Write("Text", op); // set color to the default defined in text2.Style op.Color = null; text2.Write(" with indexed color"); // both text1 and text2 should yield to the same result DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010); dxf.AddEntity(text1); dxf.AddEntity(text2); dxf.Save("MText format.dxf"); // now you can retrieve the MText text value without any formatting codes, control characters like tab '\t' will be preserved in the result, // the new paragraph command "\P" will be converted to new line feed '\r\n'. Console.WriteLine(text1.PlainText()); Console.WriteLine(); Console.WriteLine(text2.PlainText()); Console.WriteLine(); Console.WriteLine("Press a key to finish..."); Console.ReadKey(); }