diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/Text.cc | 88 | ||||
-rw-r--r-- | src/FbTk/Text.hh | 41 |
2 files changed, 129 insertions, 0 deletions
diff --git a/src/FbTk/Text.cc b/src/FbTk/Text.cc new file mode 100644 index 0000000..2a7435e --- /dev/null +++ b/src/FbTk/Text.cc | |||
@@ -0,0 +1,88 @@ | |||
1 | // Text.cc for FbTk - text utils | ||
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: Text.cc,v 1.1 2002/12/02 20:11:58 fluxgen Exp $ | ||
23 | |||
24 | #include "Text.hh" | ||
25 | |||
26 | #include "Font.hh" | ||
27 | #include "Theme.hh" | ||
28 | |||
29 | #include <strings.h> | ||
30 | |||
31 | namespace FbTk { | ||
32 | |||
33 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, | ||
34 | const FbTk::Font &font, const char * const text, | ||
35 | unsigned int textlen, unsigned int &newlen) { | ||
36 | |||
37 | if (text == 0 || textlen == 0) | ||
38 | return 0; | ||
39 | |||
40 | int l = font.textWidth(text, textlen) + bevel; | ||
41 | size_t dlen = textlen; | ||
42 | int dx = bevel; | ||
43 | if (l > max_width) { | ||
44 | for (; dlen > 0; dlen--) { | ||
45 | l = font.textWidth(text, dlen) + bevel; | ||
46 | if (l<=max_width) | ||
47 | break; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | newlen = dlen; | ||
52 | |||
53 | switch (justify) { | ||
54 | case FbTk::RIGHT: | ||
55 | dx = max_width - l - bevel; | ||
56 | break; | ||
57 | case FbTk::CENTER: | ||
58 | dx = (max_width - l)/2; | ||
59 | break; | ||
60 | case FbTk::LEFT: | ||
61 | break; | ||
62 | } | ||
63 | |||
64 | return dx; | ||
65 | } | ||
66 | |||
67 | /// specialization for Justify | ||
68 | template <> | ||
69 | void ThemeItem<FbTk::Justify>::setDefaultValue() { | ||
70 | m_value = LEFT; | ||
71 | } | ||
72 | |||
73 | template <> | ||
74 | void ThemeItem<FbTk::Justify>::setFromString(const char *value) { | ||
75 | if (strcasecmp("center", value) == 0) | ||
76 | m_value = FbTk::CENTER; | ||
77 | else if (strcasecmp("right", value) == 0) | ||
78 | m_value = FbTk::RIGHT; | ||
79 | else // default | ||
80 | setDefaultValue(); | ||
81 | } | ||
82 | |||
83 | // do nothing | ||
84 | template <> | ||
85 | void ThemeItem<FbTk::Justify>::load() { | ||
86 | } | ||
87 | |||
88 | }; // end namespace FbTk | ||
diff --git a/src/FbTk/Text.hh b/src/FbTk/Text.hh new file mode 100644 index 0000000..54abd50 --- /dev/null +++ b/src/FbTk/Text.hh | |||
@@ -0,0 +1,41 @@ | |||
1 | // Text.hh for FbTk - text utils | ||
2 | // Copyright (c) 2002 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: Text.hh,v 1.1 2002/12/02 20:11:57 fluxgen Exp $ | ||
23 | |||
24 | #ifndef FBTK_TEXT_HH | ||
25 | #define FBTK_TEXT_HH | ||
26 | |||
27 | namespace FbTk { | ||
28 | |||
29 | class Font; | ||
30 | |||
31 | enum Justify {LEFT, RIGHT, CENTER}; | ||
32 | /** | ||
33 | Aligns the text after max width and bevel | ||
34 | */ | ||
35 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, | ||
36 | const FbTk::Font &font, const char * const text, | ||
37 | unsigned int textlen, unsigned int &newlen); | ||
38 | |||
39 | }; | ||
40 | |||
41 | #endif // FBTK_TEXT_HH | ||