Esempio n. 1
0
        /// <summary>Apply a change of set bounds to data, either due to this form or for some other reason.
        /// Returns the transaction with the changes, which is not yet stored</summary>
        public static Transaction SetBoundsInData(Rectangle newBounds, bool adjustContents)
        {
            Document    document    = Globals.Root.CurrentDocument;
            Rectangle   old         = document.SAWHeader.MainWindowBounds;
            Transaction transaction = new Transaction {
                IsPageSizeChange = true
            };

            transaction.Edit(document);
            document.SAWHeader.SetWindowBounds(newBounds);
            if (newBounds.Size != old.Size)
            {
                foreach (Page p in document.Pages)
                {
                    transaction.Edit(p);
                    old = p.Bounds.ToRectangle();
                    Rectangle pageBounds = newBounds;
                    if (p.LockARToBackgroundImage)
                    {                     // has image and background mode is set to match AR (to keep things aligned)
                                          //Size imageSize = p.BackgroundImage.GetSize();
                                          //float neededAR = (float)imageSize.Height/imageSize.Width;
                                          //pageBounds.Width = (int)Math.Sqrt(pageBounds.Width * pageBounds.Height / neededAR); // formula will always give ratio X:Y = neededAR
                                          //pageBounds.Height = (int)Math.Sqrt(pageBounds.Width * pageBounds.Height * neededAR);
                        Size newSize = pageBounds.Size;
                        GUIUtilities.CalcDestSize(p.BackgroundImage.GetSize(), ref newSize);
                        pageBounds.Size = newSize;
                    }
                    p.SetSize(pageBounds.Size, p.Margin);
                    if (adjustContents)
                    {
                        TransformContents(p.Contents, transaction, true, pageBounds, old);
                    }
                    else
                    {
                        TranslateYContents(p.Contents, transaction, -pageBounds.Height + old.Height);
                    }
                    p.NotifyIndirectChange(null, ChangeAffects.RepaintNeeded,
                                           new RectangleF(-10000, -10000, 20000, 20000));      // forces a complete repaint, including any non-page areas (current non-page might include bits which were previously page)
                }
            }
            return(transaction);
        }
Esempio n. 2
0
        /// <summary>Creates a bitmap from the data (if it was WMF or SVG)</summary>
        private Bitmap GenerateBitmap(Size sz)
        {
            Debug.Assert(IsSVG || !(GetNetImage() is Bitmap));             // if it already is the code below will work, but there's something wrong (and it's inefficient!)
            if (IsSVG)
            {
                GUIUtilities.CalcDestSize(Size, ref sz);
                // we don't rely on Draw maintaining aspect:ratio, since we can only fix one coord.  if we fixed width and the image happened to be very tall it would result in a huge image
                var x = m_SVG.Draw(sz.Width, sz.Height);
                //#if DEBUG
                //				x.Save(@"d:\temp\svg draw.png");
                //#endif
                return(x);
            }
            Bitmap bmp = new Bitmap(sz.Width, sz.Height, PixelFormat.Format32bppArgb);

            using (Graphics gr = Graphics.FromImage(bmp))
            {
                gr.Clear(Color.Transparent);
                Rectangle rect = new Rectangle(Point.Empty, sz);
                GUIUtilities.CalcDestRect(sz, ref rect);
                gr.DrawImage(m_Image, rect);
            }
            return(bmp);
        }