' Gambas module file

'''
' Name: ModulePrintDrawing
' Author: Timothy Marshal-Nichols
' eMail: timothy@m-nichols.freeserve.co.uk
' Version: 1.2
' Version Date: June 2006
' Version History:
'   1.1 - 18 June 2006
'     Update to work with version 1.9.32 of Gambas
'     Added fit to page option to printing an image or drawing
'   1.2 - 02 August 2006
'     Split printing of text, images and drawings into seperate modules
'
'''
' Licence Information
'
' 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 2 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, write to the Free Software
' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
'
' http://www.gnu.org/licenses/gpl.html
'
'''
' Description:
'
' This module provides simple printing of text, images or drawings.
'
'''
' Developed using Gambas2 Version
'
'  Version: 1.9.35
'
' Gambas Components Used:
'
' gb - Gambas internal native classes
' gb.qt - Graphical QT toolkit component
'
' Look in the Project menu then Properties... and select
' the Components tab. Check that the listed components
' are in the project.
'
'''
' External Dependencies:
'
' None
'
'''
' Class Usage:
'
' Add this module to your project to provide simple printing.
' Then call the procedures.
'
' To print an Drawing centred on the printer page supply the drawing:
'
'   ModulePrintDrawing.PrintDrawing(displayDrawing)
'
' If you want to print a drawing full size on the page then
' set the FitToPage option to true:
'
'   ModulePrintDrawing.PrintDrawing(displayDrawing, TRUE)
'
'''

' Prints an drawing centered on the page.
' A drawing supports Scalable Vector Graphics (*.svg) files
' Setting the FitToPage option to true will fill the page with the drawing
PUBLIC SUB PrintDrawing(drw AS Drawing, OPTIONAL FitToPage AS Boolean)
  DIM drawingWidth AS Integer
  DIM drawingHeight AS Integer
  DIM scaleIsotropic AS Float
  ' Display printer dialog
  IF Printer.Setup() THEN RETURN
  INC Application.Busy
  ' Get drawing size for the printer resolution
  drawingWidth = (drw.Width * Printer.Resolution) / Desktop.Resolution
  drawingHeight = (drw.Height * Printer.Resolution) / Desktop.Resolution
  ' Adjust drawing size if it does not fit on the printer page
  ' Also if the fit to page option is set fill the page with the drawing
  IF FitToPage OR drawingWidth > Printer.Width OR drawingHeight > Printer.Height THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / drawingWidth, Printer.Height / drawingHeight)
    drawingWidth *= scaleIsotropic
    drawingHeight *= scaleIsotropic
  END IF
  ' Draw drawing centred on printer page
  Draw.Begin(Printer)
  Draw.Drawing(drw, (Printer.Width - drawingWidth) / 2, (Printer.Height - drawingHeight) / 2, drawingWidth, drawingHeight)
  'Draw.Rect((Printer.Width - drawingWidth) / 2, (Printer.Height - drawingHeight) / 2, drawingWidth, drawingHeight)
  Draw.End
  DEC Application.Busy
END

''' End of ModulePrintDrawing '''
