[Gambas-user] How to insert a .png file into a CairoPdfSurface (gb.cairo)
Willy Raets
willy at ...2734...
Sun Aug 25 16:01:47 CEST 2013
On Sun, 2013-08-25 at 14:28 +0200, Tobias Boege wrote:
> On Sun, 25 Aug 2013, Willy Raets wrote:
> >
> > With help of Tobias, now a image appears on the PdfSurface
> > My code now looks like this:
> >
> >
> > Public Sub MakePdf()
> >
> > Dim hPdfProjectFile As CairoPdfSurface
> > Dim sPdfPath, sPicPath As String
> > Dim picImage As Image
> > Dim iX, iY As Float
> > sPicPath = User.Home & "/MyFolder/mypicture.png"
> > sPdfPath = User.Home & "/MyFolder/project.pdf"
> > hPdfProjectFile = New CairoPdfSurface(sPdfPath, 210, 297)
> > Cairo.Begin(hPdfProjectFile)
> > '----- Draw title -----
> > ..
> > ..
> >
> > '----- Draw project logo -----
> > iX = 230
> > iY = 235
> > If Exist(sPicturePath) Then
> > Cairo.MoveTo(iX, iY) '<-- Does NOT place image
> > Cairo.Source = Cairo.ImagePattern(Image.Load(sPicturePath)
> > Cairo.Paint()
> > Endif
> > '----- Draw version -----
> > ..
> > ..
> >
> >
> > End
> >
> > Some new problems arise:
> >
> > 1. The Cairo.Move(iX,iY) (before Cairo.Source) however seems of no
> > influence on the Cairo.Paint() as the image appears top-left on the
> > PdfSurface. I don't want it there but at ccordinates X = 230, Y = 235
> >
> > Question 1: How to position the image on the CairoPdfSurface?
> >
>
> Sorry, I was so busy that I forgot to answer (the project was already
> prepared) :-)
>
> The ImagePattern method has X/Y translation parameters. I think that this
> image pattern has a separate translation matrix which can be set either when
> creating it (Cairo.ImagePattern(hImage, 40, 40) to move to 40,40) or by
> manipulating the Cairo.Source.Matrix property after assigning the image
> pattern to Cairo.Source.
Cairo.Source = Cairo.ImagePattern(Image.Load(sPicturePath, iX, iY)
This works perfectly in my project :-)
>
> > 2. What is even worse is that all the Cairo.DrawText() methods following
> > Cairo.Source and Cairo.Paint() are no longer drawn onto the
> > CairoPdfSurface as they where before!
> >
> > Question 2: How to free up the source and go back to drawing text?
> >
> > Tobias made a small example to show me how to get an icon on a
> > PdfSurface. I modified this example to show you the 2 above problems.
> >
> > First just run the example to see only text drawn on the surface (code
> > with Cairo.source and Cairo.paint are your commented out).
> > Next uncomment the lines with Cairo.source and Cairo.paint and run the
> > example again.
> >
> > You will notice that text drawn after Cairo.source and Cairo.paint no
> > longer draws on the surface and that the icon is ALWAYS top-left
> >
>
> I think that the reason for the lost text is that the image is actually only
> an image pattern so you would draw text not with a solid black line but as
> if this image was your drawing device. Resetting the source to Null works
> for me.
Cairo.Source = Null did NOT do the job for me, the text after the source
was painted still is missing.
What did work for me was:
Cairo.Source = Cairo.ColorPattern(Color.Black)
So simply setting the pattern (that is used for text as well) to black
(the default)
Next, all text after the image was painted, is drawn onto the surface in
black :-)
Thanks again for all the help.
--
Kind regards,
Willy (aka gbWilly)
http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org
More information about the User
mailing list