Hi
,
I have a question=)
First, i want to get text as polygons, then i am going to tessellate those polygons. I need this type of approach because i am working on a CAD editor as a hobby, which needs text objects as polygons.
With below code, i can get the contours of letters. Then i use contour coordinates for creating tessellated polygons.
My question is, is there a SFML way to get these tessellated polygons, or just contours?
std::string::iterator end_it = utf8::find_invalid(mytextobj->text.begin(), mytextobj->text.end());
if(end_it != mytextobj->text.end()){
std::cout << mytextobj->text<< "not a utf8 text\n";
mytextobj->text = "???";
}
std::vector<unsigned int> utf32line;
utf8::utf8to32(mytextobj->text.begin(), end_it, std::back_inserter(utf32line));
filename = "c:/fonts/verdana.ttf";
unsigned int h = 12;
FT_Library library;
if(FT_Init_FreeType(&library))
throw std::runtime_error("Freetype font error.");
FT_Face face;
if(FT_New_Face(library, filename.c_str(), 0, &face))
throw std::runtime_error("file load error.");
FT_Select_Charmap(face, ft_encoding_unicode);
FT_Set_Char_Size(face, h * 64, h * 64, 1920, 1080);
double x_counter = 0;
for(unsigned int i = 0; i < utf32line.size(); i++){
if(FT_Load_Glyph(face, FT_Get_Char_Index(face, utf32line[i]), FT_LOAD_DEFAULT )){
throw std::runtime_error("load glyph not working./n");}
FT_Glyph glyph;
if(FT_Get_Glyph(face->glyph, &glyph))
throw std::runtime_error("Glyph error.");
std::vector<Point> pv;
FT_GlyphSlot g = face->glyph;
unsigned int c1 = 0, c2 = 0;
if (utf32line.at(i) != ' ' && utf32line.at(i) != '\t'){
for(c1 = 0; c1 <= g->outline.contours[g->outline.n_contours - 1]; c1++){
pv.push_back(Point(x_counter + ((double)(g->outline.points[c1].x)), mytextobj->koordinat.y + ((double)(g->outline.points[c1].y)), mytextobj->koordinat.z));
if(c1 == g->outline.contours[c2]){
c2++;
mytextobj->pvs.push_back(pv);
pv.clear();
}
}
}
else{
x_counter += g->advance.x;
}
FT_BBox abbox;
FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_UNSCALED, &abbox);
x_counter += abbox.xMax;
FT_Done_Glyph(glyph);
}
FT_Done_Face(face);
FT_Done_FreeType(library);