1 #include "embed.h"
2 #include "config.h"
3 #include "sfnt.h"
4 #include <assert.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 const char *emb_otf_get_fontname(OTF_FILE *otf); // TODO
9
example_outfn(const char * buf,int len,void * context)10 static void example_outfn(const char *buf,int len,void *context) // {{{
11 {
12 FILE *f=(FILE *)context;
13 if (fwrite(buf,1,len,f)!=len) {
14 fprintf(stderr,"Short write: %m\n");
15 assert(0);
16 return;
17 }
18 }
19 // }}}
20
write_string(FILE * f,EMB_PARAMS * emb,const char * str)21 static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
22 {
23 assert(f);
24 assert(emb);
25 int iA;
26
27 if (emb->plan&EMB_A_MULTIBYTE) {
28 putc('<',f);
29 for (iA=0;str[iA];iA++) {
30 const unsigned short gid=emb_get(emb,(unsigned char)str[iA]);
31 fprintf(f,"%04x",gid);
32 }
33 putc('>',f);
34 } else {
35 putc('(',f);
36 for (iA=0;str[iA];iA++) {
37 emb_get(emb,(unsigned char)str[iA]);
38 }
39 fprintf(f,"%s",str); // TODO
40 putc(')',f);
41 }
42 }
43 // }}}
44
main(int argc,char ** argv)45 int main(int argc,char **argv)
46 {
47 const char *fn=TESTFONT;
48 OTF_FILE *otf=NULL;
49 if (argc==2) {
50 fn=argv[1];
51 }
52 otf=otf_load(fn);
53 if (!otf)
54 {
55 printf("Font %s was not loaded, exiting.\n", TESTFONT);
56 return 1;
57 }
58 assert(otf);
59 FONTFILE *ff=fontfile_open_sfnt(otf);
60 EMB_PARAMS *emb=emb_new(ff,
61 EMB_DEST_PS,
62 // EMB_C_FORCE_MULTIBYTE| // not yet...
63 EMB_C_TAKE_FONTFILE);
64
65 FILE *f=fopen("test.ps","w");
66 assert(f);
67
68 fprintf(f,"%%!PS-Adobe-2.0\n");
69
70 char *str="Hallo";
71
72 emb_get(emb,'a');
73
74 int iA;
75 for (iA=0;str[iA];iA++) {
76 emb_get(emb,(unsigned char)str[iA]);
77 }
78
79 emb_embed(emb,example_outfn,f);
80
81 // content
82 fprintf(f," 100 100 moveto\n" // content
83 " /%s findfont 10 scalefont setfont\n",emb_otf_get_fontname(emb->font->sfnt));
84 write_string(f,emb,"Hallo");
85 // Note that write_string sets subset bits, but it's too late
86 fprintf(f," show\n"
87 "showpage\n");
88
89 fprintf(f,"%%%%EOF\n");
90 fclose(f);
91
92 emb_close(emb);
93
94 return 0;
95 }
96