Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
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, 2013 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_DEBUG_H
21 #include FT_INTERNAL_OBJECTS_H
22 #include FT_OUTLINE_H
23 #include "ftrend1.h"
24 #include "ftraster.h"
25 #include "rastpic.h"
26 
27 #include "rasterrs.h"
28 
29 
30  /* initialize renderer -- init its raster */
31  static FT_Error
33  {
35 
36 
37  render->clazz->raster_class->raster_reset( render->raster,
38  library->raster_pool,
39  library->raster_pool_size );
40 
41  return FT_Err_Ok;
42  }
43 
44 
45  /* set render-specific mode */
46  static FT_Error
48  FT_ULong mode_tag,
50  {
51  /* we simply pass it to the raster */
52  return render->clazz->raster_class->raster_set_mode( render->raster,
53  mode_tag,
54  data );
55  }
56 
57 
58  /* transform a given glyph image */
59  static FT_Error
61  FT_GlyphSlot slot,
62  const FT_Matrix* matrix,
63  const FT_Vector* delta )
64  {
66 
67 
68  if ( slot->format != render->glyph_format )
69  {
70  error = FT_THROW( Invalid_Argument );
71  goto Exit;
72  }
73 
74  if ( matrix )
75  FT_Outline_Transform( &slot->outline, matrix );
76 
77  if ( delta )
78  FT_Outline_Translate( &slot->outline, delta->x, delta->y );
79 
80  Exit:
81  return error;
82  }
83 
84 
85  /* return the glyph's control box */
86  static void
88  FT_GlyphSlot slot,
89  FT_BBox* cbox )
90  {
91  FT_MEM_ZERO( cbox, sizeof ( *cbox ) );
92 
93  if ( slot->format == render->glyph_format )
94  FT_Outline_Get_CBox( &slot->outline, cbox );
95  }
96 
97 
98  /* convert a slot's glyph image into a bitmap */
99  static FT_Error
101  FT_GlyphSlot slot,
103  const FT_Vector* origin )
104  {
105  FT_Error error;
106  FT_Outline* outline;
107  FT_BBox cbox;
108  FT_UInt width, height, pitch;
109  FT_Bitmap* bitmap;
110  FT_Memory memory;
111 
113 
114 
115  /* check glyph image format */
116  if ( slot->format != render->glyph_format )
117  {
118  error = FT_THROW( Invalid_Argument );
119  goto Exit;
120  }
121 
122  /* check rendering mode */
123 #ifndef FT_CONFIG_OPTION_PIC
124  if ( mode != FT_RENDER_MODE_MONO )
125  {
126  /* raster1 is only capable of producing monochrome bitmaps */
127  if ( render->clazz == &ft_raster1_renderer_class )
128  return FT_THROW( Cannot_Render_Glyph );
129  }
130  else
131  {
132  /* raster5 is only capable of producing 5-gray-levels bitmaps */
133  if ( render->clazz == &ft_raster5_renderer_class )
134  return FT_THROW( Cannot_Render_Glyph );
135  }
136 #else /* FT_CONFIG_OPTION_PIC */
137  /* When PIC is enabled, we cannot get to the class object */
138  /* so instead we check the final character in the class name */
139  /* ("raster5" or "raster1"). Yes this is a hack. */
140  /* The "correct" thing to do is have different render function */
141  /* for each of the classes. */
142  if ( mode != FT_RENDER_MODE_MONO )
143  {
144  /* raster1 is only capable of producing monochrome bitmaps */
145  if ( render->clazz->root.module_name[6] == '1' )
146  return FT_THROW( Cannot_Render_Glyph );
147  }
148  else
149  {
150  /* raster5 is only capable of producing 5-gray-levels bitmaps */
151  if ( render->clazz->root.module_name[6] == '5' )
152  return FT_THROW( Cannot_Render_Glyph );
153  }
154 #endif /* FT_CONFIG_OPTION_PIC */
155 
156  outline = &slot->outline;
157 
158  /* translate the outline to the new origin if needed */
159  if ( origin )
160  FT_Outline_Translate( outline, origin->x, origin->y );
161 
162  /* compute the control box, and grid fit it */
163  FT_Outline_Get_CBox( outline, &cbox );
164 
165  /* undocumented but confirmed: bbox values get rounded */
166 #if 1
167  cbox.xMin = FT_PIX_ROUND( cbox.xMin );
168  cbox.yMin = FT_PIX_ROUND( cbox.yMin );
169  cbox.xMax = FT_PIX_ROUND( cbox.xMax );
170  cbox.yMax = FT_PIX_ROUND( cbox.yMax );
171 #else
172  cbox.xMin = FT_PIX_FLOOR( cbox.xMin );
173  cbox.yMin = FT_PIX_FLOOR( cbox.yMin );
174  cbox.xMax = FT_PIX_CEIL( cbox.xMax );
175  cbox.yMax = FT_PIX_CEIL( cbox.yMax );
176 #endif
177 
178  width = (FT_UInt)( ( cbox.xMax - cbox.xMin ) >> 6 );
179  height = (FT_UInt)( ( cbox.yMax - cbox.yMin ) >> 6 );
180 
181  if ( width > FT_USHORT_MAX || height > FT_USHORT_MAX )
182  {
183  error = FT_THROW( Invalid_Argument );
184  goto Exit;
185  }
186 
187  bitmap = &slot->bitmap;
188  memory = render->root.memory;
189 
190  /* release old bitmap buffer */
191  if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
192  {
193  FT_FREE( bitmap->buffer );
195  }
196 
197  /* allocate new one, depends on pixel format */
198  if ( !( mode & FT_RENDER_MODE_MONO ) )
199  {
200  /* we pad to 32 bits, only for backwards compatibility with FT 1.x */
201  pitch = FT_PAD_CEIL( width, 4 );
202  bitmap->pixel_mode = FT_PIXEL_MODE_GRAY;
203  bitmap->num_grays = 256;
204  }
205  else
206  {
207  pitch = ( ( width + 15 ) >> 4 ) << 1;
208  bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
209  }
210 
211  bitmap->width = width;
212  bitmap->rows = height;
213  bitmap->pitch = pitch;
214 
215  if ( FT_ALLOC_MULT( bitmap->buffer, pitch, height ) )
216  goto Exit;
217 
219 
220  /* translate outline to render it into the bitmap */
221  FT_Outline_Translate( outline, -cbox.xMin, -cbox.yMin );
222 
223  /* set up parameters */
224  params.target = bitmap;
225  params.source = outline;
226  params.flags = 0;
227 
228  if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY )
229  params.flags |= FT_RASTER_FLAG_AA;
230 
231  /* render outline into the bitmap */
232  error = render->raster_render( render->raster, &params );
233 
234  FT_Outline_Translate( outline, cbox.xMin, cbox.yMin );
235 
236  if ( error )
237  goto Exit;
238 
239  slot->format = FT_GLYPH_FORMAT_BITMAP;
240  slot->bitmap_left = (FT_Int)( cbox.xMin >> 6 );
241  slot->bitmap_top = (FT_Int)( cbox.yMax >> 6 );
242 
243  Exit:
244  return error;
245  }
246 
247 
248  FT_DEFINE_RENDERER( ft_raster1_renderer_class,
249 
251  sizeof ( FT_RendererRec ),
252 
253  "raster1",
254  0x10000L,
255  0x20000L,
256 
257  0, /* module specific interface */
258 
262  ,
263 
265 
270 
272  )
273 
274 
275  /* This renderer is _NOT_ part of the default modules; you will need */
276  /* to register it by hand in your application. It should only be */
277  /* used for backwards-compatibility with FT 1.x anyway. */
278  /* */
279  FT_DEFINE_RENDERER( ft_raster5_renderer_class,
280 
282  sizeof ( FT_RendererRec ),
283 
284  "raster5",
285  0x10000L,
286  0x20000L,
287 
288  0, /* module specific interface */
289 
290  (FT_Module_Constructor)ft_raster1_init,
293  ,
294 
296 
297  (FT_Renderer_RenderFunc) ft_raster1_render,
298  (FT_Renderer_TransformFunc)ft_raster1_transform,
299  (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,
300  (FT_Renderer_SetModeFunc) ft_raster1_set_mode,
301 
303  )
304 
305 
306 /* END */
GLint GLint GLsizei GLsizei height
#define FT_PIX_CEIL(x)
Definition: ftobjs.h:82
int FT_Error
Definition: fttypes.h:296
FT_ULong raster_pool_size
Definition: ftobjs.h:875
FT_Raster_Render_Func raster_render
Definition: ftobjs.h:700
FT_Error(* FT_Module_Constructor)(FT_Module module)
Definition: ftmodapi.h:121
unsigned long FT_ULong
Definition: fttypes.h:249
#define FT_STANDARD_RASTER_GET
Definition: rastpic.h:30
#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
return FT_THROW(Missing_Property)
unsigned char * buffer
Definition: ftimage.h:315
voidpf uLong int origin
Definition: ioapi.h:142
const FT_Bitmap * target
Definition: ftimage.h:1106
#define FT_RASTER_FLAG_AA
Definition: ftimage.h:1043
GLint GLint GLsizei width
FT_Int bitmap_top
Definition: freetype.h:1629
FT_Library library
Definition: cffdrivr.c:414
int pitch
Definition: ftimage.h:314
return FT_Err_Ok
Definition: ftbbox.c:645
FT_Raster raster
Definition: ftobjs.h:699
#define FT_GLYPH_OWN_BITMAP
Definition: ftobjs.h:409
void(* FT_Renderer_GetCBoxFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_BBox *cbox)
Definition: ftrender.h:101
FT_Outline outline
Definition: freetype.h:1631
#define FT_PAD_CEIL(x, n)
Definition: ftobjs.h:78
FT_ModuleRec root
Definition: ftobjs.h:694
#define FT_USHORT_MAX
Definition: ftstdlib.h:63
FT_Outline_Get_CBox(const FT_Outline *outline, FT_BBox *acbox)
Definition: ftoutln.c:468
FT_Bitmap bitmap
Definition: freetype.h:1627
FT_Module_Class root
Definition: ftrender.h:146
#define FT_PIX_FLOOR(x)
Definition: ftobjs.h:80
#define FT_FREE(ptr)
Definition: ftmemory.h:286
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:703
FT_Module_Constructor FT_Module_Requester
Definition: ftrend1.c:284
FT_Raster_Funcs * raster_class
Definition: ftrender.h:155
FT_Pos yMax
Definition: ftimage.h:119
FT_Pos xMin
Definition: ftimage.h:118
GLenum mode
FT_Raster_ResetFunc raster_reset
Definition: ftimage.h:1292
FT_Error error
Definition: cffdrivr.c:411
FT_Pos x
Definition: ftimage.h:77
GLsizei GLsizei GLenum GLenum const GLvoid * data
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:284
#define FT_MODULE_LIBRARY(x)
Definition: ftobjs.h:485
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:284
FT_Pos xMax
Definition: ftimage.h:119
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
int width
Definition: ftimage.h:313
FT_Glyph_Format glyph_format
Definition: ftobjs.h:696
FT_Module_Constructor FT_Renderer_RenderFunc ft_raster1_render
Definition: ftrend1.c:284
GLenum const GLfloat * params
const FT_String * module_name
Definition: ftmodapi.h:190
FT_Error(* FT_Renderer_SetModeFunc)(FT_Renderer renderer, FT_ULong mode_tag, FT_Pointer mode_ptr)
Definition: ftrender.h:107
FT_Byte * raster_pool
Definition: ftobjs.h:873
FT_Int bitmap_left
Definition: freetype.h:1628
FT_Glyph_Format format
Definition: freetype.h:1625
FT_Memory memory
Definition: ftobjs.h:477
unsigned int FT_UInt
Definition: fttypes.h:227
FT_Slot_Internal internal
Definition: freetype.h:1644
#define FT_ALLOC_MULT(ptr, count, item_size)
Definition: ftmemory.h:266
FT_Module_Constructor ft_raster1_init
Definition: ftrend1.c:284
char pixel_mode
Definition: ftimage.h:317
FT_Error(* FT_Renderer_TransformFunc)(FT_Renderer renderer, FT_GlyphSlot slot, const FT_Matrix *matrix, const FT_Vector *delta)
Definition: ftrender.h:94
FT_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
Definition: ftoutln.c:518
const void * source
Definition: ftimage.h:1107
FT_Renderer_Class * clazz
Definition: ftobjs.h:695
FT_Pos yMin
Definition: ftimage.h:118
GLuint GLenum matrix
FT_MODULE_RENDERER
Definition: ftrend1.c:281
#define FT_PIX_ROUND(x)
Definition: ftobjs.h:81
FT_Module_Constructor FT_GLYPH_FORMAT_OUTLINE
Definition: ftrend1.c:284
FT_Module_Constructor FT_Module_Destructor
Definition: ftrend1.c:284
FT_Module_Constructor FT_Renderer_RenderFunc FT_Renderer_TransformFunc FT_Renderer_GetCBoxFunc FT_Renderer_SetModeFunc ft_raster1_set_mode
Definition: ftrend1.c:284
FT_DEFINE_RENDERER(ft_raster1_renderer_class, FT_MODULE_RENDERER, sizeof(FT_RendererRec), "raster1", 0x10000L, 0x20000L, 0,(FT_Module_Constructor) ft_raster1_init,(FT_Module_Destructor) 0,(FT_Module_Requester) 0, FT_GLYPH_FORMAT_OUTLINE,(FT_Renderer_RenderFunc) ft_raster1_render,(FT_Renderer_TransformFunc) ft_raster1_transform,(FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox,(FT_Renderer_SetModeFunc) ft_raster1_set_mode,(FT_Raster_Funcs *) &FT_STANDARD_RASTER_GET) FT_DEFINE_RENDERER(ft_raster5_renderer_class
FT_Error(* FT_Renderer_RenderFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_UInt mode, const FT_Vector *origin)
Definition: ftrender.h:88