[Gambas-user] Print probleem with pictures/text

Timothy Marshal-Nichols timothy.marshal-nichols at ...247...
Thu Jul 20 14:44:51 CEST 2006


>
> The attached project should print out two images on a page. One in the top
> half, and the other - surprise, surprise - in the bottom. Above each image
> should be some text (from a text area) centred in a rectangle. I hope this
> goes some way in demonstrating what you need to do in your
> project. (I could
> not completely work out what you wanted from your email)
>
> One thing I should apologise for. This project has been done on a slightly
> out of data version of the development version of Gambas and is a
> bit quick
> and dirty. (I am in the middle of updating the Linux distribution I am
> using. And I have not reinstalled everything.) I hope this does not cause
> any problems, but I thought I had better warn just in case you have any
> problems with the project.
>
> Thanks
>
> 8-{)} Timothy Marshal-Nichols
> <mailto: timothy.marshal-nichols at ...247...>
>
>


In fact there is a bug in the code I attached to the previous email. It
positioned the upper image incorrectly. This is a revised version of the
PrintImage procedure.

I suppose this illustrates the kind of problems the originator of this topic
is having.

------------------
PRIVATE SUB PrintImage(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
  ' Display printer dialog
  IF Printer.Setup() THEN RETURN
  INC Application.Busy
  '
  ' 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) THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / imageWidth, (Printer.Height / 2) /
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) THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / imageWidth, (Printer.Height / 2) /
imageHeight)
    imageWidth *= scaleIsotropic
    imageHeight *= scaleIsotropic
  END IF
  ' Scale bottom image
  imageBottomToPrint = imageBottom.Stretch(imageWidth, imageHeight, TRUE)
  '
  ' Draw printer page
  Draw.Begin(Printer)
  ' Top text
  Draw.Text(topText, 100, 100, Printer.Width - 200,
Draw.TextHeight(topText), Align.Center)
  Draw.Rect(100, 100, Printer.Width - 200, Draw.TextHeight(topText))
  ' Print top image
  Draw.Image(imageTopToPrint, (Printer.Width - imageTopToPrint.Width) / 2,
((Printer.Height / 2) - imageTopToPrint.Height) / 2)
 ' Bottom text
  Draw.Text(bottomText, 100, (Printer.Height / 2) + 100, Printer.Width -
200, Draw.TextHeight(bottomText), Align.Center)
  Draw.Rect(100, (Printer.Height / 2) + 100, Printer.Width - 200,
Draw.TextHeight(bottomText))
  ' Print bottom image
  Draw.Image(imageBottomToPrint, (Printer.Width - imageBottomToPrint.Width)
/ 2, (Printer.Height / 2) + ((Printer.Height / 2) -
imageBottomToPrint.Height) / 2)
  Draw.End
  DEC Application.Busy
END

------------------
Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>







More information about the User mailing list