8
static void example_outfn(const char *buf,int len,void *context) // {{{
10
FILE *f=(FILE *)context;
11
if (fwrite(buf,1,len,f)!=len) {
12
fprintf(stderr,"Short write: %m\n");
20
xref[xrefpos++]=ftell(f); \
21
fprintf(f,"%d 0 obj\n",xrefpos);
24
fprintf(f,"endobj\n");
29
" /Length %d 0 R\n",xrefpos+1);
41
stream_len+=ftell(f); \
42
fprintf(f,"endstream\n" \
45
fprintf(f,"%d\n",stream_len); \
48
static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
54
if (emb->plan&EMB_A_MULTIBYTE) {
56
for (iA=0;str[iA];iA++) {
57
const unsigned short gid=emb_get(emb,(unsigned char)str[iA]);
58
fprintf(f,"%04x",gid);
63
for (iA=0;str[iA];iA++) {
64
emb_get(emb,(unsigned char)str[iA]);
66
fprintf(f,"%s",str); // TODO
72
int main(int argc,char **argv)
74
const char *fn=TESTFONT;
78
OTF_FILE *otf=otf_load(fn);
80
FONTFILE *ff=fontfile_open_sfnt(otf);
81
EMB_PARAMS *emb=emb_new(ff,
83
EMB_C_FORCE_MULTIBYTE|
86
FILE *f=fopen("test.pdf","w");
88
int xref[100],xrefpos=3;
91
fprintf(f,"%%PDF-1.3\n");
94
fprintf(f,"BT\n" // content
97
write_string(f,emb,"Hallo");
105
EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
107
EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
112
if (emb_pdf_get_fontfile_subtype(emb)) {
113
fprintf(f," /Subtype /%s\n",
114
emb_pdf_get_fontfile_subtype(emb));
116
if (emb->outtype==EMB_FMT_T1) {
117
fprintf(f," /Length1 ?\n"
120
} else if (emb->outtype==EMB_FMT_TTF) {
121
fprintf(f," /Length1 %d 0 R\n",xrefpos+2);
124
const int outlen=emb_embed(emb,example_outfn,f);
126
if (emb->outtype==EMB_FMT_TTF) {
128
fprintf(f,"%d\n",outlen);
133
const int fd_ref=xrefpos;
134
char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_ref);
142
res=emb_pdf_simple_font(emb,fdes,fwid,fd_ref);
148
if (emb->plan&EMB_A_MULTIBYTE) {
150
res=emb_pdf_simple_cidfont(emb,fdes->fontname,f_ref);
165
fprintf(f,"3 0 obj\n"
168
" /MediaBox [0 0 595 842]\n"
179
fprintf(f,"2 0 obj\n"
186
fprintf(f,"1 0 obj\n"
192
int xref_start=ftell(f);
197
for (iA=0;iA<xrefpos;iA++) {
198
fprintf(f,"%010d 00000 n \n",xref[iA]);
200
fprintf(f,"trailer\n"
208
xrefpos+1,xref_start);