TakeInitialTransform() 공개 메소드

Takes the inital state.
public TakeInitialTransform ( ) : void
리턴 void
예제 #1
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// Exports the given diagram into a PDF. The PDF is saved at the location
        /// given in <see cref="fileName"/>. If selectedOnly is true, only the selected
        /// elements of the diagram get exported.
        /// </summary>
        public void Export(Graphics g)
        {
            if (MonoHelper.IsRunningOnMono)
            {
                GlobalFontSettings.FontResolver = new NClassFontResolver();
            }

            PdfDocument document    = new PdfDocument();
            PdfPage     page        = document.AddPage();
            RectangleF  diagramSize = nclassDocument.GetPrintingArea(selectedOnly);

            page.Width  = new XUnit(diagramSize.Width, XGraphicsUnit.Presentation) + new XUnit(padding.Right * 2);
            page.Height = new XUnit(diagramSize.Height, XGraphicsUnit.Presentation) + new XUnit(padding.Bottom * 2);

            XGraphics   gfx      = XGraphics.FromPdfPage(page);
            PDFGraphics graphics = new PDFGraphics(gfx);

            //Translate because of the padding.
            graphics.TranslateTransform(padding.Left, padding.Top);

            //Do some scaling to get from pixels to dots...
            Graphics gdiGraphics = g;

            graphics.ScaleTransform(72.0f / gdiGraphics.DpiX, 72.0f / gdiGraphics.DpiY);
            //Fonts are already mesured in dots but the size of them is also scaled by the above
            //transformation. So we have to applay an opposite transformation on the fonts first.
            graphics.ScaleFont = gdiGraphics.DpiY / 72.0f;
            //PDF-Sharp also does the scaling for the images itself. So we have to revert this as
            //we did it for the fonts.
            graphics.ScaleImage = gdiGraphics.DpiX / 72.0f;

            //Move everything to the top left corner
            graphics.TranslateTransform(-diagramSize.X, -diagramSize.Y);

            graphics.TakeInitialTransform();

            nclassDocument.Print(graphics, selectedOnly, Style.CurrentStyle);

            //Clean up...
            while (gfx.GraphicsStateLevel > 0)
            {
                gfx.Restore();
            }

            document.Options.CompressContentStreams = true;
            try
            {
                document.Save(fileName);
                Successful = true;
            }
            catch (IOException e)
            {
                MessageBox.Show(String.Format(Strings.Error_CoulNotWritePDF, e.Message), Strings.ErrorDialog_Title,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
    // ========================================================================
    // Methods

    #region === Methods

    /// <summary>
    /// Exports the given diagram into a PDF. The PDF is saved at the location
    /// given in <see cref="fileName"/>. If selectedOnly is true, only the selected
    /// elements of the diagram get exported.
    /// </summary>
    public void Export()
    {
      PdfDocument document = new PdfDocument();
      PdfPage page = document.AddPage();
      RectangleF diagramSize = nclassDocument.GetPrintingArea(selectedOnly);
      page.Width = new XUnit(diagramSize.Width, XGraphicsUnit.Presentation) + new XUnit(padding.Right*2);
      page.Height = new XUnit(diagramSize.Height, XGraphicsUnit.Presentation) + new XUnit(padding.Bottom*2);

      XGraphics gfx = XGraphics.FromPdfPage(page);
      PDFGraphics graphics = new PDFGraphics(gfx);

      //Translate because of the padding.
      graphics.TranslateTransform(padding.Left, padding.Top);

      //Do some scaling to get from pixels to dots...
      Graphics gdiGraphics = (new Control()).CreateGraphics();
      graphics.ScaleTransform(72.0f/gdiGraphics.DpiX, 72.0f/gdiGraphics.DpiY);
      //Fonts are already mesured in dots but the size of them is also scaled by the above
      //transformation. So we have to applay an opposite transformation on the fonts first.
      graphics.ScaleFont = gdiGraphics.DpiY/72.0f;
      //PDF-Sharp also does the scaling for the images itself. So we have to revert this as
      //we did it for the fonts.
      graphics.ScaleImage = gdiGraphics.DpiX/72.0f;

      //Move everything to the top left corner
      graphics.TranslateTransform(-diagramSize.X, -diagramSize.Y);

      graphics.TakeInitialTransform();

      nclassDocument.Print(graphics, selectedOnly, Style.CurrentStyle);

      //Clean up...
      while(gfx.GraphicsStateLevel > 0)
      {
        gfx.Restore();
      }

      document.Options.CompressContentStreams = true;
      try
      {
        document.Save(fileName);
        Successful = true;
      }
      catch(IOException e)
      {
        MessageBox.Show(String.Format(Strings.Error_CoulNotWritePDF, e.Message), Strings.ErrorDialog_Title,
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }