/** Cheungmine * 2013-5-5 */# include <stdio. h> # include <stdlib. h> # include <time. h> # ifdef _ msc_ver # include <windows. h> # pragma warning (Disable: 4996) # endif/* Cairo API */# include ".. /lib/Cairo/include/Cairo. H "# include ".. /lib/Cairo/include/cairo-features.h "# include ".. /lib/Cairo/include/cairo-svg.h "# include ".. /lib/Cairo/include/cairo-pdf.h "# include ".. /lib/Cairo/include/cairo-ps.h "# include "../ LIB/Cairo/include/cairo-ft.h "# include ".. /lib/Cairo/include/cairo-version.h "# include ".. /lib/Cairo/include/cairo-win32.h "# pragma comment (Lib ,".. /.. /lib/Cairo. lib ") # ifdef _ msc_verstatic int bstr2utf8 (BSTR bstrin, int bstrlen, byte * pout) {int cbsize; If (! Bstrin) {return 0;} cbsize = widechartomultibyte (cp_utf8, 0, bstrin, bstrlen, 0, 0, 0); If (pout) {cbsize = widechartomultibyte (cp_utf8, 0, bstrin, bstrlen, (lpstr) pout, cbsize, 0, 0); Assert (pout [cbSize-1] = 0);} return cbsize ;} static int bytes2bstr (uint ucodepage, byte * pbytesin, DWORD cbsizein, BSTR * pbstrout) {int cchneeded; lpstr pstr; * pbstrout = 0; cchneeded = bytes (ucod Epage, 0, (lpcstr) pbytesin, cbsizein, 0, 0); If (0 = cchneeded) {return (0);} pstr = (lpstr) cotaskmemalloc (sizeof (DWORD) + sizeof (wchar) * cchneeded); If (! Pstr) {return (-1);} If (cchneeded! = Multibytetowidechar (ucodepage, 0, (lpcstr) pbytesin, cbsizein, (lpwstr) (pstr + sizeof (DWORD), cchneeded) {cotaskmemfree (pstr ); return (-2);} * (DWORD *) pstr) = sizeof (wchar) * (cchNeeded-1); * pbstrout = (BSTR) (pstr + sizeof (DWORD )); return cchneeded;} Char * ansi2utf8 (char * Str) {BSTR = 0; byte * utf8 = 0; int Len, CB; Len = bytes2bstr (cp_acp, (byte *) STR, strlen (STR) + 1, & BSTR); If (LEN> 0) {C B = bstr2utf8 (BSTR, Len, utf8); If (CB> 0) {utf8 = (byte *) malloc (CB); bstr2utf8 (BSTR, Len, utf8 );} sysfreestring (BSTR); Return (char *) utf8;} return 0;} # else # endifint drawchinatext (char * shapefile, char * shapeid, int width, int length, gde_drawsurface_format format) {cairo_surface_t * surface; cairo_t * Cr; char * font; char * text; font = ansi2utf8 (""); // "Arial Unicode ms" text = ansi2ut F8 ("Hello, Chinese! Hello, Chinese! "); Surface = crop (cairo_format_argb32, width, length); CR = cairo_create (surface); cairo_select_font_face (Cr, Font, rows, rows); cairo_set_font_size (Cr, 32.0 ); cairo_set_source_rgb (Cr, 0.0, 0.0, 1.0); cairo_move_to (Cr, 10.0, 50.0); cairo_show_text (Cr, text); cairo_destroy (CR); surface ("C: /temp/hello-cairo.png "); cairo_surface_destroy (surface); free (font); free (text); Return 0 ;}