Exemple #1
0
            public void PushStyle(TextStyle style, ref Boolean bold, ref Boolean italic)
            {
                var instance = new TextStyleInstance(style, bold, italic);

                StyleStack.Push(instance);

                if (style.Font != null)
                {
                    PushFont(style.Font);
                }

                if (style.Color.HasValue)
                {
                    PushColor(style.Color.Value);
                }

                if (style.GlyphShaders.Count > 0)
                {
                    foreach (var glyphShader in style.GlyphShaders)
                    {
                        PushGlyphShader(glyphShader);
                    }
                }

                if (style.Bold.HasValue)
                {
                    bold = style.Bold.Value;
                }

                if (style.Italic.HasValue)
                {
                    italic = style.Italic.Value;
                }
            }
        private Node CreateGraphNode(Block b)
        {
            var nl        = "\n    ";
            var model     = GenerateTextModel(b);
            var stack     = new StyleStack(uiPreferences);
            var layout    = TextViewLayout.AllLines(model, g, defaultFont, stack);
            var blockNode = new CfgBlockNode {
                Block         = b,
                TextModel     = GenerateTextModel(b),
                Layout        = layout,
                UiPreferences = uiPreferences,
            };
            var node = graph.AddNode(b.Name);

            node.Attr.LabelMargin = 5;
            node.UserData         = blockNode;
            if (useTextEngine)
            {
                node.Attr.Shape           = Shape.DrawFromGeometry;
                node.DrawNodeDelegate     = blockNode.DrawNode;
                node.NodeBoundaryDelegate = blockNode.GetNodeBoundary;
            }
            else
            {
                node.Label.FontName = "Lucida Console";
                node.Label.FontSize = 10f;
                node.LabelText      =
                    b.Name + nl +
                    string.Join(nl, b.Statements.Select(s => s.Instruction));
            }
            return(node);
        }
Exemple #3
0
        public void CountTest()
        {
            Style      root   = new Style();
            StyleStack target = new StyleStack(root);

            Assert.AreEqual(1, target.Count);

            Style one = new Style();

            target.Push(one);
            Assert.AreEqual(2, target.Count);

            Style two = new Style();

            target.Push(two);
            Assert.AreEqual(3, target.Count);

            target.Pop();
            Assert.AreEqual(2, target.Count);

            target.Pop();
            Assert.AreEqual(1, target.Count);

            target.Pop();
            Assert.AreEqual(0, target.Count);
        }
Exemple #4
0
        public void CloneTest()
        {
            Style      root   = new Style();
            StyleStack target = new StyleStack(root);

            Style one = new Style();

            target.Push(one);

            Style two = new Style();

            target.Push(two);

            StyleStack expected = target;
            StyleStack actual;

            actual = target.Clone();

            //pop them off in sequence

            Style popped = expected.Pop();

            Assert.AreEqual(popped, actual.Pop());

            popped = expected.Pop();
            Assert.AreEqual(popped, actual.Pop());

            popped = expected.Pop();
            Assert.AreEqual(popped, actual.Pop());
        }
Exemple #5
0
        public void Stst_DoubleStyles()
        {
            styles.Add("style1", new UiStyle
            {
                Background = new SolidBrush(Color.FromArgb(0x12, 0x34, 0x56))
            });
            styles.Add("style2", new UiStyle
            {
                PaddingBottom = 6.0f
            });
            mr.ReplayAll();

            var stst = new StyleStack(uiPrefs);

            stst.PushStyle("style1 style2");

            var br = stst.GetBackground(Color.Black);

            Assert.AreEqual(0x12, br.Color.R);
            Assert.AreEqual(0x34, br.Color.G);
            Assert.AreEqual(0x56, br.Color.B);
            var padding = stst.GetNumber(u => u.PaddingBottom);

            Assert.AreEqual(6.0f, padding);
        }
        public override PDFGraphics CreateGraphics(PDFWriter writer, StyleStack styles, PDFContextBase context)
        {
            Style    full = styles.GetFullStyle(this);
            PageSize size = this.GetPageSize(full);

            return(PDFGraphics.Create(writer, false, this, DrawingOrigin.TopLeft, size.Size, context));
        }
Exemple #7
0
 /// <summary>
 /// Clears all of the renderer's layout parameter stacks.
 /// </summary>
 public void ClearLayoutStacks()
 {
     StyleStack.Clear();
     FontStack.Clear();
     ColorStack.Clear();
     GlyphShaderStack.Clear();
     LinkStack.Clear();
 }
Exemple #8
0
        public void PDFStyleStackConstructorTest()
        {
            Style      root   = new Style();
            StyleStack target = new StyleStack(root);

            Assert.IsNotNull(target);
            Assert.IsNotNull(target.Current);
            Assert.AreEqual(root, target.Current);
        }
Exemple #9
0
        public void Stst_Default()
        {
            var stst = new StyleStack(uiPrefs.Object);

            var br = stst.GetBackground(Color.FromArgb(0x12, 0x23, 0x45));

            Assert.AreEqual(0x12, br.Color.R);
            Assert.AreEqual(0x23, br.Color.G);
            Assert.AreEqual(0x45, br.Color.B);
        }
Exemple #10
0
            public void PopStyle(ref Boolean bold, ref Boolean italic)
            {
                if (StyleStack.Count > 0)
                {
                    PopStyleScope();

                    var instance = StyleStack.Pop();
                    bold   = instance.Bold;
                    italic = instance.Italic;
                }
            }
 /// <summary>
 /// Creates a new PDFGraphics context within which drawing to the PDF Surface can take place
 /// </summary>
 /// <param name="writer">The writer used to write graphical instructions to</param>
 /// <param name="styles">The styles of the new graphics context</param>
 /// <returns>A newly instantiated graphics context</returns>
 public virtual PDFGraphics CreateGraphics(PDFWriter writer, StyleStack styles, PDFContextBase context)
 {
     if (this.Parent == null)
     {
         throw RecordAndRaise.NullReference(Errors.InvalidCallToGetGraphicsForStructure);
     }
     else
     {
         return(this.Parent.CreateGraphics(writer, styles, context));
     }
 }
Exemple #12
0
        public void Stst_SingleStyle()
        {
            styles.Add("style1", new UiStyle {
                Background = new SolidBrush(Color.FromArgb(0x12, 0x34, 0x56))
            });

            var stst = new StyleStack(uiPrefs.Object);

            stst.PushStyle("style1");

            var br = stst.GetBackground(Color.Black);

            Assert.AreEqual(0x12, br.Color.R);
            Assert.AreEqual(0x34, br.Color.G);
            Assert.AreEqual(0x56, br.Color.B);
        }
Exemple #13
0
        public void CurrentTest()
        {
            Style      root   = new Style();
            StyleStack target = new StyleStack(root);

            Assert.AreEqual(root, target.Current);

            Style one = new Style();

            target.Push(one);
            Assert.AreEqual(one, target.Current);

            Style two = new Style();

            target.Push(two);
            Assert.AreEqual(two, target.Current);
        }
        /// <summary>
        /// Based on the sizeing and style of the last page buids a continuation page that content can flow into
        /// </summary>
        /// <param name="copyfrom"></param>
        /// <returns></returns>
        protected virtual PDFLayoutPage BuildContinuationPage(PDFLayoutPage copyfrom, PDFSize size)
        {
            //Take a reference of the current stack and replace with the page stack from first page
            StyleStack orig = this.Context.StyleStack;

            this.Context.StyleStack = this.PageStyleStack;



            PDFLayoutPage page = this.BuildNewPage(size, copyfrom.PositionOptions, copyfrom.ContentBlock.ColumnOptions, copyfrom.OverflowAction);

            //becasue we are a continuation page, we have the same number style, so let's just register it with null
            this.DocumentLayout.RegisterPageNumbering(page, null);

            this.LayoutPageHeaderAndFooter();

            //Restore the context stack with the reference
            this.Context.StyleStack = orig;

            return(page);
        }
Exemple #15
0
        public void PopTest()
        {
            Style      root   = new Style();
            StyleStack target = new StyleStack(root);

            Style one = new Style();

            target.Push(one);

            Style two = new Style();

            target.Push(two);

            Style expected = two;
            Style actual;

            actual = target.Pop();
            Assert.AreEqual(expected, actual);

            expected = one;
            actual   = target.Pop();
            Assert.AreEqual(expected, actual);

            expected = root;
            actual   = target.Pop();
            Assert.AreEqual(expected, actual);

            try
            {
                actual = target.Pop();
                throw new ArgumentException("Stack should be empty");
            }
            catch (InvalidOperationException)
            {
                //Successfully thrown empty stack exception
            }
        }
Exemple #16
0
        public void GetFullStyleTest()
        {
            Style root = new Style();

            root.Background.Color = PDFColors.Red;             //Not inherited
            root.Font.FontFamily  = (PDFFontSelector)"Symbol"; //Font is inherited
            root.Font.FontSize    = 20;                        //Font is inherited

            StyleStack target = new StyleStack(root);

            Style one = new Style();

            one.Background.FillStyle = FillType.Pattern; //Background is not inherited
            one.Border.Width         = 2;                //Border is not inherited
            one.Font.FontSize        = 48;               //Font is inherited - override root
            target.Push(one);

            //last item will always be merged in a full style - actual, not inherited values
            Style two = new Style();

            two.Border.Color    = PDFColors.Lime;
            two.Border.Width    = 3;
            two.Font.FontItalic = true;
            target.Push(two);

            Label lbl    = new Label();
            Style actual = target.GetFullStyle(lbl);

            Assert.AreEqual("Symbol", actual.Font.FontFamily.FamilyName);   //inherited from root
            Assert.AreEqual((PDFUnit)48, actual.Font.FontSize);             //inherited from one
            Assert.AreEqual((PDFUnit)3, actual.Border.Width);               //border from two
            Assert.AreEqual(PDFColors.Lime, actual.Border.Color);           //border from two
            Assert.AreEqual(true, actual.Font.FontItalic);                  //font from two
            Assert.AreEqual(PDFColor.Transparent, actual.Background.Color); //not inherited from root
            Assert.AreEqual(FillType.None, actual.Background.FillStyle);    //not inherited from one
        }
        //
        // private and protected methods
        //

        #region protected PDFGraphics CreateGraphics(PDFStyleStack styles) + 1 overload

        /// <summary>
        /// Creates a new PDFGraphics context within which drawing to the PDF Surface can take place
        /// </summary>
        /// <param name="styles">The styles of the new graphics context</param>
        /// <returns>A newly instantiated graphics context</returns>
        public PDFGraphics CreateGraphics(StyleStack styles, PDFContextBase context)
        {
            return(this.CreateGraphics(null, styles, context));
        }
Exemple #18
0
 protected virtual PDFGraphics CreateGraphics(PDFWriter writer, StyleStack styles, PDFRenderContext context)
 {
     return(PDFGraphics.Create(writer, false, this, DrawingOrigin.TopLeft, this.Size, context));
 }