regenerate the bitmap Font
This commit is contained in:
parent
7595fbf424
commit
eb20828922
10
Makefile
10
Makefile
@ -99,14 +99,14 @@ X11FLAGS+= -lX11 -DEWOL_X11_MODE__XF86V -lXxf86vm
|
||||
#X11FLAGS+= -lX11 -DEWOL_X11_MODE__XRENDER -lXrandr
|
||||
|
||||
|
||||
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_LDFLAGS= `pkg-config --libs freetype2` -DEWOL_USE_FREE_TYPE
|
||||
else
|
||||
#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_LDFLAGS= `pkg-config --libs freetype2` -DEWOL_USE_FREE_TYPE
|
||||
#else
|
||||
FREETYPE_CFLAGS=
|
||||
FREETYPE_LDFLAGS=
|
||||
$(Info libFreeType-dev is not installed)
|
||||
endif
|
||||
#endif
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
@ -101,7 +101,8 @@ void APP_Init(int argc, char *argv[])
|
||||
}
|
||||
*/
|
||||
ewol::SetFontFolder("Font");
|
||||
ewol::SetDefaultFont("freefont/FreeMono", 14);
|
||||
//ewol::SetDefaultFont("freefont/FreeMono", 14);
|
||||
ewol::SetDefaultFont("ebtfont/Monospace", 14);
|
||||
ewol::theme::LoadDefault("dataTest/exemple.eol");
|
||||
|
||||
myWindowsExample = new Plop();
|
||||
|
@ -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
|
@ -38,9 +38,6 @@
|
||||
|
||||
#include <importgl.h>
|
||||
|
||||
|
||||
#include <app.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "AndroidJNI"
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <etk/Types.h>
|
||||
#include <etk/DebugInternal.h>
|
||||
#include <etk/File.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "etk::File"
|
||||
@ -156,7 +156,7 @@ void etk::File::SetCompleateName(etk::String &newFilename)
|
||||
if ('/' != *destFilename.c_str()) {
|
||||
// Get the command came from the running of the program :
|
||||
char cCurrentPath[FILENAME_MAX];
|
||||
#if __PLATFORM__ == Android
|
||||
#ifdef __PLATFORM__Android
|
||||
strcpy(cCurrentPath, "/data/" PACKAGE_NAME "/raw/");
|
||||
#else
|
||||
if (!getcwd(cCurrentPath, FILENAME_MAX)) {
|
||||
|
@ -31,11 +31,12 @@
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ewol::FontBitmap"
|
||||
#if 0
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef struct {
|
||||
uniChar_t unicodeCharVal;
|
||||
int32_t width;
|
||||
texCoord_ts posStart;
|
||||
texCoord_ts posStop;
|
||||
etkFloat_t ratio;
|
||||
@ -45,26 +46,27 @@ extern "C"
|
||||
|
||||
namespace ewol
|
||||
{
|
||||
class Font
|
||||
class EbtFont
|
||||
{
|
||||
public:
|
||||
Font(etk::File newFile)
|
||||
EbtFont(etk::File newFile, etk::String fontName, int32_t size)
|
||||
{
|
||||
m_loadedOK = false;
|
||||
m_filename = newFile;
|
||||
for (int32_t iii=0; iii<FONT_MODE_NUMBER; iii++) {
|
||||
m_textureId[iii] = 0;
|
||||
m_textureLoaded[iii] = false;
|
||||
m_fontName = fontName;
|
||||
m_size = size;
|
||||
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");
|
||||
if(NULL == File) {
|
||||
EWOL_ERROR("Can not find the file name=\"" << m_filename << "\"");
|
||||
@ -85,23 +87,10 @@ namespace ewol
|
||||
sscanf(elementLine, "name:%s", extractString);
|
||||
m_fontName = extractString;
|
||||
EWOL_INFO("Find font named : \"" << m_fontName << "\"");
|
||||
} else if (0 == strncmp("normal:", elementLine, 7)) {
|
||||
} else if (0 == strncmp("source:", elementLine, 7)) {
|
||||
char extractString[256] = "";
|
||||
sscanf(elementLine, "normal:%s", extractString);
|
||||
SetModeFile(FONT_MODE_NORMAL, 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);
|
||||
sscanf(elementLine, "source:%s", extractString);
|
||||
m_bitmapName = extractString;
|
||||
} else if (0 == strncmp("0x00", elementLine, 4)) {
|
||||
int32_t GlyphPositionX;
|
||||
int32_t GlyphPositionY;
|
||||
@ -125,72 +114,53 @@ namespace ewol
|
||||
}
|
||||
// close the file at end of reading...
|
||||
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;
|
||||
};
|
||||
|
||||
~Font(void)
|
||||
~EbtFont(void)
|
||||
{
|
||||
for(int32_t iii=0; iii<FONT_MODE_NUMBER; iii++) {
|
||||
if (true == m_textureLoaded[iii]) {
|
||||
ewol::UnLoadTexture(m_textureId[iii]);
|
||||
}
|
||||
if (true == m_textureLoaded) {
|
||||
ewol::UnLoadTexture(m_textureId);
|
||||
}
|
||||
};
|
||||
bool loadedOK(void) { return m_loadedOK; };
|
||||
bool loadedOK(void)
|
||||
{
|
||||
return m_loadedOK;
|
||||
};
|
||||
private:
|
||||
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++) {
|
||||
m_listOfElement[iii].posStart.u = (etkFloat_t)x / 512.0;
|
||||
m_listOfElement[iii].posStart.v = (etkFloat_t)y / 512.0;
|
||||
m_listOfElement[iii].posStop.u = (etkFloat_t)(x+w) / 512.0;
|
||||
m_listOfElement[iii].posStop.v = (etkFloat_t)(y+h) / 512.0;
|
||||
m_listOfElement[iii].ratio = (etkFloat_t)w/(etkFloat_t)h;
|
||||
m_elements[iii].posStart.u = (etkFloat_t)x / 512.0;
|
||||
m_elements[iii].posStart.v = (etkFloat_t)y / 512.0;
|
||||
m_elements[iii].posStop.u = (etkFloat_t)(x+w) / 512.0;
|
||||
m_elements[iii].posStop.v = (etkFloat_t)(y+h) / 512.0;
|
||||
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)
|
||||
{
|
||||
//EWOL_DEBUG("Add font glyph : "<< utf8Value << " (" << x << "," << y << ") (" << w << "," << h << ") ");
|
||||
EWOL_DEBUG("Add font glyph : "<< utf8Value << " (" << x << "," << y << ") (" << w << "," << h << ") ");
|
||||
if (utf8Value < 0x80) {
|
||||
m_listOfElement[utf8Value].posStart.u = (etkFloat_t)x / 512.0;
|
||||
m_listOfElement[utf8Value].posStart.v = (etkFloat_t)y / 512.0;
|
||||
m_listOfElement[utf8Value].posStop.u = (etkFloat_t)(x+w) / 512.0;
|
||||
m_listOfElement[utf8Value].posStop.v = (etkFloat_t)(y+h) / 512.0;
|
||||
m_listOfElement[utf8Value].ratio = (etkFloat_t)w/(etkFloat_t)h;
|
||||
m_elements[utf8Value].posStart.u = (etkFloat_t)x / 512.0;
|
||||
m_elements[utf8Value].posStart.v = (etkFloat_t)y / 512.0;
|
||||
m_elements[utf8Value].posStop.u = (etkFloat_t)(x+w) / 512.0;
|
||||
m_elements[utf8Value].posStop.v = (etkFloat_t)(y+h) / 512.0;
|
||||
m_elements[utf8Value].ratio = (etkFloat_t)w/(etkFloat_t)h;
|
||||
m_elements[utf8Value].width = m_size * 1.48 * m_elements[utf8Value].ratio;
|
||||
} else {
|
||||
EWOL_ERROR("not manage glyph with ID > 0x7F line : " << lineID);
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
return m_filename;
|
||||
@ -199,208 +169,155 @@ namespace ewol
|
||||
{
|
||||
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:
|
||||
etk::File m_filename;
|
||||
bool m_loadedOK;
|
||||
etk::String m_fontName;
|
||||
uint32_t m_textureId[FONT_MODE_NUMBER];
|
||||
bool m_textureLoaded[FONT_MODE_NUMBER];
|
||||
etk::String m_bitmapName[FONT_MODE_NUMBER];
|
||||
UTF8Element_ts m_listOfElement[0x80];
|
||||
int32_t m_size;
|
||||
uint32_t m_textureId;
|
||||
bool m_textureLoaded;
|
||||
etk::String m_bitmapName;
|
||||
etk::VectorType<UTF8Element_ts> m_elements; //
|
||||
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)
|
||||
{
|
||||
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) {
|
||||
delete(listLoadedFonts[iii]);
|
||||
listLoadedFonts[iii] = NULL;
|
||||
}
|
||||
listLoadedFonts.Clear();
|
||||
EWOL_TODO("later");
|
||||
}
|
||||
|
||||
// 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
|
||||
bool ewol::AddFont(etk::File fontFileName, bool bold, bool italic, bool boldItalic)
|
||||
void ewol::SetDefaultFont(etk::String fontName, int32_t size)
|
||||
{
|
||||
for (int32_t iii=0; iii<listLoadedFonts.Size(); iii++) {
|
||||
if (listLoadedFonts[iii]->GetFileName() == fontFileName) {
|
||||
if (true == bold) {
|
||||
listLoadedFonts[iii]->LoadMode(FONT_MODE_BOLD);
|
||||
}
|
||||
if (true == italic) {
|
||||
listLoadedFonts[iii]->LoadMode(FONT_MODE_ITALIC);
|
||||
}
|
||||
if (true == boldItalic) {
|
||||
listLoadedFonts[iii]->LoadMode(FONT_MODE_BOLD_ITALIC);
|
||||
}
|
||||
return true;
|
||||
if (s_currentDefaultFontName != "") {
|
||||
EWOL_WARNING("Change the default Ewol Font, old=\"" << s_currentDefaultFontName << "\"");
|
||||
}
|
||||
EWOL_INFO("New default Font Name=\"" << fontName << "\"");
|
||||
int32_t tmpId = ewol::LoadFont(fontName, size);
|
||||
if (-1 == tmpId) {
|
||||
if (s_currentDefaultFontName == "") {
|
||||
EWOL_ASSERT(-1 != tmpId, "Error to load the default Font\"" << fontName << "\"");
|
||||
} else {
|
||||
EWOL_CRITICAL("Unable to load the new default font:\"" << fontName << "\"");
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) {
|
||||
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;
|
||||
|
||||
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);
|
||||
// save the default font parameters ...
|
||||
s_currentDefaultFontName = fontName;
|
||||
s_currentDefaultFontId = tmpId;
|
||||
}
|
||||
|
||||
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,
|
||||
ewol::fontMode_te displayMode,
|
||||
int32_t size,
|
||||
coord2D_ts & drawPosition,
|
||||
const char * utf8String,
|
||||
const uniChar_t * unicodeString,
|
||||
uint32_t & fontTextureId,
|
||||
etk::VectorType<coord2D_ts> & coord,
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (false == listLoadedFonts[fontID]->IsLoaded(displayMode)) {
|
||||
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;
|
||||
etk::VectorType<UTF8Element_ts> & listOfElement = s_listLoadedFonts[fontID]->GetRefOnElement();
|
||||
|
||||
// set id of texture ... (i kwnow it was a little dangerous, but this ID is never remove while the program is running...
|
||||
fontTextureId = listLoadedFonts[fontID]->GetOglId(displayMode);
|
||||
fontTextureId = s_listLoadedFonts[fontID]->GetOglId();
|
||||
int32_t size = s_listLoadedFonts[fontID]->GetHeight();
|
||||
|
||||
etkFloat_t posDrawX = drawPosition.x;
|
||||
while(*tmpVal != '\0') {
|
||||
int32_t tmpChar = (int32_t)*tmpVal;
|
||||
while(*unicodeString != 0) {
|
||||
int32_t tmpChar = *unicodeString++;
|
||||
if (tmpChar >= 0x80) {
|
||||
tmpChar = 0;
|
||||
}
|
||||
etkFloat_t sizeWidth = size * listOfElement[tmpChar].ratio;
|
||||
etkFloat_t sizeWidth = listOfElement[tmpChar].width;
|
||||
if (tmpChar != 0x20) {
|
||||
// set texture coordonates :
|
||||
coordTex.PushBack(listOfElement[tmpChar].posStart);
|
||||
texCoord_ts tmpTex;
|
||||
tmpTex.u = listOfElement[tmpChar].posStop.u;
|
||||
@ -410,6 +327,7 @@ void ewol::DrawText(int32_t fontID,
|
||||
tmpTex.u = listOfElement[tmpChar].posStart.u;
|
||||
tmpTex.v = listOfElement[tmpChar].posStop.v;
|
||||
coordTex.PushBack(tmpTex);
|
||||
// set display positions :
|
||||
coord2D_ts tmpCoord;
|
||||
tmpCoord.x = posDrawX;
|
||||
tmpCoord.y = drawPosition.y;
|
||||
@ -421,100 +339,148 @@ void ewol::DrawText(int32_t fontID,
|
||||
tmpCoord.x = posDrawX;
|
||||
coord.PushBack(tmpCoord);
|
||||
}
|
||||
tmpVal++;
|
||||
posDrawX += sizeWidth;
|
||||
}
|
||||
drawPosition.x = posDrawX;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// set default folder name of the font :
|
||||
void ewol::SetFontFolder(etk::String folderName)
|
||||
void ewol::DrawText(int32_t fontID,
|
||||
coord2D_ts & drawPosition,
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
// unload all font loaded
|
||||
void ewol::InitFont(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ewol::UnInitFont(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// load the fonts...
|
||||
int32_t ewol::LoadFont(etk::String fontName, int32_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ewol::GetDefaultFontId(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
etkFloat_t posDrawX = 0.0;
|
||||
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;
|
||||
}
|
||||
posDrawX += listOfElement[charIndex].width;
|
||||
}
|
||||
return posDrawX;
|
||||
}
|
||||
|
||||
int32_t ewol::GetHeight(int32_t fontID)
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
|
||||
|
||||
void ewol::DrawText(int32_t fontID,
|
||||
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)
|
||||
{
|
||||
|
||||
if(fontID>=s_listLoadedFonts.Size() || fontID < 0) {
|
||||
EWOL_WARNING("try to display text with an fontID that does not existed " << fontID);
|
||||
return 10;
|
||||
}
|
||||
return s_listLoadedFonts[fontID]->GetHeight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user