... |
... |
@@ -4,11 +4,11 @@ |
4
|
4
|
#undef FT_COMPONENT
|
5
|
5
|
#define FT_COMPONENT dense
|
6
|
6
|
|
7
|
|
-#include "ftdense.h"
|
8
|
7
|
#include <freetype/ftoutln.h>
|
9
|
8
|
#include <freetype/internal/ftcalc.h>
|
10
|
9
|
#include <freetype/internal/ftdebug.h>
|
11
|
10
|
#include <freetype/internal/ftobjs.h>
|
|
11
|
+#include "ftdense.h"
|
12
|
12
|
|
13
|
13
|
#include <math.h>
|
14
|
14
|
#include "ftdenseerrs.h"
|
... |
... |
@@ -17,20 +17,17 @@ |
17
|
17
|
#define PIXEL_BITS 8
|
18
|
18
|
|
19
|
19
|
#define ONE_PIXEL ( 1 << PIXEL_BITS )
|
20
|
|
-#define TRUNC( x ) ( int )( ( x ) >> PIXEL_BITS )
|
|
20
|
+#define TRUNC( x ) (int)( ( x ) >> PIXEL_BITS )
|
21
|
21
|
|
22
|
22
|
#define UPSCALE( x ) ( ( x ) * ( ONE_PIXEL >> 6 ) )
|
23
|
23
|
#define DOWNSCALE( x ) ( ( x ) >> ( PIXEL_BITS - 6 ) )
|
24
|
24
|
|
25
|
|
-
|
26
|
|
-
|
27
|
25
|
typedef struct dense_TRaster_
|
28
|
26
|
{
|
29
|
27
|
void* memory;
|
30
|
28
|
|
31
|
29
|
} dense_TRaster, *dense_PRaster;
|
32
|
30
|
|
33
|
|
-
|
34
|
31
|
static RasterFP_Point
|
35
|
32
|
Lerp( float aT, RasterFP_Point aP0, RasterFP_Point aP1 )
|
36
|
33
|
{
|
... |
... |
@@ -49,29 +46,33 @@ dense_move_to( const FT_Vector* to, RasterFP* aRasterFP ) |
49
|
46
|
y = UPSCALE( to->y );
|
50
|
47
|
aRasterFP->prev_x = x;
|
51
|
48
|
aRasterFP->prev_y = y;
|
52
|
|
- //printf( "last point is {%f, %f}", lp.m_x, lp.m_y );
|
|
49
|
+ // printf( "last point is {%f, %f}", lp.m_x, lp.m_y );
|
53
|
50
|
return 0;
|
54
|
51
|
}
|
55
|
52
|
|
56
|
53
|
static int
|
57
|
54
|
dense_line_to( const FT_Vector* to, RasterFP* aRasterFP )
|
58
|
55
|
{
|
59
|
|
- printf("dense_line_to: %d, %d\n", to->x, to->y);
|
60
|
|
- RasterFP_Point tp = {UPSCALE(to->x), UPSCALE(to->y)};
|
|
56
|
+ printf( "dense_line_to: %d, %d\n", to->x, to->y );
|
|
57
|
+ RasterFP_Point tp = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
61
|
58
|
RasterFP_DrawLine( aRasterFP, tp.m_x, tp.m_y );
|
62
|
59
|
dense_move_to( to, aRasterFP );
|
63
|
60
|
return 0;
|
64
|
61
|
}
|
65
|
|
-void swap(long int *a, long int *b){
|
|
62
|
+void
|
|
63
|
+swap( long int* a, long int* b )
|
|
64
|
+{
|
66
|
65
|
long int temp = *a;
|
67
|
|
- *a = *b;
|
68
|
|
- *b = temp;
|
|
66
|
+ *a = *b;
|
|
67
|
+ *b = temp;
|
69
|
68
|
}
|
70
|
69
|
|
71
|
|
-void swapold(unsigned char *a, unsigned char *b){
|
|
70
|
+void
|
|
71
|
+swapold( unsigned char* a, unsigned char* b )
|
|
72
|
+{
|
72
|
73
|
unsigned char temp = *a;
|
73
|
|
- *a = *b;
|
74
|
|
- *b = temp;
|
|
74
|
+ *a = *b;
|
|
75
|
+ *b = temp;
|
75
|
76
|
}
|
76
|
77
|
|
77
|
78
|
void
|
... |
... |
@@ -88,19 +89,19 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y ) |
88
|
89
|
// aP1.m_x -= aRasterFP->m_origin_x;
|
89
|
90
|
// aP1.m_y -= aRasterFP->m_origin_y;
|
90
|
91
|
|
91
|
|
- from_x = TRUNC((int)from_x );
|
92
|
|
- from_y = TRUNC((int)from_y );
|
93
|
|
- to_x = TRUNC((int)to_x );
|
94
|
|
- to_y = TRUNC((int)to_y );
|
|
92
|
+ from_x = TRUNC( (int)from_x );
|
|
93
|
+ from_y = TRUNC( (int)from_y );
|
|
94
|
+ to_x = TRUNC( (int)to_x );
|
|
95
|
+ to_y = TRUNC( (int)to_y );
|
95
|
96
|
|
96
|
97
|
float dir;
|
97
|
98
|
if ( from_y < to_y )
|
98
|
99
|
dir = 1;
|
99
|
100
|
else
|
100
|
101
|
{
|
101
|
|
- dir = -1;
|
102
|
|
- swap(&from_x, &to_x);
|
103
|
|
- swap(&from_y, &to_y);
|
|
102
|
+ dir = -1;
|
|
103
|
+ swap( &from_x, &to_x );
|
|
104
|
+ swap( &from_y, &to_y );
|
104
|
105
|
}
|
105
|
106
|
|
106
|
107
|
// Clip to the height.
|
... |
... |
@@ -125,21 +126,21 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y ) |
125
|
126
|
by recursive calls.
|
126
|
127
|
*/
|
127
|
128
|
|
128
|
|
- /* @QUES: This code isn't present in font-rs. It was added later by graham asher
|
129
|
|
- I have a very strong feeling that this isn't necessary.
|
130
|
|
- Since probably the outline is already fitted in the bounding box. I tested
|
131
|
|
- this code a little, removing it doesn't seem to make any difference*/
|
|
129
|
+ /* @QUES: This code isn't present in font-rs. It was added later by graham
|
|
130
|
+ asher I have a very strong feeling that this isn't necessary. Since probably
|
|
131
|
+ the outline is already fitted in the bounding box. I tested this code a
|
|
132
|
+ little, removing it doesn't seem to make any difference*/
|
132
|
133
|
RasterFP_Point intersect = { 0, 0 };
|
133
|
134
|
int recursive = 0;
|
134
|
135
|
if ( from_x >= aRasterFP->m_w && to_x >= aRasterFP->m_w )
|
135
|
136
|
{
|
136
|
137
|
from_x = to_x = (float)aRasterFP->m_w;
|
137
|
|
- dxdy = 0;
|
|
138
|
+ dxdy = 0;
|
138
|
139
|
}
|
139
|
140
|
else if ( from_x <= 0 && to_x <= 0 )
|
140
|
141
|
{
|
141
|
142
|
from_x = to_x = 0;
|
142
|
|
- dxdy = 0;
|
|
143
|
+ dxdy = 0;
|
143
|
144
|
}
|
144
|
145
|
else if ( ( from_x < 0 ) != ( to_x < 0 ) )
|
145
|
146
|
{
|
... |
... |
@@ -180,7 +181,6 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y ) |
180
|
181
|
int y_limit = (int)ceil( to_y );
|
181
|
182
|
float* m_a = aRasterFP->m_a;
|
182
|
183
|
|
183
|
|
-
|
184
|
184
|
for ( int y = y0; y < y_limit; y++ )
|
185
|
185
|
{
|
186
|
186
|
int linestart = y * aRasterFP->m_w;
|
... |
... |
@@ -254,11 +254,10 @@ dense_conic_to( const FT_Vector* control, |
254
|
254
|
}
|
255
|
255
|
|
256
|
256
|
void
|
257
|
|
-RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
|
257
|
+RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
258
|
258
|
const FT_Vector* control,
|
259
|
259
|
const FT_Vector* to )
|
260
|
260
|
{
|
261
|
|
-
|
262
|
261
|
// assert( aRasterFP );
|
263
|
262
|
/*
|
264
|
263
|
Calculate devsq as the square of four times the
|
... |
... |
@@ -272,21 +271,23 @@ RasterFP_DrawQuadratic( RasterFP* aRasterFP, |
272
|
271
|
The division by four is omitted to save time.
|
273
|
272
|
*/
|
274
|
273
|
|
275
|
|
- RasterFP_Point aP0 = {aRasterFP->prev_x, aRasterFP->prev_y};
|
276
|
|
- RasterFP_Point aP1 = {UPSCALE(control->x), UPSCALE(control->y)};
|
277
|
|
- RasterFP_Point aP2 = {UPSCALE(to->x), UPSCALE(to->y)};
|
|
274
|
+ RasterFP_Point aP0 = { aRasterFP->prev_x, aRasterFP->prev_y };
|
|
275
|
+ RasterFP_Point aP1 = { UPSCALE( control->x ), UPSCALE( control->y ) };
|
|
276
|
+ RasterFP_Point aP2 = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
|
277
|
+
|
278
|
278
|
|
279
|
279
|
float devx = aP0.m_x - aP1.m_x - aP1.m_x + aP2.m_x;
|
280
|
280
|
float devy = aP0.m_y - aP1.m_y - aP1.m_y + aP2.m_y;
|
281
|
281
|
float devsq = devx * devx + devy * devy;
|
282
|
282
|
|
283
|
|
-
|
284
|
|
-
|
285
|
283
|
if ( devsq < 0.333f )
|
286
|
284
|
{
|
287
|
|
- RasterFP_DrawLine(aRasterFP, aP2.m_x, aP2.m_y );
|
|
285
|
+ RasterFP_DrawLine( aRasterFP, aP2.m_x, aP2.m_y );
|
|
286
|
+ aRasterFP->prev_x = aP2.m_x;
|
|
287
|
+ aRasterFP->prev_y = aP2.m_y;
|
288
|
288
|
return;
|
289
|
289
|
}
|
|
290
|
+
|
290
|
291
|
|
291
|
292
|
/*
|
292
|
293
|
According to Raph Levien, the reason for the subdivision by n (instead of
|
... |
... |
@@ -298,20 +299,25 @@ RasterFP_DrawQuadratic( RasterFP* aRasterFP, |
298
|
299
|
expected to be 33% more in the limit".
|
299
|
300
|
*/
|
300
|
301
|
|
|
302
|
+
|
301
|
303
|
const float tol = 3.0f;
|
302
|
304
|
int n = (int)floor( sqrt( sqrt( tol * devsq ) ) );
|
303
|
|
- // RasterFP_Point p = aP0;
|
|
305
|
+ RasterFP_Point p = aP0;
|
304
|
306
|
float nrecip = 1.0f / ( n + 1.0f );
|
305
|
307
|
float t = 0.0f;
|
306
|
308
|
for ( int i = 0; i < n; i++ )
|
307
|
309
|
{
|
308
|
310
|
t += nrecip;
|
309
|
311
|
RasterFP_Point next = Lerp( t, Lerp( t, aP0, aP1 ), Lerp( t, aP1, aP2 ) );
|
310
|
|
- RasterFP_DrawLine(aRasterFP , next.m_x, next.m_y);
|
311
|
|
- //p = next;
|
|
312
|
+ RasterFP_DrawLine( aRasterFP, next.m_x, next.m_y );
|
|
313
|
+ aRasterFP->prev_x = next.m_x;
|
|
314
|
+ aRasterFP->prev_y = next.m_y;
|
|
315
|
+ p = next;
|
312
|
316
|
}
|
313
|
317
|
|
314
|
|
- RasterFP_DrawLine( aRasterFP, aP2.m_x, aP2.m_y);
|
|
318
|
+ RasterFP_DrawLine(aRasterFP,aP2.m_x,aP2.m_y);
|
|
319
|
+ aRasterFP->prev_x = aP2.m_x;
|
|
320
|
+ aRasterFP->prev_y = aP2.m_y;
|
315
|
321
|
}
|
316
|
322
|
|
317
|
323
|
static int
|
... |
... |
@@ -320,11 +326,11 @@ dense_cubic_to( const FT_Vector* control1, |
320
|
326
|
const FT_Vector* to,
|
321
|
327
|
RasterFP* aRasterFP )
|
322
|
328
|
{
|
323
|
|
- RasterFP_Point ap1 = { UPSCALE(control1->x), UPSCALE(control1->y) };
|
324
|
|
- RasterFP_Point ap2 = { UPSCALE(control2->x), UPSCALE(control2->y) };
|
325
|
|
- RasterFP_Point ap3 = { UPSCALE(to->x), UPSCALE(to->y) };
|
|
329
|
+ RasterFP_Point ap1 = { UPSCALE( control1->x ), UPSCALE( control1->y ) };
|
|
330
|
+ RasterFP_Point ap2 = { UPSCALE( control2->x ), UPSCALE( control2->y ) };
|
|
331
|
+ RasterFP_Point ap3 = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
326
|
332
|
|
327
|
|
- RasterFP_Point lP = {aRasterFP->prev_x, aRasterFP->prev_y};
|
|
333
|
+ RasterFP_Point lP = { aRasterFP->prev_x, aRasterFP->prev_y };
|
328
|
334
|
|
329
|
335
|
RasterFP_DrawCubic( aRasterFP, lP, ap1, ap2, ap3 );
|
330
|
336
|
return 0;
|
... |
... |
@@ -349,7 +355,7 @@ RasterFP_DrawCubic( RasterFP* aRasterFP, |
349
|
355
|
|
350
|
356
|
if ( devsq < 0.333f )
|
351
|
357
|
{
|
352
|
|
- RasterFP_DrawLine( aRasterFP, aP3.m_x , aP3.m_y);
|
|
358
|
+ RasterFP_DrawLine( aRasterFP, aP3.m_x, aP3.m_y );
|
353
|
359
|
return;
|
354
|
360
|
}
|
355
|
361
|
|
... |
... |
@@ -383,7 +389,7 @@ dense_raster_new( FT_Memory memory, dense_PRaster* araster ) |
383
|
389
|
raster->memory = memory;
|
384
|
390
|
|
385
|
391
|
*araster = raster;
|
386
|
|
- printf("dense_raster_new\n");
|
|
392
|
+ printf( "dense_raster_new\n" );
|
387
|
393
|
return error;
|
388
|
394
|
}
|
389
|
395
|
|
... |
... |
@@ -406,7 +412,7 @@ dense_raster_reset( FT_Raster raster, |
406
|
412
|
FT_UNUSED( raster );
|
407
|
413
|
FT_UNUSED( pool_base );
|
408
|
414
|
FT_UNUSED( pool_size );
|
409
|
|
- printf("dense_raster_reset\n");
|
|
415
|
+ printf( "dense_raster_reset\n" );
|
410
|
416
|
}
|
411
|
417
|
|
412
|
418
|
/* @QUES: This methodisnt't called in normal ftlint execution*/
|
... |
... |
@@ -417,7 +423,7 @@ dense_raster_set_mode( FT_Raster raster, unsigned long mode, void* args ) |
417
|
423
|
FT_UNUSED( mode );
|
418
|
424
|
FT_UNUSED( args );
|
419
|
425
|
|
420
|
|
- printf("dense_raster_set_mode\n");
|
|
426
|
+ printf( "dense_raster_set_mode\n" );
|
421
|
427
|
return 0; /* nothing to do */
|
422
|
428
|
}
|
423
|
429
|
|
... |
... |
@@ -432,10 +438,9 @@ FT_DEFINE_OUTLINE_FUNCS( dense_decompose_funcs, |
432
|
438
|
0 /* delta */
|
433
|
439
|
)
|
434
|
440
|
|
435
|
|
-
|
436
|
|
-/* @QUES: So, this calls FT_Outline_Decompose, that calls the move to,
|
437
|
|
-line to, conic to, cubic to interface methods. The aRasterFP structure stores the
|
438
|
|
-well, stuff in its m_a and finally renders it to the target->buffer*/
|
|
441
|
+/* @QUES: So, this calls FT_Outline_Decompose, that calls the move to,
|
|
442
|
+line to, conic to, cubic to interface methods. The aRasterFP structure stores
|
|
443
|
+the well, stuff in its m_a and finally renders it to the target->buffer*/
|
439
|
444
|
static int
|
440
|
445
|
dense_render_glyph( RasterFP* aRasterFP, const FT_Bitmap* target )
|
441
|
446
|
{
|
... |
... |
@@ -444,37 +449,36 @@ dense_render_glyph( RasterFP* aRasterFP, const FT_Bitmap* target ) |
444
|
449
|
// Render into bitmap
|
445
|
450
|
const float* source = aRasterFP->m_a;
|
446
|
451
|
|
447
|
|
-
|
448
|
|
- //printf( "Outputting bitmap\n" );
|
449
|
|
- // for ( int i = 0; i < aRasterFP->m_h; i++ )
|
450
|
|
- // {
|
451
|
|
- // printf( "\n" );
|
452
|
|
- // for ( int j = 0; j < aRasterFP->m_w; j++ )
|
453
|
|
- // {
|
454
|
|
- // float strength = *( source + ( i * aRasterFP->m_w + j ) );
|
455
|
|
- // if ( strength > 0.90 )
|
456
|
|
- // {
|
457
|
|
- // printf( "@|" );
|
458
|
|
- // }
|
459
|
|
- // else if ( strength > 0.70 )
|
460
|
|
- // {
|
461
|
|
- // printf( "#|" );
|
462
|
|
- // }
|
463
|
|
- // else if ( strength > 0.45 )
|
464
|
|
- // {
|
465
|
|
- // printf( "+|" );
|
466
|
|
- // }
|
467
|
|
- // else if ( strength > 0.20 )
|
468
|
|
- // {
|
469
|
|
- // printf( "*|" );
|
470
|
|
- // }
|
471
|
|
- // else
|
472
|
|
- // {
|
473
|
|
- // printf( ".|" );
|
474
|
|
- // }
|
475
|
|
- // }
|
476
|
|
- // }
|
477
|
|
- // printf( "\n" );
|
|
452
|
+ // printf( "Outputting bitmap\n" );
|
|
453
|
+ // for ( int i = 0; i < aRasterFP->m_h; i++ )
|
|
454
|
+ // {
|
|
455
|
+ // printf( "\n" );
|
|
456
|
+ // for ( int j = 0; j < aRasterFP->m_w; j++ )
|
|
457
|
+ // {
|
|
458
|
+ // float strength = *( source + ( i * aRasterFP->m_w + j ) );
|
|
459
|
+ // if ( strength > 0.90 )
|
|
460
|
+ // {
|
|
461
|
+ // printf( "@|" );
|
|
462
|
+ // }
|
|
463
|
+ // else if ( strength > 0.70 )
|
|
464
|
+ // {
|
|
465
|
+ // printf( "#|" );
|
|
466
|
+ // }
|
|
467
|
+ // else if ( strength > 0.45 )
|
|
468
|
+ // {
|
|
469
|
+ // printf( "+|" );
|
|
470
|
+ // }
|
|
471
|
+ // else if ( strength > 0.20 )
|
|
472
|
+ // {
|
|
473
|
+ // printf( "*|" );
|
|
474
|
+ // }
|
|
475
|
+ // else
|
|
476
|
+ // {
|
|
477
|
+ // printf( ".|" );
|
|
478
|
+ // }
|
|
479
|
+ // }
|
|
480
|
+ // }
|
|
481
|
+ // printf( "\n" );
|
478
|
482
|
|
479
|
483
|
unsigned char* dest = target->buffer;
|
480
|
484
|
unsigned char* dest_end = target->buffer + aRasterFP->m_w * aRasterFP->m_h;
|
... |
... |
@@ -494,17 +498,18 @@ dense_render_glyph( RasterFP* aRasterFP, const FT_Bitmap* target ) |
494
|
498
|
dest++;
|
495
|
499
|
}
|
496
|
500
|
|
497
|
|
-
|
498
|
|
- for (int col = 0; col < aRasterFP->m_w; col++)
|
|
501
|
+ for ( int col = 0; col < aRasterFP->m_w; col++ )
|
499
|
502
|
{
|
500
|
|
- for (int row = 0; row < aRasterFP->m_h/2; row++)
|
|
503
|
+ for ( int row = 0; row < aRasterFP->m_h / 2; row++ )
|
501
|
504
|
{
|
502
|
|
- //printf("Swapping position: %d, %d with %d, %d with rows = %d, cols = %d",row,col, aRasterFP->m_h-row, col, aRasterFP->m_h, aRasterFP->m_w);
|
503
|
|
- swapold(target->buffer + aRasterFP->m_w*row + col, target->buffer + (aRasterFP->m_h-row-1)*aRasterFP->m_w + col);
|
|
505
|
+ // printf("Swapping position: %d, %d with %d, %d with rows = %d, cols =
|
|
506
|
+ // %d",row,col, aRasterFP->m_h-row, col, aRasterFP->m_h, aRasterFP->m_w);
|
|
507
|
+ swapold( target->buffer + aRasterFP->m_w * row + col,
|
|
508
|
+ target->buffer + ( aRasterFP->m_h - row - 1 ) * aRasterFP->m_w +
|
|
509
|
+ col );
|
504
|
510
|
}
|
505
|
|
-
|
506
|
511
|
}
|
507
|
|
-
|
|
512
|
+
|
508
|
513
|
return error;
|
509
|
514
|
}
|
510
|
515
|
|
... |
... |
@@ -541,8 +546,8 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params ) |
541
|
546
|
aRasterFP->m_origin_x = 0;
|
542
|
547
|
aRasterFP->m_origin_y = 0;
|
543
|
548
|
/* @QUES: Why are my bitmaps upsied down 😭*/
|
544
|
|
- aRasterFP->m_w = target_map->pitch;
|
545
|
|
- aRasterFP->m_h = target_map->rows;
|
|
549
|
+ aRasterFP->m_w = target_map->pitch;
|
|
550
|
+ aRasterFP->m_h = target_map->rows;
|
546
|
551
|
|
547
|
552
|
int size = aRasterFP->m_w * aRasterFP->m_h + 4;
|
548
|
553
|
|