update dev300-m57
[ooovba.git] / agg / inc / agg_glyph_raster_bin.h
blobf960735f2cc0e006e2192825a7415d1c72d5bf82
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #ifndef AGG_GLYPH_RASTER_BIN_INCLUDED
17 #define AGG_GLYPH_RASTER_BIN_INCLUDED
19 #include <string.h>
20 #include "agg_basics.h"
22 namespace agg
25 //========================================================glyph_raster_bin
26 template<class ColorT> class glyph_raster_bin
28 public:
29 typedef ColorT color_type;
31 //--------------------------------------------------------------------
32 struct glyph_rect
34 int x1,y1,x2,y2;
35 double dx, dy;
38 //--------------------------------------------------------------------
39 glyph_raster_bin(const int8u* font) :
40 m_font(font),
41 m_big_endian(false)
43 int t = 1;
44 if(*(char*)&t == 0) m_big_endian = true;
45 memset(m_span, 0, sizeof(m_span));
48 //--------------------------------------------------------------------
49 const int8u* font() const { return m_font; }
50 void font(const int8u* f) { m_font = f; }
52 //--------------------------------------------------------------------
53 double height() const { return m_font[0]; }
54 double base_line() const { return m_font[1]; }
56 //--------------------------------------------------------------------
57 template<class CharT>
58 double width(const CharT* str) const
60 unsigned start_char = m_font[2];
61 unsigned num_chars = m_font[3];
63 unsigned w = 0;
64 while(*str)
66 unsigned glyph = *str;
67 const int8u* bits = m_font + 4 + num_chars * 2 +
68 value(m_font + 4 + (glyph - start_char) * 2);
69 w += *bits;
70 ++str;
72 return w;
75 //--------------------------------------------------------------------
76 void prepare(glyph_rect* r, double x, double y, unsigned glyph, bool flip)
78 unsigned start_char = m_font[2];
79 unsigned num_chars = m_font[3];
81 m_bits = m_font + 4 + num_chars * 2 +
82 value(m_font + 4 + (glyph - start_char) * 2);
84 m_glyph_width = *m_bits++;
85 m_glyph_byte_width = (m_glyph_width + 7) >> 3;
87 r->x1 = int(x);
88 r->x2 = r->x1 + m_glyph_width - 1;
89 if(flip)
91 r->y1 = int(y) - m_font[0] + m_font[1];
92 r->y2 = r->y1 + m_font[0] - 1;
94 else
96 r->y1 = int(y) - m_font[1] + 1;
97 r->y2 = r->y1 + m_font[0] - 1;
99 r->dx = m_glyph_width;
100 r->dy = 0;
103 //--------------------------------------------------------------------
104 const cover_type* span(unsigned i)
106 i = m_font[0] - i - 1;
107 const int8u* bits = m_bits + i * m_glyph_byte_width;
108 unsigned j;
109 unsigned val = *bits;
110 unsigned nb = 0;
111 for(j = 0; j < m_glyph_width; ++j)
113 m_span[j] = (cover_type)((val & 0x80) ? cover_full : cover_none);
114 val <<= 1;
115 if(++nb >= 8)
117 val = *++bits;
118 nb = 0;
121 return m_span;
124 private:
125 //--------------------------------------------------------------------
126 int16u value(const int8u* p) const
128 int16u v;
129 if(m_big_endian)
131 *(int8u*)&v = p[1];
132 *((int8u*)&v + 1) = p[0];
134 else
136 *(int8u*)&v = p[0];
137 *((int8u*)&v + 1) = p[1];
139 return v;
143 //--------------------------------------------------------------------
144 const int8u* m_font;
145 bool m_big_endian;
146 cover_type m_span[32];
147 const int8u* m_bits;
148 unsigned m_glyph_width;
149 unsigned m_glyph_byte_width;
155 #endif