Hi everyone. At the moment, I work on personnal fontbaker like http://www.lmnopc.com/bitmapfontbuilder/ for my personnal culture.
So my mean is to have the same result as this : http://uppix.net/5/c/6/3f2437d78c4492e66fcacf8c2fdbc.bmp I wrote a super crappy code and i have this result : http://uppix.net/0/e/b/ea39dd385d434379da51679001578.png You can see i have no vertical alignement. So i try to use different Glyph metric values like startY = (line+size-top); and I have this result : http://uppix.net/f/e/2/67bc9a93807a1016ea2d215dde8c6.png My caracteres are aligned but too low. I try another values like startY = (line+size-top)+descent; : http://uppix.net/a/6/4/7e96c203860c0ce045cd84df47f50.png And is better but not good. I’m sure I miss a big fact about positioning. In attachement my font baker source code. Can you help me ? Thanks and sorry for my poor english. Ludovic.
<<wlEmoticon-smile[1].png>>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_STROKER_H
#include <vector>
#include <fstream>
#include <iostream>
#include <SFML/Graphics.hpp>
// Render the specified character in texture atlas
void AddGlyph(
FT_Library &library,
wchar_t ch,
FT_Face &face,
int size,
sf::Image &image,
int line,
int col
)
{
col *= size;
line *= size;
// Load the glyph corresponding to the code point
FT_Load_Char(face, ch, FT_LOAD_RENDER );
// Retrieve the glyph
FT_Glyph glyphDesc;
FT_Get_Glyph(face->glyph, &glyphDesc);
// Convert the glyph to a bitmap (i.e. rasterize it)
FT_Glyph_To_Bitmap(&glyphDesc, FT_RENDER_MODE_NORMAL,0, 1);
FT_BitmapGlyph bitmapGlyph = (FT_BitmapGlyph)glyphDesc;
FT_Bitmap& bitmap = bitmapGlyph->bitmap;
int width = bitmap.width;
int pitch = bitmap.pitch;
int height = bitmap.rows;
int top = bitmapGlyph->top;
int left = bitmapGlyph->left;
unsigned char* pixels = bitmap.buffer;
if ((width > 0) && (height > 0))
{
int descent = face->size->metrics.descender >>6;
int linegap =
((face->glyph->metrics.horiBearingY-face->glyph->metrics.height)>>6);//ascent -
descent;
int startY = (line);//+size-top)+descent;
for (int y = 0; y <height; ++y)
{
for (int x = 0; x < width; ++x)
{
int pixelCol =(y<height)?pixels[y*pitch+x]:255;
image.setPixel(x+col+left,y+startY,sf::Color(pixelCol,pixelCol,pixelCol,255));
}
}
}
}
int main(int argc, char **argv)
{
if (argc != 3)
{
std::cerr << "Render letter `B' of given font as a TGA
image.\n";
std::cerr << "\n";
std::cerr << "usage: example2 <font> <TGA-file>\n";
return 1;
}
// Iniialize FreeType.
FT_Library library;
FT_Init_FreeType(&library);
// Open up a font file.
std::ifstream fontFile(argv[1], std::ios::binary);
if (fontFile)
{
// Read the entire file to a memory buffer.
fontFile.seekg(0, std::ios::end);
std::fstream::pos_type fontFileSize = fontFile.tellg();
fontFile.seekg(0);
unsigned char *fontBuffer = new unsigned char[fontFileSize];
fontFile.read((char *)fontBuffer, fontFileSize);
// Create a face from a memory buffer. Be sure not to delete
the memory
// buffer until you are done using that font as FreeType will
reference
// it directly.
FT_Face face;
FT_New_Memory_Face(library, fontBuffer, fontFileSize, 0, &face);
int Quality = 32;
int TexSize = Quality * 16;
//texture bitmap font
sf::Image bitMapTexture;
bitMapTexture.create(TexSize,TexSize);
//Scale des caracteres
FT_Set_Pixel_Sizes(face,Quality, Quality );
FT_Select_Charmap(face, FT_ENCODING_UNICODE);
int charindex = 0;
for(int ligne = 0 ; ligne < 16 ; ligne++)
for(int colonne = 0 ; colonne < 16 ; colonne++ , charindex++)
{
AddGlyph(library,charindex,face,
Quality,bitMapTexture,ligne,colonne);
}
// Now that we are done it is safe to delete the memory.
delete [] fontBuffer;
sf::Image charA;
for(int x = 0 ; x < bitMapTexture.getSize().x ; x++)
for(int y = 0 ; y < bitMapTexture.getSize().y ; y++ )
{
if( x % Quality == 0 || y % Quality == 0)
bitMapTexture.setPixel(x,y,sf::Color(255,0,0,255));
}
bitMapTexture.saveToFile("Hello.png");
}
// Clean up the library
FT_Done_FreeType(library);
return 1;
}
/* EOF */
_______________________________________________ Freetype mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/freetype
