annotate font/text_stream.cc @ 59:36d92d21300f

Implemented sin opcode
author Thibaut GIRKA <thib@sitedethib.com>
date Fri, 18 Dec 2009 18:51:44 +0100
parents ddbcbd000206
children 4416cfac86ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 #include "text.h"
223b71206888 Initial import
thib
parents:
diff changeset
29 #include "codeconv.h"
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
30 #include <string.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
31 #include <stdio.h>
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
32 #include <stdlib.h>
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
33 #include "system/system_config.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 /************************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
36 **
223b71206888 Initial import
thib
parents:
diff changeset
37 ** TextStream
223b71206888 Initial import
thib
parents:
diff changeset
38 **
223b71206888 Initial import
thib
parents:
diff changeset
39 */
223b71206888 Initial import
thib
parents:
diff changeset
40
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
41 static char* wstrchr(const char* s, unsigned int chr) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
42 int ws, wc;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
43 while(*s != 0) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
44 if (*s < 0 && s[1] != 0) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
45 wc = int((unsigned char)(s[0]))*0x100 + int((unsigned char)(s[1]));
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
46 ws = 2;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
47 } else {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
48 wc = (unsigned char)(s[0]);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
49 ws = 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
50 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
51 if (wc == chr) return (char*)s;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
52 s += ws;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
53 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
54 return NULL;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
55 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
56
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
57 TextStream TextStream::ParseMoji(const char* str, int def_r, int def_g, int def_b, int def_size) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
58 TextStream ts;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
59 ts.kanji_type = TextStream::sjis;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
60 ts.SetColor(def_r, def_g, def_b);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
61 char* copy_str = new char[strlen(str)+1];
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
62 char* next_str;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
63 char* retptr;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
64 int var;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
65
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
66 while( (next_str = wstrchr(str, '#')) != NULL) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
67 int len = next_str - str;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
68 strncpy(copy_str, str, len);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
69 copy_str[len] = 0;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
70 ts.Add(copy_str);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
71 str = next_str + 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
72
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
73 switch(str[0]) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
74 case '#': // separator
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
75 str += 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
76 break;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
77 case 'D': case 'd': // return
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
78 ts.AddReturn();
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
79 str += 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
80 break;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
81 case 'C': case 'c': // color
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
82 str += 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
83 var = strtol(str, &next_str,10);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
84 if (var == 0 && str == next_str) { // no parameter
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
85 ts.SetColor(def_r, def_g, def_b);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
86 } else {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
87 int r,g,b; char key[1024];
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
88 sprintf(key, "#COLOR_TABLE.%03d", var);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
89 if (AyuSysConfig::GetInstance()->GetParam(key, 3, &r, &g, &b)) { // color not found
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
90 r = g = b = 0;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
91 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
92 ts.SetColor(r, g, b);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
93 str = next_str;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
94 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
95 break;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
96 case 'S': case 's': // size
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
97 str += 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
98 var = strtol(str, &next_str, 10);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
99 if (var == 0 && str == next_str) { // no parameter
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
100 ts.SetSize(1);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
101 } else {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
102 if (def_size == 0) def_size = 20;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
103 if (var <= 0) var = 1;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
104 ts.SetSize(double(var)/def_size);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
105 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
106 break;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
107 case 'X': case 'x': // xpos : not supported
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
108 case 'Y': case 'y': // ypos : not supported
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
109 default:
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
110 ts.Add("#");
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
111 break;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
112 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
113 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
114 ts.Add(str);
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
115 delete[] copy_str;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
116 return ts;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
117 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
118
0
223b71206888 Initial import
thib
parents:
diff changeset
119 TextStream::TextStream(void) {
223b71206888 Initial import
thib
parents:
diff changeset
120 kanji_type = euc;
223b71206888 Initial import
thib
parents:
diff changeset
121 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
122
0
223b71206888 Initial import
thib
parents:
diff changeset
123 void TextStream::SetSize(double scale) {
223b71206888 Initial import
thib
parents:
diff changeset
124 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
125 elem.type = TextElem::size;
223b71206888 Initial import
thib
parents:
diff changeset
126 elem.impl.Size.scale = scale;
223b71206888 Initial import
thib
parents:
diff changeset
127 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
128 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
129
0
223b71206888 Initial import
thib
parents:
diff changeset
130 void TextStream::SetColor(unsigned char r, unsigned char g, unsigned char b) {
223b71206888 Initial import
thib
parents:
diff changeset
131 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
132 elem.type = TextElem::color;
223b71206888 Initial import
thib
parents:
diff changeset
133 elem.impl.Color.r = r;
223b71206888 Initial import
thib
parents:
diff changeset
134 elem.impl.Color.g = g;
223b71206888 Initial import
thib
parents:
diff changeset
135 elem.impl.Color.b = b;
223b71206888 Initial import
thib
parents:
diff changeset
136 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
137 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
138
0
223b71206888 Initial import
thib
parents:
diff changeset
139 void TextStream::InsertColor(int begin_pos, int end_pos, unsigned char r, unsigned char g, unsigned char b) {
223b71206888 Initial import
thib
parents:
diff changeset
140 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
141 if (begin_pos < 0) begin_pos = 0;
223b71206888 Initial import
thib
parents:
diff changeset
142 if (begin_pos > container.size()) begin_pos = container.size();
223b71206888 Initial import
thib
parents:
diff changeset
143 if (end_pos < 0) end_pos = 0;
223b71206888 Initial import
thib
parents:
diff changeset
144 if (end_pos > container.size()) end_pos = container.size();
223b71206888 Initial import
thib
parents:
diff changeset
145 if (begin_pos >= end_pos) return;
223b71206888 Initial import
thib
parents:
diff changeset
146
223b71206888 Initial import
thib
parents:
diff changeset
147 elem.type = TextElem::color;
223b71206888 Initial import
thib
parents:
diff changeset
148 elem.impl.Color.r = 255;
223b71206888 Initial import
thib
parents:
diff changeset
149 elem.impl.Color.g = 255;
223b71206888 Initial import
thib
parents:
diff changeset
150 elem.impl.Color.b = 255;
223b71206888 Initial import
thib
parents:
diff changeset
151 container.insert(container.begin()+end_pos, elem);
223b71206888 Initial import
thib
parents:
diff changeset
152 elem.impl.Color.r = r;
223b71206888 Initial import
thib
parents:
diff changeset
153 elem.impl.Color.g = g;
223b71206888 Initial import
thib
parents:
diff changeset
154 elem.impl.Color.b = b;
223b71206888 Initial import
thib
parents:
diff changeset
155 container.insert(container.begin()+begin_pos, elem);
223b71206888 Initial import
thib
parents:
diff changeset
156 Iterator it = container.begin()+begin_pos+1;
223b71206888 Initial import
thib
parents:
diff changeset
157 Iterator end = container.begin()+end_pos+1;
223b71206888 Initial import
thib
parents:
diff changeset
158 for (; it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
159 if (it->type == TextElem::color) {
223b71206888 Initial import
thib
parents:
diff changeset
160 TextElem& elem = *it;
223b71206888 Initial import
thib
parents:
diff changeset
161 if (elem.impl.Color.r == 255 && elem.impl.Color.g == 255 && elem.impl.Color.b == 255) {
223b71206888 Initial import
thib
parents:
diff changeset
162 elem.impl.Color.r = r;
223b71206888 Initial import
thib
parents:
diff changeset
163 elem.impl.Color.g = g;
223b71206888 Initial import
thib
parents:
diff changeset
164 elem.impl.Color.b = b;
223b71206888 Initial import
thib
parents:
diff changeset
165 }
223b71206888 Initial import
thib
parents:
diff changeset
166 }
223b71206888 Initial import
thib
parents:
diff changeset
167 }
223b71206888 Initial import
thib
parents:
diff changeset
168 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
169
0
223b71206888 Initial import
thib
parents:
diff changeset
170 void TextStream::Clear(void) {
223b71206888 Initial import
thib
parents:
diff changeset
171 container.clear();
223b71206888 Initial import
thib
parents:
diff changeset
172 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
173
0
223b71206888 Initial import
thib
parents:
diff changeset
174 void TextStream::Add(const char* str) {
223b71206888 Initial import
thib
parents:
diff changeset
175 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
176 for (; *str; str++) {
223b71206888 Initial import
thib
parents:
diff changeset
177 if (*str >= 0x20) {
223b71206888 Initial import
thib
parents:
diff changeset
178 elem.type = TextElem::glyph;
223b71206888 Initial import
thib
parents:
diff changeset
179 elem.impl.Glyph.code = *str;
223b71206888 Initial import
thib
parents:
diff changeset
180 } else if (*str < 0 && str[1] != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
181 elem.type = TextElem::glyph;
223b71206888 Initial import
thib
parents:
diff changeset
182 elem.impl.Glyph.code = ((int(*(unsigned char*)str))<<8) | int(*(unsigned char*)(str+1));
223b71206888 Initial import
thib
parents:
diff changeset
183 if (kanji_type == sjis) elem.impl.Glyph.code = codeconv_sjis_to_euc(elem.impl.Glyph.code);
223b71206888 Initial import
thib
parents:
diff changeset
184 str++;
223b71206888 Initial import
thib
parents:
diff changeset
185 } else {
223b71206888 Initial import
thib
parents:
diff changeset
186 continue;
223b71206888 Initial import
thib
parents:
diff changeset
187 }
223b71206888 Initial import
thib
parents:
diff changeset
188 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
189 }
223b71206888 Initial import
thib
parents:
diff changeset
190 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
191
0
223b71206888 Initial import
thib
parents:
diff changeset
192 void TextStream::AddReturn(void) {
223b71206888 Initial import
thib
parents:
diff changeset
193 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
194 elem.type = TextElem::escape;
223b71206888 Initial import
thib
parents:
diff changeset
195 elem.impl.Escape.type = TextElem::ret;
223b71206888 Initial import
thib
parents:
diff changeset
196 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
197 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 38
diff changeset
198
0
223b71206888 Initial import
thib
parents:
diff changeset
199 void TextStream::AddName(const char* str) {
223b71206888 Initial import
thib
parents:
diff changeset
200 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
201 elem.type = TextElem::escape;
223b71206888 Initial import
thib
parents:
diff changeset
202 elem.impl.Escape.type = TextElem::name_start;
223b71206888 Initial import
thib
parents:
diff changeset
203 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
204 Add(str);
223b71206888 Initial import
thib
parents:
diff changeset
205 elem.impl.Escape.type = TextElem::name_end;
223b71206888 Initial import
thib
parents:
diff changeset
206 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
207 }
223b71206888 Initial import
thib
parents:
diff changeset
208
223b71206888 Initial import
thib
parents:
diff changeset
209 void TextStream::AddRuby(const char* str, const char* ruby) {
223b71206888 Initial import
thib
parents:
diff changeset
210 TextElem elem;
223b71206888 Initial import
thib
parents:
diff changeset
211 elem.type = TextElem::escape;
223b71206888 Initial import
thib
parents:
diff changeset
212 elem.impl.Escape.type = TextElem::ruby_start;
223b71206888 Initial import
thib
parents:
diff changeset
213 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
214 Add(str);
223b71206888 Initial import
thib
parents:
diff changeset
215 elem.impl.Escape.type = TextElem::ruby_startruby;
223b71206888 Initial import
thib
parents:
diff changeset
216 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
217 Add(ruby);
223b71206888 Initial import
thib
parents:
diff changeset
218 elem.impl.Escape.type = TextElem::ruby_end;
223b71206888 Initial import
thib
parents:
diff changeset
219 container.push_back(elem);
223b71206888 Initial import
thib
parents:
diff changeset
220 }
223b71206888 Initial import
thib
parents:
diff changeset
221
223b71206888 Initial import
thib
parents:
diff changeset
222 void TextStream::RemoveName(char* name, int namelen) {
223b71206888 Initial import
thib
parents:
diff changeset
223 Iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
224 for (it = container.begin(); it != container.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
225 if (it->type == TextElem::escape && it->impl.Escape.type == TextElem::name_start) {
223b71206888 Initial import
thib
parents:
diff changeset
226 // 行頭の名前?
223b71206888 Initial import
thib
parents:
diff changeset
227 int pt = it - container.begin();
223b71206888 Initial import
thib
parents:
diff changeset
228 Iterator name_start = it;
223b71206888 Initial import
thib
parents:
diff changeset
229 for (; it != container.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
230 if (it->type == TextElem::escape && it->impl.Escape.type == TextElem::name_end) break;
223b71206888 Initial import
thib
parents:
diff changeset
231 }
223b71206888 Initial import
thib
parents:
diff changeset
232 if (it != container.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
233 // 名前が見つかったので削除
223b71206888 Initial import
thib
parents:
diff changeset
234 if (name) { // 保存先があるなら保存する
223b71206888 Initial import
thib
parents:
diff changeset
235 Iterator name_end = it;
223b71206888 Initial import
thib
parents:
diff changeset
236 int pos = 0;
223b71206888 Initial import
thib
parents:
diff changeset
237 namelen--;
223b71206888 Initial import
thib
parents:
diff changeset
238 for (it=name_start; it != name_end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
239 if (it->type == TextElem::glyph) {
223b71206888 Initial import
thib
parents:
diff changeset
240 unsigned int code = it->impl.Glyph.code;
223b71206888 Initial import
thib
parents:
diff changeset
241 if (code < 0x100) {
223b71206888 Initial import
thib
parents:
diff changeset
242 if (pos < namelen) name[pos++] = code;
223b71206888 Initial import
thib
parents:
diff changeset
243 } else {
223b71206888 Initial import
thib
parents:
diff changeset
244 if (pos < namelen) name[pos++] = code>>8;
223b71206888 Initial import
thib
parents:
diff changeset
245 if (pos < namelen) name[pos++] = code;
223b71206888 Initial import
thib
parents:
diff changeset
246 }
223b71206888 Initial import
thib
parents:
diff changeset
247 }
223b71206888 Initial import
thib
parents:
diff changeset
248 }
223b71206888 Initial import
thib
parents:
diff changeset
249 name[pos] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
250 name = 0; // 最初に出た名前のみ保存する
223b71206888 Initial import
thib
parents:
diff changeset
251 }
223b71206888 Initial import
thib
parents:
diff changeset
252 it++;
223b71206888 Initial import
thib
parents:
diff changeset
253 container.erase(name_start, it);
223b71206888 Initial import
thib
parents:
diff changeset
254 it = container.begin() + pt;
223b71206888 Initial import
thib
parents:
diff changeset
255 }
223b71206888 Initial import
thib
parents:
diff changeset
256 }
223b71206888 Initial import
thib
parents:
diff changeset
257 for (;it != container.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
258 if (it->type == TextElem::escape && it->impl.Escape.type == TextElem::ret) break;
223b71206888 Initial import
thib
parents:
diff changeset
259 }
223b71206888 Initial import
thib
parents:
diff changeset
260 if (it == container.end()) break;
223b71206888 Initial import
thib
parents:
diff changeset
261 }
223b71206888 Initial import
thib
parents:
diff changeset
262 }
223b71206888 Initial import
thib
parents:
diff changeset
263
223b71206888 Initial import
thib
parents:
diff changeset
264 /************************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
265 **
223b71206888 Initial import
thib
parents:
diff changeset
266 ** TextStream::Save
223b71206888 Initial import
thib
parents:
diff changeset
267 **
223b71206888 Initial import
thib
parents:
diff changeset
268 */
223b71206888 Initial import
thib
parents:
diff changeset
269
223b71206888 Initial import
thib
parents:
diff changeset
270 /* escape sequence : '=XX' ; x < 0x30 || 'x>0x39 && x<0x40' (symbols) */
223b71206888 Initial import
thib
parents:
diff changeset
271 /* !"#$%&'()*+,-./:;<=>? */
223b71206888 Initial import
thib
parents:
diff changeset
272
223b71206888 Initial import
thib
parents:
diff changeset
273 void TextStream::Load(const std::string& from_s) {
223b71206888 Initial import
thib
parents:
diff changeset
274 /* kigou : !"#$%&'()*+,-./:;<=>? */
223b71206888 Initial import
thib
parents:
diff changeset
275 const char* s = from_s.c_str();
223b71206888 Initial import
thib
parents:
diff changeset
276 container.clear();
223b71206888 Initial import
thib
parents:
diff changeset
277 if (*s == '=' && *s == 'e') {kanji_type = euc; s+=2;}
223b71206888 Initial import
thib
parents:
diff changeset
278
223b71206888 Initial import
thib
parents:
diff changeset
279 TextElem e;
223b71206888 Initial import
thib
parents:
diff changeset
280 while(s && *s) {
223b71206888 Initial import
thib
parents:
diff changeset
281 e.type = TextElem::glyph;
223b71206888 Initial import
thib
parents:
diff changeset
282 if (*s == '=') {
223b71206888 Initial import
thib
parents:
diff changeset
283 if (s[1] >= 'A' && s[1] <= 'Q' && s[2] >= 'A' && s[2] <= 'Q') { // symbols
223b71206888 Initial import
thib
parents:
diff changeset
284 e.type = TextElem::glyph;
223b71206888 Initial import
thib
parents:
diff changeset
285 e.impl.Glyph.code = (s[1]-'A')*16 + (s[2]-'A');
223b71206888 Initial import
thib
parents:
diff changeset
286 s += 3;
223b71206888 Initial import
thib
parents:
diff changeset
287 } else if (s[1] == 'x') {
223b71206888 Initial import
thib
parents:
diff changeset
288 e.type = TextElem::escape;
223b71206888 Initial import
thib
parents:
diff changeset
289 e.impl.Escape.type = TextElem::EscapeType(s[2]-'A');
223b71206888 Initial import
thib
parents:
diff changeset
290 s += 3;
223b71206888 Initial import
thib
parents:
diff changeset
291 } else if (s[1] == 'c') {
223b71206888 Initial import
thib
parents:
diff changeset
292 int c;
223b71206888 Initial import
thib
parents:
diff changeset
293 e.type = TextElem::color;
223b71206888 Initial import
thib
parents:
diff changeset
294 sscanf(s+2, "%x", &c);
223b71206888 Initial import
thib
parents:
diff changeset
295 e.impl.Color.r = (c>>16)&0xff;
223b71206888 Initial import
thib
parents:
diff changeset
296 e.impl.Color.g = (c>>8)&0xff;
223b71206888 Initial import
thib
parents:
diff changeset
297 e.impl.Color.b = (c)&0xff;
223b71206888 Initial import
thib
parents:
diff changeset
298 s = strchr(s, '.');
223b71206888 Initial import
thib
parents:
diff changeset
299 if (s) s++;
223b71206888 Initial import
thib
parents:
diff changeset
300 } else if (s[1] == 's') {
223b71206888 Initial import
thib
parents:
diff changeset
301 e.impl.Size.scale = TextElem::size;
223b71206888 Initial import
thib
parents:
diff changeset
302 sscanf(s+2, "%f", &e.impl.Size.scale);
223b71206888 Initial import
thib
parents:
diff changeset
303 s = strchr(s, '.');
223b71206888 Initial import
thib
parents:
diff changeset
304 if (s) s++;
223b71206888 Initial import
thib
parents:
diff changeset
305 } else {
223b71206888 Initial import
thib
parents:
diff changeset
306 fprintf(stderr,"TextStream::Load(): Cannot convert text-stream from Serialized-data\n");
223b71206888 Initial import
thib
parents:
diff changeset
307 s++;
223b71206888 Initial import
thib
parents:
diff changeset
308 }
223b71206888 Initial import
thib
parents:
diff changeset
309 } else {
223b71206888 Initial import
thib
parents:
diff changeset
310 if (*s < 0) { // kanji-code
223b71206888 Initial import
thib
parents:
diff changeset
311 if (s[1] == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
312 if (s[1] >= 0 && s[1] < 0x40) break; // not EUC nor SJIS
223b71206888 Initial import
thib
parents:
diff changeset
313 e.type = TextElem::glyph;
223b71206888 Initial import
thib
parents:
diff changeset
314 e.impl.Glyph.code = codeconv_sjis_to_euc(int(*(unsigned char*)(s))*0x100 + int(*(unsigned char*)(s+1)));
223b71206888 Initial import
thib
parents:
diff changeset
315 s += 2;
223b71206888 Initial import
thib
parents:
diff changeset
316 } else { // ascii-code
223b71206888 Initial import
thib
parents:
diff changeset
317 if (s[0] < 0x30) break; // must be escaped
223b71206888 Initial import
thib
parents:
diff changeset
318 if (s[0] > 0x39 && s[0] < 0x40) break; // must be escaped
223b71206888 Initial import
thib
parents:
diff changeset
319 e.type = TextElem::glyph;
223b71206888 Initial import
thib
parents:
diff changeset
320 e.impl.Glyph.code = s[0];
223b71206888 Initial import
thib
parents:
diff changeset
321 s++;
223b71206888 Initial import
thib
parents:
diff changeset
322 }
223b71206888 Initial import
thib
parents:
diff changeset
323 }
223b71206888 Initial import
thib
parents:
diff changeset
324 container.push_back(e);
223b71206888 Initial import
thib
parents:
diff changeset
325 }
223b71206888 Initial import
thib
parents:
diff changeset
326 }
223b71206888 Initial import
thib
parents:
diff changeset
327
223b71206888 Initial import
thib
parents:
diff changeset
328 std::string TextStream::Save(void) {
223b71206888 Initial import
thib
parents:
diff changeset
329 /* kigou : !"#$%&'()*+,-./:;<=>? */
223b71206888 Initial import
thib
parents:
diff changeset
330 Iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
331 std::string ret_s;
223b71206888 Initial import
thib
parents:
diff changeset
332 char buf_orig[1024];
223b71206888 Initial import
thib
parents:
diff changeset
333 char* buf = buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
334 for (it=container.begin(); it != container.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
335 TextElem& e = *it;
223b71206888 Initial import
thib
parents:
diff changeset
336 switch(e.type) {
223b71206888 Initial import
thib
parents:
diff changeset
337 case TextElem::glyph: {
223b71206888 Initial import
thib
parents:
diff changeset
338 int code = e.impl.Glyph.code;
223b71206888 Initial import
thib
parents:
diff changeset
339 if (code < 0x30 || (code > 0x39 && code < 0x40)) {
223b71206888 Initial import
thib
parents:
diff changeset
340 *buf++ = '=';
223b71206888 Initial import
thib
parents:
diff changeset
341 *buf++ = (code/0x10) + 'A';
223b71206888 Initial import
thib
parents:
diff changeset
342 *buf++ = (code%0x10) + 'A';
223b71206888 Initial import
thib
parents:
diff changeset
343 } else {
223b71206888 Initial import
thib
parents:
diff changeset
344 code = codeconv_euc_to_sjis(code); // save file の漢字コードはSJIS
223b71206888 Initial import
thib
parents:
diff changeset
345 *buf++ = code/256;
223b71206888 Initial import
thib
parents:
diff changeset
346 *buf++ = code%256;
223b71206888 Initial import
thib
parents:
diff changeset
347 }
223b71206888 Initial import
thib
parents:
diff changeset
348 break;
223b71206888 Initial import
thib
parents:
diff changeset
349 }
223b71206888 Initial import
thib
parents:
diff changeset
350 case TextElem::escape:
223b71206888 Initial import
thib
parents:
diff changeset
351 sprintf(buf, "=x%c", e.impl.Escape.type+'A');
223b71206888 Initial import
thib
parents:
diff changeset
352 buf += 3;
223b71206888 Initial import
thib
parents:
diff changeset
353 break;
223b71206888 Initial import
thib
parents:
diff changeset
354 case TextElem::color:
223b71206888 Initial import
thib
parents:
diff changeset
355 sprintf(buf, "=c%x.",int(e.impl.Color.r)*256*256+int(e.impl.Color.g)*256+e.impl.Color.b);
223b71206888 Initial import
thib
parents:
diff changeset
356 buf += strlen(buf);
223b71206888 Initial import
thib
parents:
diff changeset
357 break;
223b71206888 Initial import
thib
parents:
diff changeset
358 case TextElem::size:
223b71206888 Initial import
thib
parents:
diff changeset
359 sprintf(buf, "=s%f.", e.impl.Size.scale);
223b71206888 Initial import
thib
parents:
diff changeset
360 buf += strlen(buf);
223b71206888 Initial import
thib
parents:
diff changeset
361 break;
223b71206888 Initial import
thib
parents:
diff changeset
362 }
223b71206888 Initial import
thib
parents:
diff changeset
363 if (buf-buf_orig > 1000) {
223b71206888 Initial import
thib
parents:
diff changeset
364 *buf = 0;
223b71206888 Initial import
thib
parents:
diff changeset
365 ret_s += buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
366 buf = buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
367 }
223b71206888 Initial import
thib
parents:
diff changeset
368 }
223b71206888 Initial import
thib
parents:
diff changeset
369 *buf = 0;
223b71206888 Initial import
thib
parents:
diff changeset
370 ret_s += buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
371 buf = buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
372 return ret_s;
223b71206888 Initial import
thib
parents:
diff changeset
373 }
223b71206888 Initial import
thib
parents:
diff changeset
374
223b71206888 Initial import
thib
parents:
diff changeset
375 /************************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
376 **
223b71206888 Initial import
thib
parents:
diff changeset
377 ** TextGlyphStream
223b71206888 Initial import
thib
parents:
diff changeset
378 **
223b71206888 Initial import
thib
parents:
diff changeset
379 */
223b71206888 Initial import
thib
parents:
diff changeset
380
223b71206888 Initial import
thib
parents:
diff changeset
381 void TextGlyphStream::SetColor(int r, int g, int b) {
223b71206888 Initial import
thib
parents:
diff changeset
382 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
383 for (it=begin(); it != end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
384 // if (it->r == 255 && it->g == 255 && it->b == 255) {
223b71206888 Initial import
thib
parents:
diff changeset
385 it->r = r;
223b71206888 Initial import
thib
parents:
diff changeset
386 it->g = g;
223b71206888 Initial import
thib
parents:
diff changeset
387 it->b = b;
223b71206888 Initial import
thib
parents:
diff changeset
388 // }
223b71206888 Initial import
thib
parents:
diff changeset
389 }
223b71206888 Initial import
thib
parents:
diff changeset
390 }
223b71206888 Initial import
thib
parents:
diff changeset
391 void TextGlyphStream::SetReverse(bool is_rev) {
223b71206888 Initial import
thib
parents:
diff changeset
392 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
393 for (it=begin(); it != end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
394 it->is_rev = is_rev;
223b71206888 Initial import
thib
parents:
diff changeset
395 }
223b71206888 Initial import
thib
parents:
diff changeset
396 }