Example #1
0
        /// <summary>
        /// Converts Paragraph into DDL.
        /// </summary>
        internal override void Serialize(Serializer serializer)
        {
            if (!_serializeContentOnly)
            {
                serializer.WriteComment(_comment.Value);
                serializer.WriteLine("\\paragraph");

                int pos = serializer.BeginAttributes();

                if (_style.Value != "")
                {
                    serializer.WriteLine("Style = \"" + _style.Value + "\"");
                }

                if (!IsNull("Format"))
                {
                    _format.Serialize(serializer, "Format", null);
                }

                serializer.EndAttributes(pos);

                serializer.BeginContent();
                if (!IsNull("Elements"))
                {
                    Elements.Serialize(serializer);
                }
                serializer.CloseUpLine();
                serializer.EndContent();
            }
            else
            {
                Elements.Serialize(serializer);
                serializer.CloseUpLine();
            }
        }
Example #2
0
        /// <summary>
        /// Converts Footnote into DDL.
        /// </summary>
        internal override void Serialize(Serializer serializer)
        {
            serializer.WriteLine("\\footnote");

            int pos = serializer.BeginAttributes();

            if (_reference.Value != string.Empty)
            {
                serializer.WriteSimpleAttribute("Reference", Reference);
            }
            if (_style.Value != string.Empty)
            {
                serializer.WriteSimpleAttribute("Style", Style);
            }

            if (!IsNull("Format"))
            {
                _format.Serialize(serializer, "Format", null);
            }

            serializer.EndAttributes(pos);

            pos = serializer.BeginContent();
            if (!IsNull("Elements"))
            {
                _elements.Serialize(serializer);
            }
            serializer.EndContent(pos);
        }
Example #3
0
        /// <summary>
        /// Converts HeaderFooter into DDL.
        /// </summary>
        internal void Serialize(Serializer serializer, string prefix)
        {
            serializer.WriteComment(_comment.Value);
            serializer.WriteLine("\\" + prefix + (IsHeader ? "header" : "footer"));

            int pos = serializer.BeginAttributes();

            if (!IsNull("Format"))
            {
                _format.Serialize(serializer, "Format", null);
            }
            serializer.EndAttributes(pos);

            serializer.BeginContent();
            if (!IsNull("Elements"))
            {
                _elements.Serialize(serializer);
            }
            serializer.EndContent();
        }
Example #4
0
        /// <summary>
        /// Converts Style into DDL.
        /// </summary>
        public override void Serialize(Serializer serializer)
        {
#if DEBUG_ // Test
            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.
            Styles          buildInStyles = Styles.BuildInStyles;
            Style           refStyle      = null;
            Font            refFont       = null;
            ParagraphFormat refFormat     = null;

            serializer.WriteComment(_comment.Value);
            if (_buildIn.Value)
            {
                // BaseStyle is never null, but empty only for "Normal" and "DefaultParagraphFont"
                if (BaseStyle == "")
                {
                    // case: style is "Normal"
                    if (String.Compare(_name.Value, DefaultParagraphName, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        throw new ArgumentException("public Error: BaseStyle not set.");
                    }

                    refStyle  = buildInStyles[buildInStyles.GetIndex(Name)];
                    refFormat = refStyle.ParagraphFormat;
                    refFont   = refFormat.Font;
                    string name = DdlEncoder.QuoteIfNameContainsBlanks(Name);
                    serializer.WriteLineNoCommit(name);
                }
                else
                {
                    // case: any build-in style except "Normal"
                    refStyle  = buildInStyles[buildInStyles.GetIndex(Name)];
                    refFormat = refStyle.ParagraphFormat;
                    refFont   = refFormat.Font;
                    if (String.Compare(BaseStyle, refStyle.BaseStyle, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // case: build-in style with unmodified base style name
                        string name = DdlEncoder.QuoteIfNameContainsBlanks(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(_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(Name);
                        string baseName = DdlEncoder.QuoteIfNameContainsBlanks(BaseStyle);
                        serializer.WriteLine(name + " : " + baseName);
                        refStyle  = Document.Styles[Document.Styles.GetIndex(_baseStyle.Value)];
                        refFormat = refStyle.ParagraphFormat;
                        refFont   = refFormat.Font;
                    }
                }
            }
            else
            {
                // case: user-defined style; base style always exists

                string name     = DdlEncoder.QuoteIfNameContainsBlanks(Name);
                string baseName = DdlEncoder.QuoteIfNameContainsBlanks(BaseStyle);
                serializer.WriteLine(name + " : " + baseName);

#if true
                Style refStyle0 = Document.Styles[Document.Styles.GetIndex(_baseStyle.Value)];
                refStyle  = Document.Styles[_baseStyle.Value];
                refFormat = refStyle != null ? refStyle.ParagraphFormat : null;
#else
                refFormat = null;
#endif
            }

            serializer.BeginContent();

            if (!IsNull("ParagraphFormat"))
            {
                if (!ParagraphFormat.IsNull("Font"))
                {
                    Font.Serialize(serializer, refFormat != null ? refFormat.Font : null);
                }

                if (Type == StyleType.Paragraph)
                {
                    ParagraphFormat.Serialize(serializer, "ParagraphFormat", refFormat);
                }
            }

            serializer.EndContent();
        }