Coverage Report

Created: 2021-08-22 09:07

/src/skia/third_party/externals/freetype/src/raster/ftrend1.c
Line
Count
Source (jump to first uncovered line)
1
/****************************************************************************
2
 *
3
 * ftrend1.c
4
 *
5
 *   The FreeType glyph rasterizer interface (body).
6
 *
7
 * Copyright (C) 1996-2021 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
30
  ft_raster1_init( FT_Renderer  render )
31
5
  {
32
5
    render->clazz->raster_class->raster_reset( render->raster, NULL, 0 );
33
34
5
    return FT_Err_Ok;
35
5
  }
36
37
38
  /* set render-specific mode */
39
  static FT_Error
40
  ft_raster1_set_mode( FT_Renderer  render,
41
                       FT_ULong     mode_tag,
42
                       FT_Pointer   data )
43
0
  {
44
    /* we simply pass it to the raster */
45
0
    return render->clazz->raster_class->raster_set_mode( render->raster,
46
0
                                                         mode_tag,
47
0
                                                         data );
48
0
  }
49
50
51
  /* transform a given glyph image */
52
  static FT_Error
53
  ft_raster1_transform( FT_Renderer       render,
54
                        FT_GlyphSlot      slot,
55
                        const FT_Matrix*  matrix,
56
                        const FT_Vector*  delta )
57
0
  {
58
0
    FT_Error error = FT_Err_Ok;
59
60
61
0
    if ( slot->format != render->glyph_format )
62
0
    {
63
0
      error = FT_THROW( Invalid_Argument );
64
0
      goto Exit;
65
0
    }
66
67
0
    if ( matrix )
68
0
      FT_Outline_Transform( &slot->outline, matrix );
69
70
0
    if ( delta )
71
0
      FT_Outline_Translate( &slot->outline, delta->x, delta->y );
72
73
0
  Exit:
74
0
    return error;
75
0
  }
76
77
78
  /* return the glyph's control box */
79
  static void
80
  ft_raster1_get_cbox( FT_Renderer   render,
81
                       FT_GlyphSlot  slot,
82
                       FT_BBox*      cbox )
83
0
  {
84
0
    FT_ZERO( cbox );
85
86
0
    if ( slot->format == render->glyph_format )
87
0
      FT_Outline_Get_CBox( &slot->outline, cbox );
88
0
  }
89
90
91
  /* convert a slot's glyph image into a bitmap */
92
  static FT_Error
93
  ft_raster1_render( FT_Renderer       render,
94
                     FT_GlyphSlot      slot,
95
                     FT_Render_Mode    mode,
96
                     const FT_Vector*  origin )
97
0
  {
98
0
    FT_Error     error   = FT_Err_Ok;
99
0
    FT_Outline*  outline = &slot->outline;
100
0
    FT_Bitmap*   bitmap  = &slot->bitmap;
101
0
    FT_Memory    memory  = render->root.memory;
102
0
    FT_Pos       x_shift = 0;
103
0
    FT_Pos       y_shift = 0;
104
105
0
    FT_Raster_Params  params;
106
107
108
    /* check glyph image format */
109
0
    if ( slot->format != render->glyph_format )
110
0
    {
111
0
      error = FT_THROW( Invalid_Argument );
112
0
      goto Exit;
113
0
    }
114
115
    /* check rendering mode */
116
0
    if ( mode != FT_RENDER_MODE_MONO )
117
0
    {
118
      /* raster1 is only capable of producing monochrome bitmaps */
119
0
      return FT_THROW( Cannot_Render_Glyph );
120
0
    }
121
122
    /* release old bitmap buffer */
123
0
    if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
124
0
    {
125
0
      FT_FREE( bitmap->buffer );
126
0
      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
127
0
    }
128
129
0
    if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) )
130
0
    {
131
0
      error = FT_THROW( Raster_Overflow );
132
0
      goto Exit;
133
0
    }
134
135
    /* allocate new one */
136
0
    if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
137
0
      goto Exit;
138
139
0
    slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
140
141
0
    x_shift = -slot->bitmap_left * 64;
142
0
    y_shift = ( (FT_Int)bitmap->rows - slot->bitmap_top ) * 64;
143
144
0
    if ( origin )
145
0
    {
146
0
      x_shift += origin->x;
147
0
      y_shift += origin->y;
148
0
    }
149
150
    /* translate outline to render it into the bitmap */
151
0
    if ( x_shift || y_shift )
152
0
      FT_Outline_Translate( outline, x_shift, y_shift );
153
154
    /* set up parameters */
155
0
    params.target = bitmap;
156
0
    params.source = outline;
157
0
    params.flags  = FT_RASTER_FLAG_DEFAULT;
158
159
    /* render outline into the bitmap */
160
0
    error = render->raster_render( render->raster, &params );
161
162
0
  Exit:
163
0
    if ( !error )
164
      /* everything is fine; the glyph is now officially a bitmap */
165
0
      slot->format = FT_GLYPH_FORMAT_BITMAP;
166
0
    else if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
167
0
    {
168
0
      FT_FREE( bitmap->buffer );
169
0
      slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
170
0
    }
171
172
0
    if ( x_shift || y_shift )
173
0
      FT_Outline_Translate( outline, -x_shift, -y_shift );
174
175
0
    return error;
176
0
  }
177
178
179
  FT_DEFINE_RENDERER(
180
    ft_raster1_renderer_class,
181
182
      FT_MODULE_RENDERER,
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  */
200
    (FT_Renderer_SetModeFunc)  ft_raster1_set_mode,   /* set_mode        */
201
202
    (FT_Raster_Funcs*)&ft_standard_raster             /* raster_class    */
203
  )
204
205
206
/* END */