PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/AODL/Document/Styles/Properties/ParagraphProperties.cs

https://bitbucket.org/chrisc/aodl
C# | 303 lines | 111 code | 29 blank | 163 comment | 21 complexity | c68f2f4b1a9a8d38ec2bf8f71e5c151c MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  4. *
  5. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Use is subject to license terms.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  10. * use this file except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  12. * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. *
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. ************************************************************************/
  22. using System.Xml.Linq;
  23. namespace AODL.Document.Styles.Properties
  24. {
  25. /// <summary>
  26. /// Represent access to the possible attributes of of an paragraph-propertie element.
  27. /// </summary>
  28. public class ParagraphProperties : IProperty, IHtmlStyle
  29. {
  30. private TabStopStyleCollection _tabstopstylecollection;
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="ParagraphProperties"/> class.
  33. /// </summary>
  34. /// <param name="style">The style.</param>
  35. public ParagraphProperties(IStyle style)
  36. {
  37. Style = style;
  38. Node = new XElement(Ns.Style + "paragraph-properties");
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="ParagraphProperties"/> class.
  42. /// </summary>
  43. /// <param name="style">The style.</param>
  44. /// <param name="node">The node.</param>
  45. public ParagraphProperties(IStyle style, XElement node)
  46. {
  47. Style = style;
  48. Node = node;
  49. }
  50. #region IProperty Member
  51. /// <summary>
  52. /// The XElement which represent the property element.
  53. /// </summary>
  54. /// <value>The node</value>
  55. public XElement Node { get; set; }
  56. /// <summary>
  57. /// The style object to which this property object belongs
  58. /// </summary>
  59. /// <value></value>
  60. public IStyle Style { get; set; }
  61. #endregion
  62. #region IHtmlStyle Member
  63. /// <summary>
  64. /// Get the css style fragement
  65. /// </summary>
  66. /// <returns>The css style attribute</returns>
  67. public string GetHtmlStyle()
  68. {
  69. string style = "style=\"";
  70. if (Alignment != null)
  71. style += "text-align: " + Alignment + "; ";
  72. if (MarginLeft != null)
  73. style += "text-indent: " + MarginLeft + "; ";
  74. if (LineSpacing != null)
  75. style += "line-height: " + LineSpacing + "; ";
  76. if (Border != null && Padding == null)
  77. style += "border-width:1px; border-style:solid; padding: 0.5cm; ";
  78. if (Border != null && Padding != null)
  79. style += "border-width:1px; border-style:solid; padding:" + Padding + "; ";
  80. if (!style.EndsWith("; "))
  81. style = "";
  82. else
  83. style += "\"";
  84. return style;
  85. }
  86. #endregion
  87. /// <summary>
  88. /// The ParagraphStyle object to this object belongs.
  89. /// </summary>
  90. public ParagraphStyle Paragraphstyle
  91. {
  92. get { return (ParagraphStyle) Style; }
  93. set { Style = value; }
  94. }
  95. /// <summary>
  96. /// Margin left. in cm an object .MarginLeft = "1cm";
  97. /// </summary>
  98. public string MarginLeft
  99. {
  100. get { return (string) Node.Attribute(Ns.Fo + "margin-left"); }
  101. set { Node.SetAttributeValue(Ns.Fo + "margin-left", value); }
  102. }
  103. /// <summary>
  104. /// Gets or sets the break before.
  105. /// e.g. set this to "page" if this paragraph
  106. /// should be start on the next page.
  107. /// </summary>
  108. /// <value>The break before.</value>
  109. public string BreakBefore
  110. {
  111. get { return (string) Node.Attribute(Ns.Fo + "break-before"); }
  112. set { Node.SetAttributeValue(Ns.Fo + "break-before", value); }
  113. }
  114. /// <summary>
  115. /// Gets or sets the break after.
  116. /// e.g. set this to "page" if after this paragraph
  117. /// should be added a new page.
  118. /// </summary>
  119. /// <value>The break before.</value>
  120. public string BreakAfter
  121. {
  122. get { return (string) Node.Attribute(Ns.Fo + "break-after"); }
  123. set { Node.SetAttributeValue(Ns.Fo + "break-after", value); }
  124. }
  125. /// <summary>
  126. /// Gets or sets the border.
  127. /// This could be e.g. 0.002cm solid #000000 (width, linestyle, color)
  128. /// or none
  129. /// </summary>
  130. /// <value>The border.</value>
  131. public string Border
  132. {
  133. get { return (string) Node.Attribute(Ns.Fo + "border"); }
  134. set { Node.SetAttributeValue(Ns.Fo + "border", value); }
  135. }
  136. /// <summary>
  137. /// Set the background color
  138. /// Use Colors.GetColor(Color color) to set
  139. /// on of the available .net colors
  140. /// </summary>
  141. public string BackgroundColor
  142. {
  143. get { return (string) Node.Attribute(Ns.Fo + "background-color"); }
  144. set { Node.SetAttributeValue(Ns.Fo + "background-color", value); }
  145. }
  146. /// <summary>
  147. /// Gets or sets the padding.
  148. /// Default 0.049cm
  149. /// Use this in combination with the Border property
  150. /// </summary>
  151. /// <value>The padding.</value>
  152. public string Padding
  153. {
  154. get { return (string) Node.Attribute(Ns.Fo + "padding"); }
  155. set { Node.SetAttributeValue(Ns.Fo + "padding", value); }
  156. }
  157. /// <summary>
  158. /// Gets or sets the line height in %.
  159. /// 200% means double space
  160. /// </summary>
  161. /// <value>The line height.</value>
  162. public string LineSpacing
  163. {
  164. get { return (string) Node.Attribute(Ns.Fo + "line-height"); }
  165. set { Node.SetAttributeValue(Ns.Fo + "line-height", value); }
  166. }
  167. /// <summary>
  168. /// Gets or sets the tab stop style collection.
  169. /// <b>Notice:</b> A TabStopStyleCollection will not work
  170. /// within a Standard Paragraph!
  171. /// </summary>
  172. /// <value>The tab stop style collection.</value>
  173. public TabStopStyleCollection TabStopStyleCollection
  174. {
  175. get { return _tabstopstylecollection; }
  176. set
  177. {
  178. if (Style.StyleName == "Standard")
  179. return;
  180. if (_tabstopstylecollection != null)
  181. {
  182. //Remove node and reset the collection
  183. _tabstopstylecollection.Node.Remove();
  184. _tabstopstylecollection = null;
  185. }
  186. _tabstopstylecollection = value;
  187. if (Node.Element(Ns.Style + "tab-stops") == null)
  188. Node.Add(_tabstopstylecollection.Node);
  189. }
  190. }
  191. /// <summary>
  192. /// Set paragraph alignment - object.Alignment = TextAlignments.right.ToString()
  193. /// </summary>
  194. public string Alignment
  195. {
  196. get { return (string) Node.Attribute(Ns.Fo + "text-align"); }
  197. set { Node.SetAttributeValue(Ns.Fo + "text-align", value); }
  198. }
  199. }
  200. /// <summary>
  201. /// Some helper constants for Paragraph properties
  202. /// </summary>
  203. public class ParagraphHelper
  204. {
  205. /// <summary>
  206. /// Line spacing double
  207. /// </summary>
  208. public static readonly string LineDouble = "200%";
  209. /// <summary>
  210. /// Line spacing 1.5 lines
  211. /// </summary>
  212. public static readonly string LineSpacing15 = "150%";
  213. /// <summary>
  214. /// Line spacing three lines
  215. /// </summary>
  216. public static readonly string LineSpacing3 = "300%";
  217. }
  218. }
  219. /*
  220. * $Log: ParagraphProperties.cs,v $
  221. * Revision 1.2 2008/04/29 15:39:56 mt
  222. * new copyright header
  223. *
  224. * Revision 1.1 2007/02/25 08:58:54 larsbehr
  225. * initial checkin, import from Sourceforge.net to OpenOffice.org
  226. *
  227. * Revision 1.4 2007/02/13 17:58:49 larsbm
  228. * - add first part of implementation of master style pages
  229. * - pdf exporter conversations for tables and images and added measurement helper
  230. *
  231. * Revision 1.3 2006/02/16 18:35:41 larsbm
  232. * - Add FrameBuilder class
  233. * - TextSequence implementation (Todo loading!)
  234. * - Free draing postioning via x and y coordinates
  235. * - Graphic will give access to it's full qualified path
  236. * via the GraphicRealPath property
  237. * - Fixed Bug with CellSpan in Spreadsheetdocuments
  238. * - Fixed bug graphic of loaded files won't be deleted if they
  239. * are removed from the content.
  240. * - Break-Before property for Paragraph properties for Page Break
  241. *
  242. * Revision 1.2 2006/02/05 20:03:32 larsbm
  243. * - Fixed several bugs
  244. * - clean up some messy code
  245. *
  246. * Revision 1.1 2006/01/29 11:28:23 larsbm
  247. * - Changes for the new version. 1.2. see next changelog for details
  248. *
  249. * Revision 1.6 2005/12/12 19:39:17 larsbm
  250. * - Added Paragraph Header
  251. * - Added Table Row Header
  252. * - Fixed some bugs
  253. * - better whitespace handling
  254. * - Implmemenation of HTML Exporter
  255. *
  256. * Revision 1.5 2005/11/23 19:18:17 larsbm
  257. * - New Textproperties
  258. * - New Paragraphproperties
  259. * - New Border Helper
  260. * - Textproprtie helper
  261. *
  262. * Revision 1.4 2005/11/20 17:31:20 larsbm
  263. * - added suport for XLinks, TabStopStyles
  264. * - First experimental of loading dcuments
  265. * - load and save via importer and exporter interfaces
  266. *
  267. * Revision 1.3 2005/10/09 15:52:47 larsbm
  268. * - Changed some design at the paragraph usage
  269. * - add list support
  270. *
  271. * Revision 1.2 2005/10/08 07:55:35 larsbm
  272. * - added cvs tags
  273. *
  274. */