by **Niels Ole Salscheider** » Sat Jun 07, 2008 9:39 pm

Hello,

thank you, this program works quite well except that the smallest x-coordinates of the created letters are greater than 0 for some fonts. Because of that the letterspace may be wrong.

I wrote this patch:

--- main.cpp 2003-11-29 19:23:20.000000000 +0100

+++ main.cpp 2008-06-07 13:14:58.000000000 +0200

@@ -21,6 +21,7 @@

**********************************************************************/

#include <iostream>

+#include <math.h>

#include <ft2build.h>

#include FT_FREETYPE_H

@@ -31,6 +32,8 @@

FT_Face face;

double prevx;

double prevy;

+bool firstpass;

+float xMin;

int nodes;

double factor;

int yMax;

@@ -60,23 +63,39 @@

int moveTo(FT_Vector* to, void* fp) {

- prevx = to->x;

- prevy = to->y;

+ if (firstpass)

+ {

+ if (to->x < xMin)

+ xMin = to->x;

+ }

+ else

+ {

+ prevx = to->x;

+ prevy = to->y;

+ }

return 0;

}

int lineTo(FT_Vector* to, void* fp) {

- if (fp!=NULL) {

- fprintf((FILE*)fp, "L %f,%f,%f,%f\n", prevx*factor, prevy*factor,

- (double)to->x*factor, (double)to->y*factor);

+ if (firstpass)

+ {

+ if (to->x < xMin)

+ xMin = to->x;

}

- prevx = to->x;

- prevy = to->y;

+ else

+ {

+ if (fp!=NULL) {

+ fprintf((FILE*)fp, "L %f,%f,%f,%f\n", (prevx-xMin)*factor, prevy*factor,

+ (double)(to->x-xMin)*factor, (double)to->y*factor);

+ }

+ prevx = to->x;

+ prevy = to->y;

- if (to->y>yMax) {

- yMax = to->y;

+ if (to->y>yMax) {

+ yMax = to->y;

+ }

}

return 0;

}

@@ -84,27 +103,35 @@

int conicTo(FT_Vector* control, FT_Vector* to, void* fp) {

- double px, py;

- double ox = prevx;

- double oy = prevy;

- if (fp!=NULL) {

- for (double t = 0.0; t<=1.0; t+=1.0/nodes) {

- px = pow(1.0-t, 2)*prevx + 2*t*(1.0-t)*control->x + t*t*to->x;

- py = pow(1.0-t, 2)*prevy + 2*t*(1.0-t)*control->y + t*t*to->y;

+ if (firstpass)

+ {

+ if (to->x < xMin)

+ xMin = to->x;

+ }

+ else

+ {

+ double px, py;

+ double ox = prevx;

+ double oy = prevy;

+ if (fp!=NULL) {

+ for (double t = 0.0; t<=1.0; t+=1.0/nodes) {

+ px = pow(1.0-t, 2)*prevx + 2*t*(1.0-t)*control->x + t*t*to->x;

+ py = pow(1.0-t, 2)*prevy + 2*t*(1.0-t)*control->y + t*t*to->y;

- fprintf((FILE*)fp, "L %f,%f,%f,%f\n", ox*factor, oy*factor,

- (double)px*factor, (double)py*factor);

+ fprintf((FILE*)fp, "L %f,%f,%f,%f\n", (ox-xMin)*factor, oy*factor,

+ (double)(px-xMin)*factor, (double)py*factor);

- ox = px;

- oy = py;

+ ox = px;

+ oy = py;

+ }

}

- }

- prevx = to->x;

- prevy = to->y;

+ prevx = to->x;

+ prevy = to->y;

- if (to->y>yMax) {

- yMax = to->y;

+ if (to->y>yMax) {

+ yMax = to->y;

+ }

}

return 0;

}

@@ -112,15 +139,23 @@

int cubicTo(FT_Vector* control1, FT_Vector* control2, FT_Vector* to, void* fp) {

- if (fp!=NULL) {

- fprintf((FILE*)fp, "L %f,%f,%f,%f\n", prevx*factor, prevy*factor,

- (double)to->x*factor, (double)to->y*factor);

+ if (firstpass)

+ {

+ if (to->x < xMin)

+ xMin = to->x;

}

- prevx = to->x;

- prevy = to->y;

+ else

+ {

+ if (fp!=NULL) {

+ fprintf((FILE*)fp, "L %f,%f,%f,%f\n", (prevx-xMin)*factor, prevy*factor,

+ (double)(to->x-xMin)*factor, (double)to->y*factor);

+ }

+ prevx = to->x;

+ prevy = to->y;

- if (to->y>yMax) {

- yMax = to->y;

+ if (to->y>yMax) {

+ yMax = to->y;

+ }

}

return 0;

}

@@ -151,8 +186,13 @@

if (fpCxf!=NULL) {

fprintf(fpCxf, "\n[#%04X]\n", charcode);

}

+ // trace outline of the glyph

+ xMin = 1000.0;

+ firstpass = true;

+ error = FT_Outline_Decompose(&(og->outline),

+ &funcs, fpCxf);

- // trace outline of the glyph

+ firstpass = false;

error = FT_Outline_Decompose(&(og->outline),

&funcs, fpCxf);

I'm not sure if there is a better possibility to do so, but it works.

Kind regards

Ole