Confused on how to get Chinese characters from an RTF to load and display in my sketch
in
Programming Questions
•
2 years ago
Hi all,
May have seen some of my questions before regarding displaying text from a file. I've run into a new hump with which I hope someone can help me.
I am trying to pull text from a file which will include Chinese characters. I can't seem to get them to display correctly with .txt so I am trying to load an RTF instead. Tried creating a font using the tool in the compiler, but specifying CJK font lists crashed the compiler.
Next I tried using PhiLho's advice to others to load charsets for the chinese characters in the font mingliu but it still displays the text as ????????
Any thoughts??
May have seen some of my questions before regarding displaying text from a file. I've run into a new hump with which I hope someone can help me.
I am trying to pull text from a file which will include Chinese characters. I can't seem to get them to display correctly with .txt so I am trying to load an RTF instead. Tried creating a font using the tool in the compiler, but specifying CJK font lists crashed the compiler.
Next I tried using PhiLho's advice to others to load charsets for the chinese characters in the font mingliu but it still displays the text as ????????
Any thoughts??
- /*
Beijing Your Story project
Bree Rubin 2011
*/
PFont myFont;
ArrayList texts;
void setup() {
size(800,600);
frameRate(30);
char[] charset = new char[0xFFED - 0x21 + 1];
myFont = createFont("mingliu",28,true,charset);
textFont(myFont);
//set up text array list and file loader
texts = new ArrayList();
String[] lines = loadStrings("sampleText.txt");
println("there are " + lines.length + "texts");
for (int i=0; i < lines.length; i++) {
texts.add( new Text (0,0,0,1,2,3) );
}
}
void draw() {
background(255,200,0);
int oscilli = 20;
String[] lines = loadStrings("sampleText.txt");
for (int i=0; i < lines.length; i++) {
for (int j = texts.size()-1; j >= 0; j--) {
Text text = (Text) texts.get(j);
text.moveTxt();
text.showTxt(lines[i], oscilli);
} //end texts for loop
} //end file load for loop
} //end draw
//text block class
class Text {
float randomizer;
float xPos, yPos, zPos;
float xVel, yVel, zVel;
Text(float xP, float yP, float zP, float xV, float yV, float zV) {
xPos = xP;
yPos = yP;
zPos = zP;
xVel = xV;
yVel = yV;
zVel = zV;
randomizer = random(0,80);
xPos += randomizer;
yPos += randomizer;
xVel = random(-.1,.1);
yVel = random(-.1,.1);
zVel = random(-50,50);
}
void moveTxt() {
xPos += xVel;
yPos += yVel;
zPos += zVel;
if(xPos > width || xPos < 0) {
xVel *= -1;
}
if(yPos > height || yPos < 0) {
yVel *= -1;
}
}
void showTxt(String nanka, int Alpha) {
int alph = Alpha;
float colorSet;
fill(255,0,0);
textSize(Alpha);
nanka = nanka;
text(nanka, xPos, yPos, zPos);
}
}//end class
1