We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › PFont text special symbols
Page Index Toggle Pages: 1
PFont text special symbols (Read 561 times)
PFont text special symbols
Dec 14th, 2008, 12:41pm
 
hi i want to write pictures with special symbols almost every font type has after the normal letters end... something like boxes, hearts, arrows,... but i don't know how to print them with text. my first testing-attempt was just to count and int up and converting it into char to se what i get, and after the normal letters and a few symbols some int values don't create a char, and then nothing will be displayed. is there a way to get to display all smybols, which windows lists in the symboltable for the fonts.
please let me know,
ramin
Re: PFont text special symbols
Reply #1 - Dec 14th, 2008, 3:37pm
 
Hi,

Can you mention the font and post your code (or a snippet)?

Regards,

Stephen

PS. I exported a font (Times) with all symbols ticked and this code worked for me. To get the special symbols, I just opened Word and used the insert special symbols menu option.
I then pasted them into the Processing IDE. Sadly, although the Processing IDE was fine with them, it translates to the &#9787 codes you see below on the forum. Not sure if there is a way to post the code to you some other way?


size(800, 600);
smooth();

PFont font = loadFont("TimesNewRomanPSMT-48.vlw");
textFont(font, 48);
textAlign(LEFT);

background(255);
fill(0);

text("Here is some normal text", 80, 60);
// Here there be problems posting to forum
text("Here is some strange text\n\n☺☻☼♀♂♠♣♥♦♪&#
9835;", 80, 240);

Re: PFont text special symbols
Reply #2 - Dec 14th, 2008, 4:28pm
 
Hi,

this messy code shows lots of symbols, you can page through them, though it's buggy and has lots of naughty hardcoding.

Regards,

Stephen

// Code starts
int letterCode = 33;
int page = 1;

void setup()
{
 size(800, 800);
 smooth();
 PFont font = loadFont("TimesNewRomanPSMT-48.vlw");
 textFont(font, 24);
 textAlign(LEFT);  
 noLoop();
}

void draw()
{
 background(255);
 fill(0);
 textSize(24);
 for(int r = 20; r < width - 20; r+=30)  
   for(int c = 20; c < height - 100; c+=30)    
     text(String.valueOf((char)letterCode++), c, r);
 textSize(24);
 fill(255, 0, 0);
 text("Page " + page + " Press a UP/DOWN to see more pages... codes from " + (letterCode - 598) + " to " + letterCode, 0, height-6);
}

void keyPressed()
{
 if(keyCode == UP)
 {
   page++;
   redraw();  
 }
 else if(keyCode == DOWN)
 {
   letterCode -= 1196;
   page--;
     redraw();
 }  
}
Re: PFont text special symbols
Reply #3 - Dec 14th, 2008, 4:32pm
 
Pasting Unicode characters directly in Java code isn't a very good idea (can be messed up by bad editors... or Web pages!).
A safer way is to use Java Unicode Escape Sequences, \u followed by 4 hexa digits corresponding to the Unicode code point.

Here is your selection in this portable form:

text("Here is some strange text\n\n\u263A\u263B\u263C\u2640\u2642\u2660\u2663\u2665\u2666\u266A\u266B", 80, 240);

I recommend BabelMap (Unicode Character Map) to explore Unicode pages and get these codes. There are online equivalences, like http://www.tamasoft.co.jp/en/general-info/unicode.html

Note that not all fonts have all Unicode characters. They would be too big. Fortunately, once you have exported a font with Processing, you can see immediately if it has the characters you need. BabelMap can help for that too.
Re: PFont text special symbols
Reply #4 - Dec 14th, 2008, 4:38pm
 
Hi PhilLo,

Yes, I agree with the pasting, I was only testing it would work at all in the IDE, and it did on my machine. I tried the \u, but then I thought I'd try and show all the characters in the font with the loop in the code above. Thanks for the reply.

Regards,

Stephen
Re: PFont text special symbols
Reply #5 - Dec 14th, 2008, 8:46pm
 
kk!
thanks guys.

i tried it like this
Code:


PFont font;
void setup() {
size(800,800);
String[] fontList = PFont.list();
//println(fontList);
font = createFont("Times New Roman",24);
textFont(font);
background(0);
fill(255);
// text("\u05D0",20,20);

for(int x=0; x < 36; x++)
for(int y=0; y < 40; y++)
text((char) (x+y*36),x*20,y*20);
}



you can see that there start beeing these rectangles for misssing symbols.
so i got the textpart like this
Code:

String letter = "\\"+"u"+Integer.toHexString((int)random(65532));
text(letter,x*20,y*20);


still i dont get no symbols with this, but something like
\u4db5
also there seems to be holes. there are not symbols between 0021 and FFFC (=65532)
Re: PFont text special symbols
Reply #6 - Dec 15th, 2008, 2:23pm
 
Sorry for confusing you. The \uxxxx notation is handled by the compiler, it isn't a dynamic thing, only to hard-code some characters.
Actually, I just tested your code, and it works quite well. I would just guard against negative or null page number...
I guess your issue is that you did a default export of the font: if you check "All characters" check box before exporting, you should see much more characters. But as I said, not all Unicode code points, it depends on the font. Note that I tried to export all chars from Arial Unicode MS, and got an OutOfMemory error (it is a very big font)...
Page Index Toggle Pages: 1