ReactOS 0.4.16-dev-981-g80eb313
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-2019 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
26#include "rasterrs.h"
27
28
29 /* initialize renderer -- init its raster */
30 static FT_Error
32 {
33 render->clazz->raster_class->raster_reset( render->raster, NULL, 0 );
34
35 return FT_Err_Ok;
36 }
37
38
39 /* set render-specific mode */
40 static FT_Error
42 FT_ULong mode_tag,
44 {
45 /* we simply pass it to the raster */
46 return render->clazz->raster_class->raster_set_mode( render->raster,
47 mode_tag,
48 data );
49 }
50
51
52 /* transform a given glyph image */
53 static FT_Error
56 const FT_Matrix* matrix,
57 const FT_Vector* delta )
58 {
60
61
62 if ( slot->format != render->glyph_format )
63 {
64 error = FT_THROW( Invalid_Argument );
65 goto Exit;
66 }
67
68 if ( matrix )
69 FT_Outline_Transform( &slot->outline, matrix );
70
71 if ( delta )
72 FT_Outline_Translate( &slot->outline, delta->x, delta->y );
73
74 Exit:
75 return error;
76 }
77
78
79 /* return the glyph's control box */
80 static void
83 FT_BBox* cbox )
84 {
85 FT_ZERO( cbox );
86
87 if ( slot->format == render->glyph_format )
88 FT_Outline_Get_CBox( &slot->outline, cbox );
89 }
90
91
92 /* convert a slot's glyph image into a bitmap */
93 static FT_Error
97 const FT_Vector* origin )
98 {
100 FT_Outline* outline = &slot->outline;
101 FT_Bitmap* bitmap = &slot->bitmap;
102 FT_Memory memory = render->root.memory;
103 FT_Pos x_shift = 0;
104 FT_Pos y_shift = 0;
105
107
108
109 /* check glyph image format */
110 if ( slot->format != render->glyph_format )
111 {
112 error = FT_THROW( Invalid_Argument );
113 goto Exit;
114 }
115
116 /* check rendering mode */
117 if ( mode != FT_RENDER_MODE_MONO )
118 {
119 /* raster1 is only capable of producing monochrome bitmaps */
120 return FT_THROW( Cannot_Render_Glyph );
121 }
122
123 /* release old bitmap buffer */
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
131 {
132 error = FT_THROW( Raster_Overflow );
133 goto Exit;
134 }
135
136 /* allocate new one */
137 if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
138 goto Exit;
139
140 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
141
142 x_shift = -slot->bitmap_left * 64;
143 y_shift = ( (FT_Int)bitmap->rows - slot->bitmap_top ) * 64;
144
145 if ( origin )
146 {
147 x_shift += origin->x;
148 y_shift += origin->y;
149 }
150
151 /* translate outline to render it into the bitmap */
152 if ( x_shift || y_shift )
153 FT_Outline_Translate( outline, x_shift, y_shift );
154
155 /* set up parameters */
156 params.target = bitmap;
157 params.source = outline;
159
160 /* render outline into the bitmap */
161 error = render->raster_render( render->raster, &params );
162
163 Exit:
164 if ( !error )
165 /* everything is fine; the glyph is now officially a bitmap */
166 slot->format = FT_GLYPH_FORMAT_BITMAP;
167 else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
168 {
169 FT_FREE( bitmap->buffer );
170 slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
171 }
172
173 if ( x_shift || y_shift )
174 FT_Outline_Translate( outline, -x_shift, -y_shift );
175
176 return error;
177 }
178
179
181 ft_raster1_renderer_class,
182
184 sizeof ( FT_RendererRec ),
185
186 "raster1",
187 0x10000L,
188 0x20000L,
189
190 NULL, /* module specific interface */
191
192 (FT_Module_Constructor)ft_raster1_init, /* module_init */
193 (FT_Module_Destructor) NULL, /* module_done */
194 (FT_Module_Requester) NULL, /* get_interface */
195
197
198 (FT_Renderer_RenderFunc) ft_raster1_render, /* render_glyph */
199 (FT_Renderer_TransformFunc)ft_raster1_transform, /* transform_glyph */
200 (FT_Renderer_GetCBoxFunc) ft_raster1_get_cbox, /* get_glyph_cbox */
202
203 (FT_Raster_Funcs*)&ft_standard_raster /* raster_class */
204 )
205
206
207/* END */
#define NULL
Definition: types.h:112
enum FT_Render_Mode_ FT_Render_Mode
@ FT_RENDER_MODE_MONO
Definition: freetype.h:3258
return FT_Err_Ok
Definition: ftbbox.c:527
#define FT_THROW(e)
Definition: ftdebug.h:241
#define FT_RASTER_FLAG_DEFAULT
Definition: ftimage.h:962
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:58
#define FT_ALLOC_MULT(ptr, count, item_size)
Definition: ftmemory.h:308
#define FT_FREE(ptr)
Definition: ftmemory.h:328
#define FT_ZERO(p)
Definition: ftmemory.h:237
void(* FT_Module_Destructor)(FT_Module module)
Definition: ftmodapi.h:169
#define FT_MODULE_RENDERER
Definition: ftmodapi.h:111
FT_Error(* FT_Module_Constructor)(FT_Module module)
Definition: ftmodapi.h:153
FT_Module_Interface(* FT_Module_Requester)(FT_Module module, const char *name)
Definition: ftmodapi.h:188
ft_glyphslot_preset_bitmap(FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector *origin)
Definition: ftobjs.c:348
#define FT_GLYPH_OWN_BITMAP
Definition: ftobjs.h:423
#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:1107
FT_Outline_Translate(const FT_Outline *outline, FT_Pos xOffset, FT_Pos yOffset)
Definition: ftoutln.c:509
FT_Outline_Transform(const FT_Outline *outline, const FT_Matrix *matrix)
Definition: ftoutln.c:698
FT_Outline_Get_CBox(const FT_Outline *outline, FT_BBox *acbox)
Definition: ftoutln.c:459
static FT_Error ft_raster1_transform(FT_Renderer render, FT_GlyphSlot slot, const FT_Matrix *matrix, const FT_Vector *delta)
Definition: ftrend1.c:54
static FT_Error ft_raster1_set_mode(FT_Renderer render, FT_ULong mode_tag, FT_Pointer data)
Definition: ftrend1.c:41
static void ft_raster1_get_cbox(FT_Renderer render, FT_GlyphSlot slot, FT_BBox *cbox)
Definition: ftrend1.c:81
static FT_Error ft_raster1_render(FT_Renderer render, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector *origin)
Definition: ftrend1.c:94
static FT_Error ft_raster1_init(FT_Renderer render)
Definition: ftrend1.c:31
FT_Error(* FT_Renderer_SetModeFunc)(FT_Renderer renderer, FT_ULong mode_tag, FT_Pointer mode_ptr)
Definition: ftrender.h:108
FT_Error(* FT_Renderer_TransformFunc)(FT_Renderer renderer, FT_GlyphSlot slot, const FT_Matrix *matrix, const FT_Vector *delta)
Definition: ftrender.h:95
void(* FT_Renderer_GetCBoxFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_BBox *cbox)
Definition: ftrender.h:102
FT_Error(* FT_Renderer_RenderFunc)(FT_Renderer renderer, FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector *origin)
Definition: ftrender.h:89
smooth FT_Module_Constructor FT_Module_Destructor FT_Module_Requester FT_GLYPH_FORMAT_OUTLINE
Definition: ftsmooth.c:465
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:65
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:116
static void Exit(void)
Definition: sock.c:1330
static void render(void)
Definition: ssstars.c:272
FT_Pos x
Definition: ftimage.h:78
FT_Pos y
Definition: ftimage.h:79
Definition: vfat.h:185
Definition: uimain.c:89
Definition: mesh.c:5330