I'm currently continuing developing my puzzle collection, and I ran into a strange problem.
The example below is a 2x2 grid of the 'solo' (sudoku clone) puzzle.
I want to draw the given fixed clue numbers in bold, and the user filled numbers in normal font.
Worked so far, but the different fonts are drawn with a strange and annoying vertical offset to each other. See the attachment, where I draw red lines to illustrate the problem. Horizontally both are aligned correctly.
I handle bold and normal fonts in completely the same way for drawing, only difference is I load "LiberationSans" or "LiberationSans-Bold".
The characters themselves are drawn all in the same height, both Bold and Normal.
This is the text drawing function:
Code:
void ink_draw_text(void *handle, int x, int y, int fonttype, int fontsize,
int align, int colour, const char *text) {
ifont *tempfont;
int sw, sh, flags;
bool is_bold = (fonttype == FONT_FIXED) || (fonttype == FONT_VARIABLE);
bool is_mono = (fonttype == FONT_FIXED) || (fonttype == FONT_FIXED_NORMAL);
tempfont = OpenFont( is_mono && is_bold ? "LiberationMono-Bold" :
is_bold ? "LiberationSans-Bold" :
is_mono ? "LiberationMono" :
"LiberationSans",
fontsize, 0);
flags = 0x000;
if (align & ALIGN_VNORMAL) flags |= VALIGN_TOP;
if (align & ALIGN_VCENTRE) flags |= VALIGN_MIDDLE;
if (align & ALIGN_HLEFT) flags |= ALIGN_LEFT;
if (align & ALIGN_HCENTRE) flags |= ALIGN_CENTER;
if (align & ALIGN_HRIGHT) flags |= ALIGN_RIGHT;
SetFont(tempfont, convertColor(colour));
sw = StringWidth(text);
sh = TextRectHeight(sw, text, flags);
if (align & ALIGN_VNORMAL) y -= sh;
else if (align & ALIGN_VCENTRE) y -= sh/2;
if (align & ALIGN_HCENTRE) x -= sw/2;
else if (align & ALIGN_HRIGHT) x -= sw;
DrawString(fe->xoffset + x, fe->yoffset + y, text);
CloseFont(tempfont);
}
I also tried to use DrawTextRect, same offset, no difference.
Any clue what I am doing wrong?