Cairo draw Chinese text on Windows

Source: Internet
Author: User
Tags cairo
/** 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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.