comparison font/text_stream.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 658272d883ed
children ddbcbd000206
comparison
equal deleted inserted replaced
51:cbb301016a4e 52:15a18fbe6f21
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "text.h" 28 #include "text.h"
29 #include "codeconv.h" 29 #include "codeconv.h"
30 #include<string.h> 30 #include <string.h>
31 #include<stdio.h> 31 #include <stdio.h>
32 32
33 /************************************************************************ 33 /************************************************************************
34 ** 34 **
35 ** TextStream 35 ** TextStream
36 ** 36 **
37 */ 37 */
38 38
39 TextStream::TextStream(void) { 39 TextStream::TextStream(void) {
40 kanji_type = euc; 40 kanji_type = euc;
41 } 41 }
42
42 void TextStream::SetSize(double scale) { 43 void TextStream::SetSize(double scale) {
43 TextElem elem; 44 TextElem elem;
44 elem.type = TextElem::size; 45 elem.type = TextElem::size;
45 elem.impl.Size.scale = scale; 46 elem.impl.Size.scale = scale;
46 container.push_back(elem); 47 container.push_back(elem);
47 } 48 }
49
48 void TextStream::SetColor(unsigned char r, unsigned char g, unsigned char b) { 50 void TextStream::SetColor(unsigned char r, unsigned char g, unsigned char b) {
49 TextElem elem; 51 TextElem elem;
50 elem.type = TextElem::color; 52 elem.type = TextElem::color;
51 elem.impl.Color.r = r; 53 elem.impl.Color.r = r;
52 elem.impl.Color.g = g; 54 elem.impl.Color.g = g;
53 elem.impl.Color.b = b; 55 elem.impl.Color.b = b;
54 container.push_back(elem); 56 container.push_back(elem);
55 } 57 }
58
56 void TextStream::InsertColor(int begin_pos, int end_pos, unsigned char r, unsigned char g, unsigned char b) { 59 void TextStream::InsertColor(int begin_pos, int end_pos, unsigned char r, unsigned char g, unsigned char b) {
57 TextElem elem; 60 TextElem elem;
58 if (begin_pos < 0) begin_pos = 0; 61 if (begin_pos < 0) begin_pos = 0;
59 if (begin_pos > container.size()) begin_pos = container.size(); 62 if (begin_pos > container.size()) begin_pos = container.size();
60 if (end_pos < 0) end_pos = 0; 63 if (end_pos < 0) end_pos = 0;
81 elem.impl.Color.b = b; 84 elem.impl.Color.b = b;
82 } 85 }
83 } 86 }
84 } 87 }
85 } 88 }
89
86 void TextStream::Clear(void) { 90 void TextStream::Clear(void) {
87 container.clear(); 91 container.clear();
88 } 92 }
93
89 void TextStream::Add(const char* str) { 94 void TextStream::Add(const char* str) {
90 TextElem elem; 95 TextElem elem;
91 for (; *str; str++) { 96 for (; *str; str++) {
92 if (*str >= 0x20) { 97 if (*str >= 0x20) {
93 if (*str == '#') { // Commands 98 if (*str == '#') { // Commands
128 continue; 133 continue;
129 } 134 }
130 container.push_back(elem); 135 container.push_back(elem);
131 } 136 }
132 } 137 }
138
133 void TextStream::AddReturn(void) { 139 void TextStream::AddReturn(void) {
134 TextElem elem; 140 TextElem elem;
135 elem.type = TextElem::escape; 141 elem.type = TextElem::escape;
136 elem.impl.Escape.type = TextElem::ret; 142 elem.impl.Escape.type = TextElem::ret;
137 container.push_back(elem); 143 container.push_back(elem);
138 } 144 }
145
139 void TextStream::AddName(const char* str) { 146 void TextStream::AddName(const char* str) {
140 TextElem elem; 147 TextElem elem;
141 elem.type = TextElem::escape; 148 elem.type = TextElem::escape;
142 elem.impl.Escape.type = TextElem::name_start; 149 elem.impl.Escape.type = TextElem::name_start;
143 container.push_back(elem); 150 container.push_back(elem);