| 1 | /* |
|---|
| 2 | * Copyright (c) 2004 Kazunori "jagarl" Ueno |
|---|
| 3 | * All rights reserved. |
|---|
| 4 | * |
|---|
| 5 | * Redistribution and use in source and binary forms, with or without |
|---|
| 6 | * modification, are permitted provided that the following conditions |
|---|
| 7 | * are met: |
|---|
| 8 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 9 | * notice, this list of conditions and the following disclaimer. |
|---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | * documentation and/or other materials provided with the distribution. |
|---|
| 13 | * 3. The name of the author may not be used to endorse or promote products |
|---|
| 14 | * derived from this software without specific prior written permission. |
|---|
| 15 | * |
|---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #ifndef __TEXT_H__ |
|---|
| 29 | #define __TEXT_H__ |
|---|
| 30 | |
|---|
| 31 | #include <vector> |
|---|
| 32 | #include <string> |
|---|
| 33 | |
|---|
| 34 | struct TextElem { |
|---|
| 35 | typedef enum {glyph, escape, color, size} ElemType; |
|---|
| 36 | typedef enum { ret, pos_reset, name_start, name_end, ruby_start, ruby_startruby, ruby_end} EscapeType; |
|---|
| 37 | ElemType type; |
|---|
| 38 | union Impl { |
|---|
| 39 | struct { |
|---|
| 40 | int code; |
|---|
| 41 | } Glyph; |
|---|
| 42 | struct { |
|---|
| 43 | EscapeType type; |
|---|
| 44 | } Escape; |
|---|
| 45 | struct { |
|---|
| 46 | unsigned char r, g, b; |
|---|
| 47 | } Color; |
|---|
| 48 | struct { |
|---|
| 49 | float scale; |
|---|
| 50 | } Size; |
|---|
| 51 | } impl; |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | class TextStream { |
|---|
| 55 | public: |
|---|
| 56 | TextStream(void); |
|---|
| 57 | TextStream& operator =(const TextStream& from) { |
|---|
| 58 | container = from.container; |
|---|
| 59 | kanji_type = from.kanji_type; |
|---|
| 60 | return *this; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | static TextStream ParseMoji(const char* str, int r, int g, int b, int size); |
|---|
| 64 | |
|---|
| 65 | std::string Save(void); |
|---|
| 66 | void Load(const std::string&); |
|---|
| 67 | |
|---|
| 68 | void SetSize(double size); |
|---|
| 69 | void SetColor(unsigned char r, unsigned char g, unsigned char b); |
|---|
| 70 | void SetDefaultColor(unsigned char r, unsigned char g, unsigned char b); |
|---|
| 71 | void InsertColor(int begin_pos, int end_pos, unsigned char r, unsigned char g, unsigned char b); |
|---|
| 72 | void Clear(void); |
|---|
| 73 | void Add(const char* str); |
|---|
| 74 | void AddReturn(void); |
|---|
| 75 | void AddName(const char* name); |
|---|
| 76 | void AddRuby(const char* str, const char* ruby); |
|---|
| 77 | |
|---|
| 78 | void RemoveName(char* name, int namelen); |
|---|
| 79 | |
|---|
| 80 | public: |
|---|
| 81 | std::vector<TextElem> container; |
|---|
| 82 | typedef std::vector<TextElem>::iterator Iterator; |
|---|
| 83 | |
|---|
| 84 | enum {sjis, euc} kanji_type; |
|---|
| 85 | |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | namespace XKFont { |
|---|
| 89 | class Glyph; |
|---|
| 90 | class Font; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | struct TextGlyph { |
|---|
| 94 | int x,y; |
|---|
| 95 | enum Flag { Group = 1, LineEnd = 2, Kinsoku = 4, PhraseEnd = 8} flag; |
|---|
| 96 | unsigned char r, g, b; |
|---|
| 97 | bool is_rev; |
|---|
| 98 | XKFont::Glyph* glyph; |
|---|
| 99 | }; |
|---|
| 100 | |
|---|
| 101 | struct TextGlyphStream : public std::vector<TextGlyph> { |
|---|
| 102 | XKFont::Font* font; |
|---|
| 103 | int width(void); |
|---|
| 104 | int height(void); |
|---|
| 105 | void SetColor(int r, int g, int b); |
|---|
| 106 | void SetReverse(bool rev); |
|---|
| 107 | }; |
|---|
| 108 | |
|---|
| 109 | #endif /* __TEXT_H__ */ |
|---|