' Gambas module file

'''
' Name: MudulePrintTwoImages
' Author: Timothy Marshal-Nichols
' eMail: timothy@m-nichols.freeserve.co.uk
' Version: 1.0
' Version Date: August 2006
' Version History:
'
'''
' 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 a demo of simple printing showing how
' text and images can be laid out on a page.
'
'''
' 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 and call the procedure:
'
'   ModulePrintTwoImages.PrintTwoImages(imageTop, textTop, imageBottom, textBottom)
'
'''

PUBLIC SUB PrintTwoImages(imgTop AS Image, topText AS String, imageBottom AS Image, bottomText AS String)
  DIM imageTopToPrint AS Image
  DIM imageBottomToPrint AS Image
  DIM imageWidth AS Integer
  DIM imageHeight AS Integer
  DIM scaleIsotropic AS Float
  DIM border AS Float
  DIM textHeight AS Float
  DIM top AS Float
  ' Display printer dialog
  IF Printer.Setup() THEN RETURN
  INC Application.Busy
   ' Draw printer page
  Draw.Begin(Printer)
  border = Printer.Resolution
  '
  ' Get top image size for the printer resolution
  imageWidth = (imgTop.Width * Printer.Resolution) / Desktop.Resolution
  imageHeight = (imgTop.Height * Printer.Resolution) / Desktop.Resolution
  ' Adjust image size if it does not fit on the printer page
  IF imageWidth > Printer.Width OR imageHeight > ((Printer.Height / 2) - border - Draw.TextHeight(topText)) THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / imageWidth, ((Printer.Height / 2) - border - Draw.TextHeight(topText)) / imageHeight)
    imageWidth *= scaleIsotropic
    imageHeight *= scaleIsotropic
  END IF
  ' Scale top image
  imageTopToPrint = imgTop.Stretch(imageWidth, imageHeight, TRUE)
  '
  ' Get bottom image size for the printer resolution
  imageWidth = (imageBottom.Width * Printer.Resolution) / Desktop.Resolution
  imageHeight = (imageBottom.Height * Printer.Resolution) / Desktop.Resolution
  ' Adjust image size if it does not fit on the printer page
  IF imageWidth > Printer.Width OR imageHeight > ((Printer.Height / 2) - border - Draw.TextHeight(bottomText)) THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / imageWidth, ((Printer.Height / 2) - border - Draw.TextHeight(bottomText)) / imageHeight)
    imageWidth *= scaleIsotropic
    imageHeight *= scaleIsotropic
  END IF
  ' Scale bottom image
  imageBottomToPrint = imageBottom.Stretch(imageWidth, imageHeight, TRUE)
  '
  ' Top text
  textHeight = Draw.TextHeight(topText)
  Draw.Text(topText, border, border, Printer.Width - (2 * border), textHeight, Align.Center)
  Draw.Rect(border, border, Printer.Width - (2 * border), textHeight)
  ' Print top image
  top = border + textHeight + ((Printer.Height / 2) - border - textHeight - imageTopToPrint.Height) / 2
  Draw.Image(imageTopToPrint, (Printer.Width - imageTopToPrint.Width) / 2, top)
  ' Bottom text
  textHeight = Draw.TextHeight(bottomText)
  Draw.Text(bottomText, border, Printer.Height / 2, Printer.Width - (2 * border), textHeight, Align.Center)
  Draw.Rect(border, Printer.Height / 2, Printer.Width - (2 * border), textHeight)
  ' Print bottom image
  top = (Printer.Height / 2) + textHeight + ((Printer.Height / 2) - border - textHeight - imageBottomToPrint.Height) / 2
  Draw.Image(imageBottomToPrint, (Printer.Width - imageBottomToPrint.Width) / 2, top)
  Draw.End
  DEC Application.Busy
END

''' End of MudulePrintTwoImages '''
