/// <summary> /// Initializes a new instance of the Document class. /// </summary> public Document() { _styles = new Styles(this); }
internal StyleRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer) : base(domObj, docRenderer) { this.style = domObj as Style; this.styles = DocumentRelations.GetParent(this.style) as Styles; }
/// <summary> /// Adds a new style to the document styles. /// </summary> public void Add(Style style) { Styles.Add(style); }
/// <summary> /// Initializes a new instance of the Document class. /// </summary> public Document() { _styles = new Styles(this); }
/// <summary> /// Converts Style into DDL. /// </summary> internal override void Serialize(Serializer serializer) { // For build-in styles all properties that differ from their default values // are serialized. // For user-defined styles all non-null properties are serialized. //!!!newTHHO 26.07.2007 Modified method for built-in styles. //!!!newTHHO 26.07.2007 Modified method for user-defined styles. Styles buildInStyles = Styles.BuildInStyles; Style refStyle = null; Font refFont = null; ParagraphFormat refFormat = null; serializer.WriteComment(this.comment.Value); if (this.buildIn.Value) { // BaseStyle is never null, but empty only for "Normal" and "DefaultParagraphFont" if (this.BaseStyle == "") { // case: style is "Normal" if (String.Compare(this.name.Value, Style.DefaultParagraphName, true) != 0) { throw new ArgumentException("Internal Error: BaseStyle not set."); } refStyle = buildInStyles[buildInStyles.GetIndex(this.Name)]; refFormat = refStyle.ParagraphFormat; refFont = refFormat.Font; string name = DdlEncoder.QuoteIfNameContainsBlanks(this.Name); serializer.WriteLineNoCommit(name); } else { // case: any build-in style except "Normal" refStyle = buildInStyles[buildInStyles.GetIndex(this.Name)]; refFormat = refStyle.ParagraphFormat; refFont = refFormat.Font; if (String.Compare(this.BaseStyle, refStyle.BaseStyle, true) == 0) { // case: build-in style with unmodified base style name string name = DdlEncoder.QuoteIfNameContainsBlanks(this.Name); serializer.WriteLineNoCommit(name); // It's fine if we have the predefined base style, but ... // ... the base style may have been modified or may even have a modified base style. // Methinks it's wrong to compare with the built-in style, so let's compare with the // real base style: refStyle = Document.Styles[Document.Styles.GetIndex(this.baseStyle.Value)]; refFormat = refStyle.ParagraphFormat; refFont = refFormat.Font; // Note: we must write "Underline = none" if the base style has "Underline = single" - we cannot // detect this if we compare with the built-in style that has no underline. // Known problem: Default values like "OutlineLevel = Level1" will now be serialized // TODO: optimize... } else { // case: build-in style with modified base style name string name = DdlEncoder.QuoteIfNameContainsBlanks(this.Name); string baseName = DdlEncoder.QuoteIfNameContainsBlanks(this.BaseStyle); serializer.WriteLine(name + " : " + baseName); refStyle = Document.Styles[Document.Styles.GetIndex(this.baseStyle.Value)]; refFormat = refStyle.ParagraphFormat; refFont = refFormat.Font; } } } else { // case: user-defined style; base style always exists string name = DdlEncoder.QuoteIfNameContainsBlanks(this.Name); string baseName = DdlEncoder.QuoteIfNameContainsBlanks(this.BaseStyle); serializer.WriteLine(name + " : " + baseName); #if true Style refStyle0 = Document.Styles[Document.Styles.GetIndex(this.baseStyle.Value)]; refStyle = Document.Styles[this.baseStyle.Value]; refFormat = refStyle != null ? refStyle.ParagraphFormat : null; refFont = refStyle.Font; #else refFormat = null; #endif } serializer.BeginContent(); if (!this.IsNull("ParagraphFormat")) { if (!this.ParagraphFormat.IsNull("Font")) { this.Font.Serialize(serializer, refFormat != null ? refFormat.Font : null); } if (this.Type == StyleType.Paragraph) { this.ParagraphFormat.Serialize(serializer, "ParagraphFormat", refFormat); } } serializer.EndContent(); }