libparallax and special characters

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

libparallax and special characters

Post by PrOfUnD Darkness »

I'm using libparallax to write text to the screen but I get an empty space in place of ?!éà and characters like that. The source text is encoded using utf-8, I wonder if that may be the problem? Ideas?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5661
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: libparallax and special characters

Post by BlueCrab »

There's probably two things contributing to this problem for you.

First of all, your font file that you're using may not have glyphs for the characters you're trying to print. If it doesn't have a glyph for the character you're trying to print, it will substitute a space.
Second, the plx_fcxt_draw() function only supports 8-bit characters and doesn't even try to do any UTF-8 conversions. The font format itself that is in use in that library supports 16-bit character codes (which I presume should be UCS-2/UTF-16), but that isn't really spelled out anywhere in libparallax itself. Even if you did have a string encoded in UCS-2, the plx_fcxt_draw() function wouldn't be able to handle it (since it only supports 8-bit characters). You should be able to draw individual characters by plx_fcxt_draw_ch() instead.

If you can give it UCS-2 input, this function should be able to nicely print a whole string, assuming my earlier assumption is correct that the font natively uses UCS-2 (completely untested, but it looks like it should work):

Code: Select all

void plx_fcxt_draw_wide(plx_fcxt_t * cxt, const uint16 * str) {
	float origx = cxt->pos.x;
	float ly = 0.0f;

	while (*str != 0) {
		if (*str == '\n') {
			/* Handle newlines somewhat */
			cxt->pos.x = origx;
			ly = cxt->size;
			cxt->pos.y += ly;
			str++;
		} else
			plx_fcxt_draw_ch(cxt, *str++);
	}
}
If you test this and do find that it works for you, please let me know and I'll go ahead and add it to libparallax. ;-)
These users thanked the author BlueCrab for the post:
PrOfUnD Darkness
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Re: libparallax and special characters

Post by PrOfUnD Darkness »

I am using Arial, I am pretty positive it has all the glyphs. It seems like your function might work but I am having a hard time dealing with the strings in my code after converting them from utf8 to UCS-2 (or UTF16). It breaks all my str functions. I wonder if I can use SDL instead of libparallax though.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5661
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: libparallax and special characters

Post by BlueCrab »

You could also write a function to convert from UTF-8 to UCS-2 (or adapt that function to do it). The conversion isn't that difficult to do (then you could keep your strings in UTF-8 as normal). In fact, there's already a function in KOS to do it (in ucs.c in addons/libkosfat): int fat_utf8_to_ucs2(uint16_t *out, const uint8_t *in, size_t olen, size_t ilen).

Also, I wouldn't necessarily assume that the font has all the glyphs, depending on where you obtained it from. Just because it was derived from a standard sounding font (like Arial) doesn't mean that whoever made it included more than the basic ASCII glyphs.
These users thanked the author BlueCrab for the post:
Ian Robinson
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Re: libparallax and special characters

Post by PrOfUnD Darkness »

You're right, I will double check my font. But I don't see this function in my local kos source...I just downloaded kos-2.0.0-src.tar.gz again and I don't see it in there, am I getting it from the wrong place maybe? (https://sourceforge.net/projects/cadcdev/)
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5661
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: libparallax and special characters

Post by BlueCrab »

Ah, yeah, it's not in 2.0.0... I'm so used to most people using the current source in the Git repository. Here's the file with the function in question in the current git version: https://sourceforge.net/p/cadcdev/kalli ... sfat/ucs.c

Most txf fonts that I've ever seen out on the Internet only include the basic ASCII characters, so I suspect that's going to be a problem still.
These users thanked the author BlueCrab for the post:
Ian Robinson
PrOfUnD Darkness
DCEmu Freak
DCEmu Freak
Posts: 71
Joined: Thu Feb 20, 2003 11:46 am
Has thanked: 1 time
Been thanked: 0
Contact:

Re: libparallax and special characters

Post by PrOfUnD Darkness »

I can confirm it works using the plx_fcxt_draw_wide and fat_utf8_to_ucs2 from ucs.c! Thank you so much!
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5661
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: libparallax and special characters

Post by BlueCrab »

PrOfUnD Darkness wrote: Thu Aug 13, 2020 1:33 am I can confirm it works using the plx_fcxt_draw_wide and fat_utf8_to_ucs2 from ucs.c! Thank you so much!
Thanks for letting me know. I'll add it to libparallax. :)
mrneo240
DCEmu Freak
DCEmu Freak
Posts: 86
Joined: Wed Mar 14, 2018 12:22 am
Has thanked: 16 times
Been thanked: 19 times

Re: libparallax and special characters

Post by mrneo240 »

I didn't post it anywhere but discord but I made a port recently of the psp library intrafont. It has pretty slick text output.
Post Reply