Displaying japanese characters in homebrews

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
plebihan
Posts: 10
Joined: Sun Jul 16, 2006 11:29 pm

Displaying japanese characters in homebrews

Post by plebihan »

Hi all,

does exist a way to display japanese language in homebrew ? i would like to make a japanese version of my homebrew...

thanx for your help

Pacopad
CpuWhiz
Posts: 42
Joined: Mon Jun 04, 2007 1:30 am

Post by CpuWhiz »

For inputing you could just use the built-in input dialog. If you are interested I figured out which "unknown" option you need to set to 1 to get the input method working (so you can type kanji).

As for displaying Japanese text, you could always use a character map texture for hiragana and/or katakana like you would for normal ASCII. If you want anything more complex I would say you have to use freetype (method I used) or SDL_ttf with a Japanese ttf font. I was able to pass it each Japanese character in UTF-16/UCS2 encoding which ended up the same value as the unicode code point. As a side effect, if you use UTF-16/UCS2 for encoding, you can pass it directly to the built-in input dialog and back again. The last method would be static images for all your text but I doubt that is what you wanted.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

The recent DOOM for 3.xx / Slim shows how use the built-in OSK. The comments even tell you which values to use to get the various languages in the OSK. So just go look in psp-main.c in the source.
BenHur
Posts: 28
Joined: Sat Oct 20, 2007 5:26 pm

Post by BenHur »

Hi plebihan,

I'm just about to finish a little library (called intraFont) which let's you use the PSPs internal fonts:
Image

As you can see it can also render japanese characters (these are random, I do not know what they mean!). Before I finalize it maybe you or somebody else can help me:

How do you program a japanese string in C (using UCS-2)? As an array of unsigned short? What would a typical "Hello World" string in japanese look like?

Thanks, BenHur

Edit: updated screenshot (thanks to CpuWhiz the Japanese text now has a meaning)
Last edited by BenHur on Wed Nov 14, 2007 9:16 am, edited 2 times in total.
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

BenHur wrote:Hi plebihan,

I'm just about to finish a little library (called intraFont) which let's you use the PSPs internal fonts:
Image

As you can see it can also render japanese characters (these are random, I do not know what they mean!). Before I finalize it maybe you or somebody else can help me:

How do you program a japanese string in C (using UCS-2)? As an array of unsigned short? What would a typical "Hello World" string in japanese look like?

Thanks, BenHur
Nice..
But How can we verify the authenticity, my eyes hint at P.S. :(?
[seeing it's a publically available font]
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

nice lib i like it
10011011 00101010 11010111 10001001 10111010
BenHur
Posts: 28
Joined: Sat Oct 20, 2007 5:26 pm

Post by BenHur »

KickinAezz wrote: Nice..
But How can we verify the authenticity, my eyes hint at P.S. :(?
[seeing it's a publically available font]
Sorry, I don't understand (my first language isn't Enlish):
- what authenticity? what's a P.S. ?
- do you mean the PSPs internal font is publically available? I thought some japanese company and Sony own the rights to it.

BenHur
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

BenHur wrote:Hi plebihan,

I'm just about to finish a little library (called intraFont) which let's you use the PSPs internal fonts:
Image


As you can see it can also render japanese characters (these are random, I do not know what they mean!). Before I finalize it maybe you or somebody else can help me:

How do you program a japanese string in C (using UCS-2)? As an array of unsigned short? What would a typical "Hello World" string in japanese look like?

Thanks, BenHur
That looks nice, hope you release it soon :)
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
CpuWhiz
Posts: 42
Joined: Mon Jun 04, 2007 1:30 am

Post by CpuWhiz »

An array of unsigned shorts encoded with UTF-16LE works good. I have been using libxml2 and iconv to parse xml files into a simple binary file with UTF-16LE strings that I load into an array. I load a different file per language. It's working for what I need.

You could use this for "Hello World": &#12371;&#12435;&#12395;&#12385;&#12399;&#19990;&#30028;
For those who don't have Japanese fonts: Image

Here is how it would be encoded in hex (I just used recode and hexdump on the command line):

Code: Select all

3053 3093 306b 3061 306f 4e16 754c 0000
This is what I mean:
Image
When you start typing hiragana/katakana and press triangle, it underlines the word and you get a selection of possible kanji for that word. I noticed this feature when I was entering a character name from the Japanese version of Tales of the World: Radiant Mythology. Anyway, to make a long story short, I used a memory dump of the game, searched for the string displayed in the dialog, and used a little math to figure out how they enabled it:

Code: Select all

osk.unk_00 = 1; // Enable IME
If you want my modified dialog sample: http://www.revworld.org/~cpuwhiz/psp/oskdialog.tar.gz
BenHur
Posts: 28
Joined: Sat Oct 20, 2007 5:26 pm

Post by BenHur »

Raphael wrote:That looks nice, hope you release it soon :)
Here it is: intraFont - version 0.1
http://rapidshare.com/files/69530117/in ... 1.zip.html

It's still in an early stage (not everything implemented and probably a few bugs), but it works. The archive contains samples for GU and graphics.h - just look at them to see how to use intraFont and read the readme.

(If you used pgeFont by InsertWittyName (http://insomniac.0x89.org) before: you'll feel right at home since intraFont uses parts of pgeFont - but intraFont doesn't need the freetype library!)

Have fun and let me know your comments,
BenHur


@CpuWhiz: Thank you for your nice explanation. It's exciting to write something in a language I have no clue whatsoever! :-)
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Many thanks BenHur, great work.

I will probably use it in a next app.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

BenHur wrote:
Raphael wrote:That looks nice, hope you release it soon :)
Here it is: intraFont - version 0.1
http://rapidshare.com/files/69530117/in ... 1.zip.html

It's still in an early stage (not everything implemented and probably a few bugs), but it works. The archive contains samples for GU and graphics.h - just look at them to see how to use intraFont and read the readme.

(If you used pgeFont by InsertWittyName (http://insomniac.0x89.org) before: you'll feel right at home since intraFont uses parts of pgeFont - but intraFont doesn't need the freetype library!)

Have fun and let me know your comments,
BenHur


@CpuWhiz: Thank you for your nice explanation. It's exciting to write something in a language I have no clue whatsoever! :-)
Wow! This REALLY works well! I've already put it in my app and it looks fantastic - night and day difference. One thing, it's not as useful without the text width function, so I went ahead and implemented and tested it for you. :)

Code: Select all

int intraFontMeasureText&#40;intraFont *font, const char *text&#41; &#123;
    if &#40;!text || strlen&#40;text&#41; == 0 || !font&#41; return 0;
    unsigned short* ucs2_text = &#40;unsigned short*&#41;malloc&#40;&#40;strlen&#40;text&#41;+1&#41;*sizeof&#40;unsigned short&#41;&#41;;
    if &#40;!ucs2_text&#41; return 0;
    int i;
    for &#40;i = 0; i < strlen&#40;text&#41;; i++&#41; ucs2_text&#91;i&#93; = text&#91;i&#93;;
    ucs2_text&#91;i&#93; = 0;
    i = intraFontMeasureTextUCS2&#40;font, ucs2_text&#41;;
    free&#40;ucs2_text&#41;;
    return i;
&#125;

int intraFontMeasureTextUCS2&#40;intraFont *font, const unsigned short *text&#41; &#123;
	if&#40;!font&#41; return 0;

	int i;
	int length = 0;
	int x = 0;

	float glyphscale = font->size;

	while &#40;text&#91;length&#93; > 0&#41; length++;
	if &#40;length == 0&#41; return 0;

	for&#40;i = 0; i < length; i++&#41; &#123;
		unsigned short char_id = intraFontGetID&#40;font,text&#91;i&#93;&#41;;
		if &#40;char_id >= font->n_chars&#41; char_id = 0;

		Glyph *glyph = &&#40;font->glyph&#91;char_id&#93;&#41;;

		if &#40;!&#40;glyph->flags & PGF_CACHED&#41;&#41; &#123;
			intraFontGetBMP&#40;font,char_id,PGF_CHARGLYPH&#41;;
		&#125;

		x += &#40;&#40;font->options & INTRAFONT_FIXEDWIDTH&#41; ? font->advancex*0.5f &#58; glyph->advance&#41; * glyphscale / 4.0;
	&#125;

	return x;
&#125;
You don't HAVE to cache the glyph in this routine, but I figured if you're measuring the width of some text, you're almost certainly getting ready to print it, so go ahead and cache it. :)
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

Benhur,
Awesome work, Sony will be regretting this. [Disregard my prev. post :) ]
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
Post Reply