| @@ -80,7 +80,6 @@ Global | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Debug|x86.ActiveCfg = Debug|Any CPU | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
| {1EB1EE8F-9978-425B-A742-533DCCEB4811}.Release|Any CPU.Build.0 = Release|Any CPU | |||
| @@ -98,6 +98,7 @@ | |||
| <Compile Include="Footer.cs" /> | |||
| <Compile Include="CustomProperty.cs" /> | |||
| <Compile Include="DocProperty.cs" /> | |||
| <Compile Include="FormattedText.cs" /> | |||
| <Compile Include="Header.cs" /> | |||
| <Compile Include="Headers.cs" /> | |||
| <Compile Include="HelperFunctions.cs" /> | |||
| @@ -0,0 +1,30 @@ | |||
| using System; | |||
| using System.Collections.Generic; | |||
| using System.Linq; | |||
| using System.Text; | |||
| namespace Novacode | |||
| { | |||
| public class FormattedText: IComparable | |||
| { | |||
| public FormattedText() | |||
| { | |||
| } | |||
| public int index; | |||
| public string text; | |||
| public Formatting formatting; | |||
| public int CompareTo(object obj) | |||
| { | |||
| FormattedText other = (FormattedText)obj; | |||
| FormattedText tf = (FormattedText)obj; | |||
| if (other.formatting == null || tf.formatting == null) | |||
| return -1; | |||
| return tf.formatting.CompareTo(other.formatting); | |||
| } | |||
| } | |||
| } | |||
| @@ -10,7 +10,7 @@ namespace Novacode | |||
| /// <summary> | |||
| /// A text formatting. | |||
| /// </summary> | |||
| public class Formatting | |||
| public class Formatting : IComparable | |||
| { | |||
| private XElement rPr; | |||
| private bool hidden; | |||
| @@ -67,6 +67,32 @@ namespace Novacode | |||
| } | |||
| } | |||
| public static Formatting Parse(XElement rPr) | |||
| { | |||
| Formatting formatting = new Formatting(); | |||
| // Build up the Formatting object. | |||
| foreach (XElement option in rPr.Elements()) | |||
| { | |||
| switch (option.Name.LocalName) | |||
| { | |||
| case "lang": formatting.Language = new CultureInfo(option.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value); break; | |||
| case "spacing": formatting.Spacing = Double.Parse(option.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value) / 20.0; break; | |||
| case "position": formatting.Position = Int32.Parse(option.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value) / 2; break; | |||
| case "kern": formatting.Position = Int32.Parse(option.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value) / 2; break; | |||
| case "w": formatting.PercentageScale = Int32.Parse(option.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value); break; | |||
| case "rFonts": break; | |||
| case "vanish": formatting.hidden = true; break; | |||
| case "b": formatting.Bold = true; break; | |||
| case "i": formatting.Italic = true; break; | |||
| default: break; | |||
| } | |||
| } | |||
| return formatting; | |||
| } | |||
| internal XElement Xml | |||
| { | |||
| get | |||
| @@ -217,7 +243,7 @@ namespace Novacode | |||
| /// <summary> | |||
| /// This formatting will apply Italic. | |||
| /// </summary> | |||
| public bool Italic { get { return Italic; } set { italic = value; } } | |||
| public bool Italic { get { return italic; } set { italic = value; } } | |||
| /// <summary> | |||
| /// This formatting will apply StrickThrough. | |||
| @@ -369,5 +395,65 @@ namespace Novacode | |||
| /// --> | |||
| public FontFamily FontFamily { get { return fontFamily; } set { fontFamily = value; } } | |||
| public int CompareTo(object obj) | |||
| { | |||
| Formatting other = (Formatting)obj; | |||
| if(other.hidden != this.hidden) | |||
| return -1; | |||
| if(other.bold != this.bold) | |||
| return -1; | |||
| if(other.italic != this.italic) | |||
| return -1; | |||
| if(other.strikethrough != this.strikethrough) | |||
| return -1; | |||
| if(other.script != this.script) | |||
| return -1; | |||
| if(other.highlight != this.highlight) | |||
| return -1; | |||
| if(other.size != this.size) | |||
| return -1; | |||
| if(other.fontColor != this.fontColor) | |||
| return -1; | |||
| if(other.underlineColor != this.underlineColor) | |||
| return -1; | |||
| if(other.underlineStyle != this.underlineStyle) | |||
| return -1; | |||
| if(other.misc != this.misc) | |||
| return -1; | |||
| if(other.capsStyle != this.capsStyle) | |||
| return -1; | |||
| if(other.fontFamily != this.fontFamily) | |||
| return -1; | |||
| if(other.percentageScale != this.percentageScale) | |||
| return -1; | |||
| if(other.kerning != this.kerning) | |||
| return -1; | |||
| if(other.position != this.position) | |||
| return -1; | |||
| if(other.spacing != this.spacing) | |||
| return -1; | |||
| if(other.language != this.language) | |||
| return -1; | |||
| return 0; | |||
| } | |||
| } | |||
| } | |||
| @@ -66,6 +66,69 @@ namespace Novacode | |||
| GetTextRecursive(e, ref sb); | |||
| } | |||
| internal static List<FormattedText> GetFormattedText(XElement e) | |||
| { | |||
| List<FormattedText> alist = new List<FormattedText>(); | |||
| GetFormattedTextRecursive(e, ref alist); | |||
| return alist; | |||
| } | |||
| internal static void GetFormattedTextRecursive(XElement Xml, ref List<FormattedText> alist) | |||
| { | |||
| FormattedText ft = ToFormattedText(Xml); | |||
| FormattedText last = null; | |||
| if (ft != null) | |||
| { | |||
| if (alist.Count() > 0) | |||
| last = alist.Last(); | |||
| if (last != null && last.CompareTo(ft) == 0) | |||
| { | |||
| // Update text of last entry. | |||
| last.text += ft.text; | |||
| } | |||
| else | |||
| { | |||
| if (last != null) | |||
| ft.index = last.index + last.text.Length; | |||
| alist.Add(ft); | |||
| } | |||
| } | |||
| if (Xml.HasElements) | |||
| foreach (XElement e in Xml.Elements()) | |||
| GetFormattedTextRecursive(e, ref alist); | |||
| } | |||
| internal static FormattedText ToFormattedText(XElement e) | |||
| { | |||
| // The text representation of e. | |||
| String text = ToText(e); | |||
| if (text == String.Empty) | |||
| return null; | |||
| // e is a w:t element, it must exist inside a w:r element, lets climb until we find it. | |||
| while (!e.Name.Equals(XName.Get("r", DocX.w.NamespaceName))) | |||
| e = e.Parent; | |||
| // e is a w:r element, lets find the rPr element. | |||
| XElement rPr = e.Element(XName.Get("rPr", DocX.w.NamespaceName)); | |||
| FormattedText ft = new FormattedText(); | |||
| ft.text = text; | |||
| ft.index = 0; | |||
| ft.formatting = null; | |||
| // Return text with formatting. | |||
| if (rPr != null) | |||
| ft.formatting = Formatting.Parse(rPr); | |||
| return ft; | |||
| } | |||
| internal static string ToText(XElement e) | |||
| { | |||
| switch (e.Name.LocalName) | |||
| @@ -11,6 +11,7 @@ using System.IO; | |||
| using System.Drawing; | |||
| using System.Globalization; | |||
| namespace Novacode | |||
| { | |||
| /// <summary> | |||
| @@ -1310,6 +1311,18 @@ namespace Novacode | |||
| } | |||
| } | |||
| /// <summary> | |||
| /// Gets the formatted text value of this Paragraph. | |||
| /// </summary> | |||
| public List<FormattedText> MagicText | |||
| { | |||
| // Returns the underlying XElement's Value property. | |||
| get | |||
| { | |||
| return HelperFunctions.GetFormattedText(Xml); | |||
| } | |||
| } | |||
| //public Picture InsertPicture(Picture picture) | |||
| //{ | |||
| // Picture newPicture = picture; | |||
| @@ -203,7 +203,7 @@ namespace Novacode | |||
| internal Table(DocX document, XElement xml) | |||
| : base(document, xml) | |||
| { | |||
| autofit = AutoFit.ColoumnWidth; | |||
| autofit = AutoFit.ColumnWidth; | |||
| this.Xml = xml; | |||
| XElement properties = xml.Element(XName.Get("tblPr", DocX.w.NamespaceName)); | |||
| @@ -291,7 +291,7 @@ namespace Novacode | |||
| string attributeValue = string.Empty; | |||
| switch (value) | |||
| { | |||
| case AutoFit.ColoumnWidth: | |||
| case AutoFit.ColumnWidth: | |||
| { | |||
| attributeValue = "dxa"; | |||
| break; | |||
| @@ -111,13 +111,48 @@ namespace Novacode | |||
| public enum UnderlineStyle { none, singleLine, doubleLine, thick, dotted, dottedHeavy, dash, dashedHeavy, dashLong, dashLongHeavy, dotDash, dashDotHeavy, dotDotDash, dashDotDotHeavy, wave, wavyHeavy, wavyDouble, words }; | |||
| public enum StrikeThrough { none, strike, doubleStrike }; | |||
| public enum Misc { none, shadow, outline, outlineShadow, emboss, engrave }; | |||
| public enum CapsStyle { none, caps, smallCaps }; | |||
| /// <summary> | |||
| /// Change the caps style of text, for use with Append and AppendLine. | |||
| /// </summary> | |||
| public enum CapsStyle | |||
| { | |||
| /// <summary> | |||
| /// No caps, make all characters are lowercase. | |||
| /// </summary> | |||
| none, | |||
| /// <summary> | |||
| /// All caps, make every character uppercase. | |||
| /// </summary> | |||
| caps, | |||
| /// <summary> | |||
| /// Small caps, make all characters capital but with a small font size. | |||
| /// </summary> | |||
| smallCaps }; | |||
| /// <summary> | |||
| /// Designs\Styles that can be applied to a table. | |||
| /// </summary> | |||
| public enum TableDesign { Custom, TableNormal, TableGrid, LightShading, LightShadingAccent1, LightShadingAccent2, LightShadingAccent3, LightShadingAccent4, LightShadingAccent5, LightShadingAccent6, LightList, LightListAccent1, LightListAccent2, LightListAccent3, LightListAccent4, LightListAccent5, LightListAccent6, LightGrid, LightGridAccent1, LightGridAccent2, LightGridAccent3, LightGridAccent4, LightGridAccent5, LightGridAccent6, MediumShading1, MediumShading1Accent1, MediumShading1Accent2, MediumShading1Accent3, MediumShading1Accent4, MediumShading1Accent5, MediumShading1Accent6, MediumShading2, MediumShading2Accent1, MediumShading2Accent2, MediumShading2Accent3, MediumShading2Accent4, MediumShading2Accent5, MediumShading2Accent6, MediumList1, MediumList1Accent1, MediumList1Accent2, MediumList1Accent3, MediumList1Accent4, MediumList1Accent5, MediumList1Accent6, MediumList2, MediumList2Accent1, MediumList2Accent2, MediumList2Accent3, MediumList2Accent4, MediumList2Accent5, MediumList2Accent6, MediumGrid1, MediumGrid1Accent1, MediumGrid1Accent2, MediumGrid1Accent3, MediumGrid1Accent4, MediumGrid1Accent5, MediumGrid1Accent6, MediumGrid2, MediumGrid2Accent1, MediumGrid2Accent2, MediumGrid2Accent3, MediumGrid2Accent4, MediumGrid2Accent5, MediumGrid2Accent6, MediumGrid3, MediumGrid3Accent1, MediumGrid3Accent2, MediumGrid3Accent3, MediumGrid3Accent4, MediumGrid3Accent5, MediumGrid3Accent6, DarkList, DarkListAccent1, DarkListAccent2, DarkListAccent3, DarkListAccent4, DarkListAccent5, DarkListAccent6, ColorfulShading, ColorfulShadingAccent1, ColorfulShadingAccent2, ColorfulShadingAccent3, ColorfulShadingAccent4, ColorfulShadingAccent5, ColorfulShadingAccent6, ColorfulList, ColorfulListAccent1, ColorfulListAccent2, ColorfulListAccent3, ColorfulListAccent4, ColorfulListAccent5, ColorfulListAccent6, ColorfulGrid, ColorfulGridAccent1, ColorfulGridAccent2, ColorfulGridAccent3, ColorfulGridAccent4, ColorfulGridAccent5, ColorfulGridAccent6, None }; | |||
| public enum AutoFit { Contents, Window, ColoumnWidth }; | |||
| /// <summary> | |||
| /// How a Table should auto resize. | |||
| /// </summary> | |||
| public enum AutoFit | |||
| { | |||
| /// <summary> | |||
| /// Autofit to Table contents. | |||
| /// </summary> | |||
| Contents, | |||
| /// <summary> | |||
| /// Autofit to Window. | |||
| /// </summary> | |||
| Window, | |||
| /// <summary> | |||
| /// Autofit to Column width. | |||
| /// </summary> | |||
| ColumnWidth | |||
| }; | |||
| public enum RectangleShapes | |||
| { | |||
| @@ -295,7 +330,7 @@ namespace Novacode | |||
| }; | |||
| /// <summary> | |||
| /// Text alignment of a paragraph | |||
| /// Text alignment of a Paragraph. | |||
| /// </summary> | |||
| public enum Alignment | |||
| { | |||
| @@ -305,7 +340,7 @@ namespace Novacode | |||
| left, | |||
| /// <summary> | |||
| /// Align Paragraph as Centered. | |||
| /// Align Paragraph as centered. | |||
| /// </summary> | |||
| center, | |||