FreeType如何呈现像üäö这样的特殊字符? [英] FreeType how to render special chars like ü ä ö?

查看:125
本文介绍了FreeType如何呈现像üäö这样的特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在用FreeType渲染文本.尤其是非ASCII字符让我头疼.经过一番尝试和错误后,我设法渲染了一些文本,但我的变音符号没有显示:

  std :: string text =Hauptmenü";for(std :: string :: iterator it = text.begin(); it!= text.end(); ++ it){std :: cout<<*它;FT_Face face = loadFace(faceName);FT_Set_Pixel_Sizes(face,0,fontSize);if(FT_Load_Char(face,* it,FT_LOAD_DEFAULT)){std :: cout<<无法加载字符'"<<字符<<'"<<std :: endl;}FT_Get_Glyph(face-> glyph,& glyph);FT_Glyph_To_Bitmap(&glyph,FT_RENDER_MODE_NORMAL,0,1);//将字形渲染到屏幕上,依此类推} 

加载字体,获取字形等基本上可以正常工作,但是不会渲染'ü'.这是我的输出结果:

除ü"外的所有字符都将显示!

这在我的控制台中结束,所以我猜我在字符串上的迭代一定有问题,因为ü"被分成两个字符.最后两个字符得到的字形位图的宽度和高度均为0.

我该如何解决?

解决方案

简短版

阅读: http://www.joelonsoftware.com/articles/Unicode.html

使用此: http://www.pango.org/

长版

您似乎对一般的文本表示和渲染有一些误解(您使用放弃软件来检查"文本输出会显示出它).幸运的是,乔尔(Joel)在描述问题方面做得相当不错: http://www.joelonsoftware.com/articles/Unicode.html

FreeType能够解析True Type文件,并呈现存储在文件中的字形.它不是一个成熟的文本呈现引擎.您使用的字体甚至可能没有所需的字形来呈现所需的字符,您可能需要组合不同的字形产生所需的输出.

当然,您不会自己实现整个Unicode渲染逻辑,这是一项艰巨的任务.如果您只想向其添加文本"并使其呈现,则必须使用更高级别的内容.至少是HarfBuzz或它上面的东西,例如Pango或Qt.在 SDL_Pango库中可以看到有关如何使用Pango + FreeType的一个很好的示例.

I am stuck at rendering text with FreeType. Especially non-ascii chars give me a headache. After some trial and error I managed to render some text, but my umlauts do not show:

std::string text = "Hauptmenü";
for(std::string::iterator it = text.begin(); it != text.end(); ++it) {
    std::cout << *it;

    FT_Face face = loadFace(faceName);

    FT_Set_Pixel_Sizes(face, 0, fontSize);

    if(FT_Load_Char(face, *it, FT_LOAD_DEFAULT)) {
        std::cout << "Could not load character '" << character << "'" << std::endl;
    }

    FT_Get_Glyph(face->glyph, &glyph);
    FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);

    //render the glyphs to screen and so on
}

Loading the font, getting the glyphs and so on is basically working, but the 'ü' is not rendered. This is what my output looks like:

All characters except the 'ü' get displayed!

This is ending up in my console, so I guess something must be wrong with my iteration over the string, as the 'ü' is split up into two chars. The glyph bitmaps I get for the last two chars are both of width and height 0.

How can I fix this?

解决方案

Short version

Read this: http://www.joelonsoftware.com/articles/Unicode.html

Use this: http://www.pango.org/

Long Version

You seem to have some misconceptions about text representation and rendering in general (your use of an abandonware to "check" the text output shows it). Luckily Joel did a pretty decent job at describing the problem: http://www.joelonsoftware.com/articles/Unicode.html

FreeType is able to parse True Type files, and render the glyphs stored in the files. It's not a full-fledged text rendering engine. The font you are using might not even have the glyphs necessary to render the characters you want, you might need to combine different glyphs to produce the desired output.

Of course you are not going to implement the whole Unicode rendering logic yourself, it's a daunting task. You have to use something higher level if you want to just throw "text" at it and get it rendered. At least HarfBuzz, or something on top of it, like Pango or Qt. A good example on how to use Pango+FreeType can be seen in the SDL_Pango library.

这篇关于FreeType如何呈现像üäö这样的特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆