freetype轮廓重建不匹配字体

时间:2014-03-23 14:06:50

标签: c++ fonts freetype2

以下是使用freetype提取的两个字符轮廓,并使用二次贝塞尔曲线公式在一些循环中处理(由opensans常规ttf字体帮助)。我不确定我所做的是否正确,c ++代码生成的字体与官方代码不同。

代码将得到字母的轮廓,迭代它,得到两个点和一个关闭点(贝塞尔二次控制/终点),并使用圆锥贝塞尔公式计算结果点。这些点在控制台上喷出(调试目的)。使用gnuplot绘制结果点,连接每个点(使用gnuplot中的lines选项)。

这是字母h和e:

http://imgur.com/JyHkZ7H,Aapr6zX

字母e的奇怪之处在于内部轮廓以外部点结束(Coes不与起点连接)。当对oultine poligon进行三角测量时,这将导致问题。

我在加载/字体,加载freetype中的字母时错过了一些选项吗?

Bellow你可以看到代码的相关部分。

打开字体:

FT_New_Face(ft, "OpenSans-Regular.ttf", 0, &this->face)

创建字形:

FT_GlyphSlot g = this->face->glyph;

从信中创建面孔:

for (p = text; *p; p++) {

    /* Try to load and render the character */
    if (FT_Load_Char(this->face, *p, FT_LOAD_RENDER))
        continue;

迭代Freetype生成的大纲:

char       tag           = *g->outline.tags;
    int start_point = 0;
    int end_point;
    for(int current_contour = 0; current_contour < g->outline.n_contours; current_contour++){
        end_point = g->outline.contours[current_contour];
        for(int current_point = start_point; current_point <= end_point; current_point++){
            std::bitset<8>first_tags(tag);
            FT_Vector first_point = g->outline.points[current_point];
            tag++;current_point++;
            if(first_tags[0] == FT_CURVE_TAG_ON){
                std::bitset<8>second_tags(tag);
                FT_Vector second_point = g->outline.points[current_point];
                tag++;current_point++;
                if(second_tags[0] != FT_CURVE_TAG_ON){
                    std::bitset<8>third_tags(tag);
                    FT_Vector third_point = g->outline.points[current_point];
                    if(current_point-1 == end_point){
                        third_point = g->outline.points[start_point];
                    }
                    for(double t = 0; t <= 1; t+=0.01){
                        FT_Vector letter_point;
                        letter_point.x = (1-t)*(1-t)*first_point.x+2*(1-t)*t*second_point.x + t*t*third_point.x;
                        letter_point.y = (1-t)*(1-t)*first_point.y+2*(1-t)*t*second_point.y + t*t*third_point.y;
                        if(current_letter == 1){
                            std::cout << letter_point.x << " " << letter_point.y << std::endl;
                        }
                    }
                    current_point--;
                }
            }
        }
        start_point = end_point+1;
    }

感谢。

1 个答案:

答案 0 :(得分:0)

按键访问tags数组修复了大部分问题