[cairo]about SVG file outputting

yamagata yamagata at skycom.jp
Thu Mar 1 22:58:34 PST 2007


Hello Cairo Mailing-list,

This is Ryo Yamagata, an engineer.

May I ask you a question?

When outputting any characters by SVG file format using Cairo Library,

Character strings doesn’t display correctly.

Could you please check the following sample code & advice on this?

--System Environment:
  OS:Windows XP
  Development Environment:Visual studio 6
  Cairo library Version:cairo-1.2.6

  SVG Viewer Tool :IE 7 (Adobe SVG Viewer 3.0)
                     or Firefox 2.0.0.1

--Sample Code:

#include <cairo-win32.h>
#include <cairo-svg.h>

void draw(cairo_surface_t *pSurf)
{
    int ires;
    LPWSTR wbuf=L"1234567890";
    LPSTR  putf=NULL;

    //create cairo object
    cairo_t *pCr = cairo_create(pSurf);

    //move
    cairo_move_to (pCr, 10.0, 50.0);

    //font select
    cairo_select_font_face (pCr,"Serif",CAIRO_FONT_SLANT_NORMAL,CAIRO_FONT_WEIGHT_BOLD);

    //font size
    cairo_set_font_size (pCr, 32.0);

    //color
    cairo_set_source_rgba (pCr, 0.0, 0.3, 1.0, 1.0);

    //size check 
    ires = WideCharToMultiByte(
        CP_UTF8,        // UTF8
        0,              // flag
        wbuf,           // in
        -1,             // in size
        NULL,           // out
        0,              // out size
        NULL,NULL
        );
    if (ires == 0)
    {
        delete [] wbuf;
    }

    //// create memory
    putf = new char[ires+1];
    if (putf == NULL)
    {
        delete [] wbuf;
    }
    //// change code
    ires = WideCharToMultiByte(
        CP_UTF8,        // UTF8
        0,              // flag
        wbuf,           // in
        -1,             // in size
        putf,           // out
        ires,           // out size
        NULL,NULL
        );


    if (ires == 0)
    {
        delete [] wbuf;
        delete [] putf;
    }

    cairo_show_text (pCr,putf);                   //text out
    cairo_surface_write_to_png (pSurf, "hw.png"); //png out
    cairo_show_page (pCr);                        //page end
    cairo_destroy(pCr);                           //cairo destroy
}


//----------------Windows Main-----------------------------------
INT WINAPI
WinMain (HINSTANCE hInstance,
         HINSTANCE hPrevInstance,
         PSTR      lpCmdLine,
         INT       iCmdShow)
{

    cairo_surface_t *svg_surface;                         //cairo surface
    cairo_t *svg_cr;                                      //cairo 

    svg_surface =cairo_svg_surface_create("testsvg.svg",1024,1024);//svg create file
    svg_cr = cairo_create (svg_surface);       //cairo create
    draw(svg_surface);                         //draw svg
    cairo_destroy (svg_cr);                    //cairo delete
    cairo_surface_destroy (svg_surface);       //cairo surface delete
    return 0;
}


Thank you in advance for your help.

Best regards,

Ryo Yamagata




More information about the cairo mailing list