Hi all again.. Another Cairo question..
I've got some sample Cairo "C" code to generate some text to a PDF and all works great -- the overall PDL is below : surface = cairo_pdf_surface_create(...); cr = cairo_create(surface); draw(cr); cairo_surface_destroy(surface); cairo_show_page(cr); cairo_destroy(cr); draw(cairo_t *cr) { cairo_move_to(cr, 10, 10); cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); cairo_show_text(cr, "Hello World"); } I used the sample code below to try to emulate what was done above.. However, the text in the resulting PDF has a text bitmap and looks poor IMHO (and the text is not selectable in your favorite PDF viewer). The C code above uses cairo_show_text which maps to CairoContext>>showText: aString.. I didn't find any code that uses that in the VW examples unfortunately... and it can't be used by the Layout class.. Is there a way to make this work closer to that C code above? Thanks! Here's the VW code : surface := ImageSurface format: CairoFormat argb32 extent: 576@216. surface newCairoContextWhile: [:aCr | aCr sourceColorValue: ColorValue black. aCr moveTo: 0 @ 10. layout := aCr newLayout. layout alignCenter. "layout compositionWidth: self bounds width - 10." "layout fontDescriptionString:'Monaco, 12'." layout text: 'the fox is lazy' . "works OK but is rendered as a bitmap" layout showText: 'this too'. "doesn't work" layout showOn: aCr. layout release. ]. pdf := PDFSurface path: '/tmp/sample.pdf' pointExtent: 576 @ 216. pdf newCairoContextWhile: [:cr | cr source: surface; paint; showPage]. pdf finish _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Responses inline below (untested, but hopefully enough to get you going).
On Tue, Jun 16, 2009 at 9:25 PM, Rick Flower <[hidden email]> wrote: I used the sample code below to try to emulate what was done above.. That's probably because you're creating the text bitmap (ImageSurface) and putting it into the PDF :-).
This surface should be your PDFSurface instead.
In this section, you're actually using Pango to render the text, rather than Cairo. Not a bad thing, but different from the C code you started with. Pango Layout's don't understand showText, so that's why that call doesn't work.
This surface should be what you draw on directly. By using an ImageSurface, you're basically creating the bitmap you don't want and then putting that into the PDF.
In general, I find that you can convert C-based Cairo examples almost directly to Smalltalk once you know a couple of the right idioms (like newCairoContextWhile:). Almost everything else comes straight across; if you have significantly more code in Smalltalk than in C, then you're doing more than you were in C. Again, not necessarily a bad thing, but definitely a cause of suspicion when you're looking for behavior differences. Randy -- Randy Coulman [hidden email] _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Randy Coulman wrote:
> Responses inline below (untested, but hopefully enough to get you going). > Cool! Thanks Much! I was able to do some more fiddling around and came up with this modified version which seems to work as I was hoping! pdf := PDFSurface path: '/tmp/sample.pdf' pointExtent: 576 @ 216. pdf newCairoContextWhile: [: aCr | aCr sourceColorValue: ColorValue black. aCr moveTo: 0 @ 10. layout := aCr newLayout. layout alignCenter. layout text: 'the fox is lazy' . "works OK but is rendered as a bitmap" layout showOn: aCr. layout release. ]. pdf finish It creates a small PDF that has text that can be cut-n-pasted -- just what I was looking for! Sorry that the code is a bit ugly... _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
On Jun 16, 2009, at 11:40 PM, Rick Flower wrote: > Randy Coulman wrote: >> Responses inline below (untested, but hopefully enough to get you >> going). >> > Cool! Thanks Much! I was able to do some more fiddling around and > came > up with > this modified version which seems to work as I was hoping! > > pdf := PDFSurface path: '/tmp/sample.pdf' pointExtent: 576 @ 216. > pdf newCairoContextWhile: [: aCr | > aCr sourceColorValue: ColorValue black. > aCr moveTo: 0 @ 10. > > layout := aCr newLayout. > layout alignCenter. > layout text: 'the fox is lazy' . "works OK but is rendered as a > bitmap" > layout showOn: aCr. > layout release. > ]. > pdf finish > > It creates a small PDF that has text that can be cut-n-pasted -- just > what I was > looking for! Sorry that the code is a bit ugly... You probably need to help it a little Rick. Give the layout a fontDescriptionString, something like: layout fontDescriptionString: 'Arial, 20'. I would expect that improves things. -- Travis Griggs Objologist "Every institution finally perishes by an excess of its own first principle." - Lord Acton _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |