| 1 | // ============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File: aw_font_limits.hxx // |
|---|
| 4 | // http://www.arb-home.de/ // |
|---|
| 5 | // // |
|---|
| 6 | // ============================================================== // |
|---|
| 7 | |
|---|
| 8 | #ifndef AW_FONT_LIMITS_HXX |
|---|
| 9 | #define AW_FONT_LIMITS_HXX |
|---|
| 10 | |
|---|
| 11 | #ifndef _GLIBCXX_CLIMITS |
|---|
| 12 | #include <climits> |
|---|
| 13 | #endif |
|---|
| 14 | #ifndef _GLIBCXX_ALGORITHM |
|---|
| 15 | #include <algorithm> |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | struct AW_font_limits { |
|---|
| 19 | short ascent; |
|---|
| 20 | short descent; |
|---|
| 21 | short width; |
|---|
| 22 | short min_width; |
|---|
| 23 | |
|---|
| 24 | void reset() { *this = AW_font_limits(); } |
|---|
| 25 | |
|---|
| 26 | bool was_notified() const { return min_width != SHRT_MAX; } // true when notify... called |
|---|
| 27 | |
|---|
| 28 | void notify(short ascent_, short descent_, short width_) { |
|---|
| 29 | ascent = std::max(ascent_, ascent); |
|---|
| 30 | descent = std::max(descent_, descent); |
|---|
| 31 | width = std::max(width_, width); |
|---|
| 32 | min_width = std::min(width_, min_width); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | short get_height() const { return ascent+descent+1; } |
|---|
| 36 | |
|---|
| 37 | bool is_monospaced() const { aw_assert(was_notified()); return width == min_width; } |
|---|
| 38 | |
|---|
| 39 | AW_font_limits() : |
|---|
| 40 | ascent(0), |
|---|
| 41 | descent(0), |
|---|
| 42 | width(0), |
|---|
| 43 | min_width(SHRT_MAX) |
|---|
| 44 | {} |
|---|
| 45 | AW_font_limits(const AW_font_limits& lim1, const AW_font_limits& lim2) : // works with notified and initial AW_font_limits |
|---|
| 46 | ascent(std::max(lim1.ascent, lim2.ascent)), |
|---|
| 47 | descent(std::max(lim1.descent, lim2.descent)), |
|---|
| 48 | width(std::max(lim1.width, lim2.width)), |
|---|
| 49 | min_width(std::min(lim1.min_width, lim2.min_width)) |
|---|
| 50 | { |
|---|
| 51 | aw_assert(correlated(lim1.was_notified() || lim2.was_notified(), was_notified())); |
|---|
| 52 | } |
|---|
| 53 | }; |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | #else |
|---|
| 57 | #error aw_font_limits.hxx included twice |
|---|
| 58 | #endif // AW_FONT_LIMITS_HXX |
|---|