ttf2cxf
Moderator: andrew
-
- Newbie Member
- Posts: 4
- Joined: Fri Jun 06, 2008 10:50 am
ttf2cxf
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
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
-
- Newbie Member
- Posts: 4
- Joined: Fri Jun 06, 2008 10:50 am
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
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
-
- Newbie Member
- Posts: 4
- Joined: Mon Aug 09, 2010 5:28 am
compile problem
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
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
-
- Newbie Member
- Posts: 4
- Joined: Fri Jun 06, 2008 10:50 am
-
- Newbie Member
- Posts: 4
- Joined: Mon Aug 09, 2010 5:28 am
compile problem
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
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
-
- Newbie Member
- Posts: 4
- Joined: Fri Jun 06, 2008 10:50 am
-
- Newbie Member
- Posts: 4
- Joined: Mon Aug 09, 2010 5:28 am
compile problem SOLVED
Thx a lot the problem is solved
Re: ttf2cxf
Hi,
this is a quite old post, but I found it through forum search 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
this is a quite old post, but I found it through forum search 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
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.
QCAD 3 has full support for TrueType fonts. A new community edition based on QCAD 3 is planned for later this year.
Re: ttf2cxf
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?
So the easiest / best / only way to use this font would be installing it system wide?
Re: ttf2cxf
If you are using QCAD 3, you can simply install the font, yes. QCAD 2 does not support TrueType fonts at all.