コード例 #1
0
//=====================================================================
void ofTrueTypeFont::drawStringAsShapes(string c, float x, float y) {

    if (!bLoadedOk){
    	ofLogError("ofTrueTypeFont") << "drawStringAsShapes(): font not allocated: line " << __LINE__ << " in " << __FILE__;
    	return;
    };

	//----------------------- error checking
	if (!bMakeContours){
		ofLogError("ofTrueTypeFont") << "drawStringAsShapes(): contours not created for this font, call loadFont() with makeContours set to true";
		return;
	}

	if(bFullCharacterSet && encoding==OF_ENCODING_UTF8){
		string o;
		Poco::TextConverter(Poco::UTF8Encoding(),Poco::Latin9Encoding()).convert(c,o);
		c=o;
	}

	GLint		index	= 0;
	GLfloat		X		= x;
	GLfloat		Y		= y;
	int newLineDirection		= 1;

	if(!ofIsVFlipped()){
		// 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)c.length();

	while(index < len){
		int cy = (unsigned char)c[index] - NUM_CHARACTER_TO_START;
		if (cy < nCharacters){ 			// full char set or not?
		  if (c[index] == '\n') {

				Y += lineHeight*newLineDirection;
				X = x ; //reset X Pos back to zero

		  }else if (c[index] == ' ') {
				 int cy = (int)'p' - NUM_CHARACTER_TO_START;
				 X += cps[cy].setWidth * letterSpacing * spaceSize;
				 //glTranslated(cps[cy].width, 0, 0);
		  } else if(cy > -1){
				drawCharAsShape((unsigned char)c[index], X, Y);
				X += cps[cy].setWidth * letterSpacing;
				//glTranslated(cps[cy].setWidth, 0, 0);
		  }
		}
		index++;
	}

}
コード例 #2
0
//=====================================================================
void ofTrueTypeFontWS::drawStringAsShapes(wstring c, float x, float y) {
  
  if (!bLoadedOk){
    ofLog(OF_LOG_ERROR,"Error : font not allocated -- line %d in %s", __LINE__,__FILE__);
    return;
  };
  
	//----------------------- error checking
	if (!bMakeContours){
		ofLog(OF_LOG_ERROR,"Error : contours not created for this font - call loadFont with makeContours set to true");
		return;
	}
  
  int len = (int)c.length();
  // if (less_func(NUM_MAX_CHARACTERS, len + getLoadedCharsNum())) {
  //   ofLog(OF_LOG_ERROR,"Error : too many typefaces already loaded");
  //   return;
  // }
  
	GLint		index	= 0;
	GLfloat		X		= 0;
	GLfloat		Y		= 0;
  
	glPushMatrix();
	glTranslatef(x, y, 0);
  
	while(index < len){
		int cy = getCharID(c[index]);
    if (cps[cy].value == TYPEFACE_UNLOADED){
      loadEachChar(cy);
    }
		if (cy < nCharacters){ 			// full char set or not?
		  if (c[index] == L'\n') {
        
				Y = lineHeight;
				X = 0 ; //reset X Pos back to zero
        
		  }else if (c[index] == L' ') {
        cy = getCharID(L'p');
        X += cps[cy].width;
        //glTranslated(cps[cy].width, 0, 0);
		  } else {
				drawCharAsShape(cy, X, Y);
				X += cps[cy].setWidth;
				//glTranslated(cps[cy].setWidth, 0, 0);
		  }
		}
		index++;
	}
  
	glPopMatrix();
  
}
コード例 #3
0
ファイル: ofxFreeType2.cpp プロジェクト: jellevdster/FALv07
//-----------------------------------------------------------
void ofxFreeType2::drawStringAsShapes(string s, float x, float y) {
	//Make sure the font was loaded and Contours were created
	if (!bFaceLoaded){
    	ofLog(OF_LOG_ERROR,"Error : font not allocated -- line %d in %s", __LINE__,__FILE__);
    	return;
    };
	
	
	if (!bMakeContours){
		ofLog(OF_LOG_ERROR,"Error : contours not created for this font - call loadFont with makeContours set to true");
		return;
	}
	
	GLint		index	= 0;
	GLfloat		xPos	= x;
	GLfloat		yPos	= y;
	
	//Add Line height to draw string from top left and not baseline
	yPos += getMaxCharHeight(s,true);
	
	bool firstChar		= true;
	int stringLen = (int)s.length();
	
	
	for(int i=0; i < stringLen; i++) {
		int c	= (unsigned char)s[i];
		
		//If it is a new line, move Cursor
		if(c == '\n') {
			xPos = x;
			yPos += lineHeight;
			firstChar = true;
		} else {
			c -= START_CHAR;
			//Move to bitmap left pos if not the first char in a line
			//if(!firstChar) xPos += chars[cy].left;
			
			//Draw Char
			glPushMatrix();
			glTranslatef(xPos, yPos, 0);
			ofFill();
			drawCharAsShape(c);
			glPopMatrix();
			
			//Add advance spacing, reset first char
			xPos += chars[c].advance;
			
			firstChar	= false;
		}
	}
}
コード例 #4
0
//-----------------------------------------------------------
void ofTrueTypeFont::drawStringAsShapes(const std::string& str, float x, float y) const{
    if (!bLoadedOk){
    	ofLogError("ofTrueTypeFont") << "drawStringAsShapes(): font not allocated: line " << __LINE__ << " in " << __FILE__;
    	return;
    };

	//----------------------- error checking
	if (!settings.contours){
		ofLogError("ofTrueTypeFont") << "drawStringAsShapes(): contours not created for this font, call loadFont() with makeContours set to true";
		return;
	}

	iterateString(str,x,y,true,[&](uint32_t c, ofVec2f pos){
		drawCharAsShape(c, pos.x, pos.y, ofIsVFlipped(), ofGetStyle().bFill);
	});
}
コード例 #5
0
//=====================================================================
void ofTrueTypeFont::drawStringAsShapes(string c, float x, float y) {

    if (!bLoadedOk){
    	ofLog(OF_LOG_ERROR,"Error : font not allocated -- line %d in %s", __LINE__,__FILE__);
    	return;
    };

	//----------------------- error checking
	if (!bMakeContours){
		ofLog(OF_LOG_ERROR,"Error : contours not created for this font - call loadFont with makeContours set to true");
		return;
	}

	GLint		index	= 0;
	GLfloat		X		= 0;
	GLfloat		Y		= 0;

	glPushMatrix();
	glTranslatef(x, y, 0);
	int len = (int)c.length();

	while(index < len){
		int cy = (unsigned char)c[index] - NUM_CHARACTER_TO_START;
		if (cy < nCharacters){ 			// full char set or not?
		  if (c[index] == '\n') {

				Y = lineHeight;
				X = 0 ; //reset X Pos back to zero

		  }else if (c[index] == ' ') {
				 int cy = (int)'p' - NUM_CHARACTER_TO_START;
				 X += cps[cy].width;
				 //glTranslated(cps[cy].width, 0, 0);
		  } else {
				drawCharAsShape(cy, X, Y);
				X += cps[cy].setWidth;
				//glTranslated(cps[cy].setWidth, 0, 0);
		  }
		}
		index++;
	}

	glPopMatrix();

}