@dicktom wrote:
I’m trying to display chinese characters using ofTrueTypeFont. I am using a font that supports chinese character and the .cpp file is saved as utf but nothing shows when I try to write some chinese unless I load the text from a file?
//-------------------------------------------------------------- void ofApp::setup() { ofTrueTypeFontSettings settings("chinese.msyh.ttf", 24); settings.antialiased = true; settings.dpi = 72; //settings.direction = OF_TTF_LEFT_TO_RIGHT; settings.addRanges(ofAlphabet::Chinese); settings.addRanges(ofAlphabet::Latin); settings.addRange(ofUnicode::CJKUnified); if (!font.load(settings)) cout << "couldn't load font" << endl; auto bufferLines = ofBufferFromFile("intro.txt").getText(); for (int i = 0; i < bufferLines.size(); i++) { str += bufferLines[i]; } } //-------------------------------------------------------------- void ofApp::draw() { ofBackground(0, 255, 0); string t = "你好"; ofSetColor(255, 255, 255); font.drawString(t, 20, 50); ofSetColor(255, 0, 255); font.drawString(str, 20, 70); }
Posts: 1
Participants: 1