94 |
} |
} |
95 |
|
|
96 |
|
|
97 |
|
static FT_Error |
98 |
|
ft_bitmap_assure_buffer( FT_Memory memory, |
99 |
|
FT_Bitmap* bitmap, |
100 |
|
FT_UInt xpixels, |
101 |
|
FT_UInt ypixels ) |
102 |
|
{ |
103 |
|
FT_Error error; |
104 |
|
int pitch; |
105 |
|
int new_pitch; |
106 |
|
FT_UInt ppb; |
107 |
|
FT_Int i; |
108 |
|
unsigned char* buffer; |
109 |
|
|
110 |
|
|
111 |
|
pitch = bitmap->pitch; |
112 |
|
if ( pitch < 0 ) |
113 |
|
pitch = -pitch; |
114 |
|
|
115 |
|
switch ( bitmap->pixel_mode ) |
116 |
|
{ |
117 |
|
case FT_PIXEL_MODE_MONO: |
118 |
|
ppb = 8; |
119 |
|
break; |
120 |
|
case FT_PIXEL_MODE_GRAY2: |
121 |
|
ppb = 4; |
122 |
|
break; |
123 |
|
case FT_PIXEL_MODE_GRAY4: |
124 |
|
ppb = 2; |
125 |
|
break; |
126 |
|
case FT_PIXEL_MODE_GRAY: |
127 |
|
ppb = 1; |
128 |
|
break; |
129 |
|
default: |
130 |
|
return FT_Err_Invalid_Glyph_Format; |
131 |
|
} |
132 |
|
|
133 |
|
/* check whether we must allocate memory */ |
134 |
|
if ( ypixels == 0 && pitch * ppb >= bitmap->width + xpixels ) |
135 |
|
return FT_Err_Ok; |
136 |
|
|
137 |
|
new_pitch = ( bitmap->width + xpixels + ppb - 1 ) / ppb; |
138 |
|
|
139 |
|
if ( FT_ALLOC( buffer, new_pitch * ( bitmap->rows + ypixels ) ) ) |
140 |
|
return error; |
141 |
|
|
142 |
|
if ( bitmap->pitch > 0 ) |
143 |
|
{ |
144 |
|
for ( i = 0; i < bitmap->rows; i++ ) |
145 |
|
FT_MEM_COPY( buffer + new_pitch * ( ypixels + i ), |
146 |
|
bitmap->buffer + pitch * i, pitch ); |
147 |
|
} |
148 |
|
else |
149 |
|
{ |
150 |
|
for ( i = 0; i < bitmap->rows; i++ ) |
151 |
|
FT_MEM_COPY( buffer + new_pitch * i, |
152 |
|
bitmap->buffer + pitch * i, pitch ); |
153 |
|
} |
154 |
|
|
155 |
|
FT_FREE( bitmap->buffer ); |
156 |
|
bitmap->buffer = buffer; |
157 |
|
|
158 |
|
if ( bitmap->pitch < 0 ) |
159 |
|
new_pitch = -new_pitch; |
160 |
|
|
161 |
|
/* set pitch only */ |
162 |
|
bitmap->pitch = new_pitch; |
163 |
|
|
164 |
|
return FT_Err_Ok; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
/* documentation is in ftbitmap.h */ |
169 |
|
|
170 |
|
FT_EXPORT_DEF( FT_Error ) |
171 |
|
FT_Bitmap_Embolden( FT_Library library, |
172 |
|
FT_Bitmap* bitmap, |
173 |
|
FT_Pos xStrength, |
174 |
|
FT_Pos yStrength ) |
175 |
|
{ |
176 |
|
FT_Error error; |
177 |
|
unsigned char* p; |
178 |
|
FT_Int i, x, y, pitch; |
179 |
|
FT_Int xstr, ystr; |
180 |
|
|
181 |
|
|
182 |
|
if ( !library ) |
183 |
|
return FT_Err_Invalid_Library_Handle; |
184 |
|
|
185 |
|
if ( !bitmap ) |
186 |
|
return FT_Err_Invalid_Argument; |
187 |
|
|
188 |
|
switch ( bitmap->pixel_mode ) |
189 |
|
{ |
190 |
|
case FT_PIXEL_MODE_GRAY2: |
191 |
|
case FT_PIXEL_MODE_GRAY4: |
192 |
|
return FT_Err_Invalid_Glyph_Format; |
193 |
|
} |
194 |
|
|
195 |
|
xstr = FT_PIX_ROUND( xStrength ) >> 6; |
196 |
|
ystr = FT_PIX_ROUND( yStrength ) >> 6; |
197 |
|
|
198 |
|
if ( xstr == 0 && ystr == 0 ) |
199 |
|
return FT_Err_Ok; |
200 |
|
else if ( xstr < 0 || ystr < 0 || xstr > 8 ) |
201 |
|
return FT_Err_Invalid_Argument; |
202 |
|
|
203 |
|
error = ft_bitmap_assure_buffer( library->memory, bitmap, xstr, ystr ); |
204 |
|
if ( error ) |
205 |
|
return error; |
206 |
|
|
207 |
|
pitch = bitmap->pitch; |
208 |
|
if ( pitch > 0 ) |
209 |
|
p = bitmap->buffer + pitch * ystr; |
210 |
|
else |
211 |
|
{ |
212 |
|
pitch = -pitch; |
213 |
|
p = bitmap->buffer + pitch * ( bitmap->rows - ystr - 1 ); |
214 |
|
} |
215 |
|
|
216 |
|
/* for each row */ |
217 |
|
for ( y = 0; y < bitmap->rows ; y++ ) |
218 |
|
{ |
219 |
|
/* |
220 |
|
* Horizontally: |
221 |
|
* |
222 |
|
* From the last pixel on, make each pixel or'ed with the |
223 |
|
* `xstr' pixels before it. |
224 |
|
*/ |
225 |
|
for ( x = pitch - 1; x >= 0; x-- ) |
226 |
|
{ |
227 |
|
unsigned char tmp; |
228 |
|
|
229 |
|
|
230 |
|
tmp = p[x]; |
231 |
|
for ( i = 1; i <= xstr; i++ ) |
232 |
|
{ |
233 |
|
if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO ) |
234 |
|
{ |
235 |
|
p[x] |= tmp >> i; |
236 |
|
|
237 |
|
/* the maximum value of 8 for `xstr' comes from here */ |
238 |
|
if ( x > 0 ) |
239 |
|
p[x] |= p[x - 1] << ( 8 - i ); |
240 |
|
} |
241 |
|
else if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY ) |
242 |
|
{ |
243 |
|
if ( x - i >= 0 ) |
244 |
|
{ |
245 |
|
if ( p[x] + p[x - i] > 0xff ) |
246 |
|
p[x] = 0xff; |
247 |
|
else |
248 |
|
p[x] += p[x - i]; |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
} |
253 |
|
|
254 |
|
/* |
255 |
|
* Vertically: |
256 |
|
* |
257 |
|
* Make the above `ystr' rows or'ed with it. |
258 |
|
*/ |
259 |
|
for ( x = 1; x <= ystr; x++ ) |
260 |
|
{ |
261 |
|
unsigned char* q; |
262 |
|
|
263 |
|
|
264 |
|
q = p - bitmap->pitch * x; |
265 |
|
for ( i = 0; i < pitch; i++ ) |
266 |
|
q[i] |= p[i]; |
267 |
|
} |
268 |
|
|
269 |
|
p += bitmap->pitch; |
270 |
|
} |
271 |
|
|
272 |
|
bitmap->width += xstr; |
273 |
|
bitmap->rows += ystr; |
274 |
|
|
275 |
|
return FT_Err_Ok; |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
/* documentation is in ftbitmap.h */ |
/* documentation is in ftbitmap.h */ |
280 |
|
|
281 |
FT_EXPORT_DEF( FT_Error ) |
FT_EXPORT_DEF( FT_Error ) |