Register Guidelines E-Books Today's Posts Search

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
Connoisseur
GerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of itGerReader has read War And Peace ... all of it
 
Posts: 50
Karma: 66200
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:	325
Size:	20.5 KB
ID:	189605  
GerReader is offline   Reply With Quote
Old 10-21-2021, 06:37 AM   #2
Skeeve
Zealot
Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.
 
Skeeve's Avatar
 
Posts: 142
Karma: 669192
Join Date: Nov 2013
Device: Kindle 4.1.1 no touch
I would assume it's the font's fault.

Did you try other fonts?
Skeeve is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I change body text from bold to normal? Michaelus Calibre 13 07-28-2022 04:42 PM
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


All times are GMT -4. The time now is 01:16 PM.


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