ReactOS 0.4.16-dev-2354-g16de117
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
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
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
195 FT_GLYPH_FORMAT_OUTLINE,
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 NULL
Definition: types.h:112
enum FT_Render_Mode_ FT_Render_Mode
@ FT_RENDER_MODE_MONO
Definition: freetype.h:3251
return FT_Err_Ok
Definition: ftbbox.c:526
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_RASTER_FLAG_DEFAULT
Definition: ftimage.h:966
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:57
#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
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_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
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
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
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
unsigned long FT_ULong
Definition: fttypes.h:253
int FT_Error
Definition: fttypes.h:299
signed int FT_Int
Definition: fttypes.h:220
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint GLenum matrix
Definition: glext.h:9407
GLenum mode
Definition: glext.h:6217
GLenum const GLfloat * params
Definition: glext.h:5645
voidpf uLong int origin
Definition: ioapi.h:144
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:122
static void Exit(void)
Definition: sock.c:1330
static void render(void)
Definition: ssstars.c:272
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78
Definition: vfat.h:185
Definition: uimain.c:89
Definition: mesh.c:5330