Пример #1
0
        public void Subtract_Test()
        {
            PDFUnit width  = new PDFUnit(10, PageUnits.Millimeters);
            PDFUnit height = new PDFUnit(20, PageUnits.Millimeters);
            PDFSize target = new PDFSize(width, height);

            PDFUnit m = new PDFUnit(5, PageUnits.Millimeters);

            PDFThickness margins  = new PDFThickness(m, m, m, m);
            PDFSize      expected = new PDFSize(new PDFUnit(0, PageUnits.Millimeters), new PDFUnit(10, PageUnits.Millimeters));
            PDFSize      actual;

            actual = target.Subtract(margins);
            Assert.AreEqual(expected.Width.PointsValue, actual.Width.PointsValue);
            Assert.AreEqual(Math.Round(expected.Height.PointsValue, 2), Math.Round(actual.Height.PointsValue, 2));
        }
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            PDFSize  prevSize  = context.Space;
            PDFPoint prevLoc   = context.Offset;
            Style    laststyle = context.FullStyle;

            PDFObjectRef oref;

            if (this.Owner is IPDFRenderComponent)
            {
                PDFPoint loc = context.Offset;
                loc = loc.Offset(this.TotalBounds.Location);
                PDFSize            size = this.TotalBounds.Size;
                PDFPositionOptions opts = this.PositionOptions;

                context.Offset = loc;
                context.Space  = size;

                if (opts.Margins.IsEmpty == false)
                {
                    loc  = loc.Offset(opts.Margins.Left, opts.Margins.Top);
                    size = size.Subtract(opts.Margins);
                }

                PDFPenBorders border = this.FullStyle.CreateBorderPen();


                PDFBrush background = this.FullStyle.CreateBackgroundBrush();

                PDFRect borderRect = new PDFRect(loc, size);
                if (null != background)
                {
                    this.OutputBackground(background, border.HasBorders? border.CornerRadius : null, context, borderRect);
                }


                if (opts.Padding.IsEmpty == false)
                {
                    loc  = loc.Offset(opts.Padding.Left, opts.Padding.Top);
                    size = size.Subtract(opts.Padding);
                }

                //Set the offset, size and full style on the context
                context.Offset    = loc;
                context.Space     = size;
                context.FullStyle = this.FullStyle;
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Begin(TraceLevel.Verbose, "Layout Item", "Beginning the rendering the referenced component " + this.Owner + " with context offset of " + context.Offset + " and space " + context.Space);
                }
                else if (context.ShouldLogVerbose)
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "Layout Item", "Rendering the referenced component " + this.Owner + " with context offset of " + context.Offset + " and space " + context.Space);
                }
                //Then make the component render itself
                oref = (this.Owner as IPDFRenderComponent).OutputToPDF(context, writer);

                Component owner = this.Owner as Component;
                if (null != owner)
                {
                    owner.SetArrangement(context, context.FullStyle, borderRect);
                }

                //finally if we have a border then write this
                if (null != border)
                {
                    this.OutputBorder(background, border, context, borderRect);
                }

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Verbose, "Layout Item", "Completed the rendering the referenced component " + this.Owner + " and arrangement set to border rect " + borderRect);
                }
            }
            else
            {
                oref = base.DoOutputToPDF(context, writer);
            }

            context.Space     = prevSize;
            context.Offset    = prevLoc;
            context.FullStyle = laststyle;

            return(oref);
        }