LABEL_Text with foreign characters

This forum is for general developer support questions.
Post Reply
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

LABEL_Text with foreign characters

Post by mritter0 »

I am trying to make a LabelClass with Greek letters in the text. How do I manage this?

I am writing the source code file on Windows then transferring it to my X5000. What encoding do I save it in? ANSI can't do it.
If it can be done on my X5000, using English locale, then that would be fine, too. I used Google Translate to copy/paste the text below.

I want it to be able to show on any computer regardless of language. Is that even possible?

The font could be anything, I would prefer to not specify one and use the system font.

I get random letters when I run it.

Code: Select all

	PrefsLanguageLabels[PREFS_LANG_GREEK]=IIntuition->NewObject(LabelClass,NULL,
		IA_Font,							&DejaVuSansMono17,
		LABEL_Text,							"Ελληνικά",
	TAG_DONE);
Workbench Explorer - A better way to browse drawers
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: LABEL_Text with foreign characters

Post by broadblues »

mritter0 wrote:I am trying to make a LabelClass with Greek letters in the text.
Is this a localised text? Or a specific piece of greek text that must always appear in greek what the locale is? If localised then just pass the lacalised text via the usual GetCatalogString() or macro the font etx should already be set up for that locale, if the latter then it would be a bit more complex.
How do I manage this?

I am writing the source code file on Windows then transferring it to my X5000. What encoding do I save it in? ANSI can't do it.
I'm not sure what character set greek uses, hopefully a greek user will be able to tell you exactly, but guessing by looking in locale prefs I'd say it was ISO-8850-7 (clear languges and scroll down to greek, cancel afterwards to avoid messing up your locale).
If it can be done on my X5000, using English locale, then that would be fine, too. I used Google Translate to copy/paste the text below.

I want it to be able to show on any computer regardless of language. Is that even possible?

The font could be anything, I would prefer to not specify one and use the system font.
You will not be able to use the system font if you want it to show on any machine, you will need to open a font and specify iso-8859-7 as the character set to use. Then it should work fine.
I get random letters when I run it.

Code: Select all

	PrefsLanguageLabels[PREFS_LANG_GREEK]=IIntuition->NewObject(LabelClass,NULL,
		IA_Font,							&DejaVuSansMono17,
		LABEL_Text,							"Ελληνικά",
	TAG_DONE);
Assuming that font passed is struct TTextAttr how did you allocate / initiliase it? Did you seperately open the font from disk?
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: LABEL_Text with foreign characters

Post by nbache »

It might be simpler to create the button with an image showing the greek text.

That would display correctly regardless of system fonts, system charset and locale settings.

Then again, the Locale prefs editor manages it, although not with a button, but in a listviewer, so it must be possible somehow.

Best regards,

Niels
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Re: LABEL_Text with foreign characters

Post by mritter0 »

struct TextAttr DejaVuSansMono17={ (STRPTR)"DejaVu Sans Mono.font",17,0,FPF_DISKFONT };

The Preferences->Locale->Country tab is doing what I want. Showing Greece (or Greek in my case) in English and Greek. Russian and Cyprus are doing it, also.

I have never opened a different character set. What does it entail?



I originally tried to use images. They look terrible after you scale them down and make them transparent. The anti-aliasing (?) of the text is not even close the Amiga text.
Workbench Explorer - A better way to browse drawers
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: LABEL_Text with foreign characters

Post by nbache »

mritter0 wrote:I originally tried to use images. They look terrible after you scale them down and make them transparent. The anti-aliasing (?) of the text is not even close the Amiga text.
Yeah - I guess that's not a good solution then.

But whatever else you do, you probably must specify a font yourself, since there is no guarantee that the system font (or any other font selected by the user) contains the glyphs you need to display.

Of course, even if you do that, there's still no guarantee that any font containing the glyphs is available at all on the system, so you will at least need some fallback solution.

Best regards,

Niels
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: LABEL_Text with foreign characters

Post by broadblues »

mritter0 wrote:struct TextAttr DejaVuSansMono17={ (STRPTR)"DejaVu Sans Mono.font",17,0,FPF_DISKFONT };

The Preferences->Locale->Country tab is doing what I want. Showing Greece (or Greek in my case) in English and Greek. Russian and Cyprus are doing it, also.

I have never opened a different character set. What does it entail?
You need to use a struct TTextAttr (double T is not a typo) and set the TA_Charset tag. See autodoc for diskfont.library - OpenDiskFont and look in graphics/text.h for more info.

Note TA_Charset is an IANA charset number not simply it's name, so you need to convert the name "iso-8859-7" to the number using IDiskFont->ObtainCharsetInfo()

If you want to "reopen" the screen font in the new charset so that everything matches visually checkout IDiskFont->ObtainTTextAttr() this will get you a TTextAttr that would have opened the font. Safer to copy this and modofy the copy, since some fields are "off limits". Be careful to check the taglist pointer it may or maynot be NULL.
I originally tried to use images. They look terrible after you scale them down and make them transparent. The anti-aliasing (?) of the text is not even close the Amiga text.
Antialiasing smaller text is a tricky business as simple antialiasing tends to make the image slightly thinner, and that is problematic for small font sizes. You may have noticed amigaos antilaised font glyphs are instead very slighty wider
User avatar
mritter0
Posts: 214
Joined: Mon Aug 25, 2014 9:41 pm
Location: Bettendorf, IA, USA

Re: LABEL_Text with foreign characters

Post by mritter0 »

Javier de las Rivas sent me some source code. I can directly print text correctly into the window's RastPort, but I can not get the LabelClass with IA_Font,tfISO7, to work.

Code: Select all

char testStringISO5[] = "Test ISO-8859-5: ±êÛÓÐàáÚØ",
      testStringISO2[] = "Test ISO-8859-2: èeská",
      testStringISO7[] = "Test ISO-8859-7: ελληνικά";

 struct TextFont *tfSYS = NULL;
 struct TextFont *tfISO7 = NULL;
 struct TTextAttr ttaISO7;
 struct TagItem ti[2];

 IGraphics->GetRPAttrs(MainWindow->RPort,
	 RPTAG_Font,	&tfSYS,
 TAG_DONE);
 if (tfSYS)
 {
 ttaISO7.tta_Name  = tfSYS->tf_Message.mn_Node.ln_Name;
 ttaISO7.tta_YSize = tfSYS->tf_YSize;
 ttaISO7.tta_Style = tfSYS->tf_Style | FSF_TAGGED;
 ttaISO7.tta_Flags = tfSYS->tf_Flags;
 ttaISO7.tta_Tags  = ti;
 ti[0].ti_Tag  = TA_CharSet;
 ti[0].ti_Data = 8; // ISO-8859-7 Greek is 10
 ti[1].ti_Tag  = TAG_DONE;

 if( !(tfISO7 = IDiskfont->OpenDiskFont((struct TextAttr *)&ttaISO7)) )
	{
  IDOS->Printf("could not open font in ISO-8859-7\n");
	return(FALSE);
	}
 }
	else
	{
  IDOS->Printf("could not get system font\n");
		return(FALSE);
	}

 IGraphics->SetAPen(MainWindow->RPort, 1);
 IGraphics->SetFont(MainWindow->RPort, tfISO7);
 IGraphics->Move(MainWindow->RPort, 10, 70);
 IGraphics->Text(MainWindow->RPort, testStringISO5, strlen(testStringISO5));
This example is just for testing, it's not set to Greek. Still can't get Greek to work; the letter codes are not correct. That text is just pasted from Google Translate.
ISO5.png
ISO5.png (1.83 KiB) Viewed 10097 times

Code: Select all

PrefsLanguageLabels[GREEK]=IIntuition->NewObject(LabelClass,NULL,
    IA_Font,    tfISO7,    // &tfISO7 does not work, either     
    LABEL_Text,    "±êÛÓÐàáÚØ",
TAG_DONE);
Label.png
Label.png (1.17 KiB) Viewed 10097 times
Workbench Explorer - A better way to browse drawers
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: LABEL_Text with foreign characters

Post by broadblues »

IA_Font takes (T)TextAttr not a Font so pass &ttaISO7 to it.
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 10:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: LABEL_Text with foreign characters

Post by javierdlr »

mritter0 wrote:Javier de las Rivas sent me some source code. I can directly print text correctly into the window's RastPort, but I can not get the LabelClass with IA_Font,tfISO7, to work.
...

Code: Select all

PrefsLanguageLabels[GREEK]=IIntuition->NewObject(LabelClass,NULL,
    IA_Font,    tfISO7,    // &tfISO7 does not work, either     
    LABEL_Text,    "±êÛÓÐàáÚØ",
TAG_DONE);
...
Yep, broadblues is correct pass & to IA_Font, and I suggest to add "LABEL_Underscore,0" so you don't get unwanted/strange underscored characters too.

Code: Select all

if(KM_cs == 5) // ISO_8859-2 font charset
    {
     imageM[i] = IIntuition->NewObject(LabelClass, NULL, 
                                       IA_Font,&dd->fiso[1].tta, LABEL_Underscore,0,
                                       LABEL_Text,keymapdesc, TAG_END);
Post Reply