Advertisement
taberif

Untitled

Feb 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include "WordFont.h"
  4.  
  5. WordFont::WordFont() : myVec(70, vector<char>(70, 0))
  6. {
  7. nextLetterLocation = 0;
  8. }
  9.  
  10. void WordFont::SetWord()
  11. {
  12. word = "abcdefg";
  13. if (IsValidWord(word))
  14. {
  15. PrintWord(ToLowerCase(word));
  16. }
  17. else
  18. std::cout << "not valid";
  19. //AddLetterU(0, '*', 8, true);
  20. //PrintWord();
  21. }
  22.  
  23. // DONE
  24. void WordFont::AddLetterA(int sCol, char character, int fontSize, bool isBold)
  25. {
  26. int eCol = sCol + fontSize - 1;
  27.  
  28. for (int row = 0; row < fontSize; row++)
  29. {
  30. for (int col = sCol; col < sCol + fontSize; col++)
  31. {
  32. if (isBold)
  33. {
  34. if (((row == 0 && col != sCol && col != eCol) || row == 1) || // Top
  35. ((col == sCol && row != 0) || (col == sCol + 1)) || // Left
  36. ((col == eCol && row != 0) || (col == eCol - 1)) || // Right
  37. ((row == mRow || row == mRow + 1))) // Bar
  38. {
  39. myVec.at(row).at(col) = character;
  40. }
  41. }
  42. else if ((row == 0 && col != sCol && col != eCol) || // Top
  43. (col == sCol && row != 0) || // Left
  44. (col == eCol && row != 0) || // Right
  45. (row == mRow)) // Bar
  46. {
  47. myVec.at(row).at(col) = character;
  48. }
  49. }
  50. }
  51. }
  52.  
  53. // DONE
  54. void WordFont::AddLetterB(int sCol, char character, int fontSize, bool isBold)
  55. {
  56. int eCol = sCol + fontSize - 1;
  57.  
  58. for (int row = 0; row < fontSize; row++)
  59. {
  60. for (int col = sCol; col < sCol + fontSize; col++)
  61. {
  62. if (isBold)
  63. {
  64. if (((row == 0 && col != eCol) || row == 1) || // Top
  65. ((row == eRow && col != eCol) || row == eRow - 1) || // Bottom
  66. (col == sCol || col == sCol + 1) || // Left
  67. ((col == eCol || col == eCol - 1) && (row != 0 && row != mRow && row != eRow)) || // Right
  68. ((row == mRow || row == mRow + 1) && col != eCol)) // Bar
  69. {
  70. myVec.at(row).at(col) = character;
  71. }
  72.  
  73. }
  74. else if ((row == 0 && col != eCol) || // Top
  75. (row == eRow && col != eCol) || // Bottom
  76. (col == sCol) || // Left
  77. (col == eCol && row != 0 && row != eRow && row != mRow) || // Right
  78. (row == mRow && col != eCol)) // Bar
  79. {
  80. myVec.at(row).at(col) = character;
  81. }
  82. }
  83. }
  84.  
  85.  
  86. }
  87.  
  88. // DONE
  89. void WordFont::AddLetterC(int sCol, char character, int fontSize, bool isBold)
  90. {
  91. for (int row = 0; row < fontSize; row++)
  92. {
  93. for (int col = sCol; col < sCol + fontSize; col++)
  94. {
  95. if (isBold)
  96. {
  97. if (((row == 0 && col != sCol) || row == 1) || // Top
  98. ((row == eRow && col != sCol) || row == eRow - 1) || // Bottom
  99. ((col == sCol && row != 0 && row != eRow) || col == sCol + 1) // Left
  100. )
  101. {
  102. myVec.at(row).at(col) = character;
  103. }
  104.  
  105. }
  106. else if ((row == 0 && col != sCol) || // Top
  107. (row == eRow && col != sCol) || // Bottom
  108. (col == sCol && row != 0 && row != eRow)) // Left
  109. {
  110. myVec.at(row).at(col) = character;
  111. }
  112.  
  113. }
  114. }
  115. }
  116.  
  117. // DONE
  118. void WordFont::AddLetterD(int sCol, char character, int fontSize, bool isBold)
  119. {
  120. int eCol = sCol + fontSize - 1;
  121.  
  122. for (int row = 0; row < fontSize; row++)
  123. {
  124. for (int col = sCol; col < sCol + fontSize; col++)
  125. {
  126. if (isBold)
  127. {
  128. if (((row == 0 && col != eCol) || row == 1) || // Top
  129. ((row == eRow && col != eCol) || row == eRow - 1) || // Bottom
  130. (col == sCol || col == sCol + 1) || // Left
  131. ((col == eCol && row != 0 && row != eRow) || col == eCol - 1)) // Right
  132. {
  133. myVec.at(row).at(col) = character;
  134. }
  135.  
  136. }
  137. else if ((row == 0 && col != eCol) || // Top
  138. (row == eRow && col != eCol) || // Bottom
  139. (col == sCol) || // Left
  140. (col == eCol && row != 0 && row != eRow)) // Right
  141. {
  142. myVec.at(row).at(col) = character;
  143. }
  144. }
  145. }
  146. }
  147.  
  148. // DONE
  149. void WordFont::AddLetterE(int sCol, char character, int fontSize, bool isBold)
  150. {
  151. for (int row = 0; row < fontSize; row++)
  152. {
  153. for (int col = sCol; col < sCol + fontSize; col++)
  154. {
  155. if (isBold)
  156. {
  157. if ((row == 0 || row == 1) || // Top
  158. (row == eRow || row == eRow - 1) || // Bottom
  159. (col == sCol || col == sCol + 1) || // Left
  160. (row == mRow || row == mRow + 1)) // Bar
  161. {
  162. myVec.at(row).at(col) = character;
  163. }
  164.  
  165. }
  166. else if ((row == 0) || // Top
  167. (row == eRow) || // Bottom
  168. (col == sCol) || // Left
  169. (row == mRow)) // Right
  170. {
  171. myVec.at(row).at(col) = character;
  172. }
  173. }
  174. }
  175. }
  176.  
  177. // DONE
  178. void WordFont::AddLetterF(int sCol, char character, int fontSize, bool isBold)
  179. {
  180. for (int row = 0; row < fontSize; row++)
  181. {
  182. for (int col = sCol; col < sCol + fontSize; col++)
  183. {
  184. if (isBold)
  185. {
  186. if ((row == 0 || row == 1) || // Top
  187. (col == sCol || col == sCol + 1) || // Left
  188. (row == mRow || row == mRow + 1)) // Bar
  189. {
  190. myVec.at(row).at(col) = character;
  191. }
  192. }
  193. else if ((row == 0) || // Top
  194. (col == sCol) || // Left
  195. (row == mRow)) // Right
  196. {
  197. myVec.at(row).at(col) = character;
  198. }
  199. }
  200. }
  201. }
  202.  
  203. // DONE
  204. void WordFont::AddLetterG(int sCol, char character, int fontSize, bool isBold)
  205. {
  206. int eCol = sCol + fontSize - 1;
  207. int mCol = ((eCol - sCol) / 2) + sCol;
  208.  
  209. for (int row = 0; row < fontSize; row++)
  210. {
  211. for (int col = sCol; col < sCol + fontSize; col++)
  212. {
  213. if (isBold)
  214. {
  215. if (((row == 0 && col != sCol) || row == 1) || // Top
  216. ((row == eRow && col != sCol && col != eCol) || row == eRow - 1) || // Bottom
  217. ((col == sCol && row != 0 && row != eRow) || col == sCol + 1) || // Left
  218. ((col == eCol || col == eCol - 1) && (row == 0 || (row > mRow && row < eRow))) || // Right
  219. ((row == mRow || row == mRow + 1) && col > mCol)) // Bar
  220. {
  221. myVec.at(row).at(col) = character;
  222. }
  223.  
  224. }
  225. else if ((row == 0 && col != sCol) || // Top
  226. (row == eRow && col != sCol && col != eCol) || // Bottom
  227. (col == sCol && row != 0 && row != eRow) || // Left
  228. (col == eCol && (row == 0 || (row > mRow && row < eRow))) || // Right
  229. (row == mRow && col > mCol)) // Bar
  230. {
  231. myVec.at(row).at(col) = character;
  232. }
  233. }
  234. }
  235. }
  236.  
  237. //// DONE
  238. //void WordFont::AddLetterH(int startingLocation, char character, int fontSize, bool isBold)
  239. //{
  240. // int max = fontSize - 1;
  241. // for (int row = 0; row < fontSize; row++)
  242. // {
  243. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  244. // {
  245. //
  246. // if (isBold)
  247. // {
  248. // if ((col == 0 || col == 1) || // Left
  249. // (col == max || col == max - 1) || // Right
  250. // (row == max / 2 || row == max / 2 + 1)) // Bar
  251. // {
  252. // myVec.at(row).at(col) = character;
  253. // }
  254. // }
  255. // else if ((col == 0) || // Left
  256. // (col == max) || // Right
  257. // (row == max / 2)) // Bar
  258. // {
  259. // myVec.at(row).at(col) = character;
  260. // }
  261. //
  262. // }
  263. // }
  264. //}
  265. //
  266. //// DONE
  267. //void WordFont::AddLetterI(int startingLocation, char character, int fontSize, bool isBold)
  268. //{
  269. // int max = fontSize - 1;
  270. // for (int row = 0; row < fontSize; row++)
  271. // {
  272. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  273. // {
  274. // if (isBold)
  275. // {
  276. // if ((row == 0 || row == 1) || // Top
  277. // (row == max || row == max - 1) || // Bottom
  278. // (col == max / 2 || col == max / 2 + 1)) // Bar
  279. // {
  280. // myVec.at(row).at(col) = character;
  281. // }
  282. // }
  283. // else if ((row == 0) || // Top
  284. // (row == max) || // Bottom
  285. // (col == max / 2)) // Bar
  286. // {
  287. // myVec.at(row).at(col) = character;
  288. // }
  289. // }
  290. // }
  291. //}
  292. //
  293. //// DONE
  294. //void WordFont::AddLetterL(int startingLocation, char character, int fontSize, bool isBold)
  295. //{
  296. // int max = fontSize - 1;
  297. // for (int row = 0; row < fontSize; row++)
  298. // {
  299. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  300. // {
  301. // if (isBold)
  302. // {
  303. // if ((col == 0 || col == 1) || // Left
  304. // (row == max || row == max - 1)) // Bottom
  305. // {
  306. // myVec.at(row).at(col) = character;
  307. // }
  308. // }
  309. // else if ((col == 0) || // Left
  310. // (row == max)) // Bottom
  311. // {
  312. // myVec.at(row).at(col) = character;
  313. // }
  314. // }
  315. // }
  316. //}
  317. //
  318. //// DONE
  319. //void WordFont::AddLetterO(int startingLocation, char character, int fontSize, bool isBold)
  320. //{
  321. // int max = fontSize - 1;
  322. // for (int row = 0; row < fontSize; row++)
  323. // {
  324. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  325. // {
  326. // if (isBold)
  327. // {
  328. // if (((row == 0 && col != 0 && col != max) || row == 1) || // Top
  329. // ((row == max && col != 0 && col != max) || row == max - 1) || // Bottom
  330. // ((col == 0 && row != 0 && row != max) || col == 1) || // Left
  331. // ((col == max && row != 0 && row != max) || col == max - 1)) // Right
  332. // {
  333. // myVec.at(row).at(col) = character;
  334. // }
  335. // }
  336. // else if ((row == 0 && col != 0 && col != max) || // Top
  337. // (row == max && col != 0 && col != max) || // Bottom
  338. // (col == 0 && (row != 0 && row != max)) || // Left
  339. // (col == max && (row != 0 && row != max))) // Right
  340. // {
  341. // myVec.at(row).at(col) = character;
  342. // }
  343. // }
  344. // }
  345. //}
  346. //
  347. //// DONE
  348. //void WordFont::AddLetterP(int startingLocation, char character, int fontSize, bool isBold)
  349. //{
  350. // int max = fontSize - 1;
  351. // for (int row = 0; row < fontSize; row++)
  352. // {
  353. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  354. // {
  355. // if (isBold)
  356. // {
  357. // if (((row == 0 && col != max) || row == 1) || // Top
  358. // (col == 0 || col == 1) || // Left
  359. // ((row < max / 2 && row != 0 && col == max) || (row < max / 2 && col == max - 1)) || // Right
  360. // ((row == max / 2) || (row == max / 2 + 1 && col != max))) // Bar
  361. // {
  362. // myVec.at(row).at(col) = character;
  363. // }
  364. //
  365. // }
  366. // else if ((row == 0 && col != max) || // Top
  367. // (col == 0) || // Left
  368. // (row < max / 2 && row != 0 && col == max) || // Right
  369. // (row == max / 2 && col != max)) // Bar
  370. // {
  371. // myVec.at(row).at(col) = character;
  372. // }
  373. // }
  374. // }
  375. //}
  376. //
  377. //// DONE
  378. //void WordFont::AddLetterS(int startingLocation, char character, int fontSize, bool isBold)
  379. //{
  380. // int max = fontSize - 1;
  381. // for (int row = 0; row < fontSize; row++)
  382. // {
  383. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  384. // {
  385. // if (isBold)
  386. // {
  387. // if (((row == 0 && col != 0) || row == 1) || // Top
  388. // ((row == max && col != max) || row == max - 1) || // Bottom
  389. // ((col == 0 && row < max / 2 && row != 0) || (col == 1 && row < max / 2)) || // Left
  390. // ((col == max && row > max / 2 && row != max) || (col == max - 1 && row > max / 2)) || // Right
  391. // ((row == max / 2 && col != max) || (row == max / 2 + 1 && col != 0))) // Bar
  392. // {
  393. // myVec.at(row).at(col) = character;
  394. // }
  395. //
  396. // }
  397. // else if ((row == 0 && col != 0) || // Top
  398. // (row == max && col != max) || // Bottom
  399. // (col == 0 && row < max / 2 && row != 0) || // Left
  400. // (row == max / 2 && col != 0 && col != max) || // Right
  401. // (col == max && row > max / 2 && row != max)) // Bar
  402. // {
  403. // myVec.at(row).at(col) = character;
  404. // }
  405. // }
  406. // }
  407. //}
  408. //
  409. //// DONE
  410. //void WordFont::AddLetterT(int startingLocation, char character, int fontSize, bool isBold)
  411. //{
  412. // int s = startingLocation;
  413. // int max = startingLocation + fontSize - 1;
  414. // for (int row = 0; row < fontSize; row++)
  415. // {
  416. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  417. // {
  418. // if (isBold)
  419. // {
  420. // if ((row == 0 || row == 1) || // Top
  421. // (col == ((max - s) / 2) + s || col == ((max - s) / 2 + 1) + s)) // Bar
  422. // {
  423. // myVec.at(row).at(col) = character;
  424. // }
  425. // }
  426. // else if ((row == 0) || // Top
  427. // (col == ((max - s) / 2) + s)) // Bar
  428. // {
  429. // myVec.at(row).at(col) = character;
  430. // }
  431. // }
  432. // }
  433. //}
  434. //
  435. //// DONE
  436. //void WordFont::AddLetterU(int startingLocation, char character, int fontSize, bool isBold)
  437. //{
  438. // int max = fontSize - 1;
  439. // for (int row = 0; row < fontSize; row++)
  440. // {
  441. // for (int col = startingLocation; col < startingLocation + fontSize; col++)
  442. // {
  443. // if (isBold)
  444. // {
  445. // if (((col == 0 && row != max) || col == 1) || // Left
  446. // ((row == max && col != 0 && col != max) || row == max - 1) || // Bottom
  447. // ((col == max && row != max) || col == max - 1)) // Right
  448. // {
  449. // myVec.at(row).at(col) = character;
  450. // }
  451. // }
  452. // else if ((col == 0 & row != max) || // Left
  453. // (row == max & col != 0 & col != max) || // Bottom
  454. // (col == max & row != max)) // Right
  455. // {
  456. // myVec.at(row).at(col) = character;
  457. // }
  458. // }
  459. // }
  460. //}
  461.  
  462. void WordFont::PrintWord(std::string word)
  463. {
  464. int startingLocation = 0;
  465. char c = '*';
  466. int fontSize = 8;
  467. bool isBold = false;
  468. sRow = 0;
  469. eRow = fontSize - 1;
  470. mRow = eRow / 2;
  471.  
  472.  
  473.  
  474. for (int i = 0; i < word.length(); i++) {
  475.  
  476. int sCol = i * (fontSize + 1);
  477.  
  478. switch (word[i])
  479. {
  480. case 'a':
  481. AddLetterA(sCol, c, fontSize, isBold);
  482. break;
  483. case 'b':
  484. AddLetterB(sCol, c, fontSize, isBold);
  485. break;
  486. case 'c':
  487. AddLetterC(sCol, c, fontSize, isBold);
  488. break;
  489. case 'd':
  490. AddLetterD(sCol, c, fontSize, isBold);
  491. break;
  492. case 'e':
  493. AddLetterE(sCol, c, fontSize, isBold);
  494. break;
  495. case 'f':
  496. AddLetterF(sCol, c, fontSize, isBold);
  497. break;
  498. case 'g':
  499. AddLetterG(sCol, c, fontSize, isBold);
  500. break;
  501. //case 'h':
  502. // AddLetterH(startingLocation, c, fontSize, isBold);
  503. // break;
  504. //case 'i':
  505. // AddLetterI(startingLocation, c, fontSize, isBold);
  506. // break;
  507. //case 'l':
  508. // AddLetterL(startingLocation, c, fontSize, isBold);
  509. // break;
  510. //case 'o':
  511. // AddLetterO(startingLocation, c, fontSize, isBold);
  512. // break;
  513. //case 'p':
  514. // AddLetterP(startingLocation, c, fontSize, isBold);
  515. // break;
  516. //case 's':
  517. // AddLetterS(startingLocation, c, fontSize, isBold);
  518. // break;
  519. //case 't':
  520. // AddLetterT(startingLocation, c, fontSize, isBold);
  521. // break;
  522. //case 'u':
  523. // AddLetterU(startingLocation, c, fontSize, isBold);
  524. // break;
  525. };
  526.  
  527. startingLocation += fontSize + 1;
  528. }
  529. for (int i = 0; i < 70; i++)
  530. {
  531. for (int j = 0; j < 70; j++)
  532. {
  533. //std::cout << std::setw(4) << std::right << myVec[i][j];
  534. std::cout << myVec.at(i).at(j);
  535. }
  536. std::cout << std::endl;
  537. }
  538. }
  539.  
  540.  
  541. bool WordFont::IsValidWord(std::string word)
  542. {
  543. int length = word.length();
  544. std::string valid = "abcdefghilopstuABCDEFGHILOPSTU";
  545. if (word.empty() || !(length <= 8))
  546. {
  547. return false;
  548. }
  549.  
  550. for (int i = 0; i < word.length(); i++)
  551. {
  552. if ((valid.find(word[i]) == std::string::npos))
  553. {
  554. return false;
  555. }
  556. }
  557.  
  558. return true;
  559. }
  560.  
  561. std::string WordFont::ToLowerCase(std::string word)
  562. {
  563. for (int i = 0; i < word.length(); i++)
  564. {
  565. if (word[i] <= 'Z' && word[i] >= 'A')
  566. {
  567. word[i] += 32;
  568. }
  569. }
  570.  
  571. return word;
  572. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement