//    [UnitTestFunction]
        public static void Test()
        {
            Document doc    = new Document();
            Styles   styles = doc.Styles;
            Style    style  = styles.AddStyle("MyTestA", "Heading7");

            style.ParagraphFormat.Shading.Color = Color.Aqua;
            style.ParagraphFormat.SpaceAfter    = 5;
            style.ParagraphFormat.SpaceBefore   = 12;
            style.ParagraphFormat.WidowControl  = false;
            style.ParagraphFormat.Borders.Width = 2;
            style.Font.Bold   = true;
            style.Font.Italic = true;
            style.Font.Color  = Color.DarkGray;
            style.Font.Name   = "Courier New";
            Style styleB = styles.AddStyle("MyTestB", "MyTestA");

            styleB.ParagraphFormat.OutlineLevel       = OutlineLevel.BodyText;
            styleB.ParagraphFormat.Borders.Left.Color = Color.Goldenrod;
            style.ParagraphFormat.TabStops.AddTabStop(100, TabAlignment.Right, TabLeader.MiddleDot);
            DocumentRenderer docRenderer = new DocumentRenderer();

            styleB.ParagraphFormat.TabStops.RemoveTabStop(100);
            docRenderer.Render(doc, "RtfHeader.txt", null);
            System.IO.File.Copy("RtfHeader.txt", "RtfHeader.rtf", true);
            System.Diagnostics.Process.Start("RtfHeader.txt");
        }
Exemple #2
0
        private void FindStyles(string filePath, XElement root, NamespaceScope scope, Styles styles)
        {
            var   local      = new NamespaceScope(scope);
            XName targetType = null;
            XName key        = null;

            AddNamespaces(root, local);

            foreach (var a in root.Attributes())
            {
                if (a.Name.LocalName == "TargetType")
                {
                    targetType = ParseTargetType(a.Value, local);
                }
                else if (a.Name.LocalName == "Key" && a.Name.Namespace == XamlNsUri)
                {
                    key = ParseTargetType(a.Value, local);
                }
                else if (a.Name.LocalName == "DataType")
                {
                    // todo: check DataType references.
                }
            }

            if (key != null || targetType != null)
            {
                if (root.Name.LocalName == "ControlTemplate" && targetType != null && key == null &&
                    HasParent(root, "Style"))
                {
                    // If this control template is inside a <Style> then it is not an independently
                    // addressable resource.
                }
                else
                {
                    styles.AddStyle(filePath, key, targetType, root);
                }
            }

            // Check for any nested styles first.
            foreach (var e in root.Elements())
            {
                // If we find a nested .Resources within a resource then it's styles
                // are not global, we will create localstyles for this one later.
                if (!e.Name.LocalName.EndsWith(".Resources"))
                {
                    FindStyles(filePath, e, local, styles);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Parses a style definition block within the keyword «\styles».
        /// </summary>
        private Style ParseStyleDefinition(Styles styles)
        {
            //   StyleName [: BaseStyleName]
            //   {
            //     ...
            //   }
            Style style = null;
            try
            {
                string styleName = _scanner.Token;
                string baseStyleName = null;

                if (Symbol != Symbol.Identifier && Symbol != Symbol.StringLiteral)
                    ThrowParserException(DomMsgID.StyleNameExpected, styleName);

                ReadCode();

                if (Symbol == Symbol.Colon)
                {
                    ReadCode();
                    if (Symbol != Symbol.Identifier && Symbol != Symbol.StringLiteral)
                        ThrowParserException(DomMsgID.StyleNameExpected, styleName);

                    // If baseStyle is not valid, choose InvalidStyleName by default.
                    baseStyleName = _scanner.Token;
                    if (styles.GetIndex(baseStyleName) == -1)
                    {
                        ReportParserInfo(DdlErrorLevel.Warning, DomMsgID.UseOfUndefinedBaseStyle, baseStyleName);
                        baseStyleName = StyleNames.InvalidStyleName;
                    }

                    ReadCode();
                }

                // Get or create style.
                style = styles[styleName];
                if (style != null)
                {
                    // Reset base style.
                    if (baseStyleName != null)
                        style.BaseStyle = baseStyleName;
                }
                else
                {
                    // Style does not exist and no base style is given, choose InvalidStyleName by default.
                    if (String.IsNullOrEmpty(baseStyleName))
                    {
                        baseStyleName = StyleNames.InvalidStyleName;
                        ReportParserInfo(DdlErrorLevel.Warning, DomMsgID.UseOfUndefinedStyle, styleName);
                    }

                    style = styles.AddStyle(styleName, baseStyleName);
                }

                // Parse definition (if any).

                if (Symbol == Symbol.BraceLeft)
                {
                    ParseAttributeBlock(style);
                }
            }
            catch (DdlParserException ex)
            {
                ReportParserException(ex);
                AdjustToNextBlock();
            }
            return style;
        }