added possibility to draw vertical text bottomum and topdown

This commit is contained in:
louis 2015-03-31 06:57:02 +02:00
parent 1ba2ae905a
commit 3d43200af0
10 changed files with 60 additions and 13 deletions

View File

@ -244,4 +244,6 @@ Version 0.3.3
- fixed bug that parameters with both dynamic tokens and relative width, - fixed bug that parameters with both dynamic tokens and relative width,
height, posx or posy values are not parsed correctly height, posx or posy values are not parsed correctly
- fixed bug also for loops - fixed bug also for loops
- added possibility to draw vertical text bottomum and topdown

View File

@ -108,6 +108,7 @@
fontsize CDATA #REQUIRED fontsize CDATA #REQUIRED
name NMTOKEN #IMPLIED name NMTOKEN #IMPLIED
text CDATA #REQUIRED text CDATA #REQUIRED
direction (bottomup|topdown) #IMPLIED
condition CDATA #IMPLIED condition CDATA #IMPLIED
debug (true|false) #IMPLIED debug (true|false) #IMPLIED
> >

View File

@ -1,4 +1,5 @@
#include "cairoimage.h" #include "cairoimage.h"
#include "../libtemplate/templatefunction.h"
cCairoImage::cCairoImage(void) { cCairoImage::cCairoImage(void) {
surface = NULL; surface = NULL;
@ -21,18 +22,26 @@ void cCairoImage::InitCairoImage(int width, int height) {
cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL);
} }
void cCairoImage::DrawTextVertical(string text, tColor color, string font, int size) { void cCairoImage::DrawTextVertical(string text, tColor color, string font, int size, int direction) {
int imgHeight = GetTextWidth(text, font, size); int imgHeight = GetTextWidth(text, font, size);
InitCairoImage(size * 1.2, imgHeight); InitCairoImage(size * 1.2, imgHeight);
SetColor(color); SetColor(color);
cairo_move_to (cr, size, imgHeight);
cairo_font_weight_t fontWeight = CAIRO_FONT_WEIGHT_NORMAL; cairo_font_weight_t fontWeight = CAIRO_FONT_WEIGHT_NORMAL;
cairo_font_slant_t fontSlant = CAIRO_FONT_SLANT_NORMAL; cairo_font_slant_t fontSlant = CAIRO_FONT_SLANT_NORMAL;
cairo_select_font_face (cr, font.c_str(), fontSlant, fontWeight); cairo_select_font_face (cr, font.c_str(), fontSlant, fontWeight);
cairo_set_font_size (cr, size); cairo_set_font_size (cr, size);
cairo_rotate(cr, 3*M_PI/2); int x = size;
int y = imgHeight;
double rotate = 3*M_PI/2;
if (direction == diTopDown) {
rotate = M_PI/2;
x = size*0.3;
y = 0;
}
cairo_move_to (cr, x, y);
cairo_rotate(cr, rotate);
cairo_show_text (cr, text.c_str()); cairo_show_text (cr, text.c_str());
} }

View File

@ -20,7 +20,7 @@ public:
cCairoImage(void); cCairoImage(void);
virtual ~cCairoImage(); virtual ~cCairoImage();
void InitCairoImage(int width, int height); void InitCairoImage(int width, int height);
void DrawTextVertical(string text, tColor color, string font, int size); void DrawTextVertical(string text, tColor color, string font, int size, int direction);
cImage *GetImage(void); cImage *GetImage(void);
}; };
#endif //__CAIROIMAGE_H #endif //__CAIROIMAGE_H

View File

@ -332,17 +332,17 @@ cImage *cImageCache::GetSkinpart(string name, int width, int height) {
return NULL; return NULL;
} }
cImage *cImageCache::GetVerticalText(string text, tColor color, string font, int size) { cImage *cImageCache::GetVerticalText(string text, tColor color, string font, int size, int direction) {
cMutexLock MutexLock(&mutex); cMutexLock MutexLock(&mutex);
stringstream buf; stringstream buf;
buf << text << "_" << size; buf << text << "_" << size << "_" << direction;
string imgName = buf.str(); string imgName = buf.str();
map<string, cImage*>::iterator hit = cairoImageCache.find(imgName); map<string, cImage*>::iterator hit = cairoImageCache.find(imgName);
if (hit != cairoImageCache.end()) { if (hit != cairoImageCache.end()) {
return (cImage*)hit->second; return (cImage*)hit->second;
} else { } else {
cCairoImage c; cCairoImage c;
c.DrawTextVertical(text, color, font, size); c.DrawTextVertical(text, color, font, size, direction);
cImage *image = c.GetImage(); cImage *image = c.GetImage();
cairoImageCache.insert(pair<string, cImage*>(imgName, image)); cairoImageCache.insert(pair<string, cImage*>(imgName, image));
hit = cairoImageCache.find(imgName); hit = cairoImageCache.find(imgName);

View File

@ -31,7 +31,7 @@ public:
void CacheSkinpart(string path, int width, int height); void CacheSkinpart(string path, int width, int height);
cImage *GetSkinpart(string name, int width, int height); cImage *GetSkinpart(string name, int width, int height);
//cairo special images //cairo special images
cImage *GetVerticalText(string text, tColor color, string font, int size); cImage *GetVerticalText(string text, tColor color, string font, int size, int direction);
//helpers //helpers
void Clear(void); void Clear(void);
void Debug(bool full); void Debug(bool full);

View File

@ -135,6 +135,8 @@ void cTemplateFunction::SetParameters(vector<pair<string, string> > params) {
p.first = ptCache; p.first = ptCache;
} else if (!name.compare("determinatefont")) { } else if (!name.compare("determinatefont")) {
p.first = ptDeterminateFont; p.first = ptDeterminateFont;
} else if (!name.compare("direction")) {
p.first = ptDirection;
} else { } else {
p.first = ptNone; p.first = ptNone;
} }
@ -276,6 +278,9 @@ bool cTemplateFunction::CalculateParameters(void) {
case ptBackground: case ptBackground:
paramValid = SetBackground(value); paramValid = SetBackground(value);
break; break;
case ptDirection:
paramValid = SetDirection(value);
break;
default: default:
paramValid = true; paramValid = true;
break; break;
@ -420,6 +425,8 @@ int cTemplateFunction::GetNumericParameter(eParamType type) {
return 0; return 0;
else if (type == ptBackground) else if (type == ptBackground)
return 0; return 0;
else if (type == ptDirection)
return diBottomUp;
return -1; return -1;
} }
return hit->second; return hit->second;
@ -475,6 +482,9 @@ int cTemplateFunction::GetWidth(bool cutted) {
else else
funcWidth = fontManager->Width(fontName, GetNumericParameter(ptFontSize), parsedText.c_str()); funcWidth = fontManager->Width(fontName, GetNumericParameter(ptFontSize), parsedText.c_str());
break; } break; }
case ftDrawTextVertical:
funcWidth = GetNumericParameter(ptFontSize)*1.2;
break;
case ftFill: case ftFill:
case ftDrawImage: case ftDrawImage:
case ftDrawRectangle: case ftDrawRectangle:
@ -496,6 +506,9 @@ int cTemplateFunction::GetHeight(void) {
case ftDrawText: case ftDrawText:
funcHeight = fontManager->Height(fontName, GetNumericParameter(ptFontSize)); funcHeight = fontManager->Height(fontName, GetNumericParameter(ptFontSize));
break; break;
case ftDrawTextVertical:
funcHeight = fontManager->Width(fontName, GetNumericParameter(ptFontSize), parsedText.c_str());
break;
case ftFill: case ftFill:
case ftDrawImage: case ftDrawImage:
case ftDrawRectangle: case ftDrawRectangle:
@ -1092,6 +1105,16 @@ bool cTemplateFunction::SetBackground(string value) {
return true; return true;
} }
bool cTemplateFunction::SetDirection(string value) {
int direction = diNone;
if (!value.compare("bottomup"))
direction = diBottomUp;
else if (!value.compare("topdown"))
direction = diTopDown;
numericParameters.insert(pair<eParamType, int>(ptDirection, direction));
return true;
}
void cTemplateFunction::ParseStringParameters(void) { void cTemplateFunction::ParseStringParameters(void) {
//first replace stringtokens in Text (drawText) //first replace stringtokens in Text (drawText)
stringstream text; stringstream text;
@ -1581,7 +1604,10 @@ string cTemplateFunction::GetParamName(eParamType pt) {
break; break;
case ptDeterminateFont: case ptDeterminateFont:
name = "Determinate Font"; name = "Determinate Font";
break; break;
case ptDirection:
name = "Text Direction";
break;
default: default:
name = "Unknown"; name = "Unknown";
break; break;

View File

@ -81,6 +81,7 @@ enum eParamType {
ptHideRoot, ptHideRoot,
ptCache, ptCache,
ptDeterminateFont, ptDeterminateFont,
ptDirection,
ptNone ptNone
}; };
@ -105,6 +106,12 @@ enum eOverflowType {
otCut otCut
}; };
enum eDirection {
diNone,
diBottomUp,
diTopDown
};
class cTemplateFunction { class cTemplateFunction {
protected: protected:
eFuncType type; eFuncType type;
@ -156,6 +163,7 @@ protected:
bool SetHideRoot(string value); bool SetHideRoot(string value);
bool SetDetached(string value); bool SetDetached(string value);
bool SetBackground(string value); bool SetBackground(string value);
bool SetDirection(string value);
void ParseStringParameters(void); void ParseStringParameters(void);
void ParseNumericalParameters(void); void ParseNumericalParameters(void);
void CalculateAlign(int elementWidth, int elementHeight); void CalculateAlign(int elementWidth, int elementHeight);

View File

@ -727,6 +727,7 @@ void cTemplateView::SetFunctionDefinitions(void) {
attributes.insert("height"); attributes.insert("height");
attributes.insert("align"); attributes.insert("align");
attributes.insert("valign"); attributes.insert("valign");
attributes.insert("direction");
attributes.insert("font"); attributes.insert("font");
attributes.insert("fontsize"); attributes.insert("fontsize");
attributes.insert("color"); attributes.insert("color");

View File

@ -513,10 +513,11 @@ void cView::DoDrawText(int num, cTemplateFunction *func, int x0, int y0) {
void cView::DoDrawTextVertical(int num, cTemplateFunction *func, int x0, int y0) { void cView::DoDrawTextVertical(int num, cTemplateFunction *func, int x0, int y0) {
string fontName = func->GetFontName(); string fontName = func->GetFontName();
int fontSize = func->GetNumericParameter(ptFontSize); int fontSize = func->GetNumericParameter(ptFontSize);
int direction = func->GetNumericParameter(ptDirection);
tColor clr = func->GetColorParameter(ptColor); tColor clr = func->GetColorParameter(ptColor);
tColor clrBack = clrTransparent; tColor clrBack = clrTransparent;
string text = func->GetText(false); string text = func->GetText(false);
cImage *textVertical = imgCache->GetVerticalText(text, clr, fontName, fontSize); cImage *textVertical = imgCache->GetVerticalText(text, clr, fontName, fontSize, direction);
if (!textVertical) if (!textVertical)
return; return;
@ -529,7 +530,7 @@ void cView::DoDrawTextVertical(int num, cTemplateFunction *func, int x0, int y0)
x = (containerWidth - textVertical->Width()) / 2; x = (containerWidth - textVertical->Width()) / 2;
} else if (align == alLeft) { } else if (align == alLeft) {
x = 0; x = 0;
} else if (align = alRight) { } else if (align == alRight) {
int containerWidth = func->GetContainerWidth(); int containerWidth = func->GetContainerWidth();
x = (containerWidth - textVertical->Width()); x = (containerWidth - textVertical->Width());
} else { } else {
@ -542,13 +543,12 @@ void cView::DoDrawTextVertical(int num, cTemplateFunction *func, int x0, int y0)
y = (containerHeight - textVertical->Height()) / 2; y = (containerHeight - textVertical->Height()) / 2;
} else if (align == alTop) { } else if (align == alTop) {
y = 0; y = 0;
} else if (align = alBottom) { } else if (align == alBottom) {
int containerHeight = func->GetContainerHeight(); int containerHeight = func->GetContainerHeight();
y = (containerHeight - textVertical->Height()); y = (containerHeight - textVertical->Height());
} else { } else {
y = func->GetNumericParameter(ptY); y = func->GetNumericParameter(ptY);
} }
if (x < 0) x = 0; if (x < 0) x = 0;
x += x0; x += x0;
if (y < 0) y = func->GetContainerHeight() - textVertical->Height() - 5; if (y < 0) y = func->GetContainerHeight() - textVertical->Height() - 5;