Ewol change the idea of how the Font are managed

This commit is contained in:
Edouard Dupin 2012-08-22 18:18:59 +02:00
parent e27720372b
commit 76cd7bef21
5 changed files with 51 additions and 58 deletions

View File

@ -76,8 +76,7 @@ int32_t BufferEmpty::Display(ewol::OObject2DTextColored& OOTextNormal,
// Get color : // Get color :
Colorize *myColor = NULL; Colorize *myColor = NULL;
int32_t fontId = OOTextNormal.GetFontID(); int32_t letterHeight = OOTextNormal.GetHeight();
int32_t letterHeight = ewol::GetHeight(fontId);
Vector2D<float> textPos; Vector2D<float> textPos;
textPos.x = 20; textPos.x = 20;

View File

@ -289,9 +289,8 @@ int32_t BufferText::Display(ewol::OObject2DTextColored& OOTextNormal,
bool selIsRect; bool selIsRect;
int32_t selHave; int32_t selHave;
int32_t fontId = OOTextNormal.GetFontID(); int32_t letterWidth = OOTextNormal.GetSize("A").x;
int32_t letterWidth = ewol::GetWidth(fontId, "A"); int32_t letterHeight = OOTextNormal.GetHeight();
int32_t letterHeight = ewol::GetHeight(fontId);
int32_t displayStartLineId = offsetY / letterHeight - 1; int32_t displayStartLineId = offsetY / letterHeight - 1;
displayStartLineId = etk_max(0, displayStartLineId); displayStartLineId = etk_max(0, displayStartLineId);
@ -479,9 +478,18 @@ int32_t BufferText::Display(ewol::OObject2DTextColored& OOTextNormal,
int32_t BufferText::GetMousePosition(int32_t fontId, int32_t width, int32_t height) int32_t BufferText::GetMousePosition(int32_t fontId, int32_t width, int32_t height)
{ {
// TODO : Set it back ...
#if 1
int32_t letterWidth = 8;
int32_t letterHeight = 15;
#else
int32_t letterWidth = ewol::GetWidth(fontId, "9"); int32_t letterWidth = ewol::GetWidth(fontId, "9");
int32_t letterHeight = ewol::GetHeight(fontId); int32_t letterHeight = ewol::GetHeight(fontId);
/*
int32_t letterWidth = OOTextNormal.GetSize("A").x;
int32_t letterHeight = OOTextNormal.GetHeight();
*/
#endif
int32_t lineOffset = height / letterHeight; int32_t lineOffset = height / letterHeight;
//******************************* get the X position : ******************************************* //******************************* get the X position : *******************************************
@ -513,7 +521,9 @@ int32_t BufferText::GetMousePosition(int32_t fontId, int32_t width, int32_t heig
new_i = iii; new_i = iii;
displaywidth = m_EdnBuf.GetExpandedChar(new_i, idX, displayChar, currentChar); displaywidth = m_EdnBuf.GetExpandedChar(new_i, idX, displayChar, currentChar);
if (currentChar!='\n') { if (currentChar!='\n') {
int32_t drawSize = ewol::GetWidth(fontId, displayChar); // TODO : Set it back ...
//int32_t drawSize = ewol::GetWidth(fontId, displayChar);
int32_t drawSize = 50;
APPL_VERBOSE(" Element : " << currentChar << "=\"" << (char)currentChar << "\" display offset=" << pixelX << "px width=" << drawSize << "px"); APPL_VERBOSE(" Element : " << currentChar << "=\"" << (char)currentChar << "\" display offset=" << pixelX << "px width=" << drawSize << "px");
pixelX += drawSize; pixelX += drawSize;
if (width <= pixelX) { if (width <= pixelX) {
@ -870,8 +880,13 @@ Vector2D<float> BufferText::GetPosition(int32_t fontId, bool& centerRequested)
// get font porperties : // get font porperties :
// TODO : change this : // TODO : change this :
// TODO : Set it back ...
/*
float letterWidth = ewol::GetWidth(fontId, "A"); float letterWidth = ewol::GetWidth(fontId, "A");
float letterHeight = ewol::GetHeight(fontId); float letterHeight = ewol::GetHeight(fontId);
*/
float letterWidth = 10;
float letterHeight = 15;
outputPosition.x *= letterWidth; outputPosition.x *= letterWidth;
outputPosition.y *= letterHeight; outputPosition.y *= letterHeight;
return outputPosition; return outputPosition;

View File

@ -45,11 +45,6 @@
CodeView::CodeView(void) CodeView::CodeView(void)
{ {
m_label = "CodeView is disable ..."; m_label = "CodeView is disable ...";
m_fontNormal = -1;
m_fontBold = -1;
m_fontItalic = -1;
m_fontBoldItalic = -1;
m_fontSize = 15;
m_bufferID = -1; m_bufferID = -1;
m_buttunOneSelected = false; m_buttunOneSelected = false;
@ -111,7 +106,7 @@ bool CodeView::CalculateMinSize(void)
void CodeView::CalculateMaxSize(void) void CodeView::CalculateMaxSize(void)
{ {
m_maxSize.x = 2048; m_maxSize.x = 2048;
int32_t letterHeight = ewol::GetHeight(m_fontNormal); int32_t letterHeight = m_OObjectTextNormal.GetHeight();
m_maxSize.y = BufferManager::Get(m_bufferID)->GetNumberOfLine() * letterHeight; m_maxSize.y = BufferManager::Get(m_bufferID)->GetNumberOfLine() * letterHeight;
} }
@ -134,12 +129,6 @@ void CodeView::OnRegenerateDisplay(void)
// For the scrooling windows // For the scrooling windows
CalculateMaxSize(); CalculateMaxSize();
// clean internal elements ...
m_OObjectTextNormal.SetFontID(m_fontNormal);
m_OObjectTextBold.SetFontID(m_fontBold);
m_OObjectTextItalic.SetFontID(m_fontItalic);
m_OObjectTextBoldItalic.SetFontID(m_fontBoldItalic);
m_OObjectTextNormal.Clear(); m_OObjectTextNormal.Clear();
m_OObjectTextBold.Clear(); m_OObjectTextBold.Clear();
m_OObjectTextItalic.Clear(); m_OObjectTextItalic.Clear();
@ -150,7 +139,8 @@ void CodeView::OnRegenerateDisplay(void)
if(true == BufferManager::Get(m_bufferID)->NeedToUpdateDisplayPosition() ) { if(true == BufferManager::Get(m_bufferID)->NeedToUpdateDisplayPosition() ) {
Vector2D<float> borderWidth = BufferManager::Get(m_bufferID)->GetBorderSize(); Vector2D<float> borderWidth = BufferManager::Get(m_bufferID)->GetBorderSize();
bool centerRequested = false; bool centerRequested = false;
Vector2D<float> currentPosition = BufferManager::Get(m_bufferID)->GetPosition(m_OObjectTextNormal.GetFontID(), centerRequested); // TODO : set it back ...
Vector2D<float> currentPosition = BufferManager::Get(m_bufferID)->GetPosition(999/*m_OObjectTextNormal.GetFontID()*/, centerRequested);
SetScrollingPositionDynamic(borderWidth, currentPosition, centerRequested); SetScrollingPositionDynamic(borderWidth, currentPosition, centerRequested);
} // else : nothing to do ... } // else : nothing to do ...
@ -233,7 +223,8 @@ bool CodeView::OnEventInput(ewol::inputType_te type, int32_t IdInput, ewol::even
if (ewol::EVENT_INPUT_TYPE_DOWN == typeEvent) { if (ewol::EVENT_INPUT_TYPE_DOWN == typeEvent) {
m_buttunOneSelected = true; m_buttunOneSelected = true;
ewol::widgetManager::FocusKeep(this); ewol::widgetManager::FocusKeep(this);
BufferManager::Get(m_bufferID)->MouseEvent(m_fontNormal, relativePos.x+m_originScrooled.x, relativePos.y+m_originScrooled.y); // TODO : Set something good
BufferManager::Get(m_bufferID)->MouseEvent(999/*m_fontNormal*/, relativePos.x+m_originScrooled.x, relativePos.y+m_originScrooled.y);
MarkToRedraw(); MarkToRedraw();
} else if (ewol::EVENT_INPUT_TYPE_UP == typeEvent) { } else if (ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
m_buttunOneSelected = false; m_buttunOneSelected = false;
@ -267,13 +258,15 @@ bool CodeView::OnEventInput(ewol::inputType_te type, int32_t IdInput, ewol::even
yyy = 0; yyy = 0;
} }
//APPL_INFO("mouse-motion BT1 %d, %d", xxx, yyy); //APPL_INFO("mouse-motion BT1 %d, %d", xxx, yyy);
BufferManager::Get(m_bufferID)->MouseSelectFromCursorTo(m_fontNormal, xxx+m_originScrooled.x, yyy+m_originScrooled.y); // TODO : Set something good
BufferManager::Get(m_bufferID)->MouseSelectFromCursorTo(999/*m_fontNormal*/, xxx+m_originScrooled.x, yyy+m_originScrooled.y);
MarkToRedraw(); MarkToRedraw();
} }
} }
} else if (2 == IdInput) { } else if (2 == IdInput) {
if (ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent) { if (ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent) {
BufferManager::Get(m_bufferID)->MouseEvent(m_fontNormal, relativePos.x+m_originScrooled.x, relativePos.y+m_originScrooled.y); // TODO : Set something good
BufferManager::Get(m_bufferID)->MouseEvent(999/*m_fontNormal*/, relativePos.x+m_originScrooled.x, relativePos.y+m_originScrooled.y);
ewol::clipBoard::Request(ewol::clipBoard::CLIPBOARD_SELECTION); ewol::clipBoard::Request(ewol::clipBoard::CLIPBOARD_SELECTION);
ewol::widgetManager::FocusKeep(this); ewol::widgetManager::FocusKeep(this);
} }
@ -408,38 +401,29 @@ void CodeView::OnLostFocus(void)
void CodeView::SetFontSize(int32_t size) void CodeView::SetFontSize(int32_t size)
{ {
m_fontSize = size; m_OObjectTextNormal.SetSize(size);
SetScrollingSize(m_fontSize*3.0*1.46); // 1.46 is a magic nmber ... m_OObjectTextBold.SetSize(size);
m_OObjectTextItalic.SetSize(size);
m_OObjectTextBoldItalic.SetSize(size);
SetScrollingSize(size*3.0*1.46); // 1.46 is a magic nmber ...
} }
void CodeView::SetFontNameNormal(etk::UString fontName) void CodeView::SetFontNameNormal(etk::UString fontName)
{ {
int32_t fontID = ewol::LoadFont(fontName, m_fontSize); m_OObjectTextNormal.SetFont(fontName);
if (fontID >= 0) {
m_fontNormal = fontID;
}
} }
void CodeView::SetFontNameBold(etk::UString fontName) void CodeView::SetFontNameBold(etk::UString fontName)
{ {
int32_t fontID = ewol::LoadFont(fontName, m_fontSize); m_OObjectTextBold.SetFont(fontName);
if (fontID >= 0) {
m_fontBold = fontID;
}
} }
void CodeView::SetFontNameItalic(etk::UString fontName) void CodeView::SetFontNameItalic(etk::UString fontName)
{ {
int32_t fontID = ewol::LoadFont(fontName, m_fontSize); m_OObjectTextItalic.SetFont(fontName);
if (fontID >= 0) {
m_fontItalic = fontID;
}
} }
void CodeView::SetFontNameBoldItalic(etk::UString fontName) void CodeView::SetFontNameBoldItalic(etk::UString fontName)
{ {
int32_t fontID = ewol::LoadFont(fontName, m_fontSize); m_OObjectTextBoldItalic.SetFont(fontName);
if (fontID >= 0) {
m_fontBoldItalic = fontID;
}
} }

View File

@ -33,6 +33,7 @@
#include <etk/Types.h> #include <etk/Types.h>
#include <ewol/widget/WidgetScrolled.h> #include <ewol/widget/WidgetScrolled.h>
#include <ewol/font/FontManager.h>
class CodeView :public ewol::WidgetScrooled class CodeView :public ewol::WidgetScrooled
{ {
@ -48,13 +49,13 @@ class CodeView :public ewol::WidgetScrooled
const char * const GetObjectType(void) { return "ApplCodeView"; }; const char * const GetObjectType(void) { return "ApplCodeView"; };
virtual bool CalculateMinSize(void); virtual bool CalculateMinSize(void);
private: private:
etk::UString m_label; etk::UString m_label;
draw::Color m_textColorFg; //!< Text color draw::Color m_textColorFg; //!< Text color
draw::Color m_textColorBg; //!< Background color draw::Color m_textColorBg; //!< Background color
int32_t m_bufferID; int32_t m_bufferID;
bool m_buttunOneSelected; bool m_buttunOneSelected;
etk::Vector<Vector2D<float> > m_lineNumberList; etk::Vector<Vector2D<float> > m_lineNumberList;
void UpdateNumberOfLineReference(int32_t bufferID); void UpdateNumberOfLineReference(int32_t bufferID);
// drawing elements : // drawing elements :
ewol::OObject2DTextColored m_OObjectTextNormal; ewol::OObject2DTextColored m_OObjectTextNormal;
ewol::OObject2DTextColored m_OObjectTextBold; ewol::OObject2DTextColored m_OObjectTextBold;
@ -95,12 +96,6 @@ class CodeView :public ewol::WidgetScrooled
virtual void OnGetFocus(void); virtual void OnGetFocus(void);
virtual void OnLostFocus(void); virtual void OnLostFocus(void);
private:
int32_t m_fontSize;
int32_t m_fontNormal;
int32_t m_fontBold;
int32_t m_fontItalic;
int32_t m_fontBoldItalic;
public: public:
void SetFontSize(int32_t size); void SetFontSize(int32_t size);
void SetFontNameNormal(etk::UString fontName); void SetFontNameNormal(etk::UString fontName);

View File

@ -41,6 +41,7 @@
#include <readtags.h> #include <readtags.h>
#include <CTagsManager.h> #include <CTagsManager.h>
#include <globalMsg.h> #include <globalMsg.h>
#include <ewol/font/FontManager.h>
MainWindows * basicWindows = NULL; MainWindows * basicWindows = NULL;
@ -66,14 +67,13 @@ void APP_Init(void)
ewol::ChangeSize(Vector2D<int32_t>(800, 600)); ewol::ChangeSize(Vector2D<int32_t>(800, 600));
etk::InitDefaultFolder(PROJECT_NAME); etk::InitDefaultFolder(PROJECT_NAME);
ewol::SetFontFolder("Font"); ewol::font::SetFontFolder("Font");
ewol::font::SetDefaultFont("freefont/FreeSerif.ttf");
#ifdef __TARGET_OS__Android #ifdef __TARGET_OS__Android
ewol::SetDefaultFont("freefont/FreeSerif.ttf", 19); ewol::font::SetDefaultSize(19);
#else #else
ewol::SetDefaultFont("freefont/FreeSerif.ttf", 14); ewol::font::SetDefaultSize(14);
#endif #endif
// init internal global value // init internal global value
globals::init(); globals::init();