예제 #1
0
        /// <summary>
        /// Converts FormattedText into DDL.
        /// </summary>
        internal override void Serialize(Serializer serializer)
        {
            bool isFormatted = false;

            if (!IsNull("Font"))
            {
                Font.Serialize(serializer);
                isFormatted = true;
            }
            else
            {
                if (!_style.IsNull)
                {
                    serializer.Write("\\font(\"" + Style + "\")");
                    isFormatted = true;
                }
            }

            if (isFormatted)
            {
                serializer.Write("{");
            }

            if (!IsNull("Elements"))
            {
                Elements.Serialize(serializer);
            }

            if (isFormatted)
            {
                serializer.Write("}");
            }
        }
예제 #2
0
        internal override void Serialize(XmlSerializer serializer)
        {
            //serializer.WriteStartElement("Text");

            bool isFormatted = false;

            if (!IsNull("Font"))
            {
                Font.Serialize(serializer);
                isFormatted = true;
            }
            else
            {
                if (!_style.IsNull)
                {
                    //serializer.Write("\\font(\"" + Style + "\")");
                    //serializer.WriteSimpleAttribute("Font", Style);
                    serializer.WriteStartElement("Font");
                    serializer.WriteSimpleAttribute("Style", Style);
                    isFormatted = true;
                }
            }

            //if (isFormatted)
            //serializer.Write("{");
            //  serializer.WriteStartElement("p");

            if (!IsNull("Elements"))
            {
                Elements.Serialize(serializer);
            }

            //if (isFormatted)
            //serializer.Write("}");
            //serializer.WriteEndElement();

            if (isFormatted)
            {
                serializer.WriteEndElement();
            }
        }
예제 #3
0
        /// <summary>
        /// Converts ParagraphFormat into DDL.
        /// </summary>
        internal void Serialize(Serializer serializer, string name, ParagraphFormat refFormat)
        {
            int pos = serializer.BeginContent(name);

            if (!IsNull("Font") && Parent.GetType() != typeof(Style))
            {
                Font.Serialize(serializer);
            }

            // If a refFormat is specified, it is important to compare the fields and not the properties.
            // Only the fields holds the internal information whether a value is NULL. In contrast to the
            // Efw.Application framework the nullable values and all the meta stuff is kept internal to
            // give the user the illusion of simplicity.

            if (!_alignment.IsNull && (refFormat == null || (_alignment != refFormat._alignment)))
            {
                serializer.WriteSimpleAttribute("Alignment", Alignment);
            }

            if (!_leftIndent.IsNull && (refFormat == null || (_leftIndent != refFormat._leftIndent)))
            {
                serializer.WriteSimpleAttribute("LeftIndent", LeftIndent);
            }

            if (!_firstLineIndent.IsNull && (refFormat == null || _firstLineIndent != refFormat._firstLineIndent))
            {
                serializer.WriteSimpleAttribute("FirstLineIndent", FirstLineIndent);
            }

            if (!_rightIndent.IsNull && (refFormat == null || _rightIndent != refFormat._rightIndent))
            {
                serializer.WriteSimpleAttribute("RightIndent", RightIndent);
            }

            if (!_spaceBefore.IsNull && (refFormat == null || _spaceBefore != refFormat._spaceBefore))
            {
                serializer.WriteSimpleAttribute("SpaceBefore", SpaceBefore);
            }

            if (!_spaceAfter.IsNull && (refFormat == null || _spaceAfter != refFormat._spaceAfter))
            {
                serializer.WriteSimpleAttribute("SpaceAfter", SpaceAfter);
            }

            if (!_lineSpacingRule.IsNull && (refFormat == null || _lineSpacingRule != refFormat._lineSpacingRule))
            {
                serializer.WriteSimpleAttribute("LineSpacingRule", LineSpacingRule);
            }

            if (!_lineSpacing.IsNull && (refFormat == null || _lineSpacing != refFormat._lineSpacing))
            {
                serializer.WriteSimpleAttribute("LineSpacing", LineSpacing);
            }

            if (!_keepTogether.IsNull && (refFormat == null || _keepTogether != refFormat._keepTogether))
            {
                serializer.WriteSimpleAttribute("KeepTogether", KeepTogether);
            }

            if (!_keepWithNext.IsNull && (refFormat == null || _keepWithNext != refFormat._keepWithNext))
            {
                serializer.WriteSimpleAttribute("KeepWithNext", KeepWithNext);
            }

            if (!_widowControl.IsNull && (refFormat == null || _widowControl != refFormat._widowControl))
            {
                serializer.WriteSimpleAttribute("WidowControl", WidowControl);
            }

            if (!_pageBreakBefore.IsNull && (refFormat == null || _pageBreakBefore != refFormat._pageBreakBefore))
            {
                serializer.WriteSimpleAttribute("PageBreakBefore", PageBreakBefore);
            }

            if (!_outlineLevel.IsNull && (refFormat == null || _outlineLevel != refFormat._outlineLevel))
            {
                serializer.WriteSimpleAttribute("OutlineLevel", OutlineLevel);
            }

            if (!IsNull("ListInfo"))
            {
                ListInfo.Serialize(serializer);
            }

            if (!IsNull("TabStops"))
            {
                _tabStops.Serialize(serializer);
            }

            if (!IsNull("Borders"))
            {
                if (refFormat != null)
                {
                    _borders.Serialize(serializer, refFormat.Borders);
                }
                else
                {
                    _borders.Serialize(serializer, null);
                }
            }

            if (!IsNull("Shading"))
            {
                _shading.Serialize(serializer);
            }

            serializer.EndContent(pos);
        }
예제 #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();
        }