| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2007 Pierre Marchand <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef CHARPAINTER_H |
| 7 |
#define CHARPAINTER_H |
| 8 |
|
| 9 |
/** |
| 10 |
@author Pierre Marchand <[email protected]> |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <ostream> |
| 14 |
|
| 15 |
class CharPainter |
| 16 |
{ |
| 17 |
public: |
| 18 |
CharPainter() { } |
| 19 |
~CharPainter() { } |
| 20 |
|
| 21 |
void paint(std::ostream& s, int n, double size, double x, double y); |
| 22 |
// call paint() for each digit in the number `n' |
| 23 |
void multipaint(std::ostream& s, int n, double size, double x, double y); |
| 24 |
|
| 25 |
private: |
| 26 |
// some simple helpers for writing points |
| 27 |
// TODO: nothrow annotations |
| 28 |
inline void wdir(std::ostream& s, double x1, double y1, double x2, double y2) const |
| 29 |
{ |
| 30 |
s << x1 << ' ' << y1 << " m\n" |
| 31 |
<< x2 << ' ' << y2 << " l\n"; |
| 32 |
} |
| 33 |
inline void top(std::ostream& s) const { wdir(s, m_x, m_sh, m_sw, m_x); } |
| 34 |
inline void topright(std::ostream& s) const { wdir(s, m_sw, m_sh, m_sw, m_midh); } |
| 35 |
inline void bottomright(std::ostream& s) const { wdir(s, m_sw, m_midh, m_sw, m_y); } |
| 36 |
inline void bottom(std::ostream& s) const { wdir(s, m_x, m_y, m_sw, m_y); } |
| 37 |
inline void bottomleft(std::ostream& s) const { wdir(s, m_x, m_y, m_x, m_midh); } |
| 38 |
inline void topleft(std::ostream& s) const { wdir(s, m_x, m_midh, m_x, m_sh); } |
| 39 |
inline void center(std::ostream& s) const { wdir(s, m_x, m_midh, m_sw, m_midh); } |
| 40 |
|
| 41 |
// temporaries used by paint(...) |
| 42 |
double m_size; |
| 43 |
double m_x; |
| 44 |
double m_y; |
| 45 |
double m_sh; |
| 46 |
double m_sw; |
| 47 |
double m_midh; |
| 48 |
}; |
| 49 |
|
| 50 |
#endif // CHARPAINTER_H |