Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Odd text artifacts  (Read 2576 times)

0 Members and 1 Guest are viewing this topic.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Odd text artifacts
« on: June 21, 2012, 05:32:47 am »
I'm not sure whether this is something I'm doing wrong or a bug in the library, but I'm getting boxes around some of the letters when I render text. Example:



I'm not entirely sure what code to post, since I have no idea why this is happening. I created a small program that just draws text to the screen and then waits to be closed, but wasn't able to reproduce this.

If it's relevant, I'm on a Mac using clang and libc++, for which I had to compile SFML myself. I haven't checked yet whether this occurs on Windows as well (that would require a reboot and rewriting a few functions, so it's unlikely I'll check soon).

Here's the function I'm using to draw text (the "Left" in the name refers to alignment), and its subroutines:
Code: [Select]
FloatRect drawTextLeft(short left, short top, string str, int size, Color clr, int style) {
Text text = makeText(str, size, clr, style);
FloatRect bounds = text.getLocalBounds();
drawText(left, top, text);
adjustForWhitespace(str, &bounds.left, &bounds.width, text.getFont(), size, style);
return bounds;
}

void adjustForWhitespace(string str, float* left, float* width, const Font& font, int size, int style) {
// Hack to force the text drawing functions to account for whitespace
// Only accounts for actual space, unfortunately; tabs not handled
int space = ({
Text withSpace("| |", font, size);
Text withoutSpace("||", font, size);
withSpace.setStyle(style);
withoutSpace.setStyle(style);
withSpace.getLocalBounds().width - withoutSpace.getLocalBounds().width;
});
size_t pre = str.find_first_not_of(' ');
if(pre == string::npos) pre = 0;
size_t post = str.size() - str.find_last_not_of(' ') - 1;
if(left) *left -= pre * space;
if(width) *width += (pre + post) * space;
}

Text makeText(string str, int size, Color clr, int style) {
Text text(str);
text.setCharacterSize(size);
text.setColor(clr);
text.setStyle(style);
return text;
}

void drawText(int left, int top, Text& text) {
text.setPosition(left, top);
app.draw(text);
}

When I commented out the call to adjustForWhitespace, there were less artifacts, but there were still some — less boxes, and sometimes just fragments of boxes. Also, I notice that it tends to happen to certain letters. Maybe that's a hint towards the cause of this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Odd text artifacts
« Reply #1 on: June 21, 2012, 07:22:55 am »
This is a known bug.
Laurent Gomila - SFML developer

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Odd text artifacts
« Reply #2 on: June 21, 2012, 09:19:49 am »
Well, that's good to hear, in a way; at least I know it's not me. :P I didn't find it on the issue tracker when searching for "text" though.

Is there any workaround?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Odd text artifacts
« Reply #3 on: June 21, 2012, 09:37:54 am »
It's not in the tracker yet, and there's no workaround :(
Laurent Gomila - SFML developer

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Odd text artifacts
« Reply #4 on: June 22, 2012, 07:40:37 pm »
To get past the other font issue I was having (the bold font made exclamation marks and lowercase i's merge into their dots), I wrote a class that loads a different font file based on whether the requested style is bold or italics, and now I'm no longer seeing these artifacts either. I'm not sure if that's just a fluke and they'll return later, but... this issue may be just with the default font?

 

anything