[cairo] Rendering to Windows Metafile with Cairo

Dominic Lachowicz domlachowicz at gmail.com
Tue Nov 25 09:32:44 PST 2008


GTK+ on Windows uses EMFs for its Print Preview functionality. You can
have a look @ http://svn.gnome.org/viewvc/gtk%2B/trunk/gtk/gtkprintoperation-win32.c?view=markup.
Some notable differences:

1) It uses a Win32 printing surface instead of a normal win32 surface
2) It calls CloseEnhMetaFile() after surface_destroy(). It also
deletes the metafile.
3) It calls StartPage/EndPage and uses cairo_surface_show_page

Hope this helps somewhat,
Dom

On Tue, Nov 25, 2008 at 11:47 AM, Kozhevnikov Mikhail
<mikhailkozhevnikov at yandex.ru> wrote:
> Hi All,
>
> I tried rendering smth to enhanced windows metafile. The result looks strange.
> Two files attached are results of rendering the code:
>
> void TestCairoEMF (bool emf)
> {
>   HDC hdc;
>
>   cairo_surface_t *surface;
>   cairo_t *cr;
>
>   if (emf)
>   {
>      hdc = CreateEnhMetaFile(NULL, "test.emf", NULL, NULL);
>      surface = cairo_win32_surface_create(hdc);
>   }
>   else
>      surface = cairo_pdf_surface_create("test.pdf", 100, 30);
>   cr = cairo_create (surface);
>   cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
>
>   cairo_move_to(cr, 5, 5);
>   cairo_line_to(cr, 30, 25);
>   cairo_line_to(cr, 50, 10);
>   cairo_line_to(cr, 80, 20);
>   cairo_set_source_rgb(cr, 0, 0, 1);
>   cairo_stroke(cr);
>
>   cairo_move_to(cr, 15, 15);
>   cairo_set_font_size(cr, 15);
>   cairo_set_source_rgb(cr, 0, 0, 0);
>   cairo_show_text(cr, "hello world");
>   if (emf)
>      CloseEnhMetaFile(hdc);
>   cairo_destroy (cr);
>   cairo_surface_destroy (surface);
> }
>
>
> However, if I use regular win32 DC, it works fine.
>
> Am I doing smth wrong?
> Or Windows metafile rendering is not supported at all?
>
> Thanks in advance,
> Mikhail.
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>



-- 
Counting bodies like sheep to the rhythm of the war drums.


More information about the cairo mailing list