the freType texture generation is obstract in the textured text (maybe need to create the imageFont)
This commit is contained in:
parent
3608a8f4df
commit
ff8f70d181
@ -1 +1 @@
|
||||
Subproject commit b000e558d0025cb35ef3950f46f722c4167ed0ec
|
||||
Subproject commit 63cab9e476494878fa3e946734334e2522816a6e
|
@ -34,15 +34,47 @@
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
// show : http://www.freetype.org/freetype2/docs/tutorial/step2.html
|
||||
/*
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
Y | | | |
|
||||
^ |------------| |------------|
|
||||
|
|
||||
m_advance.y:/-> |
|
||||
| |
|
||||
| |
|
||||
m_sizeTex.x/-> | | |------------| |------------|
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
| | | | A | | G |
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
| | | | | | |
|
||||
\-> | | |------------| |------------|
|
||||
/--> | |
|
||||
\--> \-> |
|
||||
m_bearing.y |
|
||||
|____*________________________*____________>> X
|
||||
|
||||
|
||||
<------------------------> : m_advance.x
|
||||
|
||||
<------------> : m_sizeTexture.x
|
||||
|
||||
<---> : m_bearing.x
|
||||
|
||||
*/
|
||||
typedef struct {
|
||||
uniChar_t unicodeCharVal;
|
||||
texCoord_ts posStart;
|
||||
texCoord_ts posStop;
|
||||
Vector2D<float> bearing;
|
||||
Vector2D<float> size;
|
||||
int32_t advance;
|
||||
}freeTypeFontElement_ts;
|
||||
uniChar_t m_UVal; // Unicode value
|
||||
int32_t m_glyphIndex; // Glyph index in the system
|
||||
Vector2D<int32_t> m_sizeTexture; // size of the element to display
|
||||
Vector2D<int32_t> m_bearing; // offset to display the data (can be negatif id the texture sise is bigger than the théoric places in the string)
|
||||
Vector2D<int32_t> m_advance; // space use in the display for this specific char
|
||||
} GlyphProperty;
|
||||
|
||||
class Font {
|
||||
private:
|
||||
@ -69,7 +101,12 @@ namespace ewol
|
||||
Vector2D<float> textPos,
|
||||
const uniChar_t unicodeChar,
|
||||
draw::Color& textColor) = 0;
|
||||
virtual bool GenerateBitmapFont(int32_t size, int32_t& height, ewol::Texture& texture, etk::Vector<freeTypeFontElement_ts>& listElement) = 0;
|
||||
virtual bool GetGlyphProperty(int32_t fontSize,
|
||||
ewol::GlyphProperty& property) = 0;
|
||||
virtual bool DrawGlyph(draw::Image& imageOut,
|
||||
int32_t fontSize,
|
||||
Vector2D<int32_t> glyphPosition,
|
||||
ewol::GlyphProperty& property) = 0;
|
||||
virtual Vector2D<float> GetSize(int32_t fontSize, const etk::UString & unicodeString) = 0;
|
||||
virtual int32_t GetHeight(int32_t fontSize) = 0;
|
||||
};
|
||||
|
@ -41,33 +41,6 @@ extern "C" {
|
||||
// free Font hnadle of librairies ... entry for acces ...
|
||||
static FT_Library library;
|
||||
|
||||
static int32_t nextP2(int32_t value)
|
||||
{
|
||||
int32_t val=1;
|
||||
for (int32_t iii=1; iii<31; iii++) {
|
||||
if (value <= val) {
|
||||
return val;
|
||||
}
|
||||
val *=2;
|
||||
}
|
||||
EWOL_CRITICAL("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
static int32_t simpleSQRT(int32_t value)
|
||||
{
|
||||
int32_t val=1;
|
||||
for (int32_t iii=1; iii<1000; iii++) {
|
||||
val =iii*iii;
|
||||
if (value <= val) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
EWOL_CRITICAL("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
void ewol::FreeTypeInit(void)
|
||||
{
|
||||
EWOL_DEBUG("==> Init Font-Manager");
|
||||
@ -155,6 +128,7 @@ int32_t ewol::FontFreeType::Draw(draw::Image& imageOut,
|
||||
if(false==m_init) {
|
||||
return 0;
|
||||
}
|
||||
// TODO : ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -167,6 +141,7 @@ int32_t ewol::FontFreeType::Draw(draw::Image& imageOut,
|
||||
if(false==m_init) {
|
||||
return 0;
|
||||
}
|
||||
// TODO : ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -175,156 +150,106 @@ Vector2D<float> ewol::FontFreeType::GetSize(int32_t fontSize, const etk::UString
|
||||
if(false==m_init) {
|
||||
return Vector2D<float>(0,0);
|
||||
}
|
||||
// TODO : ...
|
||||
Vector2D<float> outputSize(0,0);
|
||||
return outputSize;
|
||||
}
|
||||
|
||||
int32_t ewol::FontFreeType::GetHeight(int32_t fontSize)
|
||||
{
|
||||
return 0;
|
||||
return fontSize*1.43f; // this is a really "magic" number ...
|
||||
}
|
||||
|
||||
bool ewol::FontFreeType::GenerateBitmapFont(int32_t size, int32_t &height, ewol::Texture & texture, etk::Vector<freeTypeFontElement_ts> & listElement)
|
||||
bool ewol::FontFreeType::GetGlyphProperty(int32_t fontSize,
|
||||
ewol::GlyphProperty& property)
|
||||
{
|
||||
if(false==m_init) {
|
||||
return false;
|
||||
}
|
||||
// get the pointer on the image :
|
||||
draw::Image& myImage = texture.Get();
|
||||
|
||||
// 300dpi (hight quality) 96 dpi (normal quality)
|
||||
int32_t fontQuality = 96;
|
||||
//int32_t fontQuality = 150;
|
||||
//int32_t fontQuality = 300;
|
||||
// Select Size ...
|
||||
// note tha <<6==*64 corespond with the 1/64th of points calculation of freetype
|
||||
int32_t error = FT_Set_Char_Size(m_fftFace, size<<6, size<<6, fontQuality, fontQuality);
|
||||
// the line height to have a correct display
|
||||
height = size*1.43f;
|
||||
|
||||
int32_t error = FT_Set_Char_Size(m_fftFace, fontSize<<6, fontSize<<6, fontQuality, fontQuality);
|
||||
if (0!=error ) {
|
||||
EWOL_ERROR("FT_Set_Char_Size ==> error in settings ...");
|
||||
return false;
|
||||
}
|
||||
// a small shortcut
|
||||
FT_GlyphSlot slot = m_fftFace->glyph;
|
||||
/*
|
||||
EWOL_DEBUG("Max size for ths glyph size=" << size <<
|
||||
" is (" << m_fftFace->max_advance_width << "," << m_fftFace->max_advance_height << ")" <<
|
||||
"?=(" << (m_fftFace->max_advance_width>>6) << "," << (m_fftFace->max_advance_height>>6) << ")");
|
||||
*/
|
||||
// retrieve glyph index from character code
|
||||
int32_t glyph_index = FT_Get_Char_Index(m_fftFace, 'A' );
|
||||
int32_t glyph_index = FT_Get_Char_Index(m_fftFace, property.m_UVal);
|
||||
// load glyph image into the slot (erase previous one)
|
||||
error = FT_Load_Glyph(m_fftFace, // handle to face object
|
||||
glyph_index, // glyph index
|
||||
FT_LOAD_DEFAULT );
|
||||
if ( error ) {
|
||||
EWOL_ERROR("FT_Load_Glyph");
|
||||
if (0!=error ) {
|
||||
EWOL_ERROR("FT_Load_Glyph specify Glyph");
|
||||
return false;
|
||||
}
|
||||
EWOL_DEBUG("linearHoriAdvance=" << (slot->linearHoriAdvance >> 6));
|
||||
EWOL_DEBUG("linearVertAdvance=" << (slot->linearVertAdvance >> 6));
|
||||
EWOL_DEBUG("metrics.horiAdvance=" << (slot->metrics.horiAdvance >> 6));
|
||||
EWOL_DEBUG("metrics.vertAdvance=" << (slot->metrics.vertAdvance >> 6));
|
||||
// convert to an anti-aliased bitmap
|
||||
error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL );
|
||||
if (0!=error) {
|
||||
EWOL_ERROR("FT_Render_Glyph");
|
||||
return false;
|
||||
}
|
||||
// set properties :
|
||||
property.m_glyphIndex = glyph_index;
|
||||
property.m_sizeTexture.x = slot->bitmap.width;
|
||||
property.m_sizeTexture.y = slot->bitmap.rows;
|
||||
property.m_bearing.x = slot->metrics.horiBearingX>>6;
|
||||
property.m_bearing.y = slot->metrics.horiBearingY>>6;
|
||||
property.m_advance.x = slot->metrics.horiAdvance>>6;
|
||||
property.m_advance.y = slot->metrics.vertAdvance>>6;
|
||||
|
||||
int32_t nbElement = listElement.Size();
|
||||
int32_t coter = simpleSQRT(nbElement);
|
||||
// note : +1 is for the overlapping of the glyph (Part 1)
|
||||
int32_t glyphMaxWidth = /*(m_fftFace->max_advance_width>>6); */(slot->metrics.horiAdvance>>6) +1;
|
||||
int32_t glyphMaxHeight = /*(m_fftFace->max_advance_height>>6); */(slot->metrics.vertAdvance>>6) +1;
|
||||
int32_t textureWidth = nextP2(coter*glyphMaxWidth);
|
||||
int32_t nbRaws = textureWidth / glyphMaxWidth;
|
||||
if (nbRaws <= 0) {
|
||||
EWOL_ERROR("devide by 0");
|
||||
nbRaws = 1;
|
||||
}
|
||||
int32_t nbLine = (nbElement / nbRaws) + 1;
|
||||
int32_t textureHeight = nextP2(nbLine*glyphMaxHeight);
|
||||
EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")");
|
||||
// resize must be done on the texture ...
|
||||
texture.SetImageSize(Vector2D<int32_t>(textureWidth,textureHeight));
|
||||
// now we can acces directly on the image
|
||||
myImage.SetFillColor(draw::Color(0xFFFFFF00));
|
||||
myImage.Clear();
|
||||
|
||||
int32_t tmpRowStartPos = 0;
|
||||
int32_t tmpLineStartPos = 0;
|
||||
int32_t CurrentLineHigh = 0;
|
||||
// Generate for All Elements :
|
||||
for (int32_t iii=0; iii<listElement.Size(); iii++) {
|
||||
// increment the position of the texture
|
||||
/*
|
||||
if (iii!=0) {
|
||||
tmpRowId++;
|
||||
if (tmpRowId>=nbRaws) {
|
||||
tmpRowId = 0;
|
||||
tmpLineId++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// retrieve glyph index from character code
|
||||
glyph_index = FT_Get_Char_Index(m_fftFace, listElement[iii].unicodeCharVal );
|
||||
/*
|
||||
if (glyph_index < 1) {
|
||||
EWOL_WARNING("Can not load Glyph : " << listElement[iii].unicodeCharVal);
|
||||
}
|
||||
*/
|
||||
// load glyph image into the slot (erase previous one)
|
||||
error = FT_Load_Glyph(m_fftFace, // handle to face object
|
||||
glyph_index, // glyph index
|
||||
FT_LOAD_DEFAULT );
|
||||
if ( error ) {
|
||||
EWOL_ERROR("FT_Load_Glyph");
|
||||
}
|
||||
|
||||
// convert to an anti-aliased bitmap
|
||||
error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL );
|
||||
if ( error ) {
|
||||
EWOL_ERROR("FT_Render_Glyph");
|
||||
}
|
||||
int32_t tmpWidth=slot->bitmap.width;
|
||||
int32_t tmpHeight=slot->bitmap.rows;
|
||||
// check if we have enought place on the bitmap to add the current element :
|
||||
if (tmpRowStartPos+tmpWidth >= textureWidth) {
|
||||
tmpRowStartPos = 0;
|
||||
tmpLineStartPos += CurrentLineHigh;
|
||||
CurrentLineHigh = 0;
|
||||
EWOL_ASSERT(tmpLineStartPos+tmpHeight < textureHeight, "Texture dimention estimatiuon error for the current Font");
|
||||
}
|
||||
|
||||
/*
|
||||
EWOL_VERBOSE("elem=" << listElement[iii].unicodeCharVal
|
||||
<<" size=(" << tmpWidth << "," << tmpHeight << ")"
|
||||
<< " for bitmap (left=" << slot->bitmap_left << ",top=" << slot->bitmap_top << ")");
|
||||
EWOL_VERBOSE(" BEARING=(" << (slot->metrics.horiBearingX>>6) << "," << (slot->metrics.vertBearingY>>6) << ")" );
|
||||
*/
|
||||
for(int32_t j=0; j < tmpHeight;j++) {
|
||||
for(int32_t i=0; i < tmpWidth; i++){
|
||||
draw::Color tlpppp(0xFF,0xFF,0xFF,slot->bitmap.buffer[i + tmpWidth*j]);
|
||||
//EWOL_DEBUG(" plop : " << tlpppp);
|
||||
myImage.Set(Vector2D<int32_t>(tmpRowStartPos+i, tmpLineStartPos+j), tlpppp );
|
||||
}
|
||||
}
|
||||
listElement[iii].bearing.x = slot->metrics.horiBearingX>>6;
|
||||
listElement[iii].bearing.y = slot->metrics.horiBearingY>>6;
|
||||
listElement[iii].size.x = tmpWidth;
|
||||
listElement[iii].size.y = tmpHeight;
|
||||
listElement[iii].advance = slot->metrics.horiAdvance>>6;
|
||||
listElement[iii].posStart.u = (float)(tmpRowStartPos) / (float)textureWidth;
|
||||
listElement[iii].posStart.v = (float)(tmpLineStartPos) / (float)textureHeight;
|
||||
listElement[iii].posStop.u = (float)(tmpRowStartPos + tmpWidth) / (float)textureWidth;
|
||||
listElement[iii].posStop.v = (float)(tmpLineStartPos + tmpHeight) / (float)textureHeight;
|
||||
|
||||
// update the maximum of the line hight :
|
||||
if (CurrentLineHigh<tmpHeight) {
|
||||
// note : +1 is for the overlapping of the glyph (Part 2)
|
||||
CurrentLineHigh = tmpHeight+1;
|
||||
}
|
||||
// note : +1 is for the overlapping of the glyph (Part 3)
|
||||
// update the Bitmap position drawing :
|
||||
tmpRowStartPos += tmpWidth+1;
|
||||
}
|
||||
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
|
||||
texture.Flush();
|
||||
EWOL_DEBUG("end load remode tmp data");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
bool ewol::FontFreeType::DrawGlyph(draw::Image& imageOut,
|
||||
int32_t fontSize,
|
||||
Vector2D<int32_t> glyphPosition,
|
||||
ewol::GlyphProperty& property)
|
||||
{
|
||||
|
||||
if(false==m_init) {
|
||||
return false;
|
||||
}
|
||||
// 300dpi (hight quality) 96 dpi (normal quality)
|
||||
int32_t fontQuality = 96;
|
||||
// Select Size ...
|
||||
// note tha <<6==*64 corespond with the 1/64th of points calculation of freetype
|
||||
int32_t error = FT_Set_Char_Size(m_fftFace, fontSize<<6, fontSize<<6, fontQuality, fontQuality);
|
||||
if (0!=error ) {
|
||||
EWOL_ERROR("FT_Set_Char_Size ==> error in settings ...");
|
||||
return false;
|
||||
}
|
||||
// a small shortcut
|
||||
FT_GlyphSlot slot = m_fftFace->glyph;
|
||||
// load glyph image into the slot (erase previous one)
|
||||
error = FT_Load_Glyph(m_fftFace, // handle to face object
|
||||
property.m_glyphIndex, // glyph index
|
||||
FT_LOAD_DEFAULT );
|
||||
if (0!=error ) {
|
||||
EWOL_ERROR("FT_Load_Glyph specify Glyph");
|
||||
return false;
|
||||
}
|
||||
// convert to an anti-aliased bitmap
|
||||
error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL );
|
||||
if (0!=error) {
|
||||
EWOL_ERROR("FT_Render_Glyph");
|
||||
return false;
|
||||
}
|
||||
// draw it on the output Image :
|
||||
draw::Color tlpppp(0xFF,0xFF,0xFF,0x00);
|
||||
for(int32_t jjj=0; jjj < slot->bitmap.rows;jjj++) {
|
||||
for(int32_t iii=0; iii < slot->bitmap.width; iii++){
|
||||
// set only alpha :
|
||||
tlpppp.a = slot->bitmap.buffer[iii + slot->bitmap.width*jjj];
|
||||
// real set of color
|
||||
imageOut.Set(Vector2D<int32_t>(glyphPosition.x+iii, glyphPosition.y+jjj), tlpppp );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ewol::FontFreeType::Display(void)
|
||||
|
@ -34,6 +34,7 @@ extern "C" {
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
// show : http://www.freetype.org/freetype2/docs/tutorial/step2.html
|
||||
class FontFreeType : public ewol::Font
|
||||
{
|
||||
private:
|
||||
@ -55,7 +56,12 @@ namespace ewol
|
||||
Vector2D<float> textPos,
|
||||
const uniChar_t unicodeChar,
|
||||
draw::Color& textColor);
|
||||
bool GenerateBitmapFont(int32_t size, int32_t& height, ewol::Texture& texture, etk::Vector<freeTypeFontElement_ts>& listElement);
|
||||
bool GetGlyphProperty(int32_t fontSize,
|
||||
ewol::GlyphProperty& property);
|
||||
bool DrawGlyph(draw::Image& imageOut,
|
||||
int32_t fontSize,
|
||||
Vector2D<int32_t> glyphPosition,
|
||||
ewol::GlyphProperty& property);
|
||||
Vector2D<float> GetSize(int32_t fontSize, const etk::UString & unicodeString);
|
||||
int32_t GetHeight(int32_t fontSize);
|
||||
};
|
||||
|
@ -28,9 +28,38 @@
|
||||
#include <ewol/font/FontManager.h>
|
||||
|
||||
|
||||
static int32_t nextP2(int32_t value)
|
||||
{
|
||||
int32_t val=1;
|
||||
for (int32_t iii=1; iii<31; iii++) {
|
||||
if (value <= val) {
|
||||
return val;
|
||||
}
|
||||
val *=2;
|
||||
}
|
||||
EWOL_CRITICAL("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
static int32_t simpleSQRT(int32_t value)
|
||||
{
|
||||
int32_t val=1;
|
||||
for (int32_t iii=1; iii<1000; iii++) {
|
||||
val =iii*iii;
|
||||
if (value <= val) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
EWOL_CRITICAL("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
ewol::TexturedFont::TexturedFont(etk::UString fontName, int32_t size) :
|
||||
m_font(NULL),
|
||||
m_counter(1)
|
||||
m_counter(1),
|
||||
m_lastGlyphPos(0,0),
|
||||
m_lastRawHeigh(0)
|
||||
{
|
||||
m_size = size;
|
||||
m_font = ewol::font::Keep(fontName);
|
||||
@ -41,21 +70,115 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName, int32_t size) :
|
||||
// set the bassic charset:
|
||||
m_listElement.Clear();
|
||||
freeTypeFontElement_ts tmpchar1;
|
||||
tmpchar1.unicodeCharVal = 0;
|
||||
tmpchar1.property.m_UVal = 0;
|
||||
m_listElement.PushBack(tmpchar1);
|
||||
// TODO : dynamic generation of this : expected minimum of 0x20 => 0x7F ....
|
||||
for (int32_t iii=0x20; iii<0xFF; iii++) {
|
||||
freeTypeFontElement_ts tmpchar;
|
||||
tmpchar.unicodeCharVal = iii;
|
||||
tmpchar.property.m_UVal = iii;
|
||||
m_listElement.PushBack(tmpchar);
|
||||
if (0x7F == iii) {
|
||||
iii = 0x9F;
|
||||
}
|
||||
}
|
||||
// get the pointer on the image :
|
||||
draw::Image& myImage = m_texture.Get();
|
||||
|
||||
|
||||
/* this is a bad code for now ... */
|
||||
// ==> determine the texture Size
|
||||
GlyphProperty tmpproperty;
|
||||
tmpproperty.m_UVal = 'A';
|
||||
m_font->GetGlyphProperty(m_size, tmpproperty);
|
||||
|
||||
int32_t nbElement = 0xFF - 0x20 + 1;
|
||||
int32_t coter = simpleSQRT(nbElement);
|
||||
// note : +1 is for the overlapping of the glyph (Part 1)
|
||||
int32_t glyphMaxWidth = tmpproperty.m_advance.x +1;
|
||||
int32_t glyphMaxHeight = tmpproperty.m_advance.y +1;
|
||||
int32_t textureWidth = nextP2(coter*glyphMaxWidth);
|
||||
int32_t nbRaws = textureWidth / glyphMaxWidth;
|
||||
if (nbRaws <= 0) {
|
||||
EWOL_ERROR("devide by 0");
|
||||
nbRaws = 1;
|
||||
}
|
||||
int32_t nbLine = (nbElement / nbRaws) + 1;
|
||||
int32_t textureHeight = nextP2(nbLine*glyphMaxHeight);
|
||||
EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")");
|
||||
// resize must be done on the texture ...
|
||||
m_texture.SetImageSize(Vector2D<int32_t>(textureWidth,textureHeight));
|
||||
// now we can acces directly on the image
|
||||
myImage.SetFillColor(draw::Color(0xFFFFFF00));
|
||||
myImage.Clear();
|
||||
|
||||
m_height = m_font->GetHeight(m_size);
|
||||
|
||||
int32_t CurrentLineHigh = 0;
|
||||
Vector2D<int32_t> glyphPosition(1,1);
|
||||
for (int32_t iii=0; iii<m_listElement.Size(); iii++) {
|
||||
if (true == m_font->GetGlyphProperty(m_size, m_listElement[iii].property)) {
|
||||
/*
|
||||
// check internal property:
|
||||
// enought in the texture :
|
||||
//if (myImage.GetWidth() < m_lastGlyphPos.x + m_listElement[iii].property.m_sizeTexture.x
|
||||
// resize if needed ...
|
||||
|
||||
// line size :
|
||||
|
||||
// draw
|
||||
|
||||
// move the curent pointer of drawing:
|
||||
*/
|
||||
// change line if needed ...
|
||||
if (glyphPosition.x+m_listElement[iii].property.m_sizeTexture.x > textureWidth) {
|
||||
glyphPosition.x = 0;
|
||||
glyphPosition.y += CurrentLineHigh;
|
||||
CurrentLineHigh = 0;
|
||||
}
|
||||
// draw the glyph
|
||||
m_font->DrawGlyph(myImage, m_size, glyphPosition, m_listElement[iii].property);
|
||||
// set video position
|
||||
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
|
||||
m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight;
|
||||
m_listElement[iii].posStop.u = (float)(glyphPosition.x + m_listElement[iii].property.m_sizeTexture.x) / (float)textureWidth;
|
||||
m_listElement[iii].posStop.v = (float)(glyphPosition.y + m_listElement[iii].property.m_sizeTexture.y) / (float)textureHeight;
|
||||
/*
|
||||
EWOL_DEBUG("generate '" << (char)m_listElement[iii].property.m_UVal << "'");
|
||||
EWOL_DEBUG(" in tex : " << glyphPosition << " ==> " << m_listElement[iii].posStart.u<< "," << m_listElement[iii].posStart.v );
|
||||
EWOL_DEBUG(" m_sizeTexture =" << m_listElement[iii].property.m_sizeTexture );
|
||||
EWOL_DEBUG(" m_bearing =" << m_listElement[iii].property.m_bearing );
|
||||
EWOL_DEBUG(" m_advance =" << m_listElement[iii].property.m_advance );
|
||||
*/
|
||||
|
||||
// update the maximum of the line hight :
|
||||
if (CurrentLineHigh<m_listElement[iii].property.m_sizeTexture.y) {
|
||||
// note : +1 is for the overlapping of the glyph (Part 2)
|
||||
CurrentLineHigh = m_listElement[iii].property.m_sizeTexture.y+1;
|
||||
}
|
||||
// note : +1 is for the overlapping of the glyph (Part 3)
|
||||
// update the Bitmap position drawing :
|
||||
glyphPosition.x += m_listElement[iii].property.m_sizeTexture.x+1;
|
||||
}
|
||||
|
||||
}
|
||||
// For testing cheree the box are set)
|
||||
#if 0
|
||||
draw::Color tlpppp(0xFF,0xFF,0xFF,0x00);
|
||||
for(int32_t jjj=0; jjj < textureHeight;jjj++) {
|
||||
for(int32_t iii=0; iii < textureWidth; iii++){
|
||||
tlpppp = myImage.Get(Vector2D<int32_t>(iii, jjj) );
|
||||
// set only alpha :
|
||||
tlpppp.a = etk_min( tlpppp.a+0x60, 0xFF);
|
||||
// real set of color
|
||||
myImage.Set(Vector2D<int32_t>(iii, jjj), tlpppp );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
|
||||
m_texture.Flush();
|
||||
|
||||
// initilize the texture ...
|
||||
// TODO : Do a better methode that not initialize with a stupid language ... like now ...
|
||||
m_font->GenerateBitmapFont(m_size, m_height, m_texture, m_listElement);
|
||||
//m_font->GenerateBitmapFont(m_size, m_height, m_texture, m_listElement);
|
||||
}
|
||||
|
||||
ewol::TexturedFont::~TexturedFont(void)
|
||||
@ -75,7 +198,6 @@ int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
tmpPos.x += ret;
|
||||
totalSize += ret;
|
||||
}
|
||||
return totalSize;
|
||||
|
||||
#if 0
|
||||
// To display the texture ...
|
||||
@ -92,10 +214,10 @@ int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
bitmapDrawPos[2].x = 400;
|
||||
bitmapDrawPos[3].x = 10;
|
||||
|
||||
bitmapDrawPos[0].y = 10;
|
||||
bitmapDrawPos[1].y = 10;
|
||||
bitmapDrawPos[2].y = 400;
|
||||
bitmapDrawPos[3].y = 400;
|
||||
bitmapDrawPos[0].y = 400;
|
||||
bitmapDrawPos[1].y = 400;
|
||||
bitmapDrawPos[2].y = 10;
|
||||
bitmapDrawPos[3].y = 10;
|
||||
/* texture Position :
|
||||
* 0------1
|
||||
* | |
|
||||
@ -147,6 +269,7 @@ int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
coord.PushBack(bitmapDrawPos[3]);
|
||||
}
|
||||
#endif
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
@ -164,7 +287,7 @@ int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
} else {
|
||||
charIndex = 0;
|
||||
for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) {
|
||||
if (m_listElement[iii].unicodeCharVal == unicodeChar) {
|
||||
if (m_listElement[iii].property.m_UVal == unicodeChar) {
|
||||
charIndex = iii;
|
||||
break;
|
||||
}
|
||||
@ -179,10 +302,10 @@ int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
* | |
|
||||
* yD *------*
|
||||
*/
|
||||
float dxA = posDrawX + m_listElement[charIndex].bearing.x;
|
||||
float dxB = posDrawX + m_listElement[charIndex].bearing.x + m_listElement[charIndex].size.x;
|
||||
float dyC = textPos.y + m_listElement[charIndex].bearing.y + m_height - m_size;
|
||||
float dyD = dyC - m_listElement[charIndex].size.y;
|
||||
float dxA = posDrawX + m_listElement[charIndex].property.m_bearing.x;
|
||||
float dxB = posDrawX + m_listElement[charIndex].property.m_bearing.x + m_listElement[charIndex].property.m_sizeTexture.x;
|
||||
float dyC = textPos.y + m_listElement[charIndex].property.m_bearing.y + m_height - m_size;
|
||||
float dyD = dyC - m_listElement[charIndex].property.m_sizeTexture.y;
|
||||
|
||||
float tuA = m_listElement[charIndex].posStart.u;
|
||||
float tuB = m_listElement[charIndex].posStop.u;
|
||||
@ -263,7 +386,7 @@ int32_t ewol::TexturedFont::Draw(Vector2D<float> textPos,
|
||||
|
||||
}
|
||||
}
|
||||
posDrawX += m_listElement[charIndex].advance;
|
||||
posDrawX += m_listElement[charIndex].property.m_advance.x;
|
||||
int32_t sizeOut = posDrawX - textPos.x;
|
||||
textPos.x = posDrawX;
|
||||
return sizeOut;
|
||||
@ -292,7 +415,7 @@ Vector2D<float> ewol::TexturedFont::GetSize(const uniChar_t unicodeChar)
|
||||
charIndex = unicodeChar - 0x1F;
|
||||
} else {
|
||||
for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) {
|
||||
if (m_listElement[iii].unicodeCharVal == unicodeChar) {
|
||||
if (m_listElement[iii].property.m_UVal == unicodeChar) {
|
||||
charIndex = iii;
|
||||
break;
|
||||
}
|
||||
@ -300,7 +423,7 @@ Vector2D<float> ewol::TexturedFont::GetSize(const uniChar_t unicodeChar)
|
||||
// TODO : Update if possible the mapping
|
||||
charIndex = 0;
|
||||
}
|
||||
outputSize.x = m_listElement[charIndex].advance;
|
||||
outputSize.x = m_listElement[charIndex].property.m_advance.x;
|
||||
return outputSize;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,12 @@
|
||||
namespace ewol
|
||||
{
|
||||
class TexturedFont {
|
||||
|
||||
typedef struct {
|
||||
GlyphProperty property;
|
||||
texCoord_ts posStart;
|
||||
texCoord_ts posStop;
|
||||
}freeTypeFontElement_ts;
|
||||
private:
|
||||
int32_t m_size;
|
||||
int32_t m_height;
|
||||
@ -40,6 +46,9 @@ namespace ewol
|
||||
ewol::Texture m_texture;
|
||||
uint32_t m_counter;
|
||||
etk::Vector<freeTypeFontElement_ts> m_listElement;
|
||||
// for the texture generation :
|
||||
Vector2D<int32_t> m_lastGlyphPos;
|
||||
int32_t m_lastRawHeigh;
|
||||
public:
|
||||
TexturedFont(etk::UString fontName, int32_t size);
|
||||
~TexturedFont(void);
|
||||
@ -56,6 +65,7 @@ namespace ewol
|
||||
etk::Vector<texCoord_ts> & coordTex);
|
||||
Vector2D<float> GetSize(const etk::UString & unicodeString);
|
||||
Vector2D<float> GetSize(const uniChar_t unicodeChar);
|
||||
// TODO : Remove this element, it is stupid ...
|
||||
int32_t GetHeight(void) { return m_height; };
|
||||
int32_t GetFontSize(void) { return m_size; };
|
||||
ewol::Texture& GetTex(void) { return m_texture; };
|
||||
|
@ -209,7 +209,7 @@ void ewol::Button::OnRegenerateDisplay(void)
|
||||
drawClipping.y = m_padding.y;
|
||||
drawClipping.w = m_size.x - 2*m_padding.x;
|
||||
drawClipping.h = m_size.y - 2*m_padding.y;
|
||||
EWOL_DEBUG("draw tex at pos : " <<textPos << "in element size:" << m_size);
|
||||
//EWOL_DEBUG("draw tex at pos : " <<textPos << "in element size:" << m_size);
|
||||
m_oObjectText.Text(textPos/*, drawClipping*/, m_label);
|
||||
|
||||
m_oObjectDecoration.SetColor(m_textColorBg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user