Ejemplo n.º 1
0
        private static Document ResizeDocument(DocumentWorkspace documentWorkspace, AnchorEdge initialAnchor, ColorBgra background, bool loadAndSaveMaintainAspect, bool saveAnchor)
        {
            Document document2;

            CleanupManager.RequestCleanup();
            IWin32Window owner    = documentWorkspace;
            Document     document = documentWorkspace.Document;
            Size         size     = document.Size;

            using (CanvasSizeDialog dialog = new CanvasSizeDialog())
            {
                bool flag;
                if (loadAndSaveMaintainAspect)
                {
                    flag = AppSettings.Instance.Workspace.LastMaintainAspectRatioCS.Value;
                }
                else
                {
                    flag = false;
                }
                dialog.OriginalSize      = document.Size;
                dialog.OriginalDpuUnit   = document.DpuUnit;
                dialog.OriginalDpu       = document.DpuX;
                dialog.ImageWidth        = size.Width;
                dialog.ImageHeight       = size.Height;
                dialog.LayerCount        = document.Layers.Count;
                dialog.AnchorEdge        = initialAnchor;
                dialog.Units             = dialog.OriginalDpuUnit;
                dialog.Resolution        = document.DpuX;
                dialog.Units             = AppSettings.Instance.Workspace.LastNonPixelUnits.Value;
                dialog.ConstrainToAspect = flag;
                DialogResult    result     = dialog.ShowDialog(owner);
                Size            newSize    = new Size(dialog.ImageWidth, dialog.ImageHeight);
                MeasurementUnit units      = dialog.Units;
                double          resolution = dialog.Resolution;
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }
                if (loadAndSaveMaintainAspect)
                {
                    AppSettings.Instance.Workspace.LastMaintainAspectRatioCS.Value = dialog.ConstrainToAspect;
                }
                if (saveAnchor)
                {
                    AppSettings.Instance.Workspace.LastCanvasSizeAnchorEdge.Value = dialog.AnchorEdge;
                }
                if (((newSize == document.Size) && (units == document.DpuUnit)) && (resolution == document.DpuX))
                {
                    document2 = null;
                }
                else
                {
                    try
                    {
                        documentWorkspace.FlushTool();
                        CleanupManager.RequestCleanup();
                        Document document3 = ResizeDocument(document, newSize, dialog.AnchorEdge, background);
                        document3.DpuUnit = units;
                        document3.DpuX    = resolution;
                        document3.DpuY    = resolution;
                        document2         = document3;
                    }
                    catch (OutOfMemoryException exception)
                    {
                        ExceptionDialog.ShowErrorDialog(owner, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"), exception.ToString());
                        document2 = null;
                    }
                    catch (Exception)
                    {
                        document2 = null;
                    }
                }
            }
            return(document2);
        }
Ejemplo n.º 2
0
        // returns null to indicate user cancelled, or if initialNewSize = newSize that the user requested,
        // or if there was an error (out of memory)
        public static Document ResizeDocument(IWin32Window parent, 
            Document document,
            Size initialNewSize,
            AnchorEdge initialAnchor,
            ColorBgra background,
            bool loadAndSaveMaintainAspect,
            bool saveAnchor)
        {
            using (CanvasSizeDialog csd = new CanvasSizeDialog())
            {
                bool maintainAspect;

                if (loadAndSaveMaintainAspect)
                {
                    maintainAspect = Settings.CurrentUser.GetBoolean(PdnSettings.LastMaintainAspectRatioCS, false);
                }
                else
                {
                    maintainAspect = false;
                }

                csd.OriginalSize = document.Size;
                csd.OriginalDpuUnit = document.DpuUnit;
                csd.OriginalDpu = document.DpuX;
                csd.ImageWidth = initialNewSize.Width;
                csd.ImageHeight = initialNewSize.Height;
                csd.LayerCount = document.Layers.Count;
                csd.AnchorEdge = initialAnchor;
                csd.Units = csd.OriginalDpuUnit;
                csd.Resolution = document.DpuX;
                csd.Units = PdnSettings.GetLastNonPixelUnits();
                csd.ConstrainToAspect = maintainAspect;

                DialogResult result = csd.ShowDialog(parent);
                Size newSize = new Size(csd.ImageWidth, csd.ImageHeight);
                MeasurementUnit newDpuUnit = csd.Units;
                double newDpu = csd.Resolution;

                // If they cancelled, get out
                if (result == DialogResult.Cancel)
                {
                    return null;
                }

                // If they clicked OK, then we save the aspect checkbox, and maybe the anchor
                if (loadAndSaveMaintainAspect)
                {
                    Settings.CurrentUser.SetBoolean(PdnSettings.LastMaintainAspectRatioCS, csd.ConstrainToAspect);
                }

                if (saveAnchor)
                {
                    Settings.CurrentUser.SetString(PdnSettings.LastCanvasSizeAnchorEdge, csd.AnchorEdge.ToString());
                }

                if (newSize == document.Size && newDpuUnit == document.DpuUnit && newDpu == document.DpuX)
                {
                    return null;
                }

                try
                {
                    Utility.GCFullCollect();
                    Document newDoc = ResizeDocument(document, newSize, csd.AnchorEdge, background);
                    newDoc.DpuUnit = newDpuUnit;
                    newDoc.DpuX = newDpu;
                    newDoc.DpuY = newDpu;
                    return newDoc;
                }

                catch (OutOfMemoryException)
                {
                    Utility.ErrorBox(parent, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"));
                    return null;
                }

                catch
                {
                    return null;
                }
            }
        }
Ejemplo n.º 3
0
        // returns null to indicate user cancelled, or if initialNewSize = newSize that the user requested,
        // or if there was an error (out of memory)
        public static Document ResizeDocument(IWin32Window parent,
                                              Document document,
                                              Size initialNewSize,
                                              AnchorEdge initialAnchor,
                                              ColorBgra background,
                                              bool loadAndSaveMaintainAspect,
                                              bool saveAnchor)
        {
            using (CanvasSizeDialog csd = new CanvasSizeDialog())
            {
                bool maintainAspect;

                if (loadAndSaveMaintainAspect)
                {
                    maintainAspect = Settings.CurrentUser.GetBoolean(PdnSettings.LastMaintainAspectRatioCS, false);
                }
                else
                {
                    maintainAspect = false;
                }

                csd.OriginalSize      = document.Size;
                csd.OriginalDpuUnit   = document.DpuUnit;
                csd.OriginalDpu       = document.DpuX;
                csd.ImageWidth        = initialNewSize.Width;
                csd.ImageHeight       = initialNewSize.Height;
                csd.LayerCount        = document.Layers.Count;
                csd.AnchorEdge        = initialAnchor;
                csd.Units             = csd.OriginalDpuUnit;
                csd.Resolution        = document.DpuX;
                csd.Units             = PdnSettings.GetLastNonPixelUnits();
                csd.ConstrainToAspect = maintainAspect;

                DialogResult    result     = csd.ShowDialog(parent);
                Size            newSize    = new Size(csd.ImageWidth, csd.ImageHeight);
                MeasurementUnit newDpuUnit = csd.Units;
                double          newDpu     = csd.Resolution;

                // If they cancelled, get out
                if (result == DialogResult.Cancel)
                {
                    return(null);
                }

                // If they clicked OK, then we save the aspect checkbox, and maybe the anchor
                if (loadAndSaveMaintainAspect)
                {
                    Settings.CurrentUser.SetBoolean(PdnSettings.LastMaintainAspectRatioCS, csd.ConstrainToAspect);
                }

                if (saveAnchor)
                {
                    Settings.CurrentUser.SetString(PdnSettings.LastCanvasSizeAnchorEdge, csd.AnchorEdge.ToString());
                }

                if (newSize == document.Size && newDpuUnit == document.DpuUnit && newDpu == document.DpuX)
                {
                    return(null);
                }

                try
                {
                    Utility.GCFullCollect();
                    Document newDoc = ResizeDocument(document, newSize, csd.AnchorEdge, background);
                    newDoc.DpuUnit = newDpuUnit;
                    newDoc.DpuX    = newDpu;
                    newDoc.DpuY    = newDpu;
                    return(newDoc);
                }

                catch (OutOfMemoryException)
                {
                    Utility.ErrorBox(parent, PdnResources.GetString("CanvasSizeAction.ResizeDocument.OutOfMemory"));
                    return(null);
                }

                catch
                {
                    return(null);
                }
            }
        }