w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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 (C) 1996-2020 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 <freetype/internal/ftdebug.h>
20 #include <freetype/internal/ftobjs.h>
21 #include <freetype/ftoutln.h>
22 #include "ftrend1.h"
23 #include "ftraster.h"
24 
25 #include "rasterrs.h"
26 
27 
28  /* initialize renderer -- init its raster */
29  static FT_Error
31  {
32  render->clazz->raster_class->raster_reset( render->raster, NULL, 0 );
33 
34  return FT_Err_Ok;
35  }
36 
37 
38  /* set render-specific mode */
39  static FT_Error
41  FT_ULong mode_tag,
43  {
44  /* we simply pass it to the raster */
45  return render->clazz->raster_class->raster_set_mode( render->raster,
46  mode_tag,
47  data );
48  }
49 
50 
51  /* transform a given glyph image */
52  static FT_Error
55  const FT_Matrix* matrix,
56  const FT_Vector* delta )
57  {
59 
60 
61  if ( slot->format != render->glyph_format )
62  {
63  error = FT_THROW( Invalid_Argument );
64  goto Exit;
65  }
66 
67  if ( matrix )
68  FT_Outline_Transform( &slot->outline, matrix );
69 
70  if ( delta )
71  FT_Outline_Translate( &slot->outline, delta->x, delta->y );
72 
73  Exit:
74  return error;
75  }
76 
77 
78  /* return the glyph's control box */
79  static void
82  FT_BBox* cbox )
83  {
84  FT_ZERO( cbox );
85 
86  if ( slot->format == render->glyph_format )
87  FT_Outline_Get_CBox( &slot->outline, cbox );
88  }
89 
90 
91  /* convert a slot's glyph image into a bitmap */
92  static FT_Error
96  const FT_Vector* origin )
97  {
99  FT_Outline* outline = &slot->outline;
100  FT_Bitmap* bitmap = &slot->bitmap;
101  FT_Memory memory = render->root.memory;
102  FT_Pos x_shift = 0;
103  FT_Pos y_shift = 0;
104 
106 
107 
108  /* check glyph image format */
109  if ( slot->format != render->glyph_format )
110  {
111  error = FT_THROW( Invalid_Argument );
112  goto Exit;
113  }
114 
115  /* check rendering mode */
116  if ( mode != FT_RENDER_MODE_MONO )
117  {
118  /* raster1 is only capable of producing monochrome bitmaps */
119  return FT_THROW( Cannot_Render_Glyph );
120  }
121 
122  /* release old bitmap buffer */
123  if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
124  {
125  FT_FREE( bitmap->buffer );
126  slot->internal->flags &= ~~FT_GLYPH_OWN_BITMAP;
127  }
128 
129  if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
130  {
131  error = FT_THROW( Raster_Overflow );
132  goto Exit;
133  }
134 
135  /* allocate new one */
136  if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
137  goto Exit;
138 
139  slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
140 
141  x_shift = -slot->bitmap_left * 64;
142  y_shift = ( (FT_Int)bitmap->rows - slot->bitmap_top ) * 64;
143 
144  if ( origin )
145  {
146  x_shift += origin->x;
147  y_shift += origin->y;
148  }
149 
150  /* translate outline to render it into the bitmap */
151  if ( x_shift || y_shift )
152  FT_Outline_Translate( outline, x_shift, y_shift );
153 
154  /* set up parameters */
155  params.target = bitmap;
156  params.source = outline;
158 
159  /* render outline into the bitmap */
160  error = render->raster_render( render->raster, &params );
161 
162  Exit:
163  if ( !error )
164  /* everything is fine; the glyph is now officially a bitmap */
165  slot->format = FT_GLYPH_FORMAT_BITMAP;
166  else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
167  {
168  FT_FREE( bitmap->buffer );
169  slot->internal->flags &= ~~FT_GLYPH_OWN_BITMAP;
170  }
171 
172  if ( x_shift || y_shift )
173  FT_Outline_Translate( outline, -x_shift, -y_shift );
174 
175  return error;
176  }
177 
178 
180  ft_raster1_renderer_class,
181 
183  sizeof ( FT_RendererRec ),
184 
185  "raster1",
186  0x10000L,
187  0x20000L,
188 
189  NULL, /* module specific interface */
190 
191  (FT_Module_Constructor)ft_raster1_init, /* module_init */
192  (FT_Module_Destructor) NULL, /* module_done */
193  (FT_Module_Requester) NULL, /* get_interface */
194 
196 
197  (FT_Renderer_RenderFunc) ft_raster1_render, /* render_glyph */
198  (FT_Renderer_TransformFunc)ft_raster1_transform, /* transform_glyph */
199  (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox, /* get_glyph_cbox */
201 
202  (FT_Raster_Funcs*)&ft_standard_raster /* raster_class */
203  )
204 
205 
206 /* END */
#define mode
Definition: aptex-macros.h:510
int params
Definition: definitions.c:42
#define error(a)
Definition: dviinfo.c:48
struct rect data
Definition: dvipdfm.c:64
void Exit(int code)
Definition: dvispc.c:374
enum FT_Render_Mode_ FT_Render_Mode
@ FT_RENDER_MODE_MONO
Definition: freetype.h:3251
#define FT_RASTER_FLAG_DEFAULT
Definition: ftimage.h:966
@ FT_GLYPH_FORMAT_OUTLINE
Definition: ftimage.h:749
@ FT_GLYPH_FORMAT_BITMAP
Definition: ftimage.h:748
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:57
void(* FT_Module_Destructor)(FT_Module module)
Definition: ftmodapi.h:168
#define FT_MODULE_RENDERER
Definition: ftmodapi.h:110
FT_Error(* FT_Module_Constructor)(FT_Module module)
Definition: ftmodapi.h:152
FT_Module_Interface(* FT_Module_Requester)(FT_Module module, const char *name)
Definition: ftmodapi.h:187
FT_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
Definition: ftoutln.c:507
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:706
FT_Outline_Get_CBox(const FT_Outline *outline, FT_BBox *acbox)
Definition: ftoutln.c:457
FT_Error(* FT_Renderer_SetModeFunc)(FT_Renderer renderer, FT_ULong mode_tag, FT_Pointer mode_ptr)
Definition: ftrender.h:107
FT_Error(* FT_Renderer_TransformFunc)(FT_Renderer renderer, FT_GlyphSlot slot, const FT_Matrix *matrix, const FT_Vector *delta)
Definition: ftrender.h:94
void(* FT_Renderer_GetCBoxFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_BBox *cbox)
Definition: ftrender.h:101
FT_Error(* FT_Renderer_RenderFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector *origin)
Definition: ftrender.h:88
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
void * FT_Pointer
Definition: fttypes.h:310
unsigned long FT_ULong
Definition: fttypes.h:253
int FT_Error
Definition: fttypes.h:299
signed int FT_Int
Definition: fttypes.h:220
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_ALLOC_MULT(ptr, count, item_size)
Definition: ftmemory.h:317
#define FT_FREE(ptr)
Definition: ftmemory.h:337
#define FT_ZERO(p)
Definition: ftmemory.h:246
#define NULL
Definition: ftobjs.h:61
FT_Bool ft_glyphslot_preset_bitmap(FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector *origin)
Definition: ftobjs.c:347
#define FT_GLYPH_OWN_BITMAP
Definition: ftobjs.h:421
#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:1108
return FT_Err_Ok
Definition: ftbbox.c:526
@ render
Definition: spc_dvips.c:728
char * bitmap
Definition: pbmpage.c:35
static int delta
Definition: pbmtolj.c:36
float ** matrix()
static FT_Error ft_raster1_transform(FT_Renderer render, FT_GlyphSlot slot, const FT_Matrix *matrix, const FT_Vector *delta)
Definition: ftrend1.c:53
static FT_Error ft_raster1_set_mode(FT_Renderer render, FT_ULong mode_tag, FT_Pointer data)
Definition: ftrend1.c:40
static void ft_raster1_get_cbox(FT_Renderer render, FT_GlyphSlot slot, FT_BBox *cbox)
Definition: ftrend1.c:80
static FT_Error ft_raster1_render(FT_Renderer render, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector *origin)
Definition: ftrend1.c:93
static FT_Error ft_raster1_init(FT_Renderer render)
Definition: ftrend1.c:30
slotref slot
Definition: opcodes.h:237
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78
Definition: gf2pbm.c:137
TT_Outline outline
Definition: ttf2pfb.c:167