Example #1
0
        public static StackPanel Figure(CompilerState state, Argument <DocumentElement>[] content)
        {
            var panel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                Flexible    = true,
                Tag         = "figure"
            };

            var elements = content.Select(e => e.Value).OfType <DocumentElement>().ToArray();

            panel.Elements.AddRange(elements);

            var caption = elements.OfType <Paragraph>().Where(e => "caption".Equals(e.Tag, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (caption != null)
            {
                var copiedCaption = caption.Clone();
                copiedCaption.Tag = "p";

                var figureCount = FigureVariables.FigureCaptionCounter.Increment(state.Document);

                var text = new TextLeaf
                {
                    Content = $"{state.Document.Locale.GetTerm(Term.Figure)} {figureCount}: "
                };
                caption.Leaves.Insert(0, text);

                var figures      = TableVariables.TableOfFigures.Get(state.Document) ?? throw new InvalidOperationException();
                var tableElement = new TableElement(figureCount.ToString(), 1, copiedCaption, panel);
                figures.Add(tableElement);
            }

            return(panel);
        }
Example #2
0
        private static Leaf ToLeaf(TextRun run)
        {
            var textLeaf = new TextLeaf(run.Text)
            {
                Tag = "span"
            };

            var fontWeight = Text.FontWeight.Normal;

            if (run.FontWeight == Scriber.Bibliography.Styling.Formatting.FontWeight.Bold)
            {
                fontWeight |= Text.FontWeight.Bold;
            }
            if (run.FontStyle == Scriber.Bibliography.Styling.Formatting.FontStyle.Italic)
            {
                fontWeight |= Text.FontWeight.Italic;
            }

            textLeaf.Style.Set(StyleKeys.FontWeight, fontWeight);

            var fontStyle = run.VerticalAlign switch
            {
                Scriber.Bibliography.Styling.Formatting.VerticalAlign.Subscript => Text.FontStyle.Subscript,
                Scriber.Bibliography.Styling.Formatting.VerticalAlign.Superscript => Text.FontStyle.Superscript,
                _ => Text.FontStyle.Normal
            };

            textLeaf.Style.Set(StyleKeys.FontStyle, fontStyle);

            return(textLeaf);
        }
    }
Example #3
0
        public void TestFirstChildSingle()
        {
            var p    = new Paragraph();
            var leaf = new TextLeaf();

            p.Leaves.Add(leaf);
            Assert.True(FirstChildPseudo.Matches(leaf));
        }
Example #4
0
        public void TestFirstChildMultiple()
        {
            var p     = new Paragraph();
            var leaf1 = new TextLeaf();
            var leaf2 = new TextLeaf();

            p.Leaves.Add(leaf1);
            p.Leaves.Add(leaf2);
            Assert.True(FirstChildPseudo.Matches(leaf1));
            Assert.False(FirstChildPseudo.Matches(leaf2));
        }
Example #5
0
        public void TestDefaultStyle()
        {
            Assert.Equal(Unit.FromPoint(12), StyleKeys.FontSize.Default);
            var text = new TextLeaf("text")
            {
                Document = new Scriber.Document()
            };
            var fontSize = text.Style.Get(StyleKeys.FontSize);

            Assert.Equal(12, fontSize.Point);
        }
Example #6
0
        public void NotSpan()
        {
            var pSelector = new TagStyleSelector("p");
            var not       = new NotPseudoClass(pSelector);
            var leaf      = new TextLeaf
            {
                Tag = "span"
            };

            Assert.False(pSelector.Matches(leaf));
            Assert.True(not.Matches(leaf));
        }
Example #7
0
        public void TestLocalContainer()
        {
            var doc  = new Scriber.Document();
            var text = new TextLeaf("text")
            {
                Document = doc,
            };

            text.Style.Set(StyleKeys.FontSize, Unit.FromPoint(20));
            var fontSize = text.Style.Get(StyleKeys.FontSize);

            Assert.Equal(20, fontSize.Point);
        }
Example #8
0
        public void TextLeafToParagraph()
        {
            var textLeaf  = new TextLeaf("text");
            var paragraph = converter.Convert(textLeaf, typeof(Paragraph));

            Assert.IsType <Paragraph>(paragraph);
            var par           = paragraph as Paragraph;
            var paragraphLeaf = par.Leaves[0];

            Assert.IsType <TextLeaf>(paragraphLeaf);
            var text = paragraphLeaf as TextLeaf;

            Assert.Equal("text", text.Content);
        }
Example #9
0
        public void TestParentContainer()
        {
            var doc = new Scriber.Document();

            Assert.True(StyleKeys.FontSize.Inherited);
            doc.Style.Set(StyleKeys.FontSize, Unit.FromPoint(20));
            var text = new TextLeaf("text")
            {
                Document = doc
            };

            text.Parent = doc;
            var fontSize = text.Style.Get(StyleKeys.FontSize);

            Assert.Equal(20, fontSize.Point);
        }
Example #10
0
        public void TestClassContainer()
        {
            var doc       = new Scriber.Document();
            var spanStyle = new StyleContainer(".class");

            doc.Styles.Add(spanStyle);
            var text = new TextLeaf("text")
            {
                Document = doc
            };

            text.Classes.Add("class");
            spanStyle.Set(StyleKeys.FontSize, Unit.FromPoint(20));
            var fontSize = text.Style.Get(StyleKeys.FontSize);

            Assert.Equal(20, fontSize.Point);
        }
        public void ParseCorrectly(string input, int step, int offset, params int[] indices)
        {
            var pseudoClass = new NthChildPseudoClass(input);

            Assert.Equal(step, pseudoClass.Step);
            Assert.Equal(offset, pseudoClass.Offset);

            var paragraph = new Paragraph();
            int max       = indices.Length == 0 ? 0 : indices.Max();

            Leaf[] leaves = new Leaf[max];
            for (int i = 0; i < max; i++)
            {
                leaves[i] = new TextLeaf();
            }
            paragraph.Leaves.AddRange(leaves);

            for (int i = 0; i < max; i++)
            {
                Assert.Equal(indices.Contains(i + 1), pseudoClass.Matches(leaves[i]));
            }
        }
Example #12
0
        private static Leaf ToLeaf(TextRun run)
        {
            var textLeaf = new TextLeaf(run.Text);

            if (run.FontStyle == Scriber.Bibliography.Styling.Formatting.FontStyle.Italic)
            {
                textLeaf.FontWeight = Text.FontWeight.Italic;
            }
            if (run.FontWeight == Scriber.Bibliography.Styling.Formatting.FontWeight.Bold)
            {
                textLeaf.FontWeight = Text.FontWeight.Bold;
            }

            textLeaf.FontStyle = run.VerticalAlign switch
            {
                Scriber.Bibliography.Styling.Formatting.VerticalAlign.Subscript => Text.FontStyle.Subscript,
                Scriber.Bibliography.Styling.Formatting.VerticalAlign.Superscript => Text.FontStyle.Superscript,
                _ => Text.FontStyle.Normal
            };

            return(textLeaf);
        }
    }
Example #13
0
        public static object Figure(CompilerState state, Argument[] content)
        {
            var section = new Region
            {
                Flexible = true,
                Margin   = new Layout.Thickness(12, 0)
            };

            var elements = content.Select(e => e.Value).OfType <DocumentElement>().ToArray();

            section.Elements.AddRange(elements);

            foreach (var caption in elements.OfType <Paragraph>().Where(e => Equals(e.Tag, "caption")))
            {
                var text = new TextLeaf
                {
                    Content = "Figure " + NextCaptionCount(state, "figure") + ": "
                };
                caption.Leaves.Insert(0, text);
            }

            return(section);
        }
Example #14
0
        public static Paragraph Section(CompilerState state, Paragraph content)
        {
            const int level = 1;

            var vars    = state.Document.Variables;
            var pretext = CreatePretext(vars, level);
            var entry   = new TableEntry
            {
                Content  = content,
                Preamble = pretext,
                Page     = new PageReference(content)
            };

            GetEntryTable(vars).Add(entry);
            ResetNumbering(vars, level);
            var text = new TextLeaf
            {
                Content = pretext + " "
            };

            content.Leaves.Insert(0, text);

            return(SectionStar(state, content));
        }