ttf2cxf

Use this forum to ask questions about how to do things in the QCAD Community Edition.

Moderator: andrew

ttf2cxf

Postby Niels Ole Salscheider » Fri Jun 06, 2008 11:28 am

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
Niels Ole Salscheider
Newbie Member
 
Posts: 4
Joined: Fri Jun 06, 2008 10:50 am

Postby andrew » Fri Jun 06, 2008 1:02 pm

User avatar
andrew
Site Admin
 
Posts: 2379
Joined: Fri Mar 30, 2007 6:07 am

Postby 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
Niels Ole Salscheider
Newbie Member
 
Posts: 4
Joined: Fri Jun 06, 2008 10:50 am

compile problem

Postby calimero2312 » Mon Aug 09, 2010 8:05 pm

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
calimero2312
Newbie Member
 
Posts: 4
Joined: Mon Aug 09, 2010 5:28 am

Postby Niels Ole Salscheider » Tue Aug 10, 2010 8:10 am

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
Niels Ole Salscheider
Newbie Member
 
Posts: 4
Joined: Fri Jun 06, 2008 10:50 am

compile problem

Postby calimero2312 » Thu Aug 12, 2010 12:45 am

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
calimero2312
Newbie Member
 
Posts: 4
Joined: Mon Aug 09, 2010 5:28 am

Postby Niels Ole Salscheider » Thu Aug 12, 2010 7:49 am

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
Niels Ole Salscheider
Newbie Member
 
Posts: 4
Joined: Fri Jun 06, 2008 10:50 am

compile problem SOLVED

Postby calimero2312 » Thu Aug 12, 2010 9:41 pm

Thx a lot the problem is solved
calimero2312
Newbie Member
 
Posts: 4
Joined: Mon Aug 09, 2010 5:28 am

Postby wookey » Fri Aug 13, 2010 2:05 am

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.
wookey
Newbie Member
 
Posts: 9
Joined: Thu Aug 12, 2010 3:15 pm

Re: ttf2cxf

Postby smf » Tue Jul 31, 2012 9:20 am

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
smf
Active Member
 
Posts: 27
Joined: Tue Feb 28, 2012 1:05 pm

Re: ttf2cxf

Postby andrew » Tue Jul 31, 2012 10:15 am

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.
User avatar
andrew
Site Admin
 
Posts: 2379
Joined: Fri Mar 30, 2007 6:07 am

Re: ttf2cxf

Postby smf » Tue Jul 31, 2012 12:40 pm

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?
smf
Active Member
 
Posts: 27
Joined: Tue Feb 28, 2012 1:05 pm

Re: ttf2cxf

Postby andrew » Tue Jul 31, 2012 1:13 pm

If you are using QCAD 3, you can simply install the font, yes. QCAD 2 does not support TrueType fonts at all.
User avatar
andrew
Site Admin
 
Posts: 2379
Joined: Fri Mar 30, 2007 6:07 am


Return to QCAD Community 'How Do I' Questions

Who is online

Users browsing this forum: No registered users and 2 guests