1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
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.
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
20 #include "agg_basics.h"
25 //========================================================glyph_raster_bin
26 template<class ColorT
> class glyph_raster_bin
29 typedef ColorT color_type
;
31 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 glyph_raster_bin(const int8u
* font
) :
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 //--------------------------------------------------------------------
58 double width(const CharT
* str
) const
60 unsigned start_char
= m_font
[2];
61 unsigned num_chars
= m_font
[3];
66 unsigned glyph
= *str
;
67 const int8u
* bits
= m_font
+ 4 + num_chars
* 2 +
68 value(m_font
+ 4 + (glyph
- start_char
) * 2);
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;
88 r
->x2
= r
->x1
+ m_glyph_width
- 1;
91 r
->y1
= int(y
) - m_font
[0] + m_font
[1];
92 r
->y2
= r
->y1
+ m_font
[0] - 1;
96 r
->y1
= int(y
) - m_font
[1] + 1;
97 r
->y2
= r
->y1
+ m_font
[0] - 1;
99 r
->dx
= m_glyph_width
;
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
;
109 unsigned val
= *bits
;
111 for(j
= 0; j
< m_glyph_width
; ++j
)
113 m_span
[j
] = (cover_type
)((val
& 0x80) ? cover_full
: cover_none
);
125 //--------------------------------------------------------------------
126 int16u
value(const int8u
* p
) const
132 *((int8u
*)&v
+ 1) = p
[0];
137 *((int8u
*)&v
+ 1) = p
[1];
143 //--------------------------------------------------------------------
146 cover_type m_span
[32];
148 unsigned m_glyph_width
;
149 unsigned m_glyph_byte_width
;