zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ftrend1.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftrend1.c */
4 /* */
5 /* The FreeType glyph rasterizer interface (body). */
6 /* */
7 /* Copyright 1996-2003, 2005, 2006, 2011 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
17 
18 
19 #include <ft2build.h>
20 #include FT_INTERNAL_OBJECTS_H
21 #include FT_OUTLINE_H
22 #include "ftrend1.h"
23 #include "ftraster.h"
24 #include "rastpic.h"
25 
26 #include "rasterrs.h"
27 
28 
29  /* initialize renderer -- init its raster */
30  static FT_Error
32  {
34 
35 
36  render->clazz->raster_class->raster_reset( render->raster,
37  library->raster_pool,
38  library->raster_pool_size );
39 
40  return Raster_Err_Ok;
41  }
42 
43 
44  /* set render-specific mode */
45  static FT_Error
47  FT_ULong mode_tag,
49  {
50  /* we simply pass it to the raster */
51  return render->clazz->raster_class->raster_set_mode( render->raster,
52  mode_tag,
53  data );
54  }
55 
56 
57  /* transform a given glyph image */
58  static FT_Error
60  FT_GlyphSlot slot,
61  const FT_Matrix* matrix,
62  const FT_Vector* delta )
63  {
64  FT_Error error = Raster_Err_Ok;
65 
66 
67  if ( slot->format != render->glyph_format )
68  {
69  error = Raster_Err_Invalid_Argument;
70  goto Exit;
71  }
72 
73  if ( matrix )
74  FT_Outline_Transform( &slot->outline, matrix );
75 
76  if ( delta )
77  FT_Outline_Translate( &slot->outline, delta->x, delta->y );
78 
79  Exit:
80  return error;
81  }
82 
83 
84  /* return the glyph's control box */
85  static void
87  FT_GlyphSlot slot,
88  FT_BBox* cbox )
89  {
90  FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
91 
92  if ( slot->format == render->glyph_format )
93  FT_Outline_Get_CBox( &slot->outline, cbox );
94  }
95 
96 
97  /* convert a slot's glyph image into a bitmap */
98  static FT_Error
100  FT_GlyphSlot slot,
102  const FT_Vector* origin )
103  {
104  FT_Error error;
105  FT_Outline* outline;
106  FT_BBox cbox;
107  FT_UInt width, height, pitch;
108  FT_Bitmap* bitmap;
109  FT_Memory memory;
110 
112 
113 
114  /* check glyph image format */
115  if ( slot->format != render->glyph_format )
116  {
117  error = Raster_Err_Invalid_Argument;
118  goto Exit;
119  }
120 
121  /* check rendering mode */
122 #ifndef FT_CONFIG_OPTION_PIC
123  if ( mode != FT_RENDER_MODE_MONO )
124  {
125  /* raster1 is only capable of producing monochrome bitmaps */
126  if ( render->clazz == &ft_raster1_renderer_class )
127  return Raster_Err_Cannot_Render_Glyph;
128  }
129  else
130  {
131  /* raster5 is only capable of producing 5-gray-levels bitmaps */
132  if ( render->clazz == &ft_raster5_renderer_class )
133  return Raster_Err_Cannot_Render_Glyph;
134  }
135 #else /* FT_CONFIG_OPTION_PIC */
136  /* When PIC is enabled, we cannot get to the class object */
137  /* so instead we check the final character in the class name */
138  /* ("raster5" or "raster1"). Yes this is a hack. */
139  /* The "correct" thing to do is have different render function */
140  /* for each of the classes. */
141  if ( mode != FT_RENDER_MODE_MONO )
142  {
143  /* raster1 is only capable of producing monochrome bitmaps */
144  if ( render->clazz->root.module_name[6] == '1' )
145  return Raster_Err_Cannot_Render_Glyph;
146  }
147  else
148  {
149  /* raster5 is only capable of producing 5-gray-levels bitmaps */
150  if ( render->clazz->root.module_name[6] == '5' )
151  return Raster_Err_Cannot_Render_Glyph;
152  }
153 #endif /* FT_CONFIG_OPTION_PIC */
154 
155  outline = &slot->outline;
156 
157  /* translate the outline to the new origin if needed */
158  if ( origin )
159  FT_Outline_Translate( outline, origin->x, origin->y );
160 
161  /* compute the control box, and grid fit it */
162  FT_Outline_Get_CBox( outline, &cbox );
163 
164  /* undocumented but confirmed: bbox values get rounded */
165 #if 1
166  cbox.xMin = FT_PIX_ROUND( cbox.xMin );
167  cbox.yMin = FT_PIX_ROUND( cbox.yMin );
168  cbox.xMax = FT_PIX_ROUND( cbox.xMax );
169  cbox.yMax = FT_PIX_ROUND( cbox.yMax );
170 #else
171  cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
172  cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
173  cbox.xMax = FT_PIX_CEIL( cbox.xMax );
174  cbox.yMax = FT_PIX_CEIL( cbox.yMax );
175 #endif
176 
177  width = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
178  height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
179 
180  if ( width > FT_USHORT_MAX || height > FT_USHORT_MAX )
181  {
182  error = Raster_Err_Invalid_Argument;
183  goto Exit;
184  }
185 
186  bitmap = &slot->bitmap;
187  memory = render->root.memory;
188 
189  /* release old bitmap buffer */
190  if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
191  {
192  FT_FREE( bitmap->buffer );
194  }
195 
196  /* allocate new one, depends on pixel format */
197  if ( !( mode & FT_RENDER_MODE_MONO ) )
198  {
199  /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
200  pitch = FT_PAD_CEIL( width, 4 );
201  bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
202  bitmap->num_grays = 256;
203  }
204  else
205  {
206  pitch = ( ( width + 15 ) >> 4 ) << 1;
207  bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
208  }
209 
210  bitmap->width = width;
211  bitmap->rows = height;
212  bitmap->pitch = pitch;
213 
214  if ( FT_ALLOC_MULT( bitmap->buffer, pitch, height ) )
215  goto Exit;
216 
218 
219  /* translate outline to render it into the bitmap */
220  FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
221 
222  /* set up parameters */
223  params.target = bitmap;
224  params.source = outline;
225  params.flags = 0;
226 
227  if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
228  params.flags |= FT_RASTER_FLAG_AA;
229 
230  /* render outline into the bitmap */
231  error = render->raster_render( render->raster, &params );
232 
233  FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
234 
235  if ( error )
236  goto Exit;
237 
238  slot->format = FT_GLYPH_FORMAT_BITMAP;
239  slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
240  slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 );
241 
242  Exit:
243  return error;
244  }
245 
246 
247  FT_DEFINE_RENDERER( ft_raster1_renderer_class,
248 
250  sizeof ( FT_RendererRec ),
251 
252  "raster1",
253  0x10000L,
254  0x20000L,
255 
256  0, /* module specific interface */
257 
261  ,
262 
264 
269 
271  )
272 
273 
274  /* This renderer is _NOT_ part of the default modules; you will need */
275  /* to register it by hand in your application. It should only be */
276  /* used for backwards-compatibility with FT 1.x anyway. */
277  /* */
278  FT_DEFINE_RENDERER( ft_raster5_renderer_class,
279 
282 
284  0x10000L,
285  0x20000L,
286 
287  0, /* module specific interface */
288 
289  (FT_Module_Constructor)ft_raster1_init,
292  ,
293 
295 
296  (FT_Renderer_RenderFunc) ft_raster1_render,
297  (FT_Renderer_TransformFunc)ft_raster1_transform,
298  (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
299  (FT_Renderer_SetModeFunc) ft_raster1_set_mode,
300 
302  )
303 
304 
305 /* END */
#define FT_PIX_CEIL(x)
Definition: ftobjs.h:82
int FT_Error
Definition: fttypes.h:296
FT_ULong raster_pool_size
Definition: ftobjs.h:841
FT_Raster_Render_Func raster_render
Definition: ftobjs.h:666
unsigned long FT_ULong
Definition: fttypes.h:249
#define FT_STANDARD_RASTER_GET
Definition: rastpic.h:28
#define FT_MEM_ZERO(dest, count)
Definition: ftmemory.h:208
signed int FT_Int
Definition: fttypes.h:216
int rows
Definition: ftimage.h:312
enum FT_Render_Mode_ FT_Render_Mode
FT_Module_Interface(* FT_Module_Requester)(FT_Module module, const char *name)
Definition: ftmodapi.h:126
unsigned char * buffer
Definition: ftimage.h:315
const FT_Bitmap * target
Definition: ftimage.h:1106
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
#define FT_RASTER_FLAG_AA
Definition: ftimage.h:1043
EGLSurface EGLint EGLint EGLint EGLint height
Definition: eglext.h:293
FT_Int bitmap_top
Definition: freetype.h:1622
FT_Library library
Definition: cffdrivr.c:409
int pitch
Definition: ftimage.h:314
FT_Raster raster
Definition: ftobjs.h:665
#define FT_GLYPH_OWN_BITMAP
Definition: ftobjs.h:376
FT_Outline outline
Definition: freetype.h:1624
#define FT_PAD_CEIL(x, n)
Definition: ftobjs.h:78
GLenum GLvoid ** params
Definition: gl2ext.h:806
FT_ModuleRec root
Definition: ftobjs.h:660
#define FT_USHORT_MAX
Definition: ftstdlib.h:63
FT_Outline_Get_CBox(const FT_Outline *outline, FT_BBox *acbox)
Definition: ftoutln.c:460
FT_Bitmap bitmap
Definition: freetype.h:1620
FT_Module_Class root
Definition: ftrender.h:146
#define FT_PIX_FLOOR(x)
Definition: ftobjs.h:80
#define FT_MODULE_RENDERER
Definition: ftmodapi.h:56
#define FT_FREE(ptr)
Definition: ftmemory.h:286
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:695
FT_Raster_Funcs * raster_class
Definition: ftrender.h:155
FT_Pos yMax
Definition: ftimage.h:119
FT_Pos xMin
Definition: ftimage.h:118
FT_Raster_ResetFunc raster_reset
Definition: ftimage.h:1292
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
FT_Error error
Definition: cffdrivr.c:407
EGLSurface EGLint EGLint EGLint width
Definition: eglext.h:293
FT_Pos x
Definition: ftimage.h:77
void(* FT_Module_Destructor)(FT_Module module)
Definition: ftmodapi.h:109
void * FT_Pointer
Definition: fttypes.h:307
FT_Raster_SetModeFunc raster_set_mode
Definition: ftimage.h:1293
FT_Pos y
Definition: ftimage.h:78
FT_Module_Constructor FT_Renderer_RenderFunc FT_Renderer_TransformFunc ft_raster1_transform
Definition: ftrend1.c:283
#define FT_MODULE_LIBRARY(x)
Definition: ftobjs.h:451
raster5
Definition: ftrend1.c:283
short num_grays
Definition: ftimage.h:316
FT_Module_Constructor FT_Renderer_RenderFunc FT_Renderer_TransformFunc FT_Renderer_GetCBoxFunc ft_raster1_get_cbox
Definition: ftrend1.c:283
FT_Pos xMax
Definition: ftimage.h:119
GLuint GLenum matrix
Definition: glew.h:13408
void(* FT_Renderer_GetCBoxFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_BBox *cbox)
Definition: ftrender.h:101
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
int width
Definition: ftimage.h:313
#define FT_DEFINE_RENDERER(class_,flags_, size_, name_, version_, requires_,interface_, init_, done_, get_interface_,glyph_format_, render_glyph_, transform_glyph_,get_glyph_cbox_, set_mode_, raster_class_)
Definition: ftobjs.h:1120
FT_Glyph_Format glyph_format
Definition: ftobjs.h:662
FT_Error(* FT_Renderer_SetModeFunc)(FT_Renderer renderer, FT_ULong mode_tag, FT_Pointer mode_ptr)
Definition: ftrender.h:107
sizeof(FT_AutofitterRec)
FT_Error(* FT_Module_Constructor)(FT_Module module)
Definition: ftmodapi.h:94
FT_Module_Constructor FT_Renderer_RenderFunc ft_raster1_render
Definition: ftrend1.c:283
const FT_String * module_name
Definition: ftmodapi.h:163
FT_Byte * raster_pool
Definition: ftobjs.h:839
FT_Int bitmap_left
Definition: freetype.h:1621
FT_Glyph_Format format
Definition: freetype.h:1618
FT_Memory memory
Definition: ftobjs.h:443
unsigned int FT_UInt
Definition: fttypes.h:227
FT_Slot_Internal internal
Definition: freetype.h:1637
FT_Error(* FT_Renderer_TransformFunc)(FT_Renderer renderer, FT_GlyphSlot slot, const FT_Matrix *matrix, const FT_Vector *delta)
Definition: ftrender.h:94
#define FT_ALLOC_MULT(ptr, count, item_size)
Definition: ftmemory.h:266
FT_Module_Constructor ft_raster1_init
Definition: ftrend1.c:283
char pixel_mode
Definition: ftimage.h:317
FT_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
Definition: ftoutln.c:510
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
Definition: glext.h:4510
const void * source
Definition: ftimage.h:1107
FT_Renderer_Class * clazz
Definition: ftobjs.h:661
FT_Error(* FT_Renderer_RenderFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_UInt mode, const FT_Vector *origin)
Definition: ftrender.h:88
FT_Pos yMin
Definition: ftimage.h:118
GLenum mode
Definition: glew.h:2394
#define FT_PIX_ROUND(x)
Definition: ftobjs.h:81
FT_Module_Constructor FT_GLYPH_FORMAT_OUTLINE
Definition: ftrend1.c:283
FT_Module_Constructor FT_Renderer_RenderFunc FT_Renderer_TransformFunc FT_Renderer_GetCBoxFunc FT_Renderer_SetModeFunc ft_raster1_set_mode
Definition: ftrend1.c:283