| 1 | /* |
|---|
| 2 | * Copyright (c) 2004 Kazunori "jagarl" Ueno |
|---|
| 3 | * Copyright (c) 2000, 2001 Yuki Sawada |
|---|
| 4 | * All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions |
|---|
| 8 | * are met: |
|---|
| 9 | * 1. Redistributions of source code must retain the above copyright |
|---|
| 10 | * notice, this list of conditions and the following disclaimer. |
|---|
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the |
|---|
| 13 | * documentation and/or other materials provided with the distribution. |
|---|
| 14 | * 3. The name of the author may not be used to endorse or promote products |
|---|
| 15 | * derived from this software without specific prior written permission. |
|---|
| 16 | * |
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #ifndef __FONT_TYPES_H__ |
|---|
| 30 | #define __FONT_TYPES_H__ |
|---|
| 31 | |
|---|
| 32 | #ifdef HAVE_CONFIG_H |
|---|
| 33 | # include "config.h" |
|---|
| 34 | #endif |
|---|
| 35 | |
|---|
| 36 | #include <vector> |
|---|
| 37 | |
|---|
| 38 | class TextHorizLayout; |
|---|
| 39 | class TextStream; |
|---|
| 40 | class TextGlyphStream; |
|---|
| 41 | |
|---|
| 42 | namespace XKFont { |
|---|
| 43 | class Font; |
|---|
| 44 | class Face; |
|---|
| 45 | class Peer; |
|---|
| 46 | class Glyph; |
|---|
| 47 | class Cache; |
|---|
| 48 | |
|---|
| 49 | struct Font { |
|---|
| 50 | public: |
|---|
| 51 | Font(const char* fontname, int size); |
|---|
| 52 | ~Font(); |
|---|
| 53 | Face* FaceLoad(double scale); |
|---|
| 54 | int vsize; |
|---|
| 55 | private: |
|---|
| 56 | class FontImpl* pimpl; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | struct Face { |
|---|
| 60 | public: |
|---|
| 61 | Face(const char *name, int index, int hsize, int vsize); |
|---|
| 62 | ~Face(); |
|---|
| 63 | Glyph* GlyphLoad(unsigned int code); |
|---|
| 64 | |
|---|
| 65 | private: |
|---|
| 66 | Cache* cache; |
|---|
| 67 | typedef std::vector<Peer*>::iterator iterator; |
|---|
| 68 | std::vector<Peer*> peer; |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | struct Peer { |
|---|
| 72 | public: |
|---|
| 73 | Peer(void) {} |
|---|
| 74 | virtual ~Peer() {}; |
|---|
| 75 | virtual bool GlyphCreate(unsigned int code, Glyph* glyph) = 0; |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | struct Glyph { |
|---|
| 79 | public: |
|---|
| 80 | struct _bitmap { |
|---|
| 81 | int width; |
|---|
| 82 | int rows; |
|---|
| 83 | unsigned char *buffer; |
|---|
| 84 | _bitmap() : buffer(0) {} |
|---|
| 85 | ~_bitmap() { delete[] buffer;} |
|---|
| 86 | } bitmap; |
|---|
| 87 | #if 0 |
|---|
| 88 | struct _metrics { |
|---|
| 89 | int ascender; |
|---|
| 90 | int descender; |
|---|
| 91 | } metrics; |
|---|
| 92 | #endif |
|---|
| 93 | struct _advance { |
|---|
| 94 | int x; |
|---|
| 95 | int y; |
|---|
| 96 | } advance; |
|---|
| 97 | |
|---|
| 98 | Glyph() : bitmap() {} |
|---|
| 99 | ~Glyph() {} |
|---|
| 100 | int bitmap_left; |
|---|
| 101 | int bitmap_top; |
|---|
| 102 | }; |
|---|
| 103 | |
|---|
| 104 | struct HorizLayout { |
|---|
| 105 | public: |
|---|
| 106 | HorizLayout(const char* fontname, int size); |
|---|
| 107 | ~HorizLayout(); |
|---|
| 108 | void Layout(::TextStream& stream, ::TextGlyphStream& glyph, std::vector<int>& lineheights, int width); |
|---|
| 109 | ::TextGlyphStream Layout(const char* str, int width, int r=0xff, int g=0xff, int b=0xff); |
|---|
| 110 | ::TextGlyphStream Layout(TextStream ts, int width); |
|---|
| 111 | private: |
|---|
| 112 | Font* font; |
|---|
| 113 | class ::TextHorizLayout* pimpl; |
|---|
| 114 | }; |
|---|
| 115 | |
|---|
| 116 | } /* end of namespace XKFont */ |
|---|
| 117 | |
|---|
| 118 | #endif |
|---|