예제 #1
0
        private void PrintDesign()
        {
            DesignEntry country = this.design.GetCountry(1);

            bool excludeNumber        = country.Settings.ToLower().Contains("!includenumber");
            bool excludeValueAndColor = country.Settings.ToLower().Contains("!includevalueandcolor");

            Print print = new Print(PrintMode.ToDocument, excludeNumber, excludeValueAndColor);

            DialogResult result = print.ShowDialog();

            if (result == DialogResult.OK)
            {
                preview.Hide();

                PageSetup setup = PageSetup.Load();

                DesignEntry album = design.GetAlbum();

                string pdfName = album.Pdf;

                if (setup.Catalog != Catalog.None)
                {
                    pdfName += "_" + setup.Catalog;
                }

                pdfName += "_" + setup.PageFormat.FormatName;

                pdfName += "_v" + album.Version;

                if (setup.IncludeMarginForPunchHoles)
                {
                    pdfName += "_offcenter";
                }

                if (setup.IncludeSamplePagesOnly)
                {
                    pdfName += "_sample";
                }

                if (setup.FontSize == FontSize.Medium)
                {
                    pdfName += "_font6";
                }
                else if (setup.FontSize == FontSize.Large)
                {
                    pdfName += "_font7";
                }

                string bookmarksInXml = null;
                string bookmarksInHtm = null;

                if (setup.IncludePdfBookmarks)
                {
                    BookmarksHelper.GetBookmarks(this.design, album.Pdf, setup.IncludeSamplePagesOnly, out bookmarksInXml, out bookmarksInHtm);
                }

                PDF995Helper pdfHelper = new PDF995Helper(album.Pdf, pdfName, bookmarksInXml, bookmarksInHtm);

                Progress progress = new Progress(this.design.NumberOfPages());
                progress.Show();
                progress.Refresh();

                preview.PrintDocument(App.GetSetting("PDFPrinter"), setup.PageFormat.PageWidth, setup.PageFormat.PageHeight, this.design, progress.SetPrintingProgress);

                if (setup.IncludePdfImages)
                {
                    for (int pageNumber = 1; pageNumber <= this.design.NumberOfPages(); pageNumber++)
                    {
                        progress.SetCreatingProgress(pageNumber);

                        preview.ShowPreview(this.design, pageNumber, this.design.GetPagefeed(pageNumber).AlbumNumber, PrintMode.ToDocument, ScreenMode.MatchPaper);

                        preview.CreateImage(string.Format("{0}\\{1}-large.jpg", App.GetSetting("PDFImagesFolder"), pageNumber), 0.75F);
                        preview.CreateImage(string.Format("{0}\\{1}-small.jpg", App.GetSetting("PDFImagesFolder"), pageNumber), 0.25F);
                    }
                }

                progress.SetWaiting();

                pdfHelper.WaitForCompletion();

                progress.Close();
            }
        }
예제 #2
0
        private void ImmediatePreviewDesign()
        {
            if (!menuRefresh.Checked)
            {
                return;
            }

            try
            {
                int lineNumber = designMaster.PositionToPlace(designMaster.SelectionStart).iLine;

                if (lineNumber == designMaster.LinesCount - 1)
                {
                    return;
                }

                string end;
                string country = null;
                string series  = null;
                string section = null;

                int lineNumberPageFeedThis;
                int lineNumberPageFeedNext;

                int index;

                //StopwatchHelper.Start("Looking for End");
                index = designMaster.SelectionStart;
                if (!string.IsNullOrEmpty(end = FindLineBefore("End", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for PageFeed");
                index = designMaster.SelectionStart;
                if (string.IsNullOrEmpty(FindLineBefore("PageFeed", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                lineNumberPageFeedThis = designMaster.PositionToPlace(index).iLine;

                //StopwatchHelper.Start("Looking for Series");
                if (string.IsNullOrEmpty(series = FindLineBefore("Series=", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for Part");
                if (string.IsNullOrEmpty(section = FindLineBefore("Part=", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for Country");
                if (string.IsNullOrEmpty(country = FindLineBefore("Country=", ref index)))
                {
                    return;
                }
                //StopwatchHelper.Stop();

                //StopwatchHelper.Start("Looking for End or PageFeed");
                index = Math.Min(FindLineAfter("PageFeed", designMaster.SelectionStart), FindLineAfter("End", designMaster.SelectionStart));
                //StopwatchHelper.Stop();

                lineNumberPageFeedNext = designMaster.PositionToPlace(index).iLine;

                StringBuilder pageLines = new StringBuilder();

                pageLines.Append("Album | Pdf=Pdf | Version=Version\r\n");
                pageLines.Append(country).Append("\r\n");
                pageLines.Append(section).Append("\r\n");
                pageLines.Append(series).Append("\r\n");

                //StopwatchHelper.Start("Looking for Comments and Sizes");
                for (int line = lineNumberPageFeedThis; line < lineNumberPageFeedNext; line++)
                {
                    string lineText = designMaster.GetLineText(line).Trim();

                    if (!lineText.StartsWith("'"))
                    {
                        if (lineText.Contains("Comment:"))
                        {
                            string commentValue = lineText.Split("Comment:")[1].Split('|')[0].Replace("!", "").Replace("%", "");

                            if (this.comments.ContainsKey(commentValue))
                            {
                                lineText = lineText.Replace("Comment:" + commentValue, this.comments[commentValue]);
                            }
                            else
                            {
                                index = designMaster.SelectionStart;
                                string commentOrigin = FindLineBefore("Comment=" + commentValue, ref index);

                                if (commentOrigin != null)
                                {
                                    string commentContents = commentOrigin.Split("=")[1].Split('|')[0].Trim();

                                    while (commentContents.StartsWith("!") || commentContents.StartsWith("%"))
                                    {
                                        commentContents = commentContents.Substring(1);
                                    }

                                    this.comments.Add(commentValue, commentContents);

                                    lineText = lineText.Replace("Comment:" + commentValue, commentContents);
                                }
                            }
                        }

                        if (lineText.Contains("Size="))
                        {
                            string sizeValue = lineText.Split("Size=")[1].Split('|')[0].Trim();

                            if (!sizesToSkip.Contains(sizeValue))
                            {
                                if (this.sizes.ContainsKey(sizeValue))
                                {
                                    lineText = lineText.Replace("Size=" + sizeValue, this.sizes[sizeValue]);
                                }
                                else
                                {
                                    index = designMaster.SelectionStart;
                                    string sizeOrigin = FindLineBefore("Design=" + sizeValue, ref index);

                                    if (sizeOrigin == null)
                                    {
                                        this.sizesToSkip.Add(sizeValue);
                                    }
                                    else
                                    {
                                        string sizeContents = sizeOrigin.Split("|", joinAgainExceptFirstOne: true)[1].Trim();

                                        this.sizes.Add(sizeValue, sizeContents + " | Width=+4 | Height=+4");

                                        lineText = lineText.Replace("Size=" + sizeValue, this.sizes[sizeValue]);
                                    }
                                }
                            }
                        }
                    }

                    pageLines.Append(lineText).Append("\r\n");
                }
                //StopwatchHelper.Stop();

                pageLines.Append("End\r\n");

                string pageText = pageLines.ToString();

                //StopwatchHelper.Start("Parsing design");
                Design design = (new DesignParser()).Parse(pageText, null, out string error);
                //StopwatchHelper.Stop();

                if (string.IsNullOrEmpty(error))
                {
                    preview.ShowPreview(design, pageNumber: 1, albumNumber: design.GetPagefeed(1).AlbumNumber, printMode: PrintMode.ToScreen, screenMode: ScreenMode.MatchScreenHeight);
                    preview.Show();
                    preview.Activate();

                    this.Focus();
                }
                else
                {
                    //SetError(error);
                }
            }
            catch (Exception e)
            {
                SetError(e.Message);
            }
        }