diff --git a/projects/GKCore/GKCore.csproj b/projects/GKCore/GKCore.csproj index 0fb391b18..aad5d8f3f 100644 --- a/projects/GKCore/GKCore.csproj +++ b/projects/GKCore/GKCore.csproj @@ -538,6 +538,7 @@ + diff --git a/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs b/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs index 23d1182cd..af747e4f2 100644 --- a/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs +++ b/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2023 by Sergey V. Zhdanovskih. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. * * This file is part of "GEDKeeper". * @@ -18,6 +18,8 @@ * along with this program. If not, see . */ +//#define PDF_RENDER + using System.IO; using GDModel; using GKCore.Charts; @@ -277,6 +279,10 @@ public bool SelectedPersonIsReal() public async void SaveSnapshot() { string filters = GKUtils.GetImageFilter(true); +#if PDF_RENDER + filters += "|" + LangMan.LS(LSID.PDFFilter); +#endif + string fileName = await AppHost.StdDialogs.GetSaveFile("", GlobalOptions.Instance.ImageExportLastDir, filters, 2, "jpg", ""); if (!string.IsNullOrEmpty(fileName)) { GlobalOptions.Instance.ImageExportLastDir = Path.GetDirectoryName(fileName); diff --git a/projects/GKCore/GKCore/Export/PDFWriter.cs b/projects/GKCore/GKCore/Export/PDFWriter.cs index d39bb9932..a6b5d6995 100644 --- a/projects/GKCore/GKCore/Export/PDFWriter.cs +++ b/projects/GKCore/GKCore/Export/PDFWriter.cs @@ -27,6 +27,7 @@ using BSLib; using GKCore.Charts; using GKCore.Design.Graphics; +using GKCore.Types; using iTextSharp.text; using iTextSharp.text.pdf; using it = iTextSharp.text; @@ -104,6 +105,7 @@ public ExtSizeF GetTextSize(string text) private Document fDocument; private bool fMulticolumns; private PdfWriter fPdfWriter; + private GKPageSize fPredefPage; private itTable fTable; private Stack fStack; @@ -118,6 +120,12 @@ public PDFWriter() fBaseFont = BaseFont.CreateFont("FreeSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, BaseFont.CACHED, fontBytes, null); } + public PDFWriter(GKPageSize predefPage, bool albumPage) : this() + { + fPredefPage = predefPage; + fAlbumPage = albumPage; + } + protected override void Dispose(bool disposing) { if (disposing) { @@ -154,9 +162,36 @@ public override ExtRectF GetPageSize() public override void BeginWrite() { - itRectangle pageSize = !fAlbumPage ? PageSize.A4 : PageSize.A4.Rotate(); + itRectangle pageSize; + if (fPredefPage == GKPageSize.None) { + pageSize = PageSize.A4; + } else { + switch (fPredefPage) { + case GKPageSize.A0: + pageSize = PageSize.A0; + break; + case GKPageSize.A1: + pageSize = PageSize.A1; + break; + case GKPageSize.A2: + pageSize = PageSize.A2; + break; + case GKPageSize.A3: + pageSize = PageSize.A3; + break; + case GKPageSize.A4: + default: + pageSize = PageSize.A4; + break; + case GKPageSize.A5: + pageSize = PageSize.A5; + break; + } + } + + itRectangle pageRect = !fAlbumPage ? pageSize : pageSize.Rotate(); - fDocument = new Document(pageSize, fMargins.Left, fMargins.Right, fMargins.Top, fMargins.Bottom); + fDocument = new Document(pageRect, fMargins.Left, fMargins.Right, fMargins.Top, fMargins.Bottom); fPdfWriter = PdfWriter.GetInstance(fDocument, new FileStream(fFileName, FileMode.Create, FileAccess.Write)); fDocument.AddTitle(fDocumentTitle); diff --git a/projects/GKCore/GKCore/Types/GKPageSize.cs b/projects/GKCore/GKCore/Types/GKPageSize.cs new file mode 100644 index 000000000..53b5a303a --- /dev/null +++ b/projects/GKCore/GKCore/Types/GKPageSize.cs @@ -0,0 +1,27 @@ +/* + * "GEDKeeper", the personal genealogical database editor. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. + * + * This file is part of "GEDKeeper". + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace GKCore.Types +{ + public enum GKPageSize + { + None, A0, A1, A2, A3, A4, A5, + } +} diff --git a/projects/GKv2/GEDKeeper2/GKUI/Components/TreeChartBox.cs b/projects/GKv2/GEDKeeper2/GKUI/Components/TreeChartBox.cs index 7da8af5d5..2ca1853c9 100644 --- a/projects/GKv2/GEDKeeper2/GKUI/Components/TreeChartBox.cs +++ b/projects/GKv2/GEDKeeper2/GKUI/Components/TreeChartBox.cs @@ -128,7 +128,7 @@ public TreeChartOptions Options } } - public new float Scale + public override float Scale { get { return fModel.Scale; } } @@ -204,7 +204,7 @@ public override void SetRenderer(ChartRenderer renderer) fModel.SetRenderer(renderer); } - public void SetScale(float value) + public override void SetScale(float value) { fModel.Scale = value; diff --git a/projects/GKv2/GEDKeeper2/GKUI/Forms/OptionsDlg.Designer.cs b/projects/GKv2/GEDKeeper2/GKUI/Forms/OptionsDlg.Designer.cs index d3f5dc94e..483cb1592 100644 --- a/projects/GKv2/GEDKeeper2/GKUI/Forms/OptionsDlg.Designer.cs +++ b/projects/GKv2/GEDKeeper2/GKUI/Forms/OptionsDlg.Designer.cs @@ -471,7 +471,7 @@ private void InitializeComponent() // lblCertaintyAlgorithm // this.lblCertaintyAlgorithm.AutoSize = true; - this.lblCertaintyAlgorithm.Location = new System.Drawing.Point(319, 595); + this.lblCertaintyAlgorithm.Location = new System.Drawing.Point(290, 595); this.lblCertaintyAlgorithm.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lblCertaintyAlgorithm.Name = "lblCertaintyAlgorithm"; this.lblCertaintyAlgorithm.Size = new System.Drawing.Size(125, 17); @@ -624,7 +624,7 @@ private void InitializeComponent() // lblGeoSearchCountry // this.lblGeoSearchCountry.AutoSize = true; - this.lblGeoSearchCountry.Location = new System.Drawing.Point(319, 548); + this.lblGeoSearchCountry.Location = new System.Drawing.Point(290, 548); this.lblGeoSearchCountry.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lblGeoSearchCountry.Name = "lblGeoSearchCountry"; this.lblGeoSearchCountry.Size = new System.Drawing.Size(216, 17); @@ -2345,7 +2345,7 @@ private void InitializeComponent() // // chkUseExtendedNotes // - this.chkUseExtendedNotes.Location = new System.Drawing.Point(20, 61); + this.chkUseExtendedNotes.Location = new System.Drawing.Point(20, 51); this.chkUseExtendedNotes.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkUseExtendedNotes.Name = "chkUseExtendedNotes"; this.chkUseExtendedNotes.Size = new System.Drawing.Size(600, 22); @@ -2354,7 +2354,7 @@ private void InitializeComponent() // // chkKeepRichNames // - this.chkKeepRichNames.Location = new System.Drawing.Point(20, 102); + this.chkKeepRichNames.Location = new System.Drawing.Point(20, 82); this.chkKeepRichNames.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkKeepRichNames.Name = "chkKeepRichNames"; this.chkKeepRichNames.Size = new System.Drawing.Size(600, 22); @@ -2363,7 +2363,7 @@ private void InitializeComponent() // // lblChartWindowsShowMode // - this.lblChartWindowsShowMode.Location = new System.Drawing.Point(20, 143); + this.lblChartWindowsShowMode.Location = new System.Drawing.Point(20, 113); this.lblChartWindowsShowMode.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.lblChartWindowsShowMode.Name = "lblChartWindowsShowMode"; this.lblChartWindowsShowMode.Size = new System.Drawing.Size(300, 22); @@ -2373,7 +2373,7 @@ private void InitializeComponent() // cmbChartWindowsShowMode // this.cmbChartWindowsShowMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cmbChartWindowsShowMode.Location = new System.Drawing.Point(320, 143); + this.cmbChartWindowsShowMode.Location = new System.Drawing.Point(320, 113); this.cmbChartWindowsShowMode.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.cmbChartWindowsShowMode.Name = "cmbChartWindowsShowMode"; this.cmbChartWindowsShowMode.Size = new System.Drawing.Size(220, 22); @@ -2382,7 +2382,7 @@ private void InitializeComponent() // // chkExtendedTree // - this.chkExtendedTree.Location = new System.Drawing.Point(20, 184); + this.chkExtendedTree.Location = new System.Drawing.Point(20, 144); this.chkExtendedTree.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkExtendedTree.Name = "chkExtendedTree"; this.chkExtendedTree.Size = new System.Drawing.Size(600, 22); @@ -2391,7 +2391,7 @@ private void InitializeComponent() // // chkUseExtraControls // - this.chkUseExtraControls.Location = new System.Drawing.Point(20, 225); + this.chkUseExtraControls.Location = new System.Drawing.Point(20, 175); this.chkUseExtraControls.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkUseExtraControls.Name = "chkUseExtraControls"; this.chkUseExtraControls.Size = new System.Drawing.Size(600, 22); @@ -2400,7 +2400,7 @@ private void InitializeComponent() // // chkSAFByAllNames // - this.chkSAFByAllNames.Location = new System.Drawing.Point(20, 266); + this.chkSAFByAllNames.Location = new System.Drawing.Point(20, 206); this.chkSAFByAllNames.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkSAFByAllNames.Name = "chkSAFByAllNames"; this.chkSAFByAllNames.Size = new System.Drawing.Size(600, 22); @@ -2409,7 +2409,7 @@ private void InitializeComponent() // // chkShortenDateRanges // - this.chkShortenDateRanges.Location = new System.Drawing.Point(20, 307); + this.chkShortenDateRanges.Location = new System.Drawing.Point(20, 237); this.chkShortenDateRanges.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkShortenDateRanges.Name = "chkShortenDateRanges"; this.chkShortenDateRanges.Size = new System.Drawing.Size(600, 22); @@ -2418,7 +2418,7 @@ private void InitializeComponent() // // chkKeepInfoPansOverallSize // - this.chkKeepInfoPansOverallSize.Location = new System.Drawing.Point(20, 348); + this.chkKeepInfoPansOverallSize.Location = new System.Drawing.Point(20, 268); this.chkKeepInfoPansOverallSize.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkKeepInfoPansOverallSize.Name = "chkKeepInfoPansOverallSize"; this.chkKeepInfoPansOverallSize.Size = new System.Drawing.Size(600, 22); @@ -2427,7 +2427,7 @@ private void InitializeComponent() // // chkFilesOverwriteWarn // - this.chkFilesOverwriteWarn.Location = new System.Drawing.Point(20, 389); + this.chkFilesOverwriteWarn.Location = new System.Drawing.Point(20, 299); this.chkFilesOverwriteWarn.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkFilesOverwriteWarn.Name = "chkFilesOverwriteWarn"; this.chkFilesOverwriteWarn.Size = new System.Drawing.Size(600, 22); @@ -2436,7 +2436,7 @@ private void InitializeComponent() // // chkExtendedKinships // - this.chkExtendedKinships.Location = new System.Drawing.Point(20, 430); + this.chkExtendedKinships.Location = new System.Drawing.Point(20, 330); this.chkExtendedKinships.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkExtendedKinships.Name = "chkExtendedKinships"; this.chkExtendedKinships.Size = new System.Drawing.Size(600, 22); @@ -2445,7 +2445,7 @@ private void InitializeComponent() // // chkExtendedLocations // - this.chkExtendedLocations.Location = new System.Drawing.Point(20, 471); + this.chkExtendedLocations.Location = new System.Drawing.Point(20, 361); this.chkExtendedLocations.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkExtendedLocations.Name = "chkExtendedLocations"; this.chkExtendedLocations.Size = new System.Drawing.Size(600, 22); @@ -2454,7 +2454,7 @@ private void InitializeComponent() // // chkELAbbreviatedNames // - this.chkELAbbreviatedNames.Location = new System.Drawing.Point(50, 512); + this.chkELAbbreviatedNames.Location = new System.Drawing.Point(50, 392); this.chkELAbbreviatedNames.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkELAbbreviatedNames.Name = "chkELAbbreviatedNames"; this.chkELAbbreviatedNames.Size = new System.Drawing.Size(600, 22); @@ -2463,7 +2463,7 @@ private void InitializeComponent() // // chkReversePlacesOrder // - this.chkReversePlacesOrder.Location = new System.Drawing.Point(20, 553); + this.chkReversePlacesOrder.Location = new System.Drawing.Point(20, 423); this.chkReversePlacesOrder.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkReversePlacesOrder.Name = "chkReversePlacesOrder"; this.chkReversePlacesOrder.Size = new System.Drawing.Size(600, 22); @@ -2472,7 +2472,7 @@ private void InitializeComponent() // // chkShowNumberOfSubstructures // - this.chkShowNumberOfSubstructures.Location = new System.Drawing.Point(20, 594); + this.chkShowNumberOfSubstructures.Location = new System.Drawing.Point(20, 454); this.chkShowNumberOfSubstructures.Margin = new System.Windows.Forms.Padding(10, 0, 0, 5); this.chkShowNumberOfSubstructures.Name = "chkShowNumberOfSubstructures"; this.chkShowNumberOfSubstructures.Size = new System.Drawing.Size(600, 22); diff --git a/projects/GKv2/GKComponents/GKUI/Components/CustomChart.cs b/projects/GKv2/GKComponents/GKUI/Components/CustomChart.cs index 6c0262da1..44a86895b 100644 --- a/projects/GKv2/GKComponents/GKUI/Components/CustomChart.cs +++ b/projects/GKv2/GKComponents/GKUI/Components/CustomChart.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2023 by Sergey V. Zhdanovskih. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. * * This file is part of "GEDKeeper". * @@ -26,6 +26,8 @@ using GKCore; using GKCore.Charts; using GKCore.Design.Graphics; +using GKCore.Export; +using GKCore.Types; using GKUI.Platform.Handlers; namespace GKUI.Components @@ -38,6 +40,11 @@ public abstract class CustomChart : ScrollablePanel, IPrintable public event EventHandler NavRefresh; + public new virtual float Scale + { + get { return 0; } + } + protected CustomChart() { @@ -52,6 +59,10 @@ protected CustomChart() fNavman = new NavigationStack(); } + public virtual void SetScale(float value) + { + } + protected override bool IsInputKey(Keys keyData) { switch (keyData) { @@ -216,8 +227,6 @@ public IImage GetPrintableImage() return new ImageHandler(image); } - /* TODO(zsv): Need to find an appropriate icon in the general style - * for the main toolbar - screenshot capture for windows with charts. */ public void SaveSnapshot(string fileName) { string ext = FileHelper.GetFileExtension(fileName); @@ -239,6 +248,34 @@ public void SaveSnapshot(string fileName) SetRenderer(prevRenderer); } + return; + } else if (ext == ".pdf") { + var prevRenderer = fRenderer; + + var pdfWriter = new PDFWriter(GKPageSize.A4, true); + pdfWriter.SetFileName(fileName); + pdfWriter.BeginWrite(); + + var renderer = pdfWriter.GetPageRenderer(); + SetRenderer(renderer); + + var pageSize = pdfWriter.GetPageSize(); + var sf = GfxHelper.ZoomToFit(imageSize.Width, imageSize.Height, pageSize.GetWidth(), pageSize.GetHeight()); + var prevScale = this.Scale; + if (sf < 1.0f) this.SetScale(sf); + + renderer.BeginDrawing(); + try { + //GenChart(indi.IRec, indi.TreeKind, false); + RenderImage(RenderTarget.Printer); + } finally { + renderer.EndDrawing(); + pdfWriter.EndWrite(); + + SetRenderer(prevRenderer); + this.SetScale(prevScale); + } + return; } diff --git a/projects/GKv3/GKComponents/GKUI/Components/CustomChart.cs b/projects/GKv3/GKComponents/GKUI/Components/CustomChart.cs index cb44a488c..a34287add 100644 --- a/projects/GKv3/GKComponents/GKUI/Components/CustomChart.cs +++ b/projects/GKv3/GKComponents/GKUI/Components/CustomChart.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2023 by Sergey V. Zhdanovskih. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. * * This file is part of "GEDKeeper". * @@ -153,8 +153,6 @@ public IImage GetPrintableImage() return new ImageHandler(image); } - /* TODO(zsv): Need to find an appropriate icon in the general style - * for the main toolbar - screenshot capture for windows with charts. */ public void SaveSnapshot(string fileName) { string ext = FileHelper.GetFileExtension(fileName); diff --git a/projects/GKvX/GEDKeeperX/GKUI/Components/CustomChart.cs b/projects/GKvX/GEDKeeperX/GKUI/Components/CustomChart.cs index 464ecef55..deaa455ca 100644 --- a/projects/GKvX/GEDKeeperX/GKUI/Components/CustomChart.cs +++ b/projects/GKvX/GEDKeeperX/GKUI/Components/CustomChart.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2023 by Sergey V. Zhdanovskih. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. * * This file is part of "GEDKeeper". * @@ -57,8 +57,6 @@ public IImage GetPrintableImage() return null; } - /* TODO(zsv): Need to find an appropriate icon in the general style - * for the main toolbar - screenshot capture for windows with charts. */ public void SaveSnapshot(string fileName) { /*string ext = FileHelper.GetFileExtension(fileName);