CString CStringUtils::LinesWrap(const CString& longstring, int limit /* = 80 */, bool bCompactPaths /* = true */) { CString retString; if ((longstring.GetLength() < limit) || (limit == 0)) return longstring; // no wrapping needed. // now start breaking the string into lines int linepos = 0; int lineposold = 0; CString temp; while ((linepos = longstring.Find('\n', linepos)) >= 0) { temp = longstring.Mid(lineposold, linepos-lineposold); if ((linepos+1)<longstring.GetLength()) linepos++; else break; lineposold = linepos; if (!retString.IsEmpty()) retString += _T("\n"); retString += WordWrap(temp, limit, bCompactPaths); } temp = longstring.Mid(lineposold); if (!temp.IsEmpty()) retString += _T("\n"); retString += WordWrap(temp, limit, bCompactPaths); retString.Trim(); return retString; }
void OutputToFile(MovieInfo* moviePtr, //IN&OUT - keeps the first item on // the list ofstream &outFile) //OUT - output file variable { outFile << left; outFile << endl << endl; outFile << setw(75) << setfill('*') << '*'; outFile << setfill(' ') << endl; outFile << "Title: "; outFile << setw(51) << CheckTitle(moviePtr->title,50); outFile << endl; outFile << setw(75) << setfill('-') << '-'; outFile << setfill(' ') << endl; outFile << "Year: " << setw(12) << moviePtr->year; outFile << "Rating: " << moviePtr->rating << endl; outFile << setw(75) << setfill('-') << '-'; outFile << setfill(' ') << endl; outFile << setw(18) << "Leading Actor:" << setw(25); outFile << moviePtr->leadActor; outFile << "Genre 1: " << moviePtr->genre << endl; outFile << "Supporting Actor: " << setw(25); outFile << moviePtr->suppActor; outFile << "Genre 2: " << moviePtr->AltGenre << endl; outFile << setw(75) << setfill('-') << '-'; outFile << setfill(' ') << endl; outFile << "PLOT:" << endl; WordWrap(moviePtr->synopsis,75, outFile); outFile << setw(75) << setfill('*') << '*'; outFile << setfill(' ') << endl; outFile << endl << endl; outFile << right; }
void OutputTitle(DvdRec *head, ofstream& oFile) { DvdRec *dvdPtr; // CALC & OUT - pointer for dvdPtr // dvdPtr = NULL; // Initializes dvdPtr to null dvdPtr = head; // Assigns head to dvdPtr // Align left oFile << left; // Outputs * up to the specified width oFile << setfill('*') << setw(75) << '*' << setfill(' ') << endl; // Outputs movie title // IF the title is longer than specified length, will output ... // ELSE, will output the whole title if(dvdPtr->title.length() > 52) { oFile << "Title: " << dvdPtr->title.substr(0, 52) << "..." << endl; } else { oFile << "Title: " << dvdPtr->title << endl; } // Outputs - up to the specified width oFile << setfill('-') << setw(75) << '-' << setfill(' ') << endl; // Outputs year and rating oFile << setw(6) << "Year: " << setw(14) << dvdPtr->year << "Rating: " << dvdPtr->rating << endl; // Outputs - up to the specified width oFile << setfill('-') << setw(75) << '-' << setfill(' ') << endl; // Outputs leading actor and genre1 oFile << setw(20) << "Leading Actor:" << setw(26) << dvdPtr->leadActor << "Genre 1: " << dvdPtr->genre1 << endl; // Outputs supporting actor and genre2 oFile << setw(20) << "Supporting Actor:" << setw(26) << dvdPtr->suppActor << "Genre 2: " << dvdPtr->genre2 << endl; // Outputs - up to the specified width oFile << setfill('-') << setw(75) << '-' << setfill(' ') << endl; // Outputs word-wrapped synopsis oFile << "PLOT:" << endl; WordWrap(head, oFile); oFile << dvdPtr->synopsis << endl; // Outputs * up to the specified width oFile << setfill('*') << setw(75) << '*' << setfill(' ') << endl; oFile << endl; }
bool TextLayouter::LayoutMultipleLineText(List<Share<BaseFontMesh>>& outMeshes, List<TextureAtlasPage*>& outPages, Size2F& outSize, IFont& font, const WStringRef& text, Alignment alignment/*=Alignment::LeftBottom*/, const Size2F& restrictSize/*==Size2F::Zero*/, ILabel* label/*=nullptr*/, bool isStatic/*=false*/) { RETURN_FALSE_IF_EMPTY(text); outSize = restrictSize; List<WHeapString> outLines; List<float> outLineWidths; if (restrictSize.Width != 0) { if (!WordWrapWithWidth(outLines, outLineWidths, outSize.Width, font, text, restrictSize.Width)) { Log::Error("Invalid layout"); return false; } } else { if (!WordWrap(outLines, outLineWidths, outSize.Width, font, text)) { Log::Error("Invalid layout"); return false; } } outSize.Height = static_cast<float>(outLineWidths.Count()*font.LineHeight()); ReserveMesh(outMeshes, text); auto maxOrigin= LayoutMultipleLineMesh(outMeshes,outPages, font, outSize, outLineWidths, outLines, alignment, restrictSize, label); outSize = GetBoundingSize(restrictSize.Width,outSize.Height,maxOrigin, alignment, restrictSize); ShrinkMesh(outMeshes); return true; }
/*********************************************************** *FUNCTION OutputOneTitle *__________________________________________________________ * This function displays the Movie's main actor/actress, * supporting actor/actress, genre, Alternate genre, year, rating, * and synopsis. Using the linked list, for one movie. * _________________________________________________________ * * PRE-CONDITIONS * outputT : output stream * *head : Liked list of structs * * CONSTANTS * TITLE_WIDTH : Title width * CHAR_LENGHT : Max char lenght for the fill * GENRE_WIDTH : With to setw genre * ACTOR_LENGHT: Width of the actor output line * NAME_LENGHT : Width of the leading actor name * *POST-CONDITIONS * *none, only the dvd information * ***********************************************************/ void OutputOneTitle(ostream& outputT, //OUT - output stream DvdInfo *moviePtrM) //OUT & CALC - Liked list of structs { const int TITLE_WIDTH = 16; const int CHAR_LENGHT = 75; const int GENRE_WIDTH = 9; const int ACTOR_LENGHT = 19; const int NAME_LENGHT = 25; if(moviePtrM != NULL) { Fill(outputT, '*', CHAR_LENGHT); outputT << endl; outputT << left; outputT << "Title: " << StringParsing(moviePtrM -> title); outputT << endl; Fill(outputT, '-', CHAR_LENGHT); outputT << endl; outputT << left; //movie year outputT <<"Year: " << setw(TITLE_WIDTH-3) << moviePtrM -> year; outputT << right; outputT << "Rating: " << moviePtrM -> rating; outputT << endl; Fill(outputT, '-', CHAR_LENGHT); outputT << endl; //leading actor outputT << left; outputT << setw(ACTOR_LENGHT) <<"Leading Actor:" << setw(NAME_LENGHT) << moviePtrM -> leadingActor; //genre 1 outputT << right; outputT << setw(GENRE_WIDTH) <<"Genre 1: " << moviePtrM -> genre; //supporting actor outputT << endl; outputT << left; outputT << setw(ACTOR_LENGHT)<<"Supporting Actor:" << setw(NAME_LENGHT) << moviePtrM -> supActor; //genre 2 outputT << right; outputT << setw(GENRE_WIDTH-1) << "Genre 2: " << moviePtrM -> altGenre; outputT << endl; Fill(outputT, '-', CHAR_LENGHT); outputT << endl; //plot outputT <<"Plot: " << endl; WordWrap(outputT, moviePtrM -> synopsis); outputT << endl; Fill(outputT, '*', CHAR_LENGHT); outputT << endl; outputT << endl << endl; //outputT << left; }//end of if }
//calling this will undo any formatting associated with the string and will place characters in //a single row bool CTextureString::ClearFormatting() { //currently this is simple, just apply word wrapping on an infinite length row. This gives //us a single row of spaced text return WordWrap(0xFFFFFFFF); }
std::vector<std::string> WrapFontText(Font* pFont, const char* text, float width) { return WordWrap(text, width, FontWidthFinder(pFont)); }
void SearchLinkedList(MovieInfo *head, Menu item, ofstream &outFile) { MovieInfo *itemPtr; itemPtr = head; string stringKey; int intKey; int counter; counter= 0; cout << left; switch(item) { case TITLESEARCH: cout << "\nWhich title are you looking for? "; getline(cin,stringKey); cout << "\nSearching for movie " << stringKey << endl ; break; case GENRESEARCH: cout << "\nWhat genre are you looking for? "; getline(cin, stringKey); cout << "\nSearching for genre " << stringKey << endl ; break; case ACTORSEARCH: cout << "\nWhat actor are you looking for? "; getline(cin, stringKey); cout << "\nSearching for the actor " << stringKey << endl ; break; case YEARSEARCH: // cout << "\nWhat year are you looking for? "; // cin >> intKey; intKey = IntErrorCheck("\nWhat year are you looking for? ", "**** The number is an invalid entry ****", "**** Please input a number between 1878 and 3000",1878,3000); cout << "\nSearching for the year" << endl; break; case RATINGSEARCH: cout << "\nWhat rating are you looking for? "; cin >> intKey; cout << "\nSearching for the rating" << endl ; break; } // if() // { // outFile << setw(9) << "MOVIE #"; // outFile << setw(50) << "TITLE"; // outFile << setw(6) << "YEAR"; // outFile << setw(8) << "RATING"; // outFile << setw(17) << "GENRE"; // outFile << setw(17) << "ALT GENRE"; // outFile << setw(20) << "LEAD ACTOR"; // outFile << setw(18) << "SUPPORTING ACTOR" << endl; // } while(itemPtr != NULL) { if(stringKey == itemPtr->genre || stringKey == itemPtr->AltGenre || stringKey == itemPtr->leadActor || stringKey == itemPtr->suppActor || intKey == itemPtr->rating || intKey == itemPtr->year) { outFile << setw(9) << counter + 1; outFile << setw(51) <<CheckTitle(itemPtr->title,45); outFile << setw(8) << itemPtr->year; outFile << setw(5) << itemPtr->rating ; outFile << setw(17) << itemPtr->genre; outFile << setw(17) << itemPtr->AltGenre ; outFile << setw(20) << itemPtr->leadActor; outFile << setw(18) << itemPtr->suppActor << endl; counter++; } else if(stringKey == itemPtr->title) { outFile << left << endl << endl; outFile << setw(75) << setfill('*') << '*' << setfill(' ') << endl; outFile <<"Title: "; outFile << setw(51) << CheckTitle(itemPtr->title,50); outFile << endl; outFile << setw(75) << setfill('-') << '-' << setfill(' ') << endl; outFile << "Year: " << setw(12) << itemPtr->year; outFile << "Rating: " << itemPtr->rating << endl; outFile << setw(75) << setfill('-') << '-' << setfill(' ') << endl; outFile << setw(18) << "Leading Actor:"<< setw(25) << itemPtr->leadActor; outFile << "Genre 1: " << itemPtr->genre << endl; outFile << "Supporting Actor: " << setw(25) << itemPtr->suppActor; outFile << "Genre 2: "<< itemPtr->AltGenre << endl; outFile << setw(75) << setfill('-') << '-' << setfill(' ') << endl; outFile << "PLOT:" << endl; WordWrap(itemPtr->synopsis,75, outFile); outFile << setw(75) << setfill('*') << '*' << setfill(' ') << endl; outFile << endl << endl; counter++; } itemPtr = itemPtr->next; } if(counter > 0) { cout << ""; if (item == TITLESEARCH) { cout <<"Found the movie \""<< stringKey << "\""; } else if(item == GENRESEARCH) { cout << "Found "<< counter << " movies for the genre " << stringKey; } else if (item == ACTORSEARCH) { cout << "Found "<< counter << " movies for the actor " << stringKey; } else if (item == YEARSEARCH) { cout << "Found "<< counter << " movies for the year " << intKey; } else if (item == RATINGSEARCH) { cout << "Found "<< counter << " movies for the rating " << intKey; } cout << "!"<< endl << endl; } else { cout << "Sorry, "; if (item == TITLESEARCH) { cout <<"the movie \""<< stringKey << "\" was not found " << endl; } else if(item == GENRESEARCH) { cout << "no movies for the genre, " << stringKey <<" were found" << endl; } else if (item == ACTORSEARCH) { cout << "no movies for the actor" << stringKey << " were found" << endl; } else if (item == YEARSEARCH) { cout << " no movies for the year" << intKey << " were found" << endl; } else if (item == RATINGSEARCH) { cout << "no movies for the year "<< intKey << " were found;" << endl; } } }