Page 1 of 1

ttf2cxf

Posted: Fri Jun 06, 2008 11:28 am
by Niels Ole Salscheider
Hello,

I would like to use a truetype font in qcad, but it can only use cxf fonts.

When I searched with google I found some mailing list entries mentioning a program named ttf2cxf.
I could find some links to the sourcecode on ribbonsoft.com but I get a 404 error. Can someone give me a working link to that program?

Thank you.

Ole

Posted: Fri Jun 06, 2008 1:02 pm
by andrew

Posted: Sat Jun 07, 2008 9:39 pm
by Niels Ole Salscheider
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

compile problem

Posted: Mon Aug 09, 2010 8:05 pm
by calimero2312
Hi,

I am stuck, I cant compile either the original code nor the one you provide ( by replacing the code in main.cpp). I am on Ubuntu 10.04, is it a issue?

Alexis

Posted: Tue Aug 10, 2010 8:10 am
by Niels Ole Salscheider
Hi,

try to include math.h and to replace line 152 with
fprintf(fpCxf, "\n[#%04X]\n", (uint) charcode);
(charcode has to be casted to uint).

Does this fix your problem? Please post your compiler output otherwise.

Ole

compile problem

Posted: Thu Aug 12, 2010 12:45 am
by calimero2312
Hi,
thx for the answer

After making sudo make

initialy the error message was :

g++ -o ttf2cxf -I/usr/include/freetype2 -lfreetype main.cpp
main.cpp: In function ‘FT_Error convertGlyph(FT_ULong)’:
main.cpp:152: warning: format ‘%04X’ expects type ‘unsigned int’, but argument 3 has type ‘FT_ULong’

After adding include<math.h> and changing line 152 as recommended in your post
no error message, only that :
g++ -o ttf2cxf -I/usr/include/freetype2 -lfreetype main.cpp

However, if i do sudo make install it says

make: *** No rule to make target `install'. Stop

anf if i try tt2cxf font.ttf font.cxf it says:

ttf2cxf: command not found

it seem the not to be installed

any ;ore idea ?

thx a lot

Alexis

Posted: Thu Aug 12, 2010 7:49 am
by Niels Ole Salscheider
Hello,

it compiles a ttf2cxf but there are no rules in the makefile to install this binary. cd into the build folder and try to run ./ttf2cxf [...] or copy ttf2cxf to /usr/local/bin (which should be in PATH).

Ole

compile problem SOLVED

Posted: Thu Aug 12, 2010 9:41 pm
by calimero2312
Thx a lot the problem is solved

Posted: Fri Aug 13, 2010 2:05 am
by wookey
Should this program be added to the qcad package in Debian? (or packaged separately)
Are cxf fonts used anywhere other than QCAD? If not putting it in with the program seems sensible to save people having to work out how to build and install it.

Re: ttf2cxf

Posted: Tue Jul 31, 2012 9:20 am
by smf
Hi,

this is a quite old post, but I found it through forum search :D and google...

Is there an updated version of ttf2cxf? I have a ttf which I want to convert to cxf, but I the delivered binary won't run (missing library) and the source won't compile (missing files).

Thanks a lot
Stefan

Re: ttf2cxf

Posted: Tue Jul 31, 2012 10:15 am
by andrew
No, we're not planning to update this tool anymore.

QCAD 3 has full support for TrueType fonts. A new community edition based on QCAD 3 is planned for later this year.

Re: ttf2cxf

Posted: Tue Jul 31, 2012 12:40 pm
by smf
Thank you for your fast response. I have a font that is only required for QCad related stuff, so I thought putting it in QCad's fonts directory would be an option, but the ttf file is not recognized.

So the easiest / best / only way to use this font would be installing it system wide?

Re: ttf2cxf

Posted: Tue Jul 31, 2012 1:13 pm
by andrew
If you are using QCAD 3, you can simply install the font, yes. QCAD 2 does not support TrueType fonts at all.