Hi,Uli<br>thank you.cairo_show_glyphs() works,can display english words correctly.<br>but  Asian fonts(Chinese, Japanese and Korean), how to, anyidea?<br><br>I tried FT_Select_Charmap( face, FT_ENCODING_UNICODE ), details  as below,<br>
<b>1. init</b><br>    FT_Library library;<br>    FT_Face freetype_face;<br>    cairo_font_face_t *cairo_face;<br>    cairo_glyph_t glyph;<br>    FT_Init_FreeType(&amp;library);<br>    FT_New_Face(library, &quot;/usr/share/fonts/simhei.ttf&quot;, 0, &amp;freetype_face);<br>
    cairo_face = (cairo_font_face_t *) cairo_ft_font_face_create_for_ft_face( freetype_face, 0);<br>    cairo_t *cr;<br>    cairo_surface_t * surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,<br>            390, 400);<br>
    cr = cairo_create(surface);<br><br>    cairo_set_font_face(cr, cairo_face);<br>    cairo_set_font_size(cr, TEXT_SIZE);<br>    cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);<br>    cairo_paint(cr);<br>    cairo_set_source_rgb(cr,0, 0, 1.0);<br>
<b>2. try draw on cairo_t</b><br>    void draw(cairo_t *cr, int width, int height) {<br>    glyph_array_t glyphs;<br>    glyph_array_init(&amp;glyphs, 1, TEXT_SIZE);<br>    glyph_array_add_text(&amp;glyphs, cr, &quot;English&quot;, 0.0);<br>
    glyph_array_rel_move_to(&amp;glyphs, TEXT_SIZE * 1.5, 0.0);<br>    glyph_array_add_text(&amp;glyphs, cr, &quot;中文&quot;, 0.0);<br>    glyph_array_show(&amp;glyphs, cr);<br>   }<br><b>3. glyph_array_add_text</b><br>void glyph_array_add_text(glyph_array_t *glyphs, cairo_t *cr, const char *s, double spacing) {<br>
    cairo_scaled_font_t *scaled_font;<br>    cairo_status_t status;<br>    FT_Face face;<br>    unsigned long charcode;<br>    unsigned int index;<br>    cairo_text_extents_t extents;<br>    const char *p;<br>    FT_Vector kerning;<br>
    double kern_x;<br>    int first = true;<br>    scaled_font = cairo_get_scaled_font(cr);<br>    status = cairo_scaled_font_status(scaled_font);<br>    face = cairo_ft_scaled_font_lock_face(scaled_font);<br><br>    FT_Select_Charmap( face, FT_ENCODING_UNICODE );<br>
    FT_Set_Char_Size(face, 16 &lt;&lt; 6, 16 &lt;&lt; 6, 300, 300);<br>    p = s;<br>    while (*p) {<br>        charcode = *p;<br>        index = FT_Get_Char_Index(face, charcode);<br>        glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].index = index;<br>
        if (first) {<br>            first = false;<br>            glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].x = glyphs-&gt;x;<br>            glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].y = glyphs-&gt;y;<br>        } else {<br>
            cairo_glyph_extents(cr, &amp;glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs - 1],<br>                    1, &amp;extents);<br>            FT_Get_Kerning(face,<br>                    glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs - 1].index,<br>
                    glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].index,<br>                    FT_KERNING_UNSCALED, &amp;kerning);<br>            kern_x = DOUBLE_FROM_26_6(kerning.x);<br>            glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].x =<br>
                    glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs - 1].x<br>                            + extents.x_advance + kern_x + spacing;<br>            glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].y =<br>                    glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs - 1].y<br>
                            + extents.y_advance;<br>        }<br>        cairo_glyph_extents(cr, &amp;glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs], 1,<br>                &amp;extents);<br>        glyphs-&gt;x = glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].x + extents.x_advance<br>
                + spacing;<br>        glyphs-&gt;y = glyphs-&gt;glyph_list[glyphs-&gt;num_glyphs].y<br>                + extents.y_advance;<br>        p++;<br>        glyphs-&gt;num_glyphs++;<br>    }<br>    cairo_ft_scaled_font_unlock_face(scaled_font);<br>
}<br><b>4. glyph_array_show</b><br>    void glyph_array_show(glyph_array_t *glyphs, cairo_t *cr) {<br>    cairo_show_glyphs(cr, glyphs-&gt;glyph_list, glyphs-&gt;num_glyphs);<br>}<br><br>Thanks<br>Wei<br><br><br><div class="gmail_quote">
2012/6/4 Uli Schlachter <span dir="ltr">&lt;<a href="mailto:psychon@znc.in" target="_blank">psychon@znc.in</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<div><div><br>
<br>
On 04.06.2012 09:57, Jihe Wei wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
When we try to show text with multi-language,<br>
like Asian fonts(Chinese, Japanese and Korean).<br>
But can&#39;t display them except some squares.<br>
<br>
also<br>
<a href="http://blog.vlad1.com/2007/12/11/graphics-in-mozilla/" target="_blank">http://blog.vlad1.com/2007/12/<u></u>11/graphics-in-mozilla/</a><br>
says &quot;The toy font API that’s present in Cairo can be ignored,<br>
as it does not support international text and is there only for convenience<br>
for smaller projects.&quot;<br>
<br>
so what&#39;s your opinion?<br>
</blockquote>
<br></div></div>
So let&#39;s first make it clear what said toy font API is:<br>
cairo_show_text() and cairo_select_font_face()<br>
<br>
What should applications use instead? The docs point at cairo_show_glyphs() / cairo_show_text_glyphs() and font-backend specific functions like e.g. cairo_ft_font_face_create_for_<u></u>pattern().<br>
<br>
However, for these APIs, you are rendering glyphs instead of a text. Converting your text into glyphs is something that cairo does not do for you (unless you use the toy text API). If you want a solution that should work everywhere, you should take a look at Pango[0]. With PangoCairo, you can make Pango draw to a cairo_t and thus continue using cairo. Pango will convert your text to glyphs and use the non-toy API for doing its job.<br>


<br>
Hopefully this helped.<br>
Uli<br>
<br>
[0] <a href="http://www.pango.org" target="_blank">http://www.pango.org</a><br>
</blockquote></div><br>