public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { Document document = new Document(false); // must be before IF below for first branch document.Page(0).SetSize(Globals.Root.CurrentConfig.ReadSize(Config.Page_Size, Config.Page_Size_Default)); if (CurrentDocument != null) { document.ActivityID = CurrentDocument.ActivityID; document.Page(0).SetSize(CurrentDocument.Page(0).PhysicalSize, CurrentDocument.Page(0).Margin); } document.SetDefaultGridAndSnapFromActivity(); if (CurrentDocument.UserSettings != null && (CurrentDocument.UserSettings.Values.Count > 0) || CurrentDocument.BothSettings != null && (CurrentDocument.BothSettings.Values.Count > 0)) { if (GUIUtilities.QuestionBox(Strings.Item("NewDocument_CopySettings"), MessageBoxButtons.YesNo) == DialogResult.Yes) { Transaction objTransaction = new Transaction(); // settings methods below require a transaction, but we won't store this for undo if (CurrentDocument.UserSettings != null) { document.GetCreateUserSettings(objTransaction).CopyFrom(CurrentDocument.UserSettings, Datum.CopyDepth.Duplicate, Mapping.Ignore); } if (CurrentDocument.BothSettings != null) { document.GetCreateBothSettings(objTransaction).CopyFrom(CurrentDocument.BothSettings, Datum.CopyDepth.Duplicate, Mapping.Ignore); } } } if (Globals.Root.CurrentConfig.ReadBoolean(Config.Multiple_Documents) && !CurrentDocument.IsEmpty) { // create new index - current doc kept even if saved, as long as not totally empty Globals.Root.AddNewDocument(document); } else { if (!Globals.Root.Editor.CheckDiscardCurrent(false)) { return; } Globals.Root.CurrentDocument = document; } Document.NextUntitledIndex += 1; }
public static void SaveFile(EditableView pnlView) { pnlView.ConcludeOngoing(); Bitmap thumbnail = CurrentDocument.Page(0).GenerateThumbnail2(Page.FILEDOCUMENTTHUMBNAILSIZE, CurrentDocument.ApproxUnitScale, 96); try { using (DataWriter writer = new DataWriter(CurrentDocument.Filename, FileMarkers.Splash, thumbnail: thumbnail)) { writer.Write(CurrentDocument); } } catch (Exception ex) when(!Globals.Root.IsDebug) { MessageBox.Show(Strings.Item("Save_Failed").Replace("%0", ex.Message), Strings.Item("App"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; // functions can detect this failed (e.g. save before close)by detecting now m_Document.Changed is still True } CurrentDocument.Changed = false; Config.UserUser.RememberFile(CurrentDocument.Filename); Editor.SetWindowTitle(); // in case filename was changed }
public void PrintDocument_PrintPage(object sender, PrintPageEventArgs e) { // we do not use the buffers when printing (the printer is probably higher-resolution!) Graphics gr = e.Graphics; Page page = CurrentDocument.Page(m_PrintPageIndex); e.PageSettings.Landscape = page.IsLandscape; gr.ResetTransform(); gr.PageUnit = GraphicsUnit.Pixel; // GraphicsUnit.Millimeter ' it shows 600 DPI which makes the usual scaling conversion for mono impossible SizeF printable = e.PageSettings.PrintableArea.Size.MultiplyBy(Geometry.INCH / 100); // in mm. Apparently e.MarginBounds or e.PageSettings.PrintableArea is in hundredths of an inch (?) if (page.IsLandscape) { printable = printable.Flip(); // But sadly e.PageSettings.PrintableArea does not account for orientation } var pageSize = page.Size; // max scale that will fit: var scale = Math.Min(printable.Width / pageSize.Width, printable.Height / pageSize.Height); if (scale > 0.97f) // will not fit at full size (allow a bit <1 in case of slight margin issues) { scale = 1; // don't shrink } else { pageSize.Width *= scale; // update page size for centreing below pageSize.Height *= scale; } gr.ScaleTransform(scale * gr.DpiX / Geometry.INCH, scale * gr.DpiY / Geometry.INCH); gr.TranslateTransform(0, page.Size.Height - 1); // centre it gr.TranslateTransform(scale * (pageSize.Width - pageSize.Width) / 2, scale * (pageSize.Height - pageSize.Height) / 2); // No need to take account of the margins if we are centring it anyway //gr.TranslateTransform(m_objPage.Margin - INCH * e.PageSettings.HardMarginX / 100, m_objPage.Margin - INCH * e.PageSettings.HardMarginY / 100) gr.SmoothingMode = SmoothingMode.AntiAlias; gr.TextRenderingHint = TextRenderingHint.AntiAlias; // otherwise text on transparent buffer is naff using (NetCanvas canvas = new NetCanvas(gr, true)) { page.DrawBackground(canvas, scale * gr.DpiX / Geometry.INCH, page.Paper.PrintBackground, false); if (page != CurrentPage) { page.BackgroundImage?.Release(); // avoid overload if document has masses of large pages } if (e.PageSettings.PrinterSettings.PrintRange == PrintRange.Selection) { page.DrawSelected(canvas, null, scale, gr.DpiX / Geometry.INCH, true); } else { page.DrawShapes(canvas, scale, gr.DpiX / Geometry.INCH, null, !PrintMeasures); } } m_PrintPageIndex += 1; switch (m_PrintDocument.PrinterSettings.PrintRange) { case PrintRange.CurrentPage: case PrintRange.Selection: e.HasMorePages = false; break; default: e.HasMorePages = m_PrintPageIndex + 1 <= m_PrintDocument.PrinterSettings.ToPage; // +1 is the conversion from 0-based to 1-based break; } }