Ejemplo n.º 1
0
int ofxTextObject::wrapTextX(float lineWidth)	 
{  
	columnWidth = lineWidth; //soso
    
    if (words.size() > 0) {
        
        float   runningWidth = 0.0f;
        
        lines.clear();
        
        bool        newLine = true;
        lineBlock   tmpLine;
        tmpLine.wordsID.clear();
        int         activeLine = 0;
        
        for(int i=0;i < words.size(); i++)
        {
            runningWidth += (words[i].width);	
            
            
            //soso - check for new line word			
			if (words[i].isNewLine)
			{
				//printf("New Line \n");
				newLine = true;
                lines.push_back(tmpLine);
                tmpLine.wordsID.clear();
                //runningWidth = 0.0f + words[i].width;
                runningWidth = 0.0f + scaleFactor*words[i].width;   //Account for scaleFactor.
                activeLine++;
			}
			//else if (runningWidth <= (lineWidth)) {	
            else if ((scaleFactor*runningWidth) <= lineWidth) {	  //Account for scaleFactor here when wrapping lines.
                newLine = false;
            }
            else {
				//printf("Wrap New Line \n");
                newLine = true;
                lines.push_back(tmpLine);
                tmpLine.wordsID.clear();
                runningWidth = 0.0f + words[i].width;	
                activeLine++;
            }
            
            tmpLine.wordsID.push_back(i);
        }
        
        //Push in the final line.
        lines.push_back(tmpLine);
        _trimLineSpaces(); //Trim the leading and trailing spaces.
    }
    
	updatePositions(lineWidth);	//All other wrap calls eventually boil down to this wrap method, so we only have to call this once here.
    
    renderDirty = true;
    
    return lines.size();
    
}
Ejemplo n.º 2
0
int ofxTextBlock::wrapTextX(float lineWidth){

    scale = 1.0f;

    if (words.size() > 0) {

        float   runningWidth = 0.0f;

        lines.clear();

        bool        newLine = true;
        lineBlock   tmpLine;
        tmpLine.wordsID.clear();
        int         activeLine = 0;

        for(int i=0;i < words.size(); i++)
        {

            runningWidth += words[i].width;

            if (runningWidth <= lineWidth) {
                newLine = false;
            }
            else {

                newLine = true;
                lines.push_back(tmpLine);
                tmpLine.wordsID.clear();
                runningWidth = 0.0f + words[i].width;;
                activeLine++;
            }

            tmpLine.wordsID.push_back(i);
        }

        //Push in the final line.
        lines.push_back(tmpLine);
        _trimLineSpaces(); //Trim the leading and trailing spaces.

    }

    return lines.size();

}
Ejemplo n.º 3
0
int TextBlock::_wrapTextX(float lineWidth){

    if (words.size() > 0) {
        
        lines.clear();
        float       runningWidth = 0.0f;
        bool        newLine = true;
        lineBlock   tmpLine;
        tmpLine.wordsID.clear();
        int         activeLine = 0;

        for(int i = 0; i < words.size(); i++){
            
            //  Add words to each line until it fills the total amount of width
            //  available
            //
            runningWidth += words[i].width;

            if ((runningWidth <= lineWidth)){
                newLine = false;
            } else {
                newLine = true;
                lines.push_back(tmpLine);
                tmpLine.wordsID.clear();
                runningWidth = 0.0f + words[i].width;;
                activeLine++;
            }
            
            //  Store in the line the id of the words
            //
            tmpLine.wordsID.push_back(i);
        }

        //Push in the final line.
        lines.push_back(tmpLine);
        _trimLineSpaces(); //Trim the leading and trailing spaces.

    }

    return lines.size();

}