Example #1
0
 protected override void Draw(System.Windows.Forms.PaintEventArgs e)
 {
     if (this.active)
     {
         e.Graphics.Clear(this.SafeBackColor);
         var gr = DrawingGraphics.FromGraphicsAndRect(this.offGr, this.offBmp, new Rectangle(0, 0, this.offBmp.Width, this.offBmp.Height));
         this.elements.ForEach(element => element.Draw(gr.CreateChild(element.Location, element.TransformationScaling, element.TransformationCenter)));
         if (this.ShadowedAnimationMode != ShadowedAnimationOptions.None &&
             this.shadowImageX < this.offBmp.Width &&
             this.shadowImageX > -this.offBmp.Width * 3)
         {
             gr.DrawAlphaImage("righttransition.png", new Rectangle(this.shadowImageX, 0, this.offBmp.Width * 3, this.offBmp.Height).ToLogic());
         }
     }
     else
     {
         this.AnimateEntrance();
         this.active = true;
     }
 }
Example #2
0
        internal void SetupDocument(PrintDocument printDocument, IEnumerable <PaperSize> paperSizes)
        {
            bool firstPageSetupRequired = true;
            bool transformationRequired = true;

            // The setup and cleanup procedures must be executed by event handlers
            // because they are required for transformation, for preview and real printing.
            printDocument.BeginPrint += (_, printArgs) => firstPageSetupRequired = true;
            printDocument.EndPrint   += (_, printArgs) => this.CleanupGraphics();

            printDocument.PrintPage += (_, printArgs) => OnPrintPage(printArgs);
            void OnPrintPage(PrintPageEventArgs printPageEventArgs)
            {
                var graphics = new DrawingGraphics(printPageEventArgs);

                // Transformation is required only once before printing.
                // But for text wrapping the device context (graphics) is required.
                // This is only available withing this event handler.
                // Transformation is using Setup- and CleanupGraphics (internally).
                // Preview and Printing is using them too. So, we need to handle them all in this handler.
                if (transformationRequired)
                {
                    this.TransformDocument(graphics);
                    transformationRequired = false;
                }

                // After Transformation (SetupGraphics and) CleanupGraphics has been executed.
                // For Preview and Printing it required once again.
                if (firstPageSetupRequired)
                {
                    this.SetupGraphics();
                    firstPageSetupRequired = false;
                }

                // Page initialization
                this.ProcessNewPage();

                // Process all nodes for the current page
                this.PrintNodes(graphics);
            }

            this.printFactor = DefaultPrintFactor;
            var documentPaperSize = this.Document.DocumentElement.GetAttribute <string>(PaperSizeNode, "A4");
            var paperSize         = paperSizes.FirstOrDefault(
                s => s.PaperName.StartsWith(documentPaperSize, StringComparison.CurrentCultureIgnoreCase));

            if (paperSize != null)
            {
                printDocument.DefaultPageSettings.PaperSize = paperSize;
                this.DocumentWidth  = this.ToLogical(paperSize.Width);
                this.DocumentHeight = this.ToLogical(paperSize.Height);
            }
            else
            {
                this.DocumentWidth  = this.Document.DocumentElement.GetAttribute(WidthNode, A4Width);
                this.DocumentHeight = this.Document.DocumentElement.GetAttribute(HeightNode, A4Height);
                var documentScale = this.Document.DocumentElement.GetAttribute(ScaleNode, 1.0);
                this.printFactor *= documentScale;
                int width  = this.ToPhysical(this.DocumentWidth);
                int height = this.ToPhysical(this.DocumentHeight);
                printDocument.DefaultPageSettings.PaperSize = new PaperSize(documentPaperSize, width, height);
            }

            printDocument.DefaultPageSettings.Landscape =
                this.Document.DocumentElement.GetAttribute(LandscapeNode, false);
            if (printDocument.DefaultPageSettings.Landscape)
            {
                // "rotate" paper
                int newHeight = this.DocumentWidth;
                this.DocumentWidth  = this.DocumentHeight;
                this.DocumentHeight = newHeight;
            }

            this.DocumentLeftMargin   = this.Document.DocumentElement.GetAttribute(LeftNode, 0);
            this.DocumentTopMargin    = this.Document.DocumentElement.GetAttribute(TopNode, 0);
            this.DocumentBottomMargin = this.Document.DocumentElement.GetAttribute(BottomNode, 0);

            this.ProcessNewPage();
        }