[DEV] Load the font with bold italic mode and load it in the basic folder of the file system

This commit is contained in:
Edouard DUPIN 2012-11-13 22:55:02 +01:00
parent 08e97b1fba
commit 7aeb65a0aa
13 changed files with 351 additions and 235 deletions

41
data/text.frag Normal file
View File

@ -0,0 +1,41 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
// Input :
uniform sampler2D EW_texID;
varying vec2 f_texcoord;
varying vec4 f_color;
/*
void main(void) {
gl_FragColor = f_color;
vec2 tmpCoord = f_texcoord;
tmpCoord = mod(tmpCoord, 1.0);
vec4 map = texture2D(EW_texID, tmpCoord);
if (f_texcoord.x<1.0) {
// normal font :
gl_FragColor.a = gl_FragColor.a*map.a;
} else if (f_texcoord.x<2.0) {
// Italic font :
gl_FragColor.a = gl_FragColor.a*map.r;
} else if (f_texcoord.x<3.0) {
// Bold font :
gl_FragColor.a = gl_FragColor.a*map.g;
} else {
// bold italic font :
gl_FragColor.a = gl_FragColor.a*map.b;
}
}
*/
varying vec4 f_patern;
void main(void) {
gl_FragColor = f_color;
vec4 map = texture2D(EW_texID, f_texcoord);
float alphaCoef = dot(map, f_patern);
gl_FragColor.a = gl_FragColor.a*alphaCoef;
}

2
data/text.prog Normal file
View File

@ -0,0 +1,2 @@
text.vert
text.frag

47
data/text.vert Normal file
View File

@ -0,0 +1,47 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
// Input :
attribute vec2 EW_coord2d;
attribute vec2 EW_texture2d;
attribute vec4 EW_color;
uniform mat4 EW_MatrixTransformation;
// output :
varying vec4 f_color;
varying vec2 f_texcoord;
/*
void main(void) {
gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
//gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0);
// set texture output coord
f_texcoord = EW_texture2d;
// set output color :
f_color = EW_color;
}
*/
varying vec4 f_patern;
void main(void) {
gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
//gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(EW_coord2d, 0.0, 1.0);
// set output color :
f_color = EW_color;
if (EW_texture2d.x<1.0) {
// normal font :
f_patern = vec4 (0.0, 0.0, 0.0, 1.0);
} else if (EW_texture2d.x<2.0) {
// Italic font :
f_patern = vec4 (1.0, 0.0, 0.0, 0.0);
} else if (EW_texture2d.x<3.0) {
// Bold font :
f_patern = vec4 (0.0, 1.0, 0.0, 0.0);
} else {
// bold italic font :
f_patern = vec4 (0.0, 0.0, 1.0, 0.0);
}
// set texture output coord
f_texcoord = mod(EW_texture2d, 1.0);
}

2
external/etk vendored

@ -1 +1 @@
Subproject commit 381dad6f1acd5d420982dc50ab5f725d3c53472f Subproject commit c35e883279632dda8743a3d1f9bbe5ac2748146f

View File

@ -149,7 +149,7 @@ ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
CurrentLineHigh = 0; CurrentLineHigh = 0;
} }
// draw the glyph // draw the glyph
m_font->DrawGlyph(tmpUpScaledImage, m_size*SPECIAL_UPSCALER, etk::Vector2D<int32_t>(SPECIAL_BORDER*SPECIAL_UPSCALER,SPECIAL_BORDER*SPECIAL_UPSCALER), m_listElement[iii].property); m_font->DrawGlyph(tmpUpScaledImage, m_size*SPECIAL_UPSCALER, etk::Vector2D<int32_t>(SPECIAL_BORDER*SPECIAL_UPSCALER,SPECIAL_BORDER*SPECIAL_UPSCALER), m_listElement[iii].property, 0);
// set video position // set video position
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth; m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight; m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight;

View File

@ -81,7 +81,8 @@ namespace ewol
virtual bool DrawGlyph(draw::Image& imageOut, virtual bool DrawGlyph(draw::Image& imageOut,
int32_t fontSize, int32_t fontSize,
etk::Vector2D<int32_t> glyphPosition, etk::Vector2D<int32_t> glyphPosition,
ewol::GlyphProperty& property) = 0; ewol::GlyphProperty& property,
int8_t posInImage) = 0;
virtual etk::Vector2D<float> GetSize(int32_t fontSize, const etk::UString & unicodeString) = 0; virtual etk::Vector2D<float> GetSize(int32_t fontSize, const etk::UString & unicodeString) = 0;
virtual int32_t GetHeight(int32_t fontSize) = 0; virtual int32_t GetHeight(int32_t fontSize) = 0;
}; };

View File

@ -55,7 +55,7 @@ ewol::FontFreeType::FontFreeType(etk::UString fontName) :
m_FileBuffer = NULL; m_FileBuffer = NULL;
m_FileSize = 0; m_FileSize = 0;
etk::FSNode myfile(etk::UString("DATA:") + fontName); etk::FSNode myfile(fontName);
if (false == myfile.Exist()) { if (false == myfile.Exist()) {
EWOL_ERROR("File Does not exist : " << myfile); EWOL_ERROR("File Does not exist : " << myfile);
return; return;
@ -192,7 +192,8 @@ bool ewol::FontFreeType::GetGlyphProperty(int32_t fontSize,
bool ewol::FontFreeType::DrawGlyph(draw::Image& imageOut, bool ewol::FontFreeType::DrawGlyph(draw::Image& imageOut,
int32_t fontSize, int32_t fontSize,
etk::Vector2D<int32_t> glyphPosition, etk::Vector2D<int32_t> glyphPosition,
ewol::GlyphProperty& property) ewol::GlyphProperty& property,
int8_t posInImage)
{ {
if(false==m_init) { if(false==m_init) {
@ -227,8 +228,25 @@ bool ewol::FontFreeType::DrawGlyph(draw::Image& imageOut,
draw::Color tlpppp(0xFF,0xFF,0xFF,0x00); draw::Color tlpppp(0xFF,0xFF,0xFF,0x00);
for(int32_t jjj=0; jjj < slot->bitmap.rows;jjj++) { for(int32_t jjj=0; jjj < slot->bitmap.rows;jjj++) {
for(int32_t iii=0; iii < slot->bitmap.width; iii++){ for(int32_t iii=0; iii < slot->bitmap.width; iii++){
tlpppp = imageOut.Get(etk::Vector2D<int32_t>(glyphPosition.x+iii, glyphPosition.y+jjj));
uint8_t valueColor = slot->bitmap.buffer[iii + slot->bitmap.width*jjj];
// set only alpha : // set only alpha :
tlpppp.a = slot->bitmap.buffer[iii + slot->bitmap.width*jjj]; switch(posInImage)
{
default:
case 0:
tlpppp.a = valueColor;
break;
case 1:
tlpppp.r = valueColor;
break;
case 2:
tlpppp.g = valueColor;
break;
case 3:
tlpppp.b = valueColor;
break;
}
// real set of color // real set of color
imageOut.Set(etk::Vector2D<int32_t>(glyphPosition.x+iii, glyphPosition.y+jjj), tlpppp ); imageOut.Set(etk::Vector2D<int32_t>(glyphPosition.x+iii, glyphPosition.y+jjj), tlpppp );
} }

View File

@ -45,7 +45,8 @@ namespace ewol
bool DrawGlyph(draw::Image& imageOut, bool DrawGlyph(draw::Image& imageOut,
int32_t fontSize, int32_t fontSize,
etk::Vector2D<int32_t> glyphPosition, etk::Vector2D<int32_t> glyphPosition,
ewol::GlyphProperty& property); ewol::GlyphProperty& property,
int8_t posInImage);
etk::Vector2D<float> GetSize(int32_t fontSize, const etk::UString & unicodeString); etk::Vector2D<float> GetSize(int32_t fontSize, const etk::UString & unicodeString);
int32_t GetHeight(int32_t fontSize); int32_t GetHeight(int32_t fontSize);
}; };

View File

@ -10,6 +10,7 @@
#include <ewol/font/Font.h> #include <ewol/font/Font.h>
#include <ewol/font/TexturedFont.h> #include <ewol/font/TexturedFont.h>
#include <ewol/font/FontManager.h> #include <ewol/font/FontManager.h>
#include <etk/os/FSNode.h>
#include <ewol/ResourceManager.h> #include <ewol/ResourceManager.h>
@ -41,11 +42,27 @@ static int32_t simpleSQRT(int32_t value)
ewol::TexturedFont::TexturedFont(etk::UString fontName) : ewol::TexturedFont::TexturedFont(etk::UString fontName) :
ewol::Texture(fontName), ewol::Texture(fontName)
m_font(NULL),
m_lastGlyphPos(0,0),
m_lastRawHeigh(0)
{ {
m_font[0] = NULL;
m_font[1] = NULL;
m_font[2] = NULL;
m_font[3] = NULL;
m_lastGlyphPos[0].x = 0;
m_lastGlyphPos[0].y = 0;
m_lastGlyphPos[1].x = 0;
m_lastGlyphPos[1].y = 0;
m_lastGlyphPos[2].x = 0;
m_lastGlyphPos[2].y = 0;
m_lastGlyphPos[3].x = 0;
m_lastGlyphPos[3].y = 0;
m_lastRawHeigh[0] = 0;
m_lastRawHeigh[1] = 0;
m_lastRawHeigh[2] = 0;
m_lastRawHeigh[3] = 0;
int32_t tmpSize = 0; int32_t tmpSize = 0;
// extarct name and size : // extarct name and size :
char * tmpData = fontName.c_str(); char * tmpData = fontName.c_str();
@ -65,21 +82,66 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
m_name = fontName.Extract(0, (tmpPos - tmpData)); m_name = fontName.Extract(0, (tmpPos - tmpData));
m_size = tmpSize; m_size = tmpSize;
//EWOL_CRITICAL("Load FONT name : \"" << m_name << "\" ==> size=" << m_size); // find the real Font name :
ewol::resource::Keep(m_name, m_font); etk::Vector<etk::UString> output;
if (NULL == m_font) { etk::FSNode myFolder("/usr/share/fonts/truetype");
myFolder.FolderGetRecursiveFiles(output);
for (int32_t iii=0; iii<output.Size(); iii++) {
//EWOL_DEBUG(" file : " << output[iii]);
if( true == output[iii].EndWith(m_name+"-"+"bold"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"b"+".ttf", false)
|| true == output[iii].EndWith(m_name+"bold"+".ttf", false)
|| true == output[iii].EndWith(m_name+"b"+".ttf", false)) {
EWOL_INFO(" find Font [Bold] : " << output[iii]);
m_fileName[ewol::font::Bold] = output[iii];
} else if( true == output[iii].EndWith(m_name+"-"+"oblique"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"italic"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"Light"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"i"+".ttf", false)
|| true == output[iii].EndWith(m_name+"oblique"+".ttf", false)
|| true == output[iii].EndWith(m_name+"italic"+".ttf", false)
|| true == output[iii].EndWith(m_name+"light"+".ttf", false)
|| true == output[iii].EndWith(m_name+"i"+".ttf", false)) {
EWOL_INFO(" find Font [Italic] : " << output[iii]);
m_fileName[ewol::font::Italic] = output[iii];
} else if( true == output[iii].EndWith(m_name+"-"+"bolditalic"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"boldoblique"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"bi"+".ttf", false)
|| true == output[iii].EndWith(m_name+"bolditalic"+".ttf", false)
|| true == output[iii].EndWith(m_name+"boldoblique"+".ttf", false)
|| true == output[iii].EndWith(m_name+"bi"+".ttf", false)) {
EWOL_INFO(" find Font [Bold-Italic] : " << output[iii]);
m_fileName[ewol::font::BoldItalic] = output[iii];
} else if( true == output[iii].EndWith(m_name+"-"+"regular"+".ttf", false)
|| true == output[iii].EndWith(m_name+"-"+"r"+".ttf", false)
|| true == output[iii].EndWith(m_name+"regular"+".ttf", false)
|| true == output[iii].EndWith(m_name+"r"+".ttf", false)
|| true == output[iii].EndWith(m_name+".ttf", false)) {
EWOL_INFO(" find Font [Regular] : " << output[iii]);
m_fileName[ewol::font::Regular] = output[iii];
}
}
for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
if (m_fileName[iiiFontId] == "") {
EWOL_CRITICAL("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" ==> size=" << m_size );
m_font[iiiFontId] = NULL;
continue;
}
EWOL_INFO("Load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" ==> size=" << m_size);
ewol::resource::Keep(m_fileName[iiiFontId], m_font[iiiFontId]);
if (NULL == m_font[iiiFontId]) {
return; return;
} }
// set the bassic charset: // set the bassic charset:
m_listElement.Clear(); m_listElement[iiiFontId].Clear();
freeTypeFontElement_ts tmpchar1; freeTypeFontElement_ts tmpchar1;
tmpchar1.property.m_UVal = 0; tmpchar1.property.m_UVal = 0;
m_listElement.PushBack(tmpchar1); m_listElement[iiiFontId].PushBack(tmpchar1);
for (int32_t iii=0x20; iii<0xFF; iii++) { for (int32_t iii=0x20; iii<0xFF; iii++) {
freeTypeFontElement_ts tmpchar; freeTypeFontElement_ts tmpchar;
tmpchar.property.m_UVal = iii; tmpchar.property.m_UVal = iii;
m_listElement.PushBack(tmpchar); m_listElement[iiiFontId].PushBack(tmpchar);
if (0x7F == iii) { if (0x7F == iii) {
iii = 0x9F; iii = 0x9F;
} }
@ -89,7 +151,7 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
// ==> determine the texture Size // ==> determine the texture Size
GlyphProperty tmpproperty; GlyphProperty tmpproperty;
tmpproperty.m_UVal = 'A'; tmpproperty.m_UVal = 'A';
m_font->GetGlyphProperty(m_size, tmpproperty); m_font[iiiFontId]->GetGlyphProperty(m_size, tmpproperty);
int32_t nbElement = 0xFF - 0x20 + 1; int32_t nbElement = 0xFF - 0x20 + 1;
int32_t coter = simpleSQRT(nbElement); int32_t coter = simpleSQRT(nbElement);
@ -108,64 +170,46 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
textureHeight = etk_max(textureHeight, textureWidth); textureHeight = etk_max(textureHeight, textureWidth);
textureWidth = textureHeight; textureWidth = textureHeight;
if (iiiFontId == 0) {
EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")"); EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")");
// resize must be done on the texture ... // resize must be done on the texture ...
SetImageSize(etk::Vector2D<int32_t>(textureWidth,textureHeight)); SetImageSize(etk::Vector2D<int32_t>(textureWidth,textureHeight));
// now we can acces directly on the image // now we can acces directly on the image
m_data.SetFillColor(draw::Color(0xFFFFFF00)); m_data.SetFillColor(draw::Color(0x00000000));
m_data.Clear(); m_data.Clear();
}
m_height = m_font->GetHeight(m_size); m_height[iiiFontId] = m_font[iiiFontId]->GetHeight(m_size);
int32_t CurrentLineHigh = 0; int32_t CurrentLineHigh = 0;
etk::Vector2D<int32_t> glyphPosition(1,1); etk::Vector2D<int32_t> glyphPosition(1,1);
for (int32_t iii=0; iii<m_listElement.Size(); iii++) { for (int32_t iii=0; iii<m_listElement[iiiFontId].Size(); iii++) {
if (true == m_font->GetGlyphProperty(m_size, m_listElement[iii].property)) { if (true == m_font[iiiFontId]->GetGlyphProperty(m_size, (m_listElement[iiiFontId])[iii].property)) {
/*
// check internal property:
// enought in the texture :
//if (m_data.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 ... // change line if needed ...
if (glyphPosition.x+m_listElement[iii].property.m_sizeTexture.x > textureWidth) { if (glyphPosition.x+(m_listElement[iiiFontId])[iii].property.m_sizeTexture.x > textureWidth) {
glyphPosition.x = 0; glyphPosition.x = 0;
glyphPosition.y += CurrentLineHigh; glyphPosition.y += CurrentLineHigh;
CurrentLineHigh = 0; CurrentLineHigh = 0;
} }
// draw the glyph // draw the glyph
m_font->DrawGlyph(m_data, m_size, glyphPosition, m_listElement[iii].property); m_font[iiiFontId]->DrawGlyph(m_data, m_size, glyphPosition, (m_listElement[iiiFontId])[iii].property, iiiFontId);
// set video position // set video position
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth; (m_listElement[iiiFontId])[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight; (m_listElement[iiiFontId])[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[iiiFontId])[iii].posStop.u = (float)(glyphPosition.x + (m_listElement[iiiFontId])[iii].property.m_sizeTexture.x) / (float)textureWidth;
m_listElement[iii].posStop.v = (float)(glyphPosition.y + m_listElement[iii].property.m_sizeTexture.y) / (float)textureHeight; (m_listElement[iiiFontId])[iii].posStop.v = (float)(glyphPosition.y + (m_listElement[iiiFontId])[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 : // update the maximum of the line hight :
if (CurrentLineHigh<m_listElement[iii].property.m_sizeTexture.y) { if (CurrentLineHigh<(m_listElement[iiiFontId])[iii].property.m_sizeTexture.y) {
// note : +1 is for the overlapping of the glyph (Part 2) // note : +1 is for the overlapping of the glyph (Part 2)
CurrentLineHigh = m_listElement[iii].property.m_sizeTexture.y+1; CurrentLineHigh = (m_listElement[iiiFontId])[iii].property.m_sizeTexture.y+1;
} }
// note : +1 is for the overlapping of the glyph (Part 3) // note : +1 is for the overlapping of the glyph (Part 3)
// update the Bitmap position drawing : // update the Bitmap position drawing :
glyphPosition.x += m_listElement[iii].property.m_sizeTexture.x+1; glyphPosition.x += (m_listElement[iiiFontId])[iii].property.m_sizeTexture.x+1;
} }
} }
}
// For testing cheree the box are set) // For testing cheree the box are set)
#if 0 #if 0
draw::Color tlpppp(0xFF,0xFF,0xFF,0x00); draw::Color tlpppp(0xFF,0xFF,0xFF,0x00);
@ -186,8 +230,11 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
ewol::TexturedFont::~TexturedFont(void) ewol::TexturedFont::~TexturedFont(void)
{ {
if (NULL!= m_font) { for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
ewol::resource::Release(m_font); if (NULL!= m_font[iiiFontId]) {
ewol::resource::Release(m_font[iiiFontId]);
m_font[iiiFontId] = NULL;
}
} }
} }
@ -207,87 +254,18 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
const etk::UString& unicodeString, const etk::UString& unicodeString,
etk::Vector<etk::Vector2D<float> > & coord, etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex, etk::Vector<texCoord_ts> & coordTex,
etk::Vector<int32_t> & vectDisplayMode,
bool hasClipping, bool hasClipping,
clipping_ts& clipping) clipping_ts& clipping,
ewol::font::mode_te displayMode)
{ {
float totalSize = 0; float totalSize = 0;
etk::Vector2D<float> tmpPos = textPos; etk::Vector2D<float> tmpPos = textPos;
for(int32_t iii=0; iii<unicodeString.Size(); iii++) { for(int32_t iii=0; iii<unicodeString.Size(); iii++) {
int32_t ret = Draw(tmpPos, unicodeString[iii], coord, coordTex, hasClipping, clipping); int32_t ret = Draw(tmpPos, unicodeString[iii], coord, coordTex, vectDisplayMode, hasClipping, clipping, displayMode);
tmpPos.x += ret; tmpPos.x += ret;
totalSize += ret; totalSize += ret;
} }
#if 0
// To display the texture ...
{
/* Bitmap position
* 0------1
* | |
* | |
* 3------2
*/
etk::Vector2D<float> bitmapDrawPos[4];
bitmapDrawPos[0].x = 10;
bitmapDrawPos[1].x = 400;
bitmapDrawPos[2].x = 400;
bitmapDrawPos[3].x = 10;
bitmapDrawPos[0].y = 400;
bitmapDrawPos[1].y = 400;
bitmapDrawPos[2].y = 10;
bitmapDrawPos[3].y = 10;
/* texture Position :
* 0------1
* | |
* | |
* 3------2
*/
texCoord_ts texturePos[4];
texturePos[0].u = 0;
texturePos[1].u = 1;
texturePos[2].u = 1;
texturePos[3].u = 0;
texturePos[0].v = 0;
texturePos[1].v = 0;
texturePos[2].v = 1;
texturePos[3].v = 1;
// NOTE : Android does not support the Quads elements ...
/* Step 1 :
* ********
* ******
* ****
* **
*
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[1]);
coordTex.PushBack(texturePos[2]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[1]);
coord.PushBack(bitmapDrawPos[2]);
/* Step 2 :
*
* **
* ****
* ******
* ********
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[2]);
coordTex.PushBack(texturePos[3]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[2]);
coord.PushBack(bitmapDrawPos[3]);
}
#endif
return totalSize; return totalSize;
} }
@ -295,8 +273,10 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
const uniChar_t unicodeChar, const uniChar_t unicodeChar,
etk::Vector<etk::Vector2D<float> > & coord, etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex, etk::Vector<texCoord_ts> & coordTex,
etk::Vector<int32_t> & vectDisplayMode,
bool hasClipping, bool hasClipping,
clipping_ts& clipping) clipping_ts& clipping,
ewol::font::mode_te displayMode)
{ {
float posDrawX = textPos.x; float posDrawX = textPos.x;
@ -307,8 +287,8 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
charIndex = unicodeChar - 0x1F; charIndex = unicodeChar - 0x1F;
} else { } else {
charIndex = 0; charIndex = 0;
for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) { for (int32_t iii=0x80-0x20; iii < m_listElement[0].Size(); iii++) {
if (m_listElement[iii].property.m_UVal == unicodeChar) { if ((m_listElement[displayMode])[iii].property.m_UVal == unicodeChar) {
charIndex = iii; charIndex = iii;
break; break;
} }
@ -323,15 +303,15 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
* | | * | |
* yD *------* * yD *------*
*/ */
float dxA = posDrawX + m_listElement[charIndex].property.m_bearing.x; float dxA = posDrawX + (m_listElement[displayMode])[charIndex].property.m_bearing.x;
float dxB = posDrawX + m_listElement[charIndex].property.m_bearing.x + m_listElement[charIndex].property.m_sizeTexture.x; float dxB = posDrawX + (m_listElement[displayMode])[charIndex].property.m_bearing.x + (m_listElement[displayMode])[charIndex].property.m_sizeTexture.x;
float dyC = textPos.y + m_listElement[charIndex].property.m_bearing.y + m_height - m_size; float dyC = textPos.y + (m_listElement[displayMode])[charIndex].property.m_bearing.y + m_height[displayMode] - m_size;
float dyD = dyC - m_listElement[charIndex].property.m_sizeTexture.y; float dyD = dyC - (m_listElement[displayMode])[charIndex].property.m_sizeTexture.y;
float tuA = m_listElement[charIndex].posStart.u; float tuA = (m_listElement[displayMode])[charIndex].posStart.u;
float tuB = m_listElement[charIndex].posStop.u; float tuB = (m_listElement[displayMode])[charIndex].posStop.u;
float tvC = m_listElement[charIndex].posStart.v; float tvC = (m_listElement[displayMode])[charIndex].posStart.v;
float tvD = m_listElement[charIndex].posStop.v; float tvD = (m_listElement[displayMode])[charIndex].posStop.v;
// Clipping and drawing area // Clipping and drawing area
@ -348,7 +328,7 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
float drawSize = clipping.x - dxA; float drawSize = clipping.x - dxA;
// Update element start display // Update element start display
dxA = clipping.x; dxA = clipping.x;
float addElement = TexSizeX * drawSize / (float)m_listElement[charIndex].property.m_sizeTexture.x; float addElement = TexSizeX * drawSize / (float)(m_listElement[displayMode])[charIndex].property.m_sizeTexture.x;
// update texture start X Pos // update texture start X Pos
tuA += addElement; tuA += addElement;
} }
@ -357,7 +337,7 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
float drawSize = dxB - (clipping.x + clipping.w); float drawSize = dxB - (clipping.x + clipping.w);
// Update element start display // Update element start display
dxB = clipping.x + clipping.w; dxB = clipping.x + clipping.w;
float addElement = TexSizeX * drawSize / (float)m_listElement[charIndex].property.m_sizeTexture.x; float addElement = TexSizeX * drawSize / (float)(m_listElement[displayMode])[charIndex].property.m_sizeTexture.x;
// update texture start X Pos // update texture start X Pos
tuB -= addElement; tuB -= addElement;
} }
@ -367,7 +347,7 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
float drawSize = clipping.y - dyC; float drawSize = clipping.y - dyC;
// Update element start display // Update element start display
dyC = clipping.y; dyC = clipping.y;
float addElement = TexSizeY * drawSize / (float)m_listElement[charIndex].property.m_sizeTexture.x; float addElement = TexSizeY * drawSize / (float)(m_listElement[displayMode])[charIndex].property.m_sizeTexture.x;
// update texture start X Pos // update texture start X Pos
tvC += addElement; tvC += addElement;
} }
@ -376,7 +356,7 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
float drawSize = dyD - (clipping.y + clipping.h); float drawSize = dyD - (clipping.y + clipping.h);
// Update element start display // Update element start display
dyD = clipping.y + clipping.h; dyD = clipping.y + clipping.h;
float addElement = TexSizeX * drawSize / (float)m_listElement[charIndex].property.m_sizeTexture.x; float addElement = TexSizeX * drawSize / (float)(m_listElement[displayMode])[charIndex].property.m_sizeTexture.x;
// update texture start X Pos // update texture start X Pos
tvD -= addElement; tvD -= addElement;
} }
@ -408,10 +388,10 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
* 3------2 * 3------2
*/ */
texCoord_ts texturePos[4]; texCoord_ts texturePos[4];
texturePos[0].u = tuA; texturePos[0].u = tuA+displayMode;
texturePos[1].u = tuB; texturePos[1].u = tuB+displayMode;
texturePos[2].u = tuB; texturePos[2].u = tuB+displayMode;
texturePos[3].u = tuA; texturePos[3].u = tuA+displayMode;
texturePos[0].v = tvC; texturePos[0].v = tvC;
texturePos[1].v = tvC; texturePos[1].v = tvC;
@ -453,7 +433,7 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
} }
} }
} }
posDrawX += m_listElement[charIndex].property.m_advance.x; posDrawX += (m_listElement[displayMode])[charIndex].property.m_advance.x;
int32_t sizeOut = posDrawX - textPos.x; int32_t sizeOut = posDrawX - textPos.x;
textPos.x = posDrawX; textPos.x = posDrawX;
return sizeOut; return sizeOut;
@ -461,7 +441,7 @@ int32_t ewol::TexturedFont::Draw(etk::Vector2D<float> textPos,
etk::Vector2D<float> ewol::TexturedFont::GetSize(const etk::UString & unicodeString) etk::Vector2D<float> ewol::TexturedFont::GetSize(const etk::UString & unicodeString)
{ {
etk::Vector2D<float> outputSize(0,m_height); etk::Vector2D<float> outputSize(0,m_height[0]);
for(int32_t iii=0; iii<unicodeString.Size(); iii++) { for(int32_t iii=0; iii<unicodeString.Size(); iii++) {
etk::Vector2D<float> tmpp = GetSize(unicodeString[iii]); etk::Vector2D<float> tmpp = GetSize(unicodeString[iii]);
outputSize.x += tmpp.x; outputSize.x += tmpp.x;
@ -472,7 +452,7 @@ etk::Vector2D<float> ewol::TexturedFont::GetSize(const etk::UString & unicodeStr
etk::Vector2D<float> ewol::TexturedFont::GetSize(const uniChar_t unicodeChar) etk::Vector2D<float> ewol::TexturedFont::GetSize(const uniChar_t unicodeChar)
{ {
etk::Vector2D<float> outputSize(0,m_height); etk::Vector2D<float> outputSize(0,m_height[0]);
int32_t charIndex; int32_t charIndex;
if (unicodeChar >= 0x80) { if (unicodeChar >= 0x80) {
charIndex = 0; charIndex = 0;
@ -481,8 +461,8 @@ etk::Vector2D<float> ewol::TexturedFont::GetSize(const uniChar_t unicodeChar)
} else if (unicodeChar < 0x80) { } else if (unicodeChar < 0x80) {
charIndex = unicodeChar - 0x1F; charIndex = unicodeChar - 0x1F;
} else { } else {
for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) { for (int32_t iii=0x80-0x20; iii < m_listElement[0].Size(); iii++) {
if (m_listElement[iii].property.m_UVal == unicodeChar) { if ((m_listElement[0])[iii].property.m_UVal == unicodeChar) {
charIndex = iii; charIndex = iii;
break; break;
} }
@ -490,7 +470,7 @@ etk::Vector2D<float> ewol::TexturedFont::GetSize(const uniChar_t unicodeChar)
// TODO : Update if possible the mapping // TODO : Update if possible the mapping
charIndex = 0; charIndex = 0;
} }
outputSize.x = m_listElement[charIndex].property.m_advance.x; outputSize.x = (m_listElement[0])[charIndex].property.m_advance.x;
return outputSize; return outputSize;
} }

View File

@ -15,6 +15,15 @@
namespace ewol namespace ewol
{ {
namespace font
{
typedef enum {
Regular=0,
Italic,
Bold,
BoldItalic,
} mode_te;
};
class TexturedFont : public ewol::Texture { class TexturedFont : public ewol::Texture {
typedef struct { typedef struct {
@ -23,13 +32,17 @@ namespace ewol
texCoord_ts posStop; texCoord_ts posStop;
}freeTypeFontElement_ts; }freeTypeFontElement_ts;
private: private:
etk::UString m_fileName[4];
int32_t m_size; int32_t m_size;
int32_t m_height; int32_t m_height[4];
ewol::Font* m_font; // specific element to have the the know if the specify element is known...
etk::Vector<freeTypeFontElement_ts> m_listElement; // ==> otherwise I can just generate italic ...
// ==> Bold is a little more complicated (maybe with the bordersize)
ewol::Font* m_font[4];
etk::Vector<freeTypeFontElement_ts> m_listElement[4];
// for the texture generation : // for the texture generation :
etk::Vector2D<int32_t> m_lastGlyphPos; etk::Vector2D<int32_t> m_lastGlyphPos[4];
int32_t m_lastRawHeigh; int32_t m_lastRawHeigh[4];
public: public:
TexturedFont(etk::UString fontName); TexturedFont(etk::UString fontName);
~TexturedFont(void); ~TexturedFont(void);
@ -40,18 +53,24 @@ namespace ewol
const etk::UString& unicodeString, const etk::UString& unicodeString,
etk::Vector<etk::Vector2D<float> > & coord, etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex, etk::Vector<texCoord_ts> & coordTex,
etk::Vector<int32_t> & vectDisplayMode,
bool hasClipping, bool hasClipping,
clipping_ts& clipping); clipping_ts& clipping,
ewol::font::mode_te displayMode);
int32_t Draw(etk::Vector2D<float> textPos, int32_t Draw(etk::Vector2D<float> textPos,
const uniChar_t unicodeChar, const uniChar_t unicodeChar,
etk::Vector<etk::Vector2D<float> > & coord, etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex, etk::Vector<texCoord_ts> & coordTex,
etk::Vector<int32_t> & vectDisplayMode,
bool hasClipping, bool hasClipping,
clipping_ts& clipping); clipping_ts& clipping,
ewol::font::mode_te displayMode);
etk::Vector2D<float> GetSize(const etk::UString & unicodeString); etk::Vector2D<float> GetSize(const etk::UString & unicodeString);
etk::Vector2D<float> GetSize(const uniChar_t unicodeChar); etk::Vector2D<float> GetSize(const uniChar_t unicodeChar);
// TODO : Remove this element, it is stupid ... // TODO : Remove this element, it is stupid ...
int32_t GetHeight(void) { return m_height; }; int32_t GetHeight(void) { return m_height[0]; };
int32_t GetFontSize(void) { return m_size; }; int32_t GetFontSize(void) { return m_size; };
}; };

View File

@ -57,7 +57,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(etk::UString fontName, int32_t
{ {
m_color = draw::color::black; m_color = draw::color::black;
SetFontProperty(fontName, size); SetFontProperty(fontName, size);
etk::UString tmpString("DATA:textured.prog"); etk::UString tmpString("DATA:text.prog");
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) { if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
@ -76,7 +76,7 @@ ewol::OObject2DTextColored::OObject2DTextColored(void) :
{ {
m_color = draw::color::black; m_color = draw::color::black;
SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize()); SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize());
etk::UString tmpString("DATA:textured.prog"); etk::UString tmpString("DATA:text.prog");
// get the shader resource : // get the shader resource :
m_GLPosition = 0; m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) { if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
@ -135,9 +135,10 @@ void ewol::OObject2DTextColored::Clear(void)
m_coord.Clear(); m_coord.Clear();
m_coordTex.Clear(); m_coordTex.Clear();
m_coordColor.Clear(); m_coordColor.Clear();
m_displayMode.Clear();
} }
int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString) int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString, ewol::font::mode_te displayMode)
{ {
if (m_font == NULL) { if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined"); EWOL_ERROR("Font Id is not corectly defined");
@ -145,7 +146,7 @@ int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const etk
} }
int32_t nbElementInTheArray = m_coord.Size(); int32_t nbElementInTheArray = m_coord.Size();
int32_t size = 0; int32_t size = 0;
size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex, m_hasClipping, m_clipping); size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex, m_displayMode, m_hasClipping, m_clipping, displayMode);
// set the color ... // set the color ...
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) { for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
@ -153,7 +154,7 @@ int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const etk
return size; return size;
} }
int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar) int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar, ewol::font::mode_te displayMode)
{ {
if (m_font == NULL) { if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined"); EWOL_ERROR("Font Id is not corectly defined");
@ -161,7 +162,7 @@ int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const uni
} }
int32_t nbElementInTheArray = m_coord.Size(); int32_t nbElementInTheArray = m_coord.Size();
int32_t size = 0; int32_t size = 0;
size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex, m_hasClipping, m_clipping); size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex, m_displayMode, m_hasClipping, m_clipping, displayMode);
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) { for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color); m_coordColor.PushBack(m_color);
} }

View File

@ -27,13 +27,14 @@ namespace ewol {
void SetColor(draw::Color color); void SetColor(draw::Color color);
// set a specific text // set a specific text
void Clear(void); void Clear(void);
int32_t Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString); int32_t Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString, ewol::font::mode_te displayMode = ewol::font::Regular);
int32_t Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar); int32_t Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar, ewol::font::mode_te displayMode = ewol::font::Regular);
protected: protected:
ewol::Program* m_GLprogram; ewol::Program* m_GLprogram;
int32_t m_GLPosition; int32_t m_GLPosition;
int32_t m_GLMatrix; int32_t m_GLMatrix;
int32_t m_GLColor; int32_t m_GLColor;
int32_t m_GLtextMode;
int32_t m_GLtexture; int32_t m_GLtexture;
int32_t m_GLtexID; int32_t m_GLtexID;
ewol::TexturedFont* m_font; //!< ewol font system ewol::TexturedFont* m_font; //!< ewol font system
@ -41,6 +42,7 @@ namespace ewol {
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
etk::Vector<int32_t> m_displayMode; //!< Display mode availlable (bold/...)
public: public:
void SetFont(etk::UString fontName); void SetFont(etk::UString fontName);
void SetSize(int32_t fontSize); void SetSize(int32_t fontSize);

View File

@ -103,6 +103,10 @@ LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \
../data/textured.frag:textured.frag \ ../data/textured.frag:textured.frag \
../data/textured.vert:textured.vert \ ../data/textured.vert:textured.vert \
\ \
../data/text.prog:text.prog \
../data/text.frag:text.frag \
../data/text.vert:text.vert \
\
../data/theme/default/widgetEntry.prog:theme/default/widgetEntry.prog \ ../data/theme/default/widgetEntry.prog:theme/default/widgetEntry.prog \
../data/theme/default/widgetEntry.frag:theme/default/widgetEntry.frag \ ../data/theme/default/widgetEntry.frag:theme/default/widgetEntry.frag \
../data/theme/default/widgetEntry.vert:theme/default/widgetEntry.vert \ ../data/theme/default/widgetEntry.vert:theme/default/widgetEntry.vert \