internal void PrintHeaderFooter(Graphics graphics, bool drawHeader, HeaderFooterData headerFooterPrintData)
        {
            string text = drawHeader ? this.pageSetupData.HeaderTemplate : this.pageSetupData.FooterTemplate;

            string[]      strArray = text.Replace("{#}", headerFooterPrintData.CurrentPage.ToString(CultureInfo.CurrentCulture)).Replace("{##}", headerFooterPrintData.TotalPages.ToString(CultureInfo.CurrentCulture)).Replace("{Date}", headerFooterPrintData.PrintTime.ToShortDateString()).Replace("{Time}", headerFooterPrintData.PrintTime.ToShortTimeString()).Replace("{FullFileName}", headerFooterPrintData.FileName).Replace("{FileName}", Path.GetFileName(headerFooterPrintData.FileName)).Replace("{User}", SystemInformation.UserName).Split(new char[] { '\n', '\r' }, 6, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder builder  = new StringBuilder();

            for (int i = 0; i < Math.Min(strArray.Length, 5); i++)
            {
                builder.Append(strArray[i]);
                builder.Append("\r\n");
            }
            text = builder.ToString();
            Rectangle empty = Rectangle.Empty;
            SizeF     ef    = graphics.MeasureString(text, headerFooterPrintData.Font);
            int       width = Convert.ToInt32(Math.Ceiling((double)ef.Width));

            empty.Size  = new Size(width, Convert.ToInt32(Math.Ceiling((double)ef.Height)));
            empty.Width = Math.Min(headerFooterPrintData.PageBoundsWithoutMargin.Width, empty.Width);
            HorizontalAlignment alignment = drawHeader ? this.pageSetupData.HeaderAlignment : this.pageSetupData.FooterAlignment;
            StringFormat        format    = new StringFormat {
                Trimming = StringTrimming.EllipsisCharacter
            };

            switch (alignment)
            {
            case HorizontalAlignment.Left:
                empty.X          = headerFooterPrintData.PageBoundsWithoutMargin.Left;
                format.Alignment = StringAlignment.Near;
                break;

            case HorizontalAlignment.Right:
                empty.X          = headerFooterPrintData.PageBoundsWithoutMargin.Left + (headerFooterPrintData.PageBoundsWithoutMargin.Width - empty.Width);
                format.Alignment = StringAlignment.Far;
                break;

            case HorizontalAlignment.Center:
                empty.X          = headerFooterPrintData.PageBoundsWithoutMargin.Left + ((headerFooterPrintData.PageBoundsWithoutMargin.Width - empty.Width) / 2);
                format.Alignment = StringAlignment.Center;
                break;
            }
            if (drawHeader)
            {
                empty.Y = headerFooterPrintData.PageBounds.Top + headerFooterPrintData.HeaderFooterMargins.Top;
                format.LineAlignment = StringAlignment.Near;
            }
            else
            {
                empty.Y = (headerFooterPrintData.PageBounds.Bottom - headerFooterPrintData.HeaderFooterMargins.Bottom) - empty.Size.Height;
                format.LineAlignment = StringAlignment.Far;
            }
            graphics.DrawString(text, headerFooterPrintData.Font, WorkflowTheme.CurrentTheme.AmbientTheme.ForegroundBrush, empty, format);
        }
        internal void PrintHeaderFooter(Graphics graphics, bool drawHeader, HeaderFooterData headerFooterPrintData)
        {
            //Format the header/footer
            string headerFooter = (drawHeader) ? this.pageSetupData.HeaderTemplate : this.pageSetupData.FooterTemplate;

            //these are the new format strings
            headerFooter = headerFooter.Replace("{#}", headerFooterPrintData.CurrentPage.ToString(CultureInfo.CurrentCulture));
            headerFooter = headerFooter.Replace("{##}", headerFooterPrintData.TotalPages.ToString(CultureInfo.CurrentCulture));
            headerFooter = headerFooter.Replace("{Date}", headerFooterPrintData.PrintTime.ToShortDateString());
            headerFooter = headerFooter.Replace("{Time}", headerFooterPrintData.PrintTime.ToShortTimeString());
            headerFooter = headerFooter.Replace("{FullFileName}", headerFooterPrintData.FileName);
            headerFooter = headerFooter.Replace("{FileName}", Path.GetFileName(headerFooterPrintData.FileName));
            headerFooter = headerFooter.Replace("{User}", SystemInformation.UserName);

            //limit the string to 5 lines of text max
            string[] headerFooterLines = headerFooter.Split(new char[] { '\n', '\r' }, MaxHeaderFooterLines + 1, StringSplitOptions.RemoveEmptyEntries);
            System.Text.StringBuilder text = new System.Text.StringBuilder();
            for (int i = 0; i < Math.Min(headerFooterLines.Length, MaxHeaderFooterLines); i++)
            {
                text.Append(headerFooterLines[i]);
                text.Append("\r\n");
            }
            headerFooter = text.ToString();

            //Measure the header /footer string
            Rectangle layoutRectangle = Rectangle.Empty;
            SizeF stringSize = graphics.MeasureString(headerFooter, headerFooterPrintData.Font);
            layoutRectangle.Size = new Size(Convert.ToInt32(Math.Ceiling((stringSize.Width))), Convert.ToInt32(Math.Ceiling((stringSize.Height))));
            layoutRectangle.Width = Math.Min(headerFooterPrintData.PageBoundsWithoutMargin.Width, layoutRectangle.Width);

            HorizontalAlignment alignment = (drawHeader) ? this.pageSetupData.HeaderAlignment : this.pageSetupData.FooterAlignment;
            StringFormat stringFormat = new StringFormat();
            stringFormat.Trimming = StringTrimming.EllipsisCharacter;
            switch (alignment)
            {
                case HorizontalAlignment.Left:
                    layoutRectangle.X = headerFooterPrintData.PageBoundsWithoutMargin.Left;
                    stringFormat.Alignment = StringAlignment.Near;
                    break;

                case HorizontalAlignment.Center:
                    layoutRectangle.X = headerFooterPrintData.PageBoundsWithoutMargin.Left + ((headerFooterPrintData.PageBoundsWithoutMargin.Width - layoutRectangle.Width) / 2); //align to the middle
                    stringFormat.Alignment = StringAlignment.Center;
                    break;

                case HorizontalAlignment.Right:
                    layoutRectangle.X = headerFooterPrintData.PageBoundsWithoutMargin.Left + (headerFooterPrintData.PageBoundsWithoutMargin.Width - layoutRectangle.Width); //align to the right corner
                    stringFormat.Alignment = StringAlignment.Far;
                    break;
            }

            //Align header footer vertically
            if (drawHeader)
            {
                layoutRectangle.Y = headerFooterPrintData.PageBounds.Top + headerFooterPrintData.HeaderFooterMargins.Top;
                stringFormat.LineAlignment = StringAlignment.Near;
            }
            else
            {
                layoutRectangle.Y = headerFooterPrintData.PageBounds.Bottom - headerFooterPrintData.HeaderFooterMargins.Bottom - layoutRectangle.Size.Height;
                stringFormat.LineAlignment = StringAlignment.Far;
            }

            //Draw header/footer string
            graphics.DrawString(headerFooter, headerFooterPrintData.Font, WorkflowTheme.CurrentTheme.AmbientTheme.ForegroundBrush, layoutRectangle, stringFormat);
        }
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);

            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;

            Graphics graphics = printPageArg.Graphics;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode = SmoothingMode.HighQuality;

            //STEP1: We get the printer graphics only in the OnPrintPage function hence for layouting we need to call this function
            if (this.currentPrintablePage.IsEmpty)
                PrepareToPrint(printPageArg);

            //STEP2: GET ALL THE VALUES NEEDED FOR CALCULATION
            Margins hardMargins = GetHardMargins(graphics);
            Margins margins = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left),
                                          Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right),
                                          Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top),
                                          Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size printableArea = new Size(printPageArg.PageBounds.Size.Width - (margins.Left + margins.Right), printPageArg.PageBounds.Size.Height - (margins.Top + margins.Bottom));
            Rectangle boundingRectangle = new Rectangle(margins.Left, margins.Top, printableArea.Width, printableArea.Height);
            Region clipRegion = new Region(boundingRectangle);

            try
            {
                graphics.TranslateTransform(-hardMargins.Left, -hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, boundingRectangle);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, boundingRectangle);

                //Draw the watermark image
                if (ambientTheme.WorkflowWatermarkImage != null)
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, boundingRectangle, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, AmbientTheme.WatermarkTransparency, false);

                Matrix oldTransform = graphics.Transform;
                Region oldClipRegion = graphics.Clip;
                graphics.Clip = clipRegion;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                //STEP3: PRINT
                //Printer bitmap starts at the unprintable top left corner, hence, need to take it into account - move by the unprintable area:
                //Setup the translation and scaling for the page printing
                Point pageOffset = new Point(this.currentPrintablePage.X * printableArea.Width - this.workflowAlignment.X, this.currentPrintablePage.Y * printableArea.Height - this.workflowAlignment.Y);
                graphics.TranslateTransform(boundingRectangle.Left - pageOffset.X, boundingRectangle.Top - pageOffset.Y);
                graphics.ScaleTransform(this.scaling, this.scaling);

                //Calculate the viewport by reverse scaling the printable area size
                Size viewPortSize = Size.Empty;
                viewPortSize.Width = Convert.ToInt32(Math.Ceiling((float)printableArea.Width / this.scaling));
                viewPortSize.Height = Convert.ToInt32(Math.Ceiling((float)printableArea.Height / this.scaling));

                Point scaledAlignment = Point.Empty;
                scaledAlignment.X = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.X / this.scaling));
                scaledAlignment.Y = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.Y / this.scaling));

                Rectangle viewPort = new Rectangle(this.currentPrintablePage.X * viewPortSize.Width - scaledAlignment.X, this.currentPrintablePage.Y * viewPortSize.Height - scaledAlignment.Y, viewPortSize.Width, viewPortSize.Height);

                using (PaintEventArgs paintEventArgs = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(paintEventArgs, viewPort);
                }

                graphics.Clip = oldClipRegion;
                graphics.Transform = oldTransform;

                //Now prepare the graphics for header footer printing
                HeaderFooterData headerFooterData = new HeaderFooterData();
                headerFooterData.Font = ambientTheme.Font;
                headerFooterData.PageBounds = printPageArg.PageBounds;
                headerFooterData.PageBoundsWithoutMargin = boundingRectangle;
                headerFooterData.HeaderFooterMargins = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin);
                headerFooterData.PrintTime = this.printTime;
                headerFooterData.CurrentPage = this.currentPrintablePage.X + this.currentPrintablePage.Y * this.totalPrintablePages.X + 1;
                headerFooterData.TotalPages = this.totalPrintablePages.X * this.totalPrintablePages.Y;
                headerFooterData.Scaling = this.scaling;
                WorkflowDesignerLoader serviceDesignerLoader = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterData.FileName = (serviceDesignerLoader != null) ? serviceDesignerLoader.FileName : String.Empty;

                //Print the header
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                    PrintHeaderFooter(graphics, true, headerFooterData);

                //footer
                if (this.pageSetupData.FooterTemplate.Length > 0)
                    PrintHeaderFooter(graphics, false, headerFooterData);

                //are there more pages left?
                printPageArg.HasMorePages = MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString(DR.SelectedPrinterIsInvalidErrorMessage) + "\n" + exception.Message);
                printPageArg.Cancel = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                clipRegion.Dispose();
            }

            if (!printPageArg.HasMorePages)
                this.workflowView.PerformLayout(); //no more pages - redo regular layout using screen graphics
        }
示例#4
0
        public ExtendedXlsFile TestExecuteBalansHierLev0_Valtage_220_330_Full(BalansHierLev0Result HierLev0,
                                                                              TExportExcelAdapterType ExportType, IVisualDataRequestObjectsNames getNameInterface)
        {
            Dictionary <ID_TypeHierarchy, string> dictionaryOfNames = HierLev0.DictionaryOfNames;
            InitData     data         = new InitData(HierLev0.VoltageClassPoints);
            InternalData internalData = new InternalData(ExportType);
            InitBlock    initBlock    = new InitBlock(data, internalData);

            Classes.TitleInfo titleData =
                new Classes.TitleInfo(getNameInterface.GetBalanceNameForHierLev0(HierLev0.BalanceId), HierLev0.DTStart, HierLev0.DTEnd);
            TitleBlock titleBlock = new TitleBlock(titleData);

            initBlock.AddBlock(titleBlock);
            HeaderFooterData  headFootData = new HeaderFooterData(HierLev0.VoltageClass, HierLev0.HighLimit);
            HeaderFooterBlock headerFooter = new HeaderFooterBlock(headFootData, internalData);

            initBlock.AddBlock(headerFooter);

            foreach (TIntegral_HierLev0_Values balanceSection in HierLev0.Result_Values)
            {
                BalancePartData balData = new BalancePartData(getNameInterface.GetBalanceSectionName(balanceSection.HierLev0Group_Name),
                                                              HierLev0.BalPartList.Where(x => x.IsUseInGeneralBalance).Select(x => x.Name).Contains(balanceSection.HierLev0Group_Name),
                                                              HierLev0.BalPartList.Where(x => x.IsRsk).Select(x => x.Name).Contains(balanceSection.HierLev0Group_Name));

                BalancePartBlock balPartBlock = new BalancePartBlock(balData, internalData);
                foreach (KeyValuePair <ID_IsOurSide, TIntegral_PS_ValuesForHierLev0> psBalSect in balanceSection.HierLev0DetailGroupResult)
                {
                    string psName;
                    TIntegral_PS_ValuesForHierLev0 psBalSectData = psBalSect.Value;
                    ID_IsOurSide     side = psBalSect.Key;
                    ID_TypeHierarchy key  = new ID_TypeHierarchy(enumTypeHierarchy.Dict_PS, -1);
                    key.TypeHierarchy = side.IsOurSide ? enumTypeHierarchy.Dict_PS : enumTypeHierarchy.Dict_Contr_PS;
                    key.ID            = side.ID;

                    if (!dictionaryOfNames.TryGetValue(key, out psName))
                    {
                        psName = getNameInterface.GetPSName(side.ID, !side.IsOurSide);
                    }
                    PsBlock psBlock = new PsBlock(psName, internalData);
                    foreach (TI_Integral_ValuesForHierLev0 tiPsBalSect in psBalSectData.TI_List)
                    {
                        string tIName = string.Empty;
                        key.TypeHierarchy = tiPsBalSect.TypeHierarchy;
                        key.ID            = tiPsBalSect.ID;
                        if (!dictionaryOfNames.TryGetValue(key, out tIName))
                        {
                            switch (tiPsBalSect.TypeHierarchy)
                            {
                            case enumTypeHierarchy.Dict_PS:
                                tIName = getNameInterface.GetPSName(tiPsBalSect.ID, !side.IsOurSide);
                                break;

                            case enumTypeHierarchy.Info_TI:
                                tIName = getNameInterface.GetTIName(tiPsBalSect.ID, false);
                                break;

                            case enumTypeHierarchy.Info_ContrTI:
                                tIName = getNameInterface.GetTIName(tiPsBalSect.ID, true);
                                break;

                            case enumTypeHierarchy.Info_TP:
                                tIName = getNameInterface.GetTPName(tiPsBalSect.ID);
                                break;
                            }
                        }

                        List <TVALUES_DB> inputValues;
                        List <TVALUES_DB> outputValues;
                        Data.Full.TiData  tiData = new Data.Full.TiData(tIName);
                        if (tiPsBalSect.Val_List.TryGetValue(1, out inputValues))
                        {
                            tiData.InputByVoltages.Add(tiPsBalSect.VoltageClassPoint, inputValues[0]);
                        }
                        if (tiPsBalSect.Val_List.TryGetValue(2, out outputValues))
                        {
                            tiData.OutputByVoltages.Add(tiPsBalSect.VoltageClassPoint, outputValues[0]);
                        }

                        TiBlock tiBlock = new TiBlock(tiData, internalData);
                        psBlock.AddBlock(tiBlock);
                    }
                    balPartBlock.AddBlock(psBlock);
                }
                headerFooter.AddBlock(balPartBlock);
            }

            ExtendedXlsFile xls = new ExtendedXlsFile(ExportType);

            initBlock.Render(xls);

            return(xls);
        }
 protected override void OnPrintPage(PrintPageEventArgs printPageArg)
 {
     base.OnPrintPage(printPageArg);
     AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
     Graphics graphics = printPageArg.Graphics;
     graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
     graphics.SmoothingMode = SmoothingMode.HighQuality;
     if (this.currentPrintablePage.IsEmpty)
     {
         this.PrepareToPrint(printPageArg);
     }
     Margins hardMargins = this.GetHardMargins(graphics);
     Margins margins2 = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left), Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right), Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top), Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
     Size size = new Size(printPageArg.PageBounds.Size.Width - (margins2.Left + margins2.Right), printPageArg.PageBounds.Size.Height - (margins2.Top + margins2.Bottom));
     Rectangle rect = new Rectangle(margins2.Left, margins2.Top, size.Width, size.Height);
     Region region = new Region(rect);
     try
     {
         graphics.TranslateTransform((float) -hardMargins.Left, (float) -hardMargins.Top);
         graphics.FillRectangle(ambientTheme.BackgroundBrush, rect);
         graphics.DrawRectangle(ambientTheme.ForegroundPen, rect);
         if (ambientTheme.WorkflowWatermarkImage != null)
         {
             ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, rect, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, 0.25f, false);
         }
         Matrix transform = graphics.Transform;
         Region clip = graphics.Clip;
         graphics.Clip = region;
         graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
         Point point = new Point((this.currentPrintablePage.X * size.Width) - this.workflowAlignment.X, (this.currentPrintablePage.Y * size.Height) - this.workflowAlignment.Y);
         graphics.TranslateTransform((float) (rect.Left - point.X), (float) (rect.Top - point.Y));
         graphics.ScaleTransform(this.scaling, this.scaling);
         Size empty = Size.Empty;
         empty.Width = Convert.ToInt32(Math.Ceiling((double) (((float) size.Width) / this.scaling)));
         empty.Height = Convert.ToInt32(Math.Ceiling((double) (((float) size.Height) / this.scaling)));
         Point point2 = Point.Empty;
         point2.X = Convert.ToInt32(Math.Ceiling((double) (((float) this.workflowAlignment.X) / this.scaling)));
         point2.Y = Convert.ToInt32(Math.Ceiling((double) (((float) this.workflowAlignment.Y) / this.scaling)));
         Rectangle viewPort = new Rectangle((this.currentPrintablePage.X * empty.Width) - point2.X, (this.currentPrintablePage.Y * empty.Height) - point2.Y, empty.Width, empty.Height);
         using (PaintEventArgs args = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
         {
             ((IWorkflowDesignerMessageSink) this.workflowView.RootDesigner).OnPaint(args, viewPort);
         }
         graphics.Clip = clip;
         graphics.Transform = transform;
         HeaderFooterData headerFooterPrintData = new HeaderFooterData {
             Font = ambientTheme.Font,
             PageBounds = printPageArg.PageBounds,
             PageBoundsWithoutMargin = rect,
             HeaderFooterMargins = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin),
             PrintTime = this.printTime,
             CurrentPage = (this.currentPrintablePage.X + (this.currentPrintablePage.Y * this.totalPrintablePages.X)) + 1,
             TotalPages = this.totalPrintablePages.X * this.totalPrintablePages.Y,
             Scaling = this.scaling
         };
         WorkflowDesignerLoader service = ((IServiceProvider) this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
         headerFooterPrintData.FileName = (service != null) ? service.FileName : string.Empty;
         if (this.pageSetupData.HeaderTemplate.Length > 0)
         {
             this.PrintHeaderFooter(graphics, true, headerFooterPrintData);
         }
         if (this.pageSetupData.FooterTemplate.Length > 0)
         {
             this.PrintHeaderFooter(graphics, false, headerFooterPrintData);
         }
         printPageArg.HasMorePages = this.MoveNextPage();
     }
     catch (Exception exception)
     {
         DesignerHelpers.ShowError(this.workflowView, DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]) + "\n" + exception.Message);
         printPageArg.Cancel = true;
         printPageArg.HasMorePages = false;
     }
     finally
     {
         region.Dispose();
     }
     if (!printPageArg.HasMorePages)
     {
         this.workflowView.PerformLayout();
     }
 }
        internal void PrintHeaderFooter(Graphics graphics, bool drawHeader, HeaderFooterData headerFooterPrintData)
        {
            string text = drawHeader ? this.pageSetupData.HeaderTemplate : this.pageSetupData.FooterTemplate;
            string[] strArray = text.Replace("{#}", headerFooterPrintData.CurrentPage.ToString(CultureInfo.CurrentCulture)).Replace("{##}", headerFooterPrintData.TotalPages.ToString(CultureInfo.CurrentCulture)).Replace("{Date}", headerFooterPrintData.PrintTime.ToShortDateString()).Replace("{Time}", headerFooterPrintData.PrintTime.ToShortTimeString()).Replace("{FullFileName}", headerFooterPrintData.FileName).Replace("{FileName}", Path.GetFileName(headerFooterPrintData.FileName)).Replace("{User}", SystemInformation.UserName).Split(new char[] { '\n', '\r' }, 6, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < Math.Min(strArray.Length, 5); i++)
            {
                builder.Append(strArray[i]);
                builder.Append("\r\n");
            }
            text = builder.ToString();
            Rectangle empty = Rectangle.Empty;
            SizeF ef = graphics.MeasureString(text, headerFooterPrintData.Font);
            int width = Convert.ToInt32(Math.Ceiling((double) ef.Width));
            empty.Size = new Size(width, Convert.ToInt32(Math.Ceiling((double) ef.Height)));
            empty.Width = Math.Min(headerFooterPrintData.PageBoundsWithoutMargin.Width, empty.Width);
            HorizontalAlignment alignment = drawHeader ? this.pageSetupData.HeaderAlignment : this.pageSetupData.FooterAlignment;
            StringFormat format = new StringFormat {
                Trimming = StringTrimming.EllipsisCharacter
            };
            switch (alignment)
            {
                case HorizontalAlignment.Left:
                    empty.X = headerFooterPrintData.PageBoundsWithoutMargin.Left;
                    format.Alignment = StringAlignment.Near;
                    break;

                case HorizontalAlignment.Right:
                    empty.X = headerFooterPrintData.PageBoundsWithoutMargin.Left + (headerFooterPrintData.PageBoundsWithoutMargin.Width - empty.Width);
                    format.Alignment = StringAlignment.Far;
                    break;

                case HorizontalAlignment.Center:
                    empty.X = headerFooterPrintData.PageBoundsWithoutMargin.Left + ((headerFooterPrintData.PageBoundsWithoutMargin.Width - empty.Width) / 2);
                    format.Alignment = StringAlignment.Center;
                    break;
            }
            if (drawHeader)
            {
                empty.Y = headerFooterPrintData.PageBounds.Top + headerFooterPrintData.HeaderFooterMargins.Top;
                format.LineAlignment = StringAlignment.Near;
            }
            else
            {
                empty.Y = (headerFooterPrintData.PageBounds.Bottom - headerFooterPrintData.HeaderFooterMargins.Bottom) - empty.Size.Height;
                format.LineAlignment = StringAlignment.Far;
            }
            graphics.DrawString(text, headerFooterPrintData.Font, WorkflowTheme.CurrentTheme.AmbientTheme.ForegroundBrush, empty, format);
        }
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);
            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
            Graphics     graphics     = printPageArg.Graphics;

            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;
            if (this.currentPrintablePage.IsEmpty)
            {
                this.PrepareToPrint(printPageArg);
            }
            Margins   hardMargins = this.GetHardMargins(graphics);
            Margins   margins2    = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left), Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right), Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top), Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size      size        = new Size(printPageArg.PageBounds.Size.Width - (margins2.Left + margins2.Right), printPageArg.PageBounds.Size.Height - (margins2.Top + margins2.Bottom));
            Rectangle rect        = new Rectangle(margins2.Left, margins2.Top, size.Width, size.Height);
            Region    region      = new Region(rect);

            try
            {
                graphics.TranslateTransform((float)-hardMargins.Left, (float)-hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, rect);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, rect);
                if (ambientTheme.WorkflowWatermarkImage != null)
                {
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, rect, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, 0.25f, false);
                }
                Matrix transform = graphics.Transform;
                Region clip      = graphics.Clip;
                graphics.Clip = region;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                Point point = new Point((this.currentPrintablePage.X * size.Width) - this.workflowAlignment.X, (this.currentPrintablePage.Y * size.Height) - this.workflowAlignment.Y);
                graphics.TranslateTransform((float)(rect.Left - point.X), (float)(rect.Top - point.Y));
                graphics.ScaleTransform(this.scaling, this.scaling);
                Size empty = Size.Empty;
                empty.Width  = Convert.ToInt32(Math.Ceiling((double)(((float)size.Width) / this.scaling)));
                empty.Height = Convert.ToInt32(Math.Ceiling((double)(((float)size.Height) / this.scaling)));
                Point point2 = Point.Empty;
                point2.X = Convert.ToInt32(Math.Ceiling((double)(((float)this.workflowAlignment.X) / this.scaling)));
                point2.Y = Convert.ToInt32(Math.Ceiling((double)(((float)this.workflowAlignment.Y) / this.scaling)));
                Rectangle viewPort = new Rectangle((this.currentPrintablePage.X * empty.Width) - point2.X, (this.currentPrintablePage.Y * empty.Height) - point2.Y, empty.Width, empty.Height);
                using (PaintEventArgs args = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(args, viewPort);
                }
                graphics.Clip      = clip;
                graphics.Transform = transform;
                HeaderFooterData headerFooterPrintData = new HeaderFooterData {
                    Font       = ambientTheme.Font,
                    PageBounds = printPageArg.PageBounds,
                    PageBoundsWithoutMargin = rect,
                    HeaderFooterMargins     = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin),
                    PrintTime   = this.printTime,
                    CurrentPage = (this.currentPrintablePage.X + (this.currentPrintablePage.Y * this.totalPrintablePages.X)) + 1,
                    TotalPages  = this.totalPrintablePages.X * this.totalPrintablePages.Y,
                    Scaling     = this.scaling
                };
                WorkflowDesignerLoader service = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterPrintData.FileName = (service != null) ? service.FileName : string.Empty;
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                {
                    this.PrintHeaderFooter(graphics, true, headerFooterPrintData);
                }
                if (this.pageSetupData.FooterTemplate.Length > 0)
                {
                    this.PrintHeaderFooter(graphics, false, headerFooterPrintData);
                }
                printPageArg.HasMorePages = this.MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]) + "\n" + exception.Message);
                printPageArg.Cancel       = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                region.Dispose();
            }
            if (!printPageArg.HasMorePages)
            {
                this.workflowView.PerformLayout();
            }
        }
示例#8
0
        internal void PrintHeaderFooter(Graphics graphics, bool drawHeader, HeaderFooterData headerFooterPrintData)
        {
            //Format the header/footer
            string headerFooter = (drawHeader) ? this.pageSetupData.HeaderTemplate : this.pageSetupData.FooterTemplate;

            //these are the new format strings
            headerFooter = headerFooter.Replace("{#}", headerFooterPrintData.CurrentPage.ToString(CultureInfo.CurrentCulture));
            headerFooter = headerFooter.Replace("{##}", headerFooterPrintData.TotalPages.ToString(CultureInfo.CurrentCulture));
            headerFooter = headerFooter.Replace("{Date}", headerFooterPrintData.PrintTime.ToShortDateString());
            headerFooter = headerFooter.Replace("{Time}", headerFooterPrintData.PrintTime.ToShortTimeString());
            headerFooter = headerFooter.Replace("{FullFileName}", headerFooterPrintData.FileName);
            headerFooter = headerFooter.Replace("{FileName}", Path.GetFileName(headerFooterPrintData.FileName));
            headerFooter = headerFooter.Replace("{User}", SystemInformation.UserName);

            //limit the string to 5 lines of text max
            string[] headerFooterLines     = headerFooter.Split(new char[] { '\n', '\r' }, MaxHeaderFooterLines + 1, StringSplitOptions.RemoveEmptyEntries);
            System.Text.StringBuilder text = new System.Text.StringBuilder();
            for (int i = 0; i < Math.Min(headerFooterLines.Length, MaxHeaderFooterLines); i++)
            {
                text.Append(headerFooterLines[i]);
                text.Append("\r\n");
            }
            headerFooter = text.ToString();

            //Measure the header /footer string
            Rectangle layoutRectangle = Rectangle.Empty;
            SizeF     stringSize      = graphics.MeasureString(headerFooter, headerFooterPrintData.Font);

            layoutRectangle.Size  = new Size(Convert.ToInt32(Math.Ceiling((stringSize.Width))), Convert.ToInt32(Math.Ceiling((stringSize.Height))));
            layoutRectangle.Width = Math.Min(headerFooterPrintData.PageBoundsWithoutMargin.Width, layoutRectangle.Width);

            HorizontalAlignment alignment    = (drawHeader) ? this.pageSetupData.HeaderAlignment : this.pageSetupData.FooterAlignment;
            StringFormat        stringFormat = new StringFormat();

            stringFormat.Trimming = StringTrimming.EllipsisCharacter;
            switch (alignment)
            {
            case HorizontalAlignment.Left:
                layoutRectangle.X      = headerFooterPrintData.PageBoundsWithoutMargin.Left;
                stringFormat.Alignment = StringAlignment.Near;
                break;

            case HorizontalAlignment.Center:
                layoutRectangle.X      = headerFooterPrintData.PageBoundsWithoutMargin.Left + ((headerFooterPrintData.PageBoundsWithoutMargin.Width - layoutRectangle.Width) / 2); //align to the middle
                stringFormat.Alignment = StringAlignment.Center;
                break;

            case HorizontalAlignment.Right:
                layoutRectangle.X      = headerFooterPrintData.PageBoundsWithoutMargin.Left + (headerFooterPrintData.PageBoundsWithoutMargin.Width - layoutRectangle.Width); //align to the right corner
                stringFormat.Alignment = StringAlignment.Far;
                break;
            }

            //Align header footer vertically
            if (drawHeader)
            {
                layoutRectangle.Y          = headerFooterPrintData.PageBounds.Top + headerFooterPrintData.HeaderFooterMargins.Top;
                stringFormat.LineAlignment = StringAlignment.Near;
            }
            else
            {
                layoutRectangle.Y          = headerFooterPrintData.PageBounds.Bottom - headerFooterPrintData.HeaderFooterMargins.Bottom - layoutRectangle.Size.Height;
                stringFormat.LineAlignment = StringAlignment.Far;
            }

            //Draw header/footer string
            graphics.DrawString(headerFooter, headerFooterPrintData.Font, WorkflowTheme.CurrentTheme.AmbientTheme.ForegroundBrush, layoutRectangle, stringFormat);
        }
示例#9
0
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);

            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;

            Graphics graphics = printPageArg.Graphics;

            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;

            //STEP1: We get the printer graphics only in the OnPrintPage function hence for layouting we need to call this function
            if (this.currentPrintablePage.IsEmpty)
            {
                PrepareToPrint(printPageArg);
            }

            //STEP2: GET ALL THE VALUES NEEDED FOR CALCULATION
            Margins hardMargins = GetHardMargins(graphics);
            Margins margins     = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left),
                                              Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right),
                                              Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top),
                                              Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size      printableArea     = new Size(printPageArg.PageBounds.Size.Width - (margins.Left + margins.Right), printPageArg.PageBounds.Size.Height - (margins.Top + margins.Bottom));
            Rectangle boundingRectangle = new Rectangle(margins.Left, margins.Top, printableArea.Width, printableArea.Height);
            Region    clipRegion        = new Region(boundingRectangle);

            try
            {
                graphics.TranslateTransform(-hardMargins.Left, -hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, boundingRectangle);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, boundingRectangle);

                //Draw the watermark image
                if (ambientTheme.WorkflowWatermarkImage != null)
                {
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, boundingRectangle, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, AmbientTheme.WatermarkTransparency, false);
                }

                Matrix oldTransform  = graphics.Transform;
                Region oldClipRegion = graphics.Clip;
                graphics.Clip = clipRegion;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                //STEP3: PRINT
                //Printer bitmap starts at the unprintable top left corner, hence, need to take it into account - move by the unprintable area:
                //Setup the translation and scaling for the page printing
                Point pageOffset = new Point(this.currentPrintablePage.X * printableArea.Width - this.workflowAlignment.X, this.currentPrintablePage.Y * printableArea.Height - this.workflowAlignment.Y);
                graphics.TranslateTransform(boundingRectangle.Left - pageOffset.X, boundingRectangle.Top - pageOffset.Y);
                graphics.ScaleTransform(this.scaling, this.scaling);

                //Calculate the viewport by reverse scaling the printable area size
                Size viewPortSize = Size.Empty;
                viewPortSize.Width  = Convert.ToInt32(Math.Ceiling((float)printableArea.Width / this.scaling));
                viewPortSize.Height = Convert.ToInt32(Math.Ceiling((float)printableArea.Height / this.scaling));

                Point scaledAlignment = Point.Empty;
                scaledAlignment.X = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.X / this.scaling));
                scaledAlignment.Y = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.Y / this.scaling));

                Rectangle viewPort = new Rectangle(this.currentPrintablePage.X * viewPortSize.Width - scaledAlignment.X, this.currentPrintablePage.Y * viewPortSize.Height - scaledAlignment.Y, viewPortSize.Width, viewPortSize.Height);

                using (PaintEventArgs paintEventArgs = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(paintEventArgs, viewPort);
                }

                graphics.Clip      = oldClipRegion;
                graphics.Transform = oldTransform;

                //Now prepare the graphics for header footer printing
                HeaderFooterData headerFooterData = new HeaderFooterData();
                headerFooterData.Font       = ambientTheme.Font;
                headerFooterData.PageBounds = printPageArg.PageBounds;
                headerFooterData.PageBoundsWithoutMargin = boundingRectangle;
                headerFooterData.HeaderFooterMargins     = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin);
                headerFooterData.PrintTime   = this.printTime;
                headerFooterData.CurrentPage = this.currentPrintablePage.X + this.currentPrintablePage.Y * this.totalPrintablePages.X + 1;
                headerFooterData.TotalPages  = this.totalPrintablePages.X * this.totalPrintablePages.Y;
                headerFooterData.Scaling     = this.scaling;
                WorkflowDesignerLoader serviceDesignerLoader = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterData.FileName = (serviceDesignerLoader != null) ? serviceDesignerLoader.FileName : String.Empty;

                //Print the header
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                {
                    PrintHeaderFooter(graphics, true, headerFooterData);
                }

                //footer
                if (this.pageSetupData.FooterTemplate.Length > 0)
                {
                    PrintHeaderFooter(graphics, false, headerFooterData);
                }

                //are there more pages left?
                printPageArg.HasMorePages = MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString(DR.SelectedPrinterIsInvalidErrorMessage) + "\n" + exception.Message);
                printPageArg.Cancel       = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                clipRegion.Dispose();
            }

            if (!printPageArg.HasMorePages)
            {
                this.workflowView.PerformLayout(); //no more pages - redo regular layout using screen graphics
            }
        }