//PEND not updated to new system yet void ofxTextObject::wrapTextArea(float rWidth, float rHeight) { float tmpScale = 0.0f; float maxIterations = _getLinedWords(); float scales[1000]; //scale = 1.0f; //Reset the scale for the height and width calculations. //soso columnWidth = rWidth; //soso if (words.size() > 0) { //Check each possible line layout and check it will fit vertically for (int iteration=1; iteration <= maxIterations; iteration++){ //printf("Iteration %i...\n", iteration); wrapTextForceLines(iteration); tmpScale = rWidth / getWidth(); if ((tmpScale * getHeight()) < rHeight) { scales[iteration] = tmpScale; } else { scales[iteration] = -1; } } //Now see which is biggest int maxIndex = 1; bool bScaleAvailable = false; for (int i=1; i <= maxIterations; i++) { ofLog(OF_LOG_VERBOSE,"Scales %i = %f\n", i, scales[maxIndex]); if (scales[i] != -1) bScaleAvailable = true; if (scales[i] > scales[maxIndex]) { maxIndex = i; } } /* //soso //When only one line is needed an appropriate on the Y scale can sometimes not be found. In these occasions scale the size to the Y dimension if (bScaleAvailable) { scale = scales[maxIndex]; } else { scale = (float)rHeight / (float)getHeight(); } */ //float persistScale = scale; //Need to persist the scale as the wrapTextForceLines will overwrite. //soso wrapTextForceLines(maxIndex); //scale = persistScale; //soso //ofLog(OF_LOG_VERBOSE,"Scaling with %i at scale %f...\n", maxIndex, scale); //soso } renderDirty = true; }
void ofxBlackText::loadTextFrom(const string& path){ ifstream fs( ofToDataPath(path).c_str()); if (fs.is_open()){ // agregar font != NULL string palabra; vector <string> palabras; palabras.clear(); // Load the data to a temporal vector call ´file´ while(!(fs >> palabra).fail()) palabras.push_back(palabra); fs.close(); wordBlock tmpWord; for (int i = 0; i < palabras.size(); i++){ tmpWord.rawWord = palabras[i]; tmpWord.width = defaultFont->stringWidth(tmpWord.rawWord); tmpWord.height = defaultFont->stringHeight(tmpWord.rawWord); tmpWord.color.r = tmpWord.color.g = tmpWord.color.b = 255; words.push_back(tmpWord); //add spaces into the words vector if it is not the last word. if (i != palabras.size()) words.push_back(blankSpaceWord); } for(int i=0;i < words.size(); i++) ofLog(OF_LOG_VERBOSE, "Loaded word: %i, %s\n", i, words[i].rawWord.c_str()); wrapTextForceLines(1); wrapTextX(width); // Setea el largo height = getTextHeight(); }
void ofxTextBlock::setText(string _inputText){ rawText = _inputText; _loadWords(); wrapTextForceLines(1); }