Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > PocketBook > PocketBook Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 10-13-2021, 12:56 PM   #1
GerReader
Enthusiast
GerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileReadGerReader has read every ebook posted at MobileRead
 
Posts: 44
Karma: 65762
Join Date: Oct 2020
Location: Germany, Rhein-Main
Device: PocketBook Touch HD 3
Strange vertical offset between normal and bold font

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?

Attached Thumbnails
Click image for larger version

Name:	font_offset.png
Views:	54
Size:	20.5 KB
ID:	189605  
GerReader is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two strange vertical lines appearing in koreader Pajamaman KOReader 2 04-11-2020 11:31 PM
How to converse bold font into normal font output in calibre? Percivale Kobo Reader 3 11-09-2015 09:21 PM
Re Entering Title in Bold or Bold And Colour Font pricespringer Library Management 1 05-09-2011 04:45 AM
italic, bold etc to normal cybmole Sigil 11 03-04-2011 10:37 AM
How can I change body text from bold to normal? Michaelus Calibre 11 09-18-2010 09:21 PM


All times are GMT -4. The time now is 11:21 PM.


MobileRead.com is a privately owned, operated and funded community.