1
|
|
-/** The 'dense' renderer */
|
|
1
|
+ /** The 'dense' renderer */
|
2
|
2
|
|
3
|
|
-/* END */ |
|
|
\ No newline at end of file |
|
3
|
+#include <freetype/ftoutln.h>
|
|
4
|
+#include <freetype/internal/ftdebug.h>
|
|
5
|
+#include <freetype/internal/ftobjs.h>
|
|
6
|
+#include "ftdenserend.h"
|
|
7
|
+#include "ftdense.h"
|
|
8
|
+
|
|
9
|
+#include "ftdenseerrs.h"
|
|
10
|
+
|
|
11
|
+ /**************************************************************************
|
|
12
|
+ *
|
|
13
|
+ * The macro FT_COMPONENT is used in trace mode. It is an implicit
|
|
14
|
+ * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
|
|
15
|
+ * messages during execution.
|
|
16
|
+ */
|
|
17
|
+#undef FT_COMPONENT
|
|
18
|
+#define FT_COMPONENT dense
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+ /**************************************************************************
|
|
23
|
+ *
|
|
24
|
+ * interface functions
|
|
25
|
+ *
|
|
26
|
+ */
|
|
27
|
+
|
|
28
|
+ /* set render specific modes or attributes */
|
|
29
|
+ static FT_Error
|
|
30
|
+ ft_dense_set_mode( FT_Renderer render, FT_ULong mode_tag, FT_Pointer data )
|
|
31
|
+ {
|
|
32
|
+ /* pass it to the rasterizer */
|
|
33
|
+ return render->clazz->raster_class->raster_set_mode( render->raster, mode_tag,
|
|
34
|
+ data );
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ /* transform the glyph using matrix and/or delta */
|
|
38
|
+ static FT_Error
|
|
39
|
+ ft_dense_transform( FT_Renderer render,
|
|
40
|
+ FT_GlyphSlot slot,
|
|
41
|
+ const FT_Matrix* matrix,
|
|
42
|
+ const FT_Vector* delta )
|
|
43
|
+ {
|
|
44
|
+
|
|
45
|
+ FT_Error error = FT_Err_Ok;
|
|
46
|
+
|
|
47
|
+ if ( slot->format != render->glyph_format )
|
|
48
|
+ {
|
|
49
|
+ error = FT_THROW( Invalid_Argument );
|
|
50
|
+ goto Exit;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ if ( matrix )
|
|
54
|
+ FT_Outline_Transform( &slot->outline, matrix );
|
|
55
|
+
|
|
56
|
+ if ( delta )
|
|
57
|
+ FT_Outline_Translate( &slot->outline, delta->x, delta->y );
|
|
58
|
+
|
|
59
|
+ Exit:
|
|
60
|
+ return error;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ /* return the control box of a glyph's outline */
|
|
64
|
+ static void
|
|
65
|
+ ft_dense_get_cbox( FT_Renderer render, FT_GlyphSlot slot, FT_BBox* cbox )
|
|
66
|
+ {
|
|
67
|
+
|
|
68
|
+ FT_ZERO( cbox );
|
|
69
|
+
|
|
70
|
+ if ( slot->format == render->glyph_format )
|
|
71
|
+ FT_Outline_Get_CBox( &slot->outline, cbox );
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ static FT_Error
|
|
75
|
+ ft_dense_init( FT_Renderer render )
|
|
76
|
+ {
|
|
77
|
+ return FT_Err_Ok;
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ static void
|
|
81
|
+ ft_dense_done( FT_Renderer render )
|
|
82
|
+ {
|
|
83
|
+ FT_UNUSED( render );
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ /* generate bitmap from a glyph's slot image */
|
|
87
|
+ static FT_Error
|
|
88
|
+ ft_dense_render( FT_Renderer render,
|
|
89
|
+ FT_GlyphSlot slot,
|
|
90
|
+ FT_Render_Mode mode,
|
|
91
|
+ const FT_Vector* origin )
|
|
92
|
+ {
|
|
93
|
+ FT_Error error = FT_Err_Ok;
|
|
94
|
+ FT_Outline* outline = &slot->outline;
|
|
95
|
+ FT_Bitmap* bitmap = &slot->bitmap;
|
|
96
|
+
|
|
97
|
+ /* FT_FREE and FT_ALLOC_MULT macros need a variable named 'memory' */
|
|
98
|
+ FT_Memory memory = render->root.memory;
|
|
99
|
+
|
|
100
|
+ FT_Pos x_shift = 0;
|
|
101
|
+ FT_Pos y_shift = 0;
|
|
102
|
+
|
|
103
|
+ FT_Raster_Params params;
|
|
104
|
+
|
|
105
|
+ /* check whether slot format is correct before rendering */
|
|
106
|
+ if ( slot->format != render->glyph_format )
|
|
107
|
+ {
|
|
108
|
+ error = FT_THROW( Invalid_Glyph_Format );
|
|
109
|
+ goto Exit;
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ /* check mode */
|
|
113
|
+ if ( mode != FT_RENDER_MODE_NORMAL &&
|
|
114
|
+ mode != FT_RENDER_MODE_LIGHT &&
|
|
115
|
+ mode != FT_RENDER_MODE_LCD &&
|
|
116
|
+ mode != FT_RENDER_MODE_LCD_V )
|
|
117
|
+ {
|
|
118
|
+ error = FT_THROW( Cannot_Render_Glyph );
|
|
119
|
+ goto Exit;
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+ /* deallocate the previously allocated bitmap */
|
|
124
|
+ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
|
|
125
|
+ {
|
|
126
|
+ FT_FREE( bitmap->buffer );
|
|
127
|
+ slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ /* preset the bitmap using the glyph's outline */
|
|
131
|
+ if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
|
|
132
|
+ {
|
|
133
|
+ error = FT_THROW( Raster_Overflow );
|
|
134
|
+ goto Exit;
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ if ( !bitmap->rows || !bitmap->pitch )
|
|
138
|
+ goto Exit;
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+ /* allocate new one */
|
|
142
|
+ if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
|
|
143
|
+ goto Exit;
|
|
144
|
+
|
|
145
|
+ slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
|
|
146
|
+
|
|
147
|
+ /* Calculate shift in 26.6 format */
|
|
148
|
+ x_shift = 64 * -slot->bitmap_left;
|
|
149
|
+ y_shift = 64 * -slot->bitmap_top;
|
|
150
|
+
|
|
151
|
+ if ( bitmap->pixel_mode == FT_PIXEL_MODE_LCD_V )
|
|
152
|
+ y_shift += 64 * (FT_Int)bitmap->rows / 3;
|
|
153
|
+ else
|
|
154
|
+ y_shift += 64 * (FT_Int)bitmap->rows;
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+ if ( origin )
|
|
158
|
+ {
|
|
159
|
+ x_shift += origin->x;
|
|
160
|
+ y_shift += origin->y;
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ /* translate outline to render it into the bitmap */
|
|
164
|
+ if ( x_shift || y_shift )
|
|
165
|
+ FT_Outline_Translate( outline, x_shift, y_shift );
|
|
166
|
+
|
|
167
|
+ /* set up parameters */
|
|
168
|
+ params.target = bitmap;
|
|
169
|
+ params.source = outline;
|
|
170
|
+
|
|
171
|
+ /* render the outline */
|
|
172
|
+ error =
|
|
173
|
+ render->raster_render( render->raster, (const FT_Raster_Params*)¶ms );
|
|
174
|
+
|
|
175
|
+ Exit:
|
|
176
|
+ if ( !error )
|
|
177
|
+ {
|
|
178
|
+ /* the glyph is successfully rendered to a bitmap */
|
|
179
|
+ slot->format = FT_GLYPH_FORMAT_BITMAP;
|
|
180
|
+ }
|
|
181
|
+ else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
|
|
182
|
+ {
|
|
183
|
+ FT_FREE( bitmap->buffer );
|
|
184
|
+ slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ if ( x_shift || y_shift )
|
|
188
|
+ FT_Outline_Translate( outline, -x_shift, -y_shift );
|
|
189
|
+
|
|
190
|
+ return error;
|
|
191
|
+ }
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+ FT_DEFINE_RENDERER(
|
|
195
|
+ ft_dense_renderer_class,
|
|
196
|
+
|
|
197
|
+ FT_MODULE_RENDERER,
|
|
198
|
+ sizeof( FT_RendererRec ),
|
|
199
|
+
|
|
200
|
+ "dense",
|
|
201
|
+ 0x10000L,
|
|
202
|
+ 0x20000L,
|
|
203
|
+
|
|
204
|
+ NULL,
|
|
205
|
+
|
|
206
|
+ (FT_Module_Constructor)ft_dense_init,
|
|
207
|
+ (FT_Module_Destructor)ft_dense_done,
|
|
208
|
+ (FT_Module_Requester)NULL,
|
|
209
|
+
|
|
210
|
+ FT_GLYPH_FORMAT_OUTLINE,
|
|
211
|
+
|
|
212
|
+ (FT_Renderer_RenderFunc)ft_dense_render, /* render_glyph */
|
|
213
|
+ (FT_Renderer_TransformFunc)ft_dense_transform, /* transform_glyph */
|
|
214
|
+ (FT_Renderer_GetCBoxFunc)ft_dense_get_cbox, /* get_glyph_cbox */
|
|
215
|
+ (FT_Renderer_SetModeFunc)ft_dense_set_mode, /* set_mode */
|
|
216
|
+
|
|
217
|
+ (FT_Raster_Funcs*)&ft_dense_raster /* raster_class */
|
|
218
|
+ )
|
|
219
|
+
|
|
220
|
+ /* END */ |