Пример #1
0
        /// <summary>
        /// Converts Text into DDL.
        /// </summary>
        internal override void Serialize(Serializer serializer)
        {
            string text = DdlEncoder.StringToText(content.Value);

            // To make DDL more readable write soft hypens as keywords.
            text = text.Replace(new string((char)173, 1), "\\-");
            serializer.Write(text);
        }
Пример #2
0
        /// <summary>
        /// Converts Style into DDL.
        /// </summary>
        internal override void Serialize(Serializer serializer)
        {
#if DEBUG // Test
            // THHO4THHO debug code only...
            if (Name == StyleNames.Heading1 || Name == StyleNames.Heading2)
            {
                Name.GetType();
            }
#endif

            // 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);
                        //!!!newTHHO 26.07.2007 begin
                        // 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...
                        //!!!newTHHO 26.07.2007 begin
                    }
                    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;
#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();
        }