| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2007 Pierre Marchand <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "charpainter.h" |
| 7 |
|
| 8 |
#include <vector> |
| 9 |
|
| 10 |
using namespace std; |
| 11 |
|
| 12 |
namespace |
| 13 |
{ |
| 14 |
// write the digits of `n' to `d'. The digits are ordered by increasing |
| 15 |
// place value. |
| 16 |
void digits(int n, vector<int>& d) |
| 17 |
{ |
| 18 |
while (n > 0) |
| 19 |
{ |
| 20 |
d.push_back(n % 10); |
| 21 |
n = n / 10; |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
void CharPainter::paint(ostream& s, int n, double size, double x, double y) |
| 27 |
{ |
| 28 |
// update working variables used by topleft() etc |
| 29 |
m_y = y; |
| 30 |
m_x = x; |
| 31 |
m_size = size; |
| 32 |
m_sh = m_size + m_y; |
| 33 |
m_midh = (m_size / 2.0) + m_y; |
| 34 |
m_sw = (m_size / 2.0) + m_x; |
| 35 |
|
| 36 |
switch (n) |
| 37 |
{ |
| 38 |
case 1: |
| 39 |
topright(s); |
| 40 |
bottomright(s); |
| 41 |
break; |
| 42 |
case 2: |
| 43 |
top(s); |
| 44 |
topright(s); |
| 45 |
center(s); |
| 46 |
bottomleft(s); |
| 47 |
bottom(s); |
| 48 |
break; |
| 49 |
case 3: |
| 50 |
top(s); |
| 51 |
topright(s); |
| 52 |
bottomright(s); |
| 53 |
bottom(s); |
| 54 |
center(s); |
| 55 |
break; |
| 56 |
case 4: |
| 57 |
topleft(s); |
| 58 |
center(s); |
| 59 |
bottomright(s); |
| 60 |
topright(s); |
| 61 |
break; |
| 62 |
case 5: |
| 63 |
top(s); |
| 64 |
topleft(s); |
| 65 |
center(s); |
| 66 |
bottomright(s); |
| 67 |
bottom(s); |
| 68 |
break; |
| 69 |
case 6: |
| 70 |
top(s); |
| 71 |
topleft(s); |
| 72 |
center(s); |
| 73 |
bottomright(s); |
| 74 |
bottom(s); |
| 75 |
bottomleft(s); |
| 76 |
break; |
| 77 |
case 7: |
| 78 |
top(s); |
| 79 |
topright(s); |
| 80 |
bottomright(s); |
| 81 |
break; |
| 82 |
case 8: |
| 83 |
top(s); |
| 84 |
topleft(s); |
| 85 |
center(s); |
| 86 |
bottomright(s); |
| 87 |
bottom(s); |
| 88 |
bottomleft(s); |
| 89 |
topright(s); |
| 90 |
break; |
| 91 |
case 9: |
| 92 |
top(s); |
| 93 |
topleft(s); |
| 94 |
center(s); |
| 95 |
bottomright(s); |
| 96 |
bottom(s); |
| 97 |
topright(s); |
| 98 |
break; |
| 99 |
case 0: |
| 100 |
top(s); |
| 101 |
topleft(s); |
| 102 |
bottomright(s); |
| 103 |
bottom(s); |
| 104 |
bottomleft(s); |
| 105 |
topright(s); |
| 106 |
break; |
| 107 |
} |
| 108 |
s << "S\n"; |
| 109 |
} |
| 110 |
|
| 111 |
void CharPainter::multipaint(ostream& s, int n, double size, double x, double y) |
| 112 |
{ |
| 113 |
vector<int> d; |
| 114 |
digits(n, d); |
| 115 |
|
| 116 |
vector<int>::const_reverse_iterator itEnd = d.rend(); |
| 117 |
int i = (int)d.size() - 1; |
| 118 |
for (vector<int>::const_reverse_iterator it = d.rbegin(); it != itEnd; it++, i--) |
| 119 |
paint(s, *it, size, x + (size * i / 1.6), y); |
| 120 |
} |