Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to print/draw a pound sterling sign (£)

Credits go to Arthur Kalliokoski, Dizzy Egg, and Elias for helping out!
This thread is locked; no one can reply to it. rss feed Print
How to print/draw a pound sterling sign (£)
superbriggs
Member #14,521
August 2012

I am using allegro to print text onto the screen, which I have had no problems with. But I am unable to print a `£' sign. When try to print a string with a `£' sign in it, then nothing happens, as if I never called al_draw_text.

I have tried a number of fonts, as I wondered if it was just that the font I used didn't have the symbol. None of them worked, so I figured it must be something else.

Could anyone help me?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I see DejaVuSans.ttf (distributed with A5) has a pound sign, maybe you forgot something else, such as al_init_ttf_addon()?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Dizzy Egg
Member #10,824
March 2009
avatar

I noticed this too, last night. Using Allegro 5.07, Code::Blocks & Mingw. I tried with Arial.ttf but couldn't get it working, so decided to leave it for now.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Arthur Kalliokoski
Second in Command
February 2005
avatar

Strange, this prog stops printing the entire string when it gets to the pound sign.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_ttf.h> 3 4ALLEGRO_FONT *DejaVuSans28font; 5 6 7int main(void) 8{ 9 ALLEGRO_DISPLAY *display; 10 11 if (!al_init()) 12 { 13 fprintf(stderr,"Could not init Allegro.\n"); 14 return 1; 15 } 16 17 al_init_font_addon(); 18 al_init_ttf_addon(); 19 20 display = al_create_display(640, 480); 21 if (!display) 22 { 23 fprintf(stderr,"Could not create display.\n"); 24 return 1; 25 } 26 27 DejaVuSans28font = al_load_font("DejaVuSans.ttf",-28,0); 28 if(!DejaVuSans28font) 29 { 30 fprintf(stderr,"Couldn't load font\n"); 31 return 1; 32 } 33 al_draw_text(DejaVuSans28font, al_map_rgb(255,255,255), 0.0,0.0,0,"pound sign -> £ <- pound sign"); 34 al_flip_display(); 35 al_rest(10.0); 36 return 0; 37}

pepsi@fractal:/home/prog/gui 05:24 AM $ tail r.c
        {
                fprintf(stderr,"Couldn't load font\n");
                return 1;
        }

        al_draw_text(DejaVuSans28font, al_map_rgb(255,255,255), 0.0,0.0,0,"pound sign -> £ <- pound sign");
        al_flip_display();
        al_rest(10.0);
        return 0;
}

[EDIT]
I can get it to appear in ex_ttf.c
{"name":"606501","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/e\/9ece7ec2cbdf15047945ca18d7c0133e.png","w":652,"h":508,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/e\/9ece7ec2cbdf15047945ca18d7c0133e"}606501
but I can't see what's different about the ttf code.

[EDIT 2]

When I look at ex_ttf.c with the joe editor, it shows uppercase 'A's among the weird characters, but the test code doesn't show that. The kwrite editor I normally use now won't even move the cursor when I open the test code, it's like it's locked up.

[EDIT 3]

I finally got it to work by using a hex editor on the source file :P

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_ttf.h> 3#include <allegro5/allegro_primitives.h> 4 5ALLEGRO_FONT *DejaVuSans28font; 6ALLEGRO_USTR_INFO info; 7ALLEGRO_USTR *us; 8 9int main(void) 10{ 11 ALLEGRO_DISPLAY *display; 12 13 if (!al_init()) 14 { 15 fprintf(stderr,"Could not init Allegro.\n"); 16 return 1; 17 } 18 19 al_init_primitives_addon(); 20 al_init_font_addon(); 21 al_init_ttf_addon(); 22 23 display = al_create_display(640, 480); 24 if (!display) 25 { 26 fprintf(stderr,"Could not create display.\n"); 27 return 1; 28 } 29 30 al_clear_to_color(al_map_rgb(255,255,255)); 31 32 DejaVuSans28font = al_load_font("DejaVuSans.ttf",-28,0); 33 if(!DejaVuSans28font) 34 { 35 fprintf(stderr,"Couldn't load font\n"); 36 return 1; 37 } 38 //us = al_ref_cstr((ALLEGRO_USTR_INFO *)&info, (char *) "pound sign -> vxy²■µ÷ <- pound sign"); 39 //al_draw_ustr(DejaVuSans28font, al_map_rgb(255,255,255), 0.0,0.0,0,us); 40 al_draw_textf(DejaVuSans28font, al_map_rgb(0,0,0), 50, 300, 0, "%s", "texty├¢├¥├ª├Â┬ú"); 41 al_flip_display(); 42 al_rest(3.0); 43 return 0; 44}

{"name":"606502","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/1\/21388d0651c192891e5a3962535870f3.png","w":246,"h":84,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/1\/21388d0651c192891e5a3962535870f3"}606502

[EDIT 5]
And now when I copy the code off this post, and save it and compile, it doesn't work. Fuck it, I'm going back to ASCII!

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Elias
Member #358
May 2000

It's simple. Your files have to be in UTF8 encoding.

--
"Either help out or stop whining" - Evert

superbriggs
Member #14,521
August 2012

Thanks guys.

For anyone else who comes across this post and is using Microsoft Visual Studios, you can change the file encoding by opening the file, and going to File > Advanced Save Options. Then under Encoding, select a UTF-8 encoding. The only one I could find was "Unicode (UTF-8 without signature - Codepage 65001".

Arthur Kalliokoski
Second in Command
February 2005
avatar

Elias said:

Your files have to be in UTF8 encoding.

Been there, done that, that's what was making kwrite lock up. Kate wasn't any better really. And I can't (or rather don't know how) to create symbols such as the sterling pound sign directly from the keyboard, and I don't know how far I can trust the clipboard either.

[EDIT]

pepsi@fractal:/home/prog/ttf_crap 06:57 AM $ file *.c
common.c: ASCII C program text
ex8.c:    UTF-8 Unicode English text
ex_ttf.c: UTF-8 Unicode C program text
r.c:      ISO-8859 C program text
r3.c:     empty
r4.c:     UTF-8 Unicode C program text

Both r.c and ex_ttf.c show the pound sign correctly as they are right now.

But the source is weird, this is an altered line in ex_ttf.c viewed in gvim.
{"name":"606503","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/49800a3a20abdea26687c504ae04bb78.png","w":752,"h":31,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/9\/49800a3a20abdea26687c504ae04bb78"}606503

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Elias
Member #358
May 2000

KWrite and Kate most likely will use UTF8 by default already, so no need to change anything.

--
"Either help out or stop whining" - Evert

Arthur Kalliokoski
Second in Command
February 2005
avatar

Look at that image I pasted into my previous post.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Elias
Member #358
May 2000

Well, geany, gedit and vim are all UTF8 by default here. So I was quite sure all Linux editors are.

--
"Either help out or stop whining" - Evert

Arthur Kalliokoski
Second in Command
February 2005
avatar

Well I can't get it to work, OTOH, I'm an obnoxious American who has no need for UTF-8. :P

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Elias
Member #358
May 2000

I just downloaded Kate here, I think it's encoding is broken - once a file is not UTF8 it will never convert it back for me. If you use any one of the editors I mentioned (and convert the file to UTF8) does it work for you?

--
"Either help out or stop whining" - Evert

Arthur Kalliokoski
Second in Command
February 2005
avatar

Elias said:

If you use any other editor (and convert the file to UTF8) does it work for you?

Not for me. I selected "Settings"|"Configure Editor"| "Open/Save"|"Encoding" to UTF-8 in both Kate and Kwrite and it still doesn't work. I'm working on an input box for an A5 gui, and might post an example in a week to see if accented characters are accepted. Maybe it's something to do with xfce displaying characters incorrectly? Shooting blind, as it were.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Thomas Fjellstrom
Member #476
June 2000
avatar

I've had kate convert just fine for me. Just recently too with some stuff at work. Someone decided to use special unicode quote/apostrophe marks rather than normal ones.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Elias
Member #358
May 2000

I tried doing it with Tools->Encoding, which doesn't seem to work.

--
"Either help out or stop whining" - Evert

Thomas Fjellstrom
Member #476
June 2000
avatar

Works fine for me. What version of kate do you have?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

I re-opened the altered ex_ttf.c with kwrite, and the line was "yýþæö£" (copy paste directly), when I clicked Tools->Encoding->Unicode->UTF-8 and selected UTF-8 it shows "yýþæö£".

[EDIT]

Kate version 3.5.5, Kwrite version Version 4.5.5

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Thomas Fjellstrom
Member #476
June 2000
avatar

Ouch. Those are bout a year old, maybe closer to two years old. I'm on 3.8.4. Each minor (3.x) is generally released with each minor (4.x) KDE release, which happens every 6 months, and 4.9 is almost out.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

I just got the ex_ttf.c program to display two consecutive pound signs by using the character mapper to find out the code in octal.

al_draw_textf(ex.f3, green, 50, 300, 0, "%s", "yýþæö£\302\243");

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Go to: