Commit 062e4174 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Fixed setting font from font string

parent 0e6c4ce7
...@@ -1221,23 +1221,14 @@ int FlowDrawQt::nav_line_erase( ...@@ -1221,23 +1221,14 @@ int FlowDrawQt::nav_line_erase(
#define FONTSTR "Lucida Sans" #define FONTSTR "Lucida Sans"
#define FONT_SCALE 0.7 #define FONT_SCALE 0.7
static char* font_string(flow_eDrawType painter_type, double size) static QFont font(flow_eDrawType painter_type, double size)
{ {
static char str[80]; QFont res(FONTSTR);
switch (painter_type) { res.setPointSizeF(FONT_SCALE * size);
case flow_eDrawType_TextHelveticaBold: if (painter_type == flow_eDrawType_TextHelveticaBold || painter_type == flow_eDrawType_TextHelveticaEraseBold) {
case flow_eDrawType_TextHelveticaEraseBold: res.setWeight(QFont::Bold);
sprintf(str, "%s Bold %f", FONTSTR, FONT_SCALE * size);
break;
default:
sprintf(str, "%s %f", FONTSTR, FONT_SCALE * size);
}
for (char* s = str; *s; s++) {
if (*s == ',') {
*s = '.';
}
} }
return str; return res;
} }
int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text, int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text,
...@@ -1261,7 +1252,7 @@ int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text, ...@@ -1261,7 +1252,7 @@ int FlowDrawQt::text_pango_helper(FlowCtx* ctx, int x, int y, char* text,
str = QString::fromUtf8(text); str = QString::fromUtf8(text);
} }
painter->setFont(fl(font_string(painter_type, size))); painter->setFont(font(painter_type, size));
QRect rect = painter->fontMetrics().boundingRect(str); QRect rect = painter->fontMetrics().boundingRect(str);
int height = rect.height(); int height = rect.height();
...@@ -1743,7 +1734,7 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx* ctx, const char* text, int len, ...@@ -1743,7 +1734,7 @@ int FlowDrawQt::get_text_extent_pango(FlowCtx* ctx, const char* text, int len,
str = QString::fromUtf8(text); str = QString::fromUtf8(text);
} }
painter->setFont(fl(font_string(painter_type, size))); painter->setFont(font(painter_type, size));
QRect boundingRect = painter->fontMetrics().boundingRect(str); QRect boundingRect = painter->fontMetrics().boundingRect(str);
......
...@@ -3116,40 +3116,33 @@ int GlowDrawQt::gradient_fill_polyline(GlowWind* wind, glow_sPointX* points, ...@@ -3116,40 +3116,33 @@ int GlowDrawQt::gradient_fill_polyline(GlowWind* wind, glow_sPointX* points,
#define FONT_SCALE 0.7 #define FONT_SCALE 0.7
#define FONT_DESCENT 0.22 #define FONT_DESCENT 0.22
static char* font_string(int font_idx, int font_type, double size) static QFont font(int font_idx, int font_type, double size)
{ {
static char str[80]; QFont res;
char bold_str[20];
if (font_type == glow_eDrawFont_HelveticaBold) {
strcpy(bold_str, "Bold ");
} else {
strcpy(bold_str, "");
}
switch (font_idx) { switch (font_idx) {
case glow_eFont_Helvetica: case glow_eFont_Helvetica:
sprintf(str, "%s %s%f", "Helvetica", bold_str, FONT_SCALE * size); res = QFont("Helvetica");
break; break;
case glow_eFont_Times: case glow_eFont_Times:
sprintf(str, "%s %s%f", "DejaVu Serif", bold_str, FONT_SCALE * size); res = QFont("DejaVu Serif");
break; break;
case glow_eFont_NewCenturySchoolbook: case glow_eFont_NewCenturySchoolbook:
sprintf( res = QFont("Century Schoolbook L");
str, "%s %s%f", "Century Schoolbook L", bold_str, FONT_SCALE * size);
break; break;
case glow_eFont_Courier: case glow_eFont_Courier:
sprintf(str, "%s %s%f", "Courier 10 pitch", bold_str, FONT_SCALE * size); res = QFont("Courier 10 pitch");
break; break;
default: default:
sprintf(str, "%s %s%f", "Lucida Sans", bold_str, FONT_SCALE * size); res = QFont("Lucida Sans");
break;
} }
for (char* s = str; *s; s++) {
if (*s == ',') { res.setPointSizeF(FONT_SCALE * size);
*s = '.'; if (font_type == glow_eDrawFont_HelveticaBold) {
} res.setWeight(QFont::Bold);
} }
return str; return res;
} }
int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len, int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
...@@ -3190,7 +3183,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len, ...@@ -3190,7 +3183,7 @@ int GlowDrawQt::text_qt(GlowWind* wind, int x, int y, char* text, int len,
painter->rotate(rot); painter->rotate(rot);
} }
painter->setFont(fl(font_string(font_idx, font_type, size))); painter->setFont(font(font_idx, font_type, size));
QRect rect = painter->fontMetrics().boundingRect(str); QRect rect = painter->fontMetrics().boundingRect(str);
int width = rect.width(); int width = rect.width();
...@@ -3252,7 +3245,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len, ...@@ -3252,7 +3245,7 @@ int GlowDrawQt::text_erase_qt(GlowWind* wind, int x, int y, char* text, int len,
str = QString::fromUtf8(text); str = QString::fromUtf8(text);
} }
painter->setFont(fl(font_string(font_idx, font_type, size))); painter->setFont(font(font_idx, font_type, size));
QRect rect = painter->fontMetrics().boundingRect(str); QRect rect = painter->fontMetrics().boundingRect(str);
width = rect.width(); width = rect.width();
...@@ -3309,8 +3302,7 @@ int GlowDrawQt::get_text_extent_qt(const char* text, int len, ...@@ -3309,8 +3302,7 @@ int GlowDrawQt::get_text_extent_qt(const char* text, int len,
} }
QPainter* painter = get_painter(w->buffer, this, painter_type, 0); QPainter* painter = get_painter(w->buffer, this, painter_type, 0);
painter->setFont( painter->setFont(font(font_idx, get_font_type(painter_type), size));
fl(font_string(font_idx, get_font_type(painter_type), size)));
QString str; QString str;
if (((GrowCtx*)ctx)->text_coding != glow_eTextCoding_UTF_8) { if (((GrowCtx*)ctx)->text_coding != glow_eTextCoding_UTF_8) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment