//----------------------------------------------------------- vector<ofTTFCharacter> ofTrueTypeFont::getStringAsPoints(const string & str, bool vflip, bool filled) const{ vector<ofTTFCharacter> shapes; if (!bLoadedOk){ ofLogError("ofxTrueTypeFont") << "getStringAsPoints(): font not allocated: line " << __LINE__ << " in " << __FILE__; return shapes; }; iterateString(str,0,0,vflip,[&](uint32_t c, ofVec2f pos){ shapes.push_back(getCharacterAsPoints(c,vflip,filled)); shapes.back().translate(pos); }); return shapes; }
//----------------------------------------------------------- vector<ofTTFCharacter> ofTrueTypeFont::getStringAsPoints(string str, bool vflip){ if(bFullCharacterSet && encoding==OF_ENCODING_UTF8){ string o; Poco::TextConverter(Poco::UTF8Encoding(),Poco::Latin9Encoding()).convert(str,o); str=o; } vector<ofTTFCharacter> shapes; if (!bLoadedOk){ ofLogError("ofxTrueTypeFont") << "getStringAsPoints(): font not allocated: line " << __LINE__ << " in " << __FILE__; return shapes; }; GLint index = 0; GLfloat X = 0; GLfloat Y = 0; int newLineDirection = 1; if(vflip){ // this would align multiline texts to the last line when vflip is disabled //int lines = ofStringTimesInString(c,"\n"); //Y = lines*lineHeight; newLineDirection = -1; } int len = (int)str.length(); while(index < len){ int cy = (unsigned char)str[index] - NUM_CHARACTER_TO_START; if (cy < nCharacters){ // full char set or not? if (str[index] == '\n') { Y += lineHeight*newLineDirection; X = 0 ; //reset X Pos back to zero }else if (str[index] == ' ') { int cy = (int)'p' - NUM_CHARACTER_TO_START; X += cps[cy].setWidth * letterSpacing * spaceSize; } else if(cy > -1){ shapes.push_back(getCharacterAsPoints((unsigned char)str[index],vflip)); shapes.back().translate(ofPoint(X,Y)); X += cps[cy].setWidth * letterSpacing; } } index++; } return shapes; }
//----------------------------------------------------------- vector<ofTTFCharacter> ofTrueTypeFont::getStringAsPoints(string str){ vector<ofTTFCharacter> shapes; if (!bLoadedOk){ ofLog(OF_LOG_ERROR,"Error : font not allocated -- line %d in %s", __LINE__,__FILE__); return shapes; }; GLint index = 0; GLfloat X = 0; GLfloat Y = 0; int len = (int)str.length(); while(index < len){ int cy = (unsigned char)str[index] - NUM_CHARACTER_TO_START; if (cy < nCharacters){ // full char set or not? if (str[index] == '\n') { Y += lineHeight; X = 0 ; //reset X Pos back to zero }else if (str[index] == ' ') { int cy = (int)'p' - NUM_CHARACTER_TO_START; X += cps[cy].setWidth * letterSpacing * spaceSize; } else { shapes.push_back(getCharacterAsPoints(str[index])); shapes.back().translate(ofPoint(X,Y)); X += cps[cy].setWidth * letterSpacing; } } index++; } return shapes; }