annotate font/text.h @ 21:d1bb7b365816

Fixed dynamic strings in selections (Fuko Pranks for instance)
author thib
date Fri, 31 Oct 2008 14:30:37 +0000
parents 223b71206888
children 15a18fbe6f21
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 #ifndef __TEXT_H__
223b71206888 Initial import
thib
parents:
diff changeset
29 #define __TEXT_H__
223b71206888 Initial import
thib
parents:
diff changeset
30
223b71206888 Initial import
thib
parents:
diff changeset
31 #include<vector>
223b71206888 Initial import
thib
parents:
diff changeset
32 #include<string>
223b71206888 Initial import
thib
parents:
diff changeset
33
223b71206888 Initial import
thib
parents:
diff changeset
34 struct TextElem {
223b71206888 Initial import
thib
parents:
diff changeset
35 typedef enum {glyph, escape, color, size} ElemType;
223b71206888 Initial import
thib
parents:
diff changeset
36 typedef enum { ret, pos_reset, name_start, name_end, ruby_start, ruby_startruby, ruby_end} EscapeType;
223b71206888 Initial import
thib
parents:
diff changeset
37 ElemType type;
223b71206888 Initial import
thib
parents:
diff changeset
38 union Impl {
223b71206888 Initial import
thib
parents:
diff changeset
39 struct {
223b71206888 Initial import
thib
parents:
diff changeset
40 int code;
223b71206888 Initial import
thib
parents:
diff changeset
41 } Glyph;
223b71206888 Initial import
thib
parents:
diff changeset
42 struct {
223b71206888 Initial import
thib
parents:
diff changeset
43 EscapeType type;
223b71206888 Initial import
thib
parents:
diff changeset
44 } Escape;
223b71206888 Initial import
thib
parents:
diff changeset
45 struct {
223b71206888 Initial import
thib
parents:
diff changeset
46 unsigned char r, g, b;
223b71206888 Initial import
thib
parents:
diff changeset
47 } Color;
223b71206888 Initial import
thib
parents:
diff changeset
48 struct {
223b71206888 Initial import
thib
parents:
diff changeset
49 float scale;
223b71206888 Initial import
thib
parents:
diff changeset
50 } Size;
223b71206888 Initial import
thib
parents:
diff changeset
51 } impl;
223b71206888 Initial import
thib
parents:
diff changeset
52 };
223b71206888 Initial import
thib
parents:
diff changeset
53
223b71206888 Initial import
thib
parents:
diff changeset
54 struct TextStream {
223b71206888 Initial import
thib
parents:
diff changeset
55 std::vector<TextElem> container;
223b71206888 Initial import
thib
parents:
diff changeset
56 typedef std::vector<TextElem>::iterator Iterator;
223b71206888 Initial import
thib
parents:
diff changeset
57 enum {sjis, euc} kanji_type;
223b71206888 Initial import
thib
parents:
diff changeset
58
223b71206888 Initial import
thib
parents:
diff changeset
59 std::string Save(void);
223b71206888 Initial import
thib
parents:
diff changeset
60 void Load(const std::string&);
223b71206888 Initial import
thib
parents:
diff changeset
61
223b71206888 Initial import
thib
parents:
diff changeset
62 void SetSize(double size);
223b71206888 Initial import
thib
parents:
diff changeset
63 void SetColor(unsigned char r, unsigned char g, unsigned char b);
223b71206888 Initial import
thib
parents:
diff changeset
64 void SetDefaultColor(unsigned char r, unsigned char g, unsigned char b);
223b71206888 Initial import
thib
parents:
diff changeset
65 void InsertColor(int begin_pos, int end_pos, unsigned char r, unsigned char g, unsigned char b);
223b71206888 Initial import
thib
parents:
diff changeset
66 void Clear(void);
223b71206888 Initial import
thib
parents:
diff changeset
67 void Add(const char* str);
223b71206888 Initial import
thib
parents:
diff changeset
68 void AddReturn(void);
223b71206888 Initial import
thib
parents:
diff changeset
69 void AddName(const char* name);
223b71206888 Initial import
thib
parents:
diff changeset
70 void AddRuby(const char* str, const char* ruby);
223b71206888 Initial import
thib
parents:
diff changeset
71
223b71206888 Initial import
thib
parents:
diff changeset
72 void RemoveName(char* name, int namelen);
223b71206888 Initial import
thib
parents:
diff changeset
73
223b71206888 Initial import
thib
parents:
diff changeset
74 TextStream(void);
223b71206888 Initial import
thib
parents:
diff changeset
75 TextStream& operator =(const TextStream& from) {
223b71206888 Initial import
thib
parents:
diff changeset
76 container = from.container;
223b71206888 Initial import
thib
parents:
diff changeset
77 kanji_type = from.kanji_type;
223b71206888 Initial import
thib
parents:
diff changeset
78 return *this;
223b71206888 Initial import
thib
parents:
diff changeset
79 }
223b71206888 Initial import
thib
parents:
diff changeset
80 };
223b71206888 Initial import
thib
parents:
diff changeset
81
223b71206888 Initial import
thib
parents:
diff changeset
82 namespace XKFont {
223b71206888 Initial import
thib
parents:
diff changeset
83 class Glyph;
223b71206888 Initial import
thib
parents:
diff changeset
84 class Font;
223b71206888 Initial import
thib
parents:
diff changeset
85 };
223b71206888 Initial import
thib
parents:
diff changeset
86
223b71206888 Initial import
thib
parents:
diff changeset
87 struct TextGlyph {
223b71206888 Initial import
thib
parents:
diff changeset
88 int x,y;
223b71206888 Initial import
thib
parents:
diff changeset
89 enum Flag { Group = 1, LineEnd = 2, Kinsoku = 4, PhraseEnd = 8} flag;
223b71206888 Initial import
thib
parents:
diff changeset
90 unsigned char r, g, b;
223b71206888 Initial import
thib
parents:
diff changeset
91 bool is_rev;
223b71206888 Initial import
thib
parents:
diff changeset
92 XKFont::Glyph* glyph;
223b71206888 Initial import
thib
parents:
diff changeset
93 };
223b71206888 Initial import
thib
parents:
diff changeset
94
223b71206888 Initial import
thib
parents:
diff changeset
95 struct TextGlyphStream : public std::vector<TextGlyph> {
223b71206888 Initial import
thib
parents:
diff changeset
96 XKFont::Font* font;
223b71206888 Initial import
thib
parents:
diff changeset
97 int width(void);
223b71206888 Initial import
thib
parents:
diff changeset
98 int height(void);
223b71206888 Initial import
thib
parents:
diff changeset
99 void SetColor(int r, int g, int b);
223b71206888 Initial import
thib
parents:
diff changeset
100 void SetReverse(bool rev);
223b71206888 Initial import
thib
parents:
diff changeset
101 };
223b71206888 Initial import
thib
parents:
diff changeset
102
223b71206888 Initial import
thib
parents:
diff changeset
103 #endif /* __TEXT_H__ */