regenerate the bitmap Font

This commit is contained in:
Edouard Dupin 2011-12-05 10:12:08 +01:00
parent 7595fbf424
commit eb20828922
6 changed files with 287 additions and 356 deletions

View File

@ -99,14 +99,14 @@ X11FLAGS+= -lX11 -DEWOL_X11_MODE__XF86V -lXxf86vm
#X11FLAGS+= -lX11 -DEWOL_X11_MODE__XRENDER -lXrandr #X11FLAGS+= -lX11 -DEWOL_X11_MODE__XRENDER -lXrandr
ifeq ($(shell if `pkg-config --exists freetype2` ; then echo "yes"; else echo "no"; fi), yes) #ifeq ($(shell if `pkg-config --exists freetype2` ; then echo "yes"; else echo "no"; fi), yes)
FREETYPE_CFLAGS= `pkg-config --cflags freetype2` -DEWOL_USE_FREE_TYPE # FREETYPE_CFLAGS= `pkg-config --cflags freetype2` -DEWOL_USE_FREE_TYPE
FREETYPE_LDFLAGS= `pkg-config --libs freetype2` -DEWOL_USE_FREE_TYPE # FREETYPE_LDFLAGS= `pkg-config --libs freetype2` -DEWOL_USE_FREE_TYPE
else #else
FREETYPE_CFLAGS= FREETYPE_CFLAGS=
FREETYPE_LDFLAGS= FREETYPE_LDFLAGS=
$(Info libFreeType-dev is not installed) $(Info libFreeType-dev is not installed)
endif #endif
############################################################################### ###############################################################################

View File

@ -101,7 +101,8 @@ void APP_Init(int argc, char *argv[])
} }
*/ */
ewol::SetFontFolder("Font"); ewol::SetFontFolder("Font");
ewol::SetDefaultFont("freefont/FreeMono", 14); //ewol::SetDefaultFont("freefont/FreeMono", 14);
ewol::SetDefaultFont("ebtfont/Monospace", 14);
ewol::theme::LoadDefault("dataTest/exemple.eol"); ewol::theme::LoadDefault("dataTest/exemple.eol");
myWindowsExample = new Plop(); myWindowsExample = new Plop();

View File

@ -1,33 +0,0 @@
#ifndef APP_H_INCLUDED
#define APP_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#define WINDOW_DEFAULT_WIDTH 640
#define WINDOW_DEFAULT_HEIGHT 480
#define WINDOW_BPP 16
// The simple framework expects the application code to define these functions.
extern void appInit();
extern void appDeinit();
extern void appRender(long tick, int width, int height);
extern void appMove(double x, double y);
/* Value is non-zero when application is alive, and 0 when it is closing.
* Defined by the application framework.
*/
extern int gAppAlive;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -38,9 +38,6 @@
#include <importgl.h> #include <importgl.h>
#include <app.h>
#undef __class__ #undef __class__
#define __class__ "AndroidJNI" #define __class__ "AndroidJNI"

View File

@ -26,7 +26,7 @@
#include <etk/Types.h> #include <etk/Types.h>
#include <etk/DebugInternal.h> #include <etk/DebugInternal.h>
#include <etk/File.h> #include <etk/File.h>
#include <unistd.h>
#undef __class__ #undef __class__
#define __class__ "etk::File" #define __class__ "etk::File"
@ -156,7 +156,7 @@ void etk::File::SetCompleateName(etk::String &newFilename)
if ('/' != *destFilename.c_str()) { if ('/' != *destFilename.c_str()) {
// Get the command came from the running of the program : // Get the command came from the running of the program :
char cCurrentPath[FILENAME_MAX]; char cCurrentPath[FILENAME_MAX];
#if __PLATFORM__ == Android #ifdef __PLATFORM__Android
strcpy(cCurrentPath, "/data/" PACKAGE_NAME "/raw/"); strcpy(cCurrentPath, "/data/" PACKAGE_NAME "/raw/");
#else #else
if (!getcwd(cCurrentPath, FILENAME_MAX)) { if (!getcwd(cCurrentPath, FILENAME_MAX)) {

View File

@ -31,11 +31,12 @@
#undef __class__ #undef __class__
#define __class__ "ewol::FontBitmap" #define __class__ "ewol::FontBitmap"
#if 0
extern "C" extern "C"
{ {
typedef struct { typedef struct {
uniChar_t unicodeCharVal;
int32_t width;
texCoord_ts posStart; texCoord_ts posStart;
texCoord_ts posStop; texCoord_ts posStop;
etkFloat_t ratio; etkFloat_t ratio;
@ -45,26 +46,27 @@ extern "C"
namespace ewol namespace ewol
{ {
class Font class EbtFont
{ {
public: public:
Font(etk::File newFile) EbtFont(etk::File newFile, etk::String fontName, int32_t size)
{ {
m_loadedOK = false; m_loadedOK = false;
m_filename = newFile; m_filename = newFile;
for (int32_t iii=0; iii<FONT_MODE_NUMBER; iii++) { m_fontName = fontName;
m_textureId[iii] = 0; m_size = size;
m_textureLoaded[iii] = false; m_elements.Clear();
for (int32_t iii=0x0; iii<0x81; iii++) {
UTF8Element_ts tmpchar;
tmpchar.unicodeCharVal = iii;
tmpchar.width = 0;
tmpchar.posStart.u = 0;
tmpchar.posStart.v = 0;
tmpchar.posStop.u = 0;
tmpchar.posStop.v = 0;
tmpchar.ratio = 0;
m_elements.PushBack(tmpchar);
} }
if (m_filename.GetExtention() != "ebt") {
EWOL_ERROR("Not the coorect extention of the file" << m_filename);
return;
}
if (false == m_filename.Exist()) {
EWOL_ERROR("File does not Exist ... " << m_filename);
return;
}
FILE* File=fopen(m_filename.GetCompleateName().c_str(),"r"); FILE* File=fopen(m_filename.GetCompleateName().c_str(),"r");
if(NULL == File) { if(NULL == File) {
EWOL_ERROR("Can not find the file name=\"" << m_filename << "\""); EWOL_ERROR("Can not find the file name=\"" << m_filename << "\"");
@ -85,23 +87,10 @@ namespace ewol
sscanf(elementLine, "name:%s", extractString); sscanf(elementLine, "name:%s", extractString);
m_fontName = extractString; m_fontName = extractString;
EWOL_INFO("Find font named : \"" << m_fontName << "\""); EWOL_INFO("Find font named : \"" << m_fontName << "\"");
} else if (0 == strncmp("normal:", elementLine, 7)) { } else if (0 == strncmp("source:", elementLine, 7)) {
char extractString[256] = ""; char extractString[256] = "";
sscanf(elementLine, "normal:%s", extractString); sscanf(elementLine, "source:%s", extractString);
SetModeFile(FONT_MODE_NORMAL, extractString); m_bitmapName = extractString;
LoadMode(FONT_MODE_NORMAL);
} else if (0 == strncmp("bold-italic:", elementLine, 12)) {
char extractString[256] = "";
sscanf(elementLine, "bold-italic:%s", extractString);
SetModeFile(FONT_MODE_BOLD_ITALIC, extractString);
} else if (0 == strncmp("bold:", elementLine, 5)) {
char extractString[256] = "";
sscanf(elementLine, "bold:%s", extractString);
SetModeFile(FONT_MODE_BOLD, extractString);
} else if (0 == strncmp("italic:", elementLine, 7)) {
char extractString[256] = "";
sscanf(elementLine, "italic:%s", extractString);
SetModeFile(FONT_MODE_ITALIC, extractString);
} else if (0 == strncmp("0x00", elementLine, 4)) { } else if (0 == strncmp("0x00", elementLine, 4)) {
int32_t GlyphPositionX; int32_t GlyphPositionX;
int32_t GlyphPositionY; int32_t GlyphPositionY;
@ -125,72 +114,53 @@ namespace ewol
} }
// close the file at end of reading... // close the file at end of reading...
fclose(File); fclose(File);
// Load Bitmap :
etk::String bitmapRealFile = m_filename.GetFolder() + "/" + m_bitmapName;
EWOL_INFO("load text font image : \"" << bitmapRealFile << "\"");
m_textureId = ewol::LoadTexture(bitmapRealFile);
m_textureLoaded = true;
m_loadedOK = true; m_loadedOK = true;
}; };
~Font(void) ~EbtFont(void)
{ {
for(int32_t iii=0; iii<FONT_MODE_NUMBER; iii++) { if (true == m_textureLoaded) {
if (true == m_textureLoaded[iii]) { ewol::UnLoadTexture(m_textureId);
ewol::UnLoadTexture(m_textureId[iii]);
}
} }
}; };
bool loadedOK(void) { return m_loadedOK; }; bool loadedOK(void)
{
return m_loadedOK;
};
private: private:
void ClearAll(int32_t x, int32_t y, int32_t w, int32_t h) void ClearAll(int32_t x, int32_t y, int32_t w, int32_t h)
{ {
//EWOL_DEBUG("Find default font glyph : (" << x << "," << y << ") (" << w << "," << h << ") "); EWOL_DEBUG("Find default font glyph : (" << x << "," << y << ") (" << w << "," << h << ") ");
for (int32_t iii=0; iii< 0x80; iii++) { for (int32_t iii=0; iii< 0x80; iii++) {
m_listOfElement[iii].posStart.u = (etkFloat_t)x / 512.0; m_elements[iii].posStart.u = (etkFloat_t)x / 512.0;
m_listOfElement[iii].posStart.v = (etkFloat_t)y / 512.0; m_elements[iii].posStart.v = (etkFloat_t)y / 512.0;
m_listOfElement[iii].posStop.u = (etkFloat_t)(x+w) / 512.0; m_elements[iii].posStop.u = (etkFloat_t)(x+w) / 512.0;
m_listOfElement[iii].posStop.v = (etkFloat_t)(y+h) / 512.0; m_elements[iii].posStop.v = (etkFloat_t)(y+h) / 512.0;
m_listOfElement[iii].ratio = (etkFloat_t)w/(etkFloat_t)h; m_elements[iii].ratio = (etkFloat_t)w/(etkFloat_t)h;
m_elements[iii].width = m_size * 1.48 * m_elements[iii].ratio;
} }
}; };
void SetGlyphID(int32_t utf8Value, int32_t lineID, int32_t x, int32_t y, int32_t w, int32_t h) void SetGlyphID(int32_t utf8Value, int32_t lineID, int32_t x, int32_t y, int32_t w, int32_t h)
{ {
//EWOL_DEBUG("Add font glyph : "<< utf8Value << " (" << x << "," << y << ") (" << w << "," << h << ") "); EWOL_DEBUG("Add font glyph : "<< utf8Value << " (" << x << "," << y << ") (" << w << "," << h << ") ");
if (utf8Value < 0x80) { if (utf8Value < 0x80) {
m_listOfElement[utf8Value].posStart.u = (etkFloat_t)x / 512.0; m_elements[utf8Value].posStart.u = (etkFloat_t)x / 512.0;
m_listOfElement[utf8Value].posStart.v = (etkFloat_t)y / 512.0; m_elements[utf8Value].posStart.v = (etkFloat_t)y / 512.0;
m_listOfElement[utf8Value].posStop.u = (etkFloat_t)(x+w) / 512.0; m_elements[utf8Value].posStop.u = (etkFloat_t)(x+w) / 512.0;
m_listOfElement[utf8Value].posStop.v = (etkFloat_t)(y+h) / 512.0; m_elements[utf8Value].posStop.v = (etkFloat_t)(y+h) / 512.0;
m_listOfElement[utf8Value].ratio = (etkFloat_t)w/(etkFloat_t)h; m_elements[utf8Value].ratio = (etkFloat_t)w/(etkFloat_t)h;
m_elements[utf8Value].width = m_size * 1.48 * m_elements[utf8Value].ratio;
} else { } else {
EWOL_ERROR("not manage glyph with ID > 0x7F line : " << lineID); EWOL_ERROR("not manage glyph with ID > 0x7F line : " << lineID);
} }
}; };
public: public:
void SetModeFile(ewol::fontMode_te displayMode, etk::String newFile)
{
if (displayMode < FONT_MODE_NUMBER) {
m_bitmapName[displayMode] = newFile;
}
};
void LoadMode(ewol::fontMode_te displayMode)
{
if (displayMode < FONT_MODE_NUMBER) {
if (m_bitmapName[displayMode] == "") {
EWOL_ERROR("Can not load en empty file for the Font : " << m_filename );
return;
}
if (m_textureLoaded[displayMode] == true) {
EWOL_WARNING("Mode of font is alredy loaded : " << m_filename );
return;
}
etk::String elementName = m_filename.GetFolder();
elementName += '/';
elementName += m_bitmapName[displayMode];
EWOL_INFO("load text font image : \"" << elementName << "\"");
m_textureId[displayMode] = ewol::LoadTexture(elementName);
m_textureLoaded[displayMode] = true;
}
};
etk::File GetFileName(void) etk::File GetFileName(void)
{ {
return m_filename; return m_filename;
@ -199,208 +169,155 @@ namespace ewol
{ {
return m_fontName; return m_fontName;
}; };
bool IsLoaded(ewol::fontMode_te displayMode) bool IsLoaded(void)
{ {
return m_textureLoaded[displayMode]; return m_textureLoaded;
}; };
bool Check(etk::String fontName, int32_t size)
{
if (m_loadedOK == -1) {
return false;
}
if( m_fontName == fontName
&& m_size == size)
{
return true;
}
return false;
};
private: private:
etk::File m_filename; etk::File m_filename;
bool m_loadedOK; bool m_loadedOK;
etk::String m_fontName; etk::String m_fontName;
uint32_t m_textureId[FONT_MODE_NUMBER]; int32_t m_size;
bool m_textureLoaded[FONT_MODE_NUMBER]; uint32_t m_textureId;
etk::String m_bitmapName[FONT_MODE_NUMBER]; bool m_textureLoaded;
UTF8Element_ts m_listOfElement[0x80]; etk::String m_bitmapName;
etk::VectorType<UTF8Element_ts> m_elements; //
public: public:
UTF8Element_ts * GetPointerOnElement(void) etk::VectorType<UTF8Element_ts> & GetRefOnElement(void)
{ {
return m_listOfElement; return m_elements;
}; };
uint32_t GetOglId(ewol::fontMode_te displayMode) uint32_t GetOglId(void)
{ {
return m_textureId[displayMode]; return m_textureId;
};
int32_t GetHeight(void)
{
return m_size*1.42;
};
int32_t GetSize(void)
{
return m_size;
}; };
}; };
}; };
static etk::VectorType<ewol::Font*> listLoadedFonts; static etk::VectorType<ewol::EbtFont*> s_listLoadedFonts;
static etk::String s_currentFolderName = "";
static etk::String s_currentDefaultFontName = "";
static int32_t s_currentDefaultFontId = -1;
void ewol::SetFontFolder(etk::String folderName)
{
if (s_currentFolderName != "") {
EWOL_WARNING("Change the FontFolder, old=\"" << s_currentFolderName << "\"");
}
EWOL_TODO("Check if folder exist");
s_currentFolderName = folderName;
EWOL_INFO("New default font folder name=\"" << s_currentFolderName << "\"");
}
void ewol::InitFont(void)
{
// nothing to do ...
}
void ewol::UnInitFont(void) void ewol::UnInitFont(void)
{ {
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) { EWOL_TODO("later");
delete(listLoadedFonts[iii]);
listLoadedFonts[iii] = NULL;
}
listLoadedFonts.Clear();
} }
// load a font in momory, can be done many time for a specific fontname, if you specify true the font will be loaded in memory, otherwise, font is loaded only when needed the first time void ewol::SetDefaultFont(etk::String fontName, int32_t size)
bool ewol::AddFont(etk::File fontFileName, bool bold, bool italic, bool boldItalic)
{ {
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) { if (s_currentDefaultFontName != "") {
if (listLoadedFonts[iii]->GetFileName() == fontFileName) { EWOL_WARNING("Change the default Ewol Font, old=\"" << s_currentDefaultFontName << "\"");
if (true == bold) { }
listLoadedFonts[iii]->LoadMode(FONT_MODE_BOLD); EWOL_INFO("New default Font Name=\"" << fontName << "\"");
} int32_t tmpId = ewol::LoadFont(fontName, size);
if (true == italic) { if (-1 == tmpId) {
listLoadedFonts[iii]->LoadMode(FONT_MODE_ITALIC); if (s_currentDefaultFontName == "") {
} EWOL_ASSERT(-1 != tmpId, "Error to load the default Font\"" << fontName << "\"");
if (true == boldItalic) { } else {
listLoadedFonts[iii]->LoadMode(FONT_MODE_BOLD_ITALIC); EWOL_CRITICAL("Unable to load the new default font:\"" << fontName << "\"");
}
return true;
} }
}
if (fontFileName.GetExtention() != "ebt") {
EWOL_ERROR("Not the correct extention of the file" << fontFileName << "supported only *.ebt" );
return false;
}
ewol::Font * tmpFont = new ewol::Font(fontFileName);
if (false == tmpFont->loadedOK()) {
EWOL_ERROR("An error apear when loading Font file : " << fontFileName);
return false;
}
if (true == bold) {
tmpFont->LoadMode(FONT_MODE_BOLD);
}
if (true == italic) {
tmpFont->LoadMode(FONT_MODE_ITALIC);
}
if (true == boldItalic) {
tmpFont->LoadMode(FONT_MODE_BOLD_ITALIC);
}
listLoadedFonts.PushBack(tmpFont);
return true;
}
// get the name of the font
etk::String ewol::GetFontName(int32_t Id)
{
if(Id<listLoadedFonts.Size() && Id>=0) {
return listLoadedFonts[Id]->GetName();
}
return "No-Name";
}
int32_t ewol::GetFontIdWithFileName(etk::File fontFileName)
{
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) {
if (listLoadedFonts[iii]->GetFileName() == fontFileName) {
return iii;
}
}
return -1;
}
int32_t ewol::GetFontIdWithName(etk::String fontName)
{
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) {
if (listLoadedFonts[iii]->GetName() == fontName) {
return iii;
}
}
return -1;
}
// get the size of a long string in UTF8 (note that \n and \r represent unknown char...)
int32_t ewol::GetStringWidth(int32_t fontID, ewol::fontMode_te displayMode, int32_t size, const char * utf8String)
{
return 0;
}
// get the size of a specific char in UTF8
int32_t ewol::GetCharWidth(int32_t fontID, ewol::fontMode_te displayMode, int32_t size, const char * utf8String)
{
return 0;
}
// draw the text without background
void ewol::DrawText(int32_t fontID,
ewol::fontMode_te displayMode,
int32_t size,
coord3D_ts & drawPosition,
color_ts textColorFg,
const char * utf8String)
{
if(fontID>=listLoadedFonts.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return; return;
} }
if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) { // save the default font parameters ...
listLoadedFonts[fontID]->LoadMode(displayMode); s_currentDefaultFontName = fontName;
if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) { s_currentDefaultFontId = tmpId;
EWOL_ERROR("Can not load Font mode : " << displayMode << "of font " << listLoadedFonts[fontID]->GetName() );
return;
}
}
UTF8Element_ts * listOfElement = listLoadedFonts[fontID]->GetPointerOnElement();
char * tmpVal = (char*)utf8String;
glColor4f(textColorFg.red, textColorFg.green, textColorFg.blue, textColorFg.alpha);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, listLoadedFonts[fontID]->GetOglId(displayMode));
etkFloat_t posDrawX = drawPosition.x;
while(*tmpVal != '\0') {
int32_t tmpChar = (int32_t)*tmpVal;
if (tmpChar >= 0x80) {
tmpChar = 0;
}
etkFloat_t sizeWidth = size * listOfElement[tmpChar].ratio;
if (tmpChar != 0x20) {
// TODO : this is really not availlable in the OpenGL ES ==> make with vertex system ...
glBegin(GL_QUADS);
//m_listOfElement[utf8Value].ratio = (etkFloat_t)w/(etkFloat_t)h;
glTexCoord2f(listOfElement[tmpChar].posStart.u, listOfElement[tmpChar].posStart.v); glVertex3f(posDrawX, drawPosition.y, 0.0);
glTexCoord2f(listOfElement[tmpChar].posStop.u, listOfElement[tmpChar].posStart.v); glVertex3f(posDrawX + sizeWidth, drawPosition.y, 0.0);
glTexCoord2f(listOfElement[tmpChar].posStop.u, listOfElement[tmpChar].posStop.v); glVertex3f(posDrawX + sizeWidth, drawPosition.y + size, 0.0);
glTexCoord2f(listOfElement[tmpChar].posStart.u, listOfElement[tmpChar].posStop.v); glVertex3f(posDrawX, drawPosition.y + size, 0.0);
glEnd();
}
tmpVal++;
posDrawX += sizeWidth;
}
drawPosition.x = posDrawX;
glDisable(GL_TEXTURE_2D);
} }
int32_t ewol::GetDefaultFontId(void)
{
return s_currentDefaultFontId;
}
int32_t ewol::LoadFont(etk::String fontName, int32_t size)
{
// check if folder file
etk::String tmpFileName = s_currentFolderName + "/" + fontName + ".ebt";
etk::File fileName(tmpFileName);
if (false == fileName.Exist()) {
EWOL_ERROR("Font does not exist: \"" << fileName.GetCompleateName() << "\"");
return -1;
}
for (int32_t iii=0; iii < s_listLoadedFonts.Size(); iii++) {
if (true == s_listLoadedFonts[iii]->Check(fontName, size)) {
return iii;
}
}
EbtFont * tmpFont = new EbtFont(fileName, fontName, size);
s_listLoadedFonts.PushBack(tmpFont);
return s_listLoadedFonts.Size()-1;
}
void ewol::UnloadFont(int32_t id)
{
EWOL_TODO("I do not think it was a good idea... will be done later");
}
void ewol::DrawText(int32_t fontID, void ewol::DrawText(int32_t fontID,
ewol::fontMode_te displayMode,
int32_t size,
coord2D_ts & drawPosition, coord2D_ts & drawPosition,
const char * utf8String, const uniChar_t * unicodeString,
uint32_t & fontTextureId, uint32_t & fontTextureId,
etk::VectorType<coord2D_ts> & coord, etk::VectorType<coord2D_ts> & coord,
etk::VectorType<texCoord_ts> & coordTex) etk::VectorType<texCoord_ts> & coordTex)
{ {
if(fontID>=listLoadedFonts.Size() || fontID < 0) { if(fontID>=s_listLoadedFonts.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID); EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return; return;
} }
if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) { etk::VectorType<UTF8Element_ts> & listOfElement = s_listLoadedFonts[fontID]->GetRefOnElement();
listLoadedFonts[fontID]->LoadMode(displayMode);
if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) {
EWOL_ERROR("Can not load Font mode : " << displayMode << "of font " << listLoadedFonts[fontID]->GetName() );
return;
}
}
UTF8Element_ts * listOfElement = listLoadedFonts[fontID]->GetPointerOnElement();
char * tmpVal = (char*)utf8String;
// set id of texture ... (i kwnow it was a little dangerous, but this ID is never remove while the program is running... fontTextureId = s_listLoadedFonts[fontID]->GetOglId();
fontTextureId = listLoadedFonts[fontID]->GetOglId(displayMode); int32_t size = s_listLoadedFonts[fontID]->GetHeight();
etkFloat_t posDrawX = drawPosition.x; etkFloat_t posDrawX = drawPosition.x;
while(*tmpVal != '\0') { while(*unicodeString != 0) {
int32_t tmpChar = (int32_t)*tmpVal; int32_t tmpChar = *unicodeString++;
if (tmpChar >= 0x80) { if (tmpChar >= 0x80) {
tmpChar = 0; tmpChar = 0;
} }
etkFloat_t sizeWidth = size * listOfElement[tmpChar].ratio; etkFloat_t sizeWidth = listOfElement[tmpChar].width;
if (tmpChar != 0x20) { if (tmpChar != 0x20) {
// set texture coordonates :
coordTex.PushBack(listOfElement[tmpChar].posStart); coordTex.PushBack(listOfElement[tmpChar].posStart);
texCoord_ts tmpTex; texCoord_ts tmpTex;
tmpTex.u = listOfElement[tmpChar].posStop.u; tmpTex.u = listOfElement[tmpChar].posStop.u;
@ -410,6 +327,7 @@ void ewol::DrawText(int32_t fontID,
tmpTex.u = listOfElement[tmpChar].posStart.u; tmpTex.u = listOfElement[tmpChar].posStart.u;
tmpTex.v = listOfElement[tmpChar].posStop.v; tmpTex.v = listOfElement[tmpChar].posStop.v;
coordTex.PushBack(tmpTex); coordTex.PushBack(tmpTex);
// set display positions :
coord2D_ts tmpCoord; coord2D_ts tmpCoord;
tmpCoord.x = posDrawX; tmpCoord.x = posDrawX;
tmpCoord.y = drawPosition.y; tmpCoord.y = drawPosition.y;
@ -421,100 +339,148 @@ void ewol::DrawText(int32_t fontID,
tmpCoord.x = posDrawX; tmpCoord.x = posDrawX;
coord.PushBack(tmpCoord); coord.PushBack(tmpCoord);
} }
tmpVal++;
posDrawX += sizeWidth; posDrawX += sizeWidth;
} }
drawPosition.x = posDrawX; drawPosition.x = posDrawX;
} }
#endif
void ewol::DrawText(int32_t fontID,
// set default folder name of the font : coord2D_ts & drawPosition,
void ewol::SetFontFolder(etk::String folderName) const char * utf8String,
uint32_t & fontTextureId,
etk::VectorType<coord2D_ts> & coord,
etk::VectorType<texCoord_ts> & coordTex)
{ {
// TODO : This code des not work, why ????
/*
int32_t tmpstringLen = strlen(utf8String);
int32_t * tmpUnicodeString = new int32_t(tmpstringLen+1);
// TODO : generate a better convertor...
for (int32_t iii=0; iii<tmpstringLen; iii++) {
tmpUnicodeString[iii] = utf8String[iii];
}
tmpUnicodeString[tmpstringLen] = 0;
// unicode display ...
//DrawText(fontID, drawPosition, tmpUnicodeString, fontTextureId, coord, coordTex);
// clean temporary data ..
delete [] tmpUnicodeString;
*/
if(fontID>=s_listLoadedFonts.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return;
}
etk::VectorType<UTF8Element_ts> & listOfElement = s_listLoadedFonts[fontID]->GetRefOnElement();
char * tmpVal = (char*)utf8String;
fontTextureId = s_listLoadedFonts[fontID]->GetOglId();
int32_t size = s_listLoadedFonts[fontID]->GetHeight();
etkFloat_t posDrawX = drawPosition.x;
while(*tmpVal != 0) {
int32_t tmpChar = *tmpVal++;
int32_t charIndex;
if (tmpChar >= 0x80) {
charIndex = 0;
} else if (tmpChar < 0x20) {
charIndex = 0;
} else if (tmpChar < 0x80) {
charIndex = tmpChar; // - 0x1F;
} else {
for (int32_t iii=0x80/*-0x20*/; iii < listOfElement.Size(); iii++) {
if (listOfElement[iii].unicodeCharVal == tmpChar) {
charIndex = iii;
break;
}
}
// TODO : Update if possible the mapping
charIndex = 0;
}
etkFloat_t sizeWidth = listOfElement[charIndex].width;
// 0x01 == 0x20 == ' ';
if (tmpChar != 0x01) {
// set texture coordonates :
coordTex.PushBack(listOfElement[charIndex].posStart);
texCoord_ts tmpTex;
tmpTex.u = listOfElement[charIndex].posStop.u;
tmpTex.v = listOfElement[charIndex].posStart.v;
coordTex.PushBack(tmpTex);
coordTex.PushBack(listOfElement[charIndex].posStop);
tmpTex.u = listOfElement[charIndex].posStart.u;
tmpTex.v = listOfElement[charIndex].posStop.v;
coordTex.PushBack(tmpTex);
// set display positions :
/*int32_t xxxx = posDrawX;
int32_t yyyy = drawPosition.y;*/
coord2D_ts tmpCoord;
tmpCoord.x = posDrawX;
tmpCoord.y = drawPosition.y;
coord.PushBack(tmpCoord);
tmpCoord.x = posDrawX + sizeWidth;
coord.PushBack(tmpCoord);
tmpCoord.y = drawPosition.y + size;
coord.PushBack(tmpCoord);
tmpCoord.x = posDrawX;
coord.PushBack(tmpCoord);
}
posDrawX += sizeWidth;
}
drawPosition.x = posDrawX;
} }
void ewol::SetDefaultFont(etk::String fontName, int32_t size) int32_t ewol::GetWidth(int32_t fontID, const char * utf8String)
{ {
if(fontID>=s_listLoadedFonts.Size() || fontID < 0) {
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return 0;
}
etk::VectorType<UTF8Element_ts> & listOfElement = s_listLoadedFonts[fontID]->GetRefOnElement();
char * tmpVal = (char*)utf8String;
} etkFloat_t posDrawX = 0.0;
while(*tmpVal != 0) {
// unload all font loaded int32_t tmpChar = *tmpVal++;
void ewol::InitFont(void) int32_t charIndex;
{ if (tmpChar >= 0x80) {
charIndex = 0;
} } else if (tmpChar < 0x20) {
charIndex = 0;
void ewol::UnInitFont(void) } else if (tmpChar < 0x80) {
{ charIndex = tmpChar /*- 0x1F*/;
} else {
} for (int32_t iii=0x80/*-0x20*/; iii < listOfElement.Size(); iii++) {
if (listOfElement[iii].unicodeCharVal == tmpChar) {
// load the fonts... charIndex = iii;
int32_t ewol::LoadFont(etk::String fontName, int32_t size) break;
{ }
return 0; }
} // TODO : Update if possible the mapping
charIndex = 0;
int32_t ewol::GetDefaultFontId(void) }
{ posDrawX += listOfElement[charIndex].width;
return 0; }
} return posDrawX;
void ewol::UnloadFont(int32_t id)
{
}
// get the size of a long string in UTF8 (note that \n and \r represent unknown char...)
int32_t ewol::GetWidth(int32_t fontID, const uniChar_t * unicodeString)
{
return 20;
}
int32_t ewol::GetWidth(int32_t fontID, const char * utf8String)
{
return 20;
} }
int32_t ewol::GetHeight(int32_t fontID) int32_t ewol::GetHeight(int32_t fontID)
{ {
return 25; if(fontID>=s_listLoadedFonts.Size() || fontID < 0) {
} EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
return 10;
}
void ewol::DrawText(int32_t fontID, return s_listLoadedFonts[fontID]->GetHeight();
coord2D_ts & drawPosition,
const char * utf8String,
uint32_t & fontTextureId,
etk::VectorType<coord2D_ts> & coord,
etk::VectorType<texCoord_ts> & coordTex)
{
}
void ewol::DrawText(int32_t fontID,
coord2D_ts & drawPosition,
const uniChar_t * unicodeString,
uint32_t & fontTextureId,
etk::VectorType<coord2D_ts> & coord,
etk::VectorType<texCoord_ts> & coordTex)
{
}
int32_t ewol::LoadFont(etk::File fontFileName)
{
}
void ewol::DrawText(etkFloat_t x, etkFloat_t y, const char * myString)
{
} }