Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include "WordFont.h"
- WordFont::WordFont() : myVec(70, vector<char>(70, 0))
- {
- nextLetterLocation = 0;
- }
- void WordFont::SetWord()
- {
- word = "abcdefg";
- if (IsValidWord(word))
- {
- PrintWord(ToLowerCase(word));
- }
- else
- std::cout << "not valid";
- //AddLetterU(0, '*', 8, true);
- //PrintWord();
- }
- // DONE
- void WordFont::AddLetterA(int sCol, char character, int fontSize, bool isBold)
- {
- int eCol = sCol + fontSize - 1;
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if (((row == 0 && col != sCol && col != eCol) || row == 1) || // Top
- ((col == sCol && row != 0) || (col == sCol + 1)) || // Left
- ((col == eCol && row != 0) || (col == eCol - 1)) || // Right
- ((row == mRow || row == mRow + 1))) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0 && col != sCol && col != eCol) || // Top
- (col == sCol && row != 0) || // Left
- (col == eCol && row != 0) || // Right
- (row == mRow)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- // DONE
- void WordFont::AddLetterB(int sCol, char character, int fontSize, bool isBold)
- {
- int eCol = sCol + fontSize - 1;
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if (((row == 0 && col != eCol) || row == 1) || // Top
- ((row == eRow && col != eCol) || row == eRow - 1) || // Bottom
- (col == sCol || col == sCol + 1) || // Left
- ((col == eCol || col == eCol - 1) && (row != 0 && row != mRow && row != eRow)) || // Right
- ((row == mRow || row == mRow + 1) && col != eCol)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0 && col != eCol) || // Top
- (row == eRow && col != eCol) || // Bottom
- (col == sCol) || // Left
- (col == eCol && row != 0 && row != eRow && row != mRow) || // Right
- (row == mRow && col != eCol)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- // DONE
- void WordFont::AddLetterC(int sCol, char character, int fontSize, bool isBold)
- {
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if (((row == 0 && col != sCol) || row == 1) || // Top
- ((row == eRow && col != sCol) || row == eRow - 1) || // Bottom
- ((col == sCol && row != 0 && row != eRow) || col == sCol + 1) // Left
- )
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0 && col != sCol) || // Top
- (row == eRow && col != sCol) || // Bottom
- (col == sCol && row != 0 && row != eRow)) // Left
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- // DONE
- void WordFont::AddLetterD(int sCol, char character, int fontSize, bool isBold)
- {
- int eCol = sCol + fontSize - 1;
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if (((row == 0 && col != eCol) || row == 1) || // Top
- ((row == eRow && col != eCol) || row == eRow - 1) || // Bottom
- (col == sCol || col == sCol + 1) || // Left
- ((col == eCol && row != 0 && row != eRow) || col == eCol - 1)) // Right
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0 && col != eCol) || // Top
- (row == eRow && col != eCol) || // Bottom
- (col == sCol) || // Left
- (col == eCol && row != 0 && row != eRow)) // Right
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- // DONE
- void WordFont::AddLetterE(int sCol, char character, int fontSize, bool isBold)
- {
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if ((row == 0 || row == 1) || // Top
- (row == eRow || row == eRow - 1) || // Bottom
- (col == sCol || col == sCol + 1) || // Left
- (row == mRow || row == mRow + 1)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0) || // Top
- (row == eRow) || // Bottom
- (col == sCol) || // Left
- (row == mRow)) // Right
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- // DONE
- void WordFont::AddLetterF(int sCol, char character, int fontSize, bool isBold)
- {
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if ((row == 0 || row == 1) || // Top
- (col == sCol || col == sCol + 1) || // Left
- (row == mRow || row == mRow + 1)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0) || // Top
- (col == sCol) || // Left
- (row == mRow)) // Right
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- // DONE
- void WordFont::AddLetterG(int sCol, char character, int fontSize, bool isBold)
- {
- int eCol = sCol + fontSize - 1;
- int mCol = ((eCol - sCol) / 2) + sCol;
- for (int row = 0; row < fontSize; row++)
- {
- for (int col = sCol; col < sCol + fontSize; col++)
- {
- if (isBold)
- {
- if (((row == 0 && col != sCol) || row == 1) || // Top
- ((row == eRow && col != sCol && col != eCol) || row == eRow - 1) || // Bottom
- ((col == sCol && row != 0 && row != eRow) || col == sCol + 1) || // Left
- ((col == eCol || col == eCol - 1) && (row == 0 || (row > mRow && row < eRow))) || // Right
- ((row == mRow || row == mRow + 1) && col > mCol)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- else if ((row == 0 && col != sCol) || // Top
- (row == eRow && col != sCol && col != eCol) || // Bottom
- (col == sCol && row != 0 && row != eRow) || // Left
- (col == eCol && (row == 0 || (row > mRow && row < eRow))) || // Right
- (row == mRow && col > mCol)) // Bar
- {
- myVec.at(row).at(col) = character;
- }
- }
- }
- }
- //// DONE
- //void WordFont::AddLetterH(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- //
- // if (isBold)
- // {
- // if ((col == 0 || col == 1) || // Left
- // (col == max || col == max - 1) || // Right
- // (row == max / 2 || row == max / 2 + 1)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // else if ((col == 0) || // Left
- // (col == max) || // Right
- // (row == max / 2)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- //
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterI(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if ((row == 0 || row == 1) || // Top
- // (row == max || row == max - 1) || // Bottom
- // (col == max / 2 || col == max / 2 + 1)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // else if ((row == 0) || // Top
- // (row == max) || // Bottom
- // (col == max / 2)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterL(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if ((col == 0 || col == 1) || // Left
- // (row == max || row == max - 1)) // Bottom
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // else if ((col == 0) || // Left
- // (row == max)) // Bottom
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterO(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if (((row == 0 && col != 0 && col != max) || row == 1) || // Top
- // ((row == max && col != 0 && col != max) || row == max - 1) || // Bottom
- // ((col == 0 && row != 0 && row != max) || col == 1) || // Left
- // ((col == max && row != 0 && row != max) || col == max - 1)) // Right
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // else if ((row == 0 && col != 0 && col != max) || // Top
- // (row == max && col != 0 && col != max) || // Bottom
- // (col == 0 && (row != 0 && row != max)) || // Left
- // (col == max && (row != 0 && row != max))) // Right
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterP(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if (((row == 0 && col != max) || row == 1) || // Top
- // (col == 0 || col == 1) || // Left
- // ((row < max / 2 && row != 0 && col == max) || (row < max / 2 && col == max - 1)) || // Right
- // ((row == max / 2) || (row == max / 2 + 1 && col != max))) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- //
- // }
- // else if ((row == 0 && col != max) || // Top
- // (col == 0) || // Left
- // (row < max / 2 && row != 0 && col == max) || // Right
- // (row == max / 2 && col != max)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterS(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if (((row == 0 && col != 0) || row == 1) || // Top
- // ((row == max && col != max) || row == max - 1) || // Bottom
- // ((col == 0 && row < max / 2 && row != 0) || (col == 1 && row < max / 2)) || // Left
- // ((col == max && row > max / 2 && row != max) || (col == max - 1 && row > max / 2)) || // Right
- // ((row == max / 2 && col != max) || (row == max / 2 + 1 && col != 0))) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- //
- // }
- // else if ((row == 0 && col != 0) || // Top
- // (row == max && col != max) || // Bottom
- // (col == 0 && row < max / 2 && row != 0) || // Left
- // (row == max / 2 && col != 0 && col != max) || // Right
- // (col == max && row > max / 2 && row != max)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterT(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int s = startingLocation;
- // int max = startingLocation + fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if ((row == 0 || row == 1) || // Top
- // (col == ((max - s) / 2) + s || col == ((max - s) / 2 + 1) + s)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // else if ((row == 0) || // Top
- // (col == ((max - s) / 2) + s)) // Bar
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- //
- //// DONE
- //void WordFont::AddLetterU(int startingLocation, char character, int fontSize, bool isBold)
- //{
- // int max = fontSize - 1;
- // for (int row = 0; row < fontSize; row++)
- // {
- // for (int col = startingLocation; col < startingLocation + fontSize; col++)
- // {
- // if (isBold)
- // {
- // if (((col == 0 && row != max) || col == 1) || // Left
- // ((row == max && col != 0 && col != max) || row == max - 1) || // Bottom
- // ((col == max && row != max) || col == max - 1)) // Right
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // else if ((col == 0 & row != max) || // Left
- // (row == max & col != 0 & col != max) || // Bottom
- // (col == max & row != max)) // Right
- // {
- // myVec.at(row).at(col) = character;
- // }
- // }
- // }
- //}
- void WordFont::PrintWord(std::string word)
- {
- int startingLocation = 0;
- char c = '*';
- int fontSize = 8;
- bool isBold = false;
- sRow = 0;
- eRow = fontSize - 1;
- mRow = eRow / 2;
- for (int i = 0; i < word.length(); i++) {
- int sCol = i * (fontSize + 1);
- switch (word[i])
- {
- case 'a':
- AddLetterA(sCol, c, fontSize, isBold);
- break;
- case 'b':
- AddLetterB(sCol, c, fontSize, isBold);
- break;
- case 'c':
- AddLetterC(sCol, c, fontSize, isBold);
- break;
- case 'd':
- AddLetterD(sCol, c, fontSize, isBold);
- break;
- case 'e':
- AddLetterE(sCol, c, fontSize, isBold);
- break;
- case 'f':
- AddLetterF(sCol, c, fontSize, isBold);
- break;
- case 'g':
- AddLetterG(sCol, c, fontSize, isBold);
- break;
- //case 'h':
- // AddLetterH(startingLocation, c, fontSize, isBold);
- // break;
- //case 'i':
- // AddLetterI(startingLocation, c, fontSize, isBold);
- // break;
- //case 'l':
- // AddLetterL(startingLocation, c, fontSize, isBold);
- // break;
- //case 'o':
- // AddLetterO(startingLocation, c, fontSize, isBold);
- // break;
- //case 'p':
- // AddLetterP(startingLocation, c, fontSize, isBold);
- // break;
- //case 's':
- // AddLetterS(startingLocation, c, fontSize, isBold);
- // break;
- //case 't':
- // AddLetterT(startingLocation, c, fontSize, isBold);
- // break;
- //case 'u':
- // AddLetterU(startingLocation, c, fontSize, isBold);
- // break;
- };
- startingLocation += fontSize + 1;
- }
- for (int i = 0; i < 70; i++)
- {
- for (int j = 0; j < 70; j++)
- {
- //std::cout << std::setw(4) << std::right << myVec[i][j];
- std::cout << myVec.at(i).at(j);
- }
- std::cout << std::endl;
- }
- }
- bool WordFont::IsValidWord(std::string word)
- {
- int length = word.length();
- std::string valid = "abcdefghilopstuABCDEFGHILOPSTU";
- if (word.empty() || !(length <= 8))
- {
- return false;
- }
- for (int i = 0; i < word.length(); i++)
- {
- if ((valid.find(word[i]) == std::string::npos))
- {
- return false;
- }
- }
- return true;
- }
- std::string WordFont::ToLowerCase(std::string word)
- {
- for (int i = 0; i < word.length(); i++)
- {
- if (word[i] <= 'Z' && word[i] >= 'A')
- {
- word[i] += 32;
- }
- }
- return word;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement