PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/AODL/Document/Styles/TextStyle.cs

https://bitbucket.org/chrisc/aodl
C# | 151 lines | 59 code | 9 blank | 83 comment | 2 complexity | ac70388d337a8b55ed88a3ee5839f5ad 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. using AODL.Document.Styles.Properties;
  24. namespace AODL.Document.Styles
  25. {
  26. /// <summary>
  27. /// Represent the style for a FormatedText object.
  28. /// </summary>
  29. public class TextStyle : AbstractStyle
  30. {
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="TextStyle"/> class.
  33. /// </summary>
  34. /// <param name="document">The document.</param>
  35. /// <param name="node">The node.</param>
  36. public TextStyle(IDocument document, XElement node)
  37. {
  38. Document = document;
  39. Node = node;
  40. InitStandards();
  41. }
  42. /// <summary>
  43. /// Initializes a new instance of the <see cref="TextStyle"/> class.
  44. /// </summary>
  45. /// <param name="document">The document.</param>
  46. /// <param name="styleName">Name of the style.</param>
  47. public TextStyle(IDocument document, string styleName)
  48. {
  49. Document = document;
  50. Node = new XElement(Ns.Style + "style");
  51. Node.SetAttributeValue(Ns.Style + "name", styleName);
  52. Node.SetAttributeValue(Ns.Style + "family", FamiliyStyles.Text);
  53. InitStandards();
  54. }
  55. /// <summary>
  56. /// Gets or sets the text properties.
  57. /// </summary>
  58. /// <value>The text properties.</value>
  59. public TextProperties TextProperties
  60. {
  61. get
  62. {
  63. foreach (IProperty property in PropertyCollection)
  64. if (property is TextProperties)
  65. return (TextProperties) property;
  66. TextProperties textProperties = new TextProperties(this);
  67. PropertyCollection.Add(textProperties);
  68. return textProperties;
  69. }
  70. set
  71. {
  72. if (PropertyCollection.Contains(value))
  73. PropertyCollection.Remove(value);
  74. PropertyCollection.Add(value);
  75. }
  76. }
  77. /// <summary>
  78. /// The family tyle to this object belongs.
  79. /// </summary>
  80. public string Family
  81. {
  82. get { return (string) Node.Attribute(Ns.Style + "family"); }
  83. set { Node.SetAttributeValue(Ns.Style + "family", value); }
  84. }
  85. /// <summary>
  86. /// Inits the standards.
  87. /// </summary>
  88. private void InitStandards()
  89. {
  90. PropertyCollection = new IPropertyCollection();
  91. PropertyCollection.Inserted += PropertyCollection_Inserted;
  92. PropertyCollection.Removed += PropertyCollection_Removed;
  93. // this.Document.Styles.Add(this);
  94. }
  95. /// <summary>
  96. /// Properties the collection_ inserted.
  97. /// </summary>
  98. /// <param name="index">The index.</param>
  99. /// <param name="value">The value.</param>
  100. private void PropertyCollection_Inserted(int index, object value)
  101. {
  102. Node.Add(((IProperty) value).Node);
  103. }
  104. /// <summary>
  105. /// Properties the collection_ removed.
  106. /// </summary>
  107. /// <param name="index">The index.</param>
  108. /// <param name="value">The value.</param>
  109. private static void PropertyCollection_Removed(int index, object value)
  110. {
  111. ((IProperty) value).Node.Remove();
  112. }
  113. }
  114. }
  115. /*
  116. * $Log: TextStyle.cs,v $
  117. * Revision 1.2 2008/04/29 15:39:55 mt
  118. * new copyright header
  119. *
  120. * Revision 1.1 2007/02/25 08:58:50 larsbehr
  121. * initial checkin, import from Sourceforge.net to OpenOffice.org
  122. *
  123. * Revision 1.2 2006/01/29 18:52:51 larsbm
  124. * - Added support for common styles (style templates in OpenOffice)
  125. * - Draw TextBox import and export
  126. * - DrawTextBox html export
  127. *
  128. * Revision 1.1 2006/01/29 11:28:23 larsbm
  129. * - Changes for the new version. 1.2. see next changelog for details
  130. *
  131. * Revision 1.4 2005/10/22 15:52:10 larsbm
  132. * - Changed some styles from Enum to Class with statics
  133. * - Add full support for available OpenOffice fonts
  134. *
  135. * Revision 1.3 2005/10/09 15:52:47 larsbm
  136. * - Changed some design at the paragraph usage
  137. * - add list support
  138. *
  139. * Revision 1.2 2005/10/08 07:55:35 larsbm
  140. * - added cvs tags
  141. *
  142. */