[Pkg-cups-devel] r830 - in cupsys/trunk/debian/local/filters/pdf-filters: . filter filter/fontembed
Till Kamppeter
till-guest at alioth.debian.org
Mon Aug 18 08:56:30 UTC 2008
Author: till-guest
Date: Mon Aug 18 08:56:29 2008
New Revision: 830
Log:
texttopdf: Gracefule handling of missing or bad fonts, fall back to std14 fonts if fonts not configured.
Added:
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/fontfile.c
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/fontfile.h
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/iofn.h
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_ps.c
Modified:
cupsys/trunk/debian/local/filters/pdf-filters/addtocups
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/Makefile
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/main.c
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/sfnt.h
cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_pdf.c
cupsys/trunk/debian/local/filters/pdf-filters/filter/pdfutils.c
cupsys/trunk/debian/local/filters/pdf-filters/filter/test_pdf2.c
cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c
Modified: cupsys/trunk/debian/local/filters/pdf-filters/addtocups
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/addtocups (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/addtocups Mon Aug 18 08:56:29 2008
@@ -125,3 +125,4 @@
EOF
perl -p -i -e 's/^(\s*DIRS\s*=.*\s+filter\s+)/$1pdftopdf /' Makefile
perl -p -i -e 's/^(\s*LIBS\s*=.*$)/$1\nPOPPLER_LIBS\t=\t\@POPPLER_LIBS\@ \$(LIBS)/' Makedefs.in
+perl -p -i -e 's/^(\s*ALL_CFLAGS\s*=\s*)/$1-Ifontembed /' Makedefs.in
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/Makefile
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/Makefile (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/Makefile Mon Aug 18 08:56:29 2008
@@ -1,6 +1,6 @@
-SOURCES=main.c sfnt.c embed.c embed_sfnt.c test_analyse.c dynstring.c test_pdf.c
-LIBOBJ=sfnt.o embed.o embed_sfnt.o dynstring.o
-EXEC=ttfread test_analyze test_pdf
+SOURCES=main.c sfnt.c embed.c embed_sfnt.c test_analyse.c dynstring.c test_pdf.c fontfile.c
+LIBOBJ=sfnt.o embed.o embed_sfnt.o dynstring.o fontfile.o
+EXEC=ttfread test_analyze test_pdf test_ps
LIB=libfontembed.a
#CPPFLAGS=-O3 -funroll-all-loops -finline-functions -Wall -g
@@ -45,3 +45,6 @@
test_pdf: test_pdf.o $(LIB)
$(CXX) -o $@ $^ $(LDFLAGS)
+
+test_ps: test_ps.o $(LIB)
+ $(CXX) -o $@ $^ $(LDFLAGS)
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c Mon Aug 18 08:56:29 2008
@@ -17,19 +17,6 @@
void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret);
-struct _FONTFILE {
- OTF_FILE *sfnt;
- // ??? *cff;
-};
-void fontfile_close(FONTFILE *ff)
-{
- if (ff) {
- otf_close(ff->sfnt);
- // ??? cff_close(ff->cff);
- free(ff);
- }
-}
-
static inline int copy_file(FILE *f,OUTPUT_FN output,void *context) // {{{
{
assert(f);
@@ -80,10 +67,17 @@
}
// determine intype
- // if (font->
- ret->intype=EMB_INPUT_TTF; // for now
- ret->rights=emb_otf_get_rights(ret->font->sfnt);
- const int numGlyphs=ret->font->sfnt->numGlyphs; // TODO
+ int numGlyphs=0;
+ if (font->sfnt) {
+ ret->intype=EMB_INPUT_TTF; // for now
+ ret->rights=emb_otf_get_rights(ret->font->sfnt);
+ numGlyphs=ret->font->sfnt->numGlyphs; // TODO
+ } else if (font->stdname) {
+ ret->intype=EMB_INPUT_STDFONT;
+ ret->rights=EMB_RIGHT_NONE;
+ } else {
+ assert(0);
+ }
/*
if ( (ret->intype==EMB_INPUT_CFF)&&
(ret->cffFont.is_cid()) ) {
@@ -100,6 +94,15 @@
} else {
ret->outtype=EMB_OUTPUT_TTF;
}
+ } else if (ret->intype==EMB_INPUT_STDFONT) {
+ // the stdfonts are treated as Type1 for now
+ ret->outtype=EMB_OUTPUT_T1;
+ if (mode&EMB_C_FORCE_MULTIBYTE) {
+ fprintf(stderr,"Multibyte stdfonts are not possible\n");
+ emb_close(ret);
+ return NULL;
+ }
+ return ret; // never subset
} else { // T1, OTF, CFF
if (ret->intype==EMB_INPUT_T1) {
ret->plan|=EMB_A_CONVERT_CFF;
@@ -147,7 +150,7 @@
{
assert(emb);
- if (emb->outtype==EMB_DEST_PS) {
+ if (emb->dest==EMB_DEST_PS) {
int ret=0;
const char *fontname=emb_otf_get_fontname(emb->font->sfnt); // TODO!!
(*output)("%%BeginFont: ",13,context);
@@ -355,6 +358,8 @@
if (emb->intype==EMB_INPUT_TTF) {
assert(emb->font->sfnt);
fontname=emb_otf_get_fontname(emb->font->sfnt);
+ } else if (emb->intype==EMB_INPUT_STDFONT) {
+ return NULL;
} else {
fprintf(stderr,"NOT IMPLEMENTED\n");
assert(0);
@@ -614,6 +619,33 @@
return ret;
}
// }}}
+
+char *emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
+{
+ assert(emb);
+ assert(emb->font->stdname);
+
+ char *ret=NULL,*pos;
+ int len,size;
+
+ size=300;
+ pos=ret=malloc(size);
+ if (!ret) {
+ fprintf(stderr,"Bad alloc: %m\n");
+ return NULL;
+ }
+
+ len=snprintf(pos,size,
+ "<</Type/Font\n"
+ " /Subtype /Type1\n"
+ " /BaseFont /%s\n"
+ ">>\n",
+ emb->font->stdname);
+ NEXT;
+
+ return ret;
+}
+// }}}
#undef NEXT
//...
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h Mon Aug 18 08:56:29 2008
@@ -2,11 +2,14 @@
#define EMBED_H
#include "bitset.h"
+#include "fontfile.h"
+#include "iofn.h"
typedef enum { EMB_INPUT_T1, // type1-lib, with AFM/PFM,PFA/PFB
EMB_INPUT_TTF, // sfnt-lib, for TTF(glyf)
EMB_INPUT_OTF, // sfnt-lib + cff-lib, for OTF
- EMB_INPUT_CFF // cff-lib, for raw CFF
+ EMB_INPUT_CFF, // cff-lib, for raw CFF
+ EMB_INPUT_STDFONT // don't embed (already present)
} EMB_INPUT_FORMAT;
typedef enum { EMB_OUTPUT_T1, // original type1
EMB_OUTPUT_TTF, // ttf(glyf)
@@ -26,12 +29,11 @@
typedef enum { EMB_A_MULTIBYTE=0x01, // embedd as multibyte font?
EMB_A_SUBSET=0x02, // do subsetting?
EMB_A_CONVERT_CFF=0x04, // convert Type1 to CFF?
- EMB_A_WRAP_SFNT=0x08, // wrap in sfnt?
+ EMB_A_WRAP_SFNT=0x08, // wrap in sfnt? (OTF)
EMB_A_CLOSE_FONTFILE=0x8000
} EMB_ACTIONS;
-typedef struct _FONTFILE FONTFILE;
typedef struct _EMB_PARAMS {
EMB_INPUT_FORMAT intype;
EMB_OUTPUT_FORMAT outtype;
@@ -59,10 +61,6 @@
EMB_C_TAKE_FONTFILE=0x8000 // take ownership of fontfile
} EMB_CONSTRAINTS;
-#ifndef OUTPUT_FN_DECLARED
-#define OUTPUT_FN_DECLARED
-typedef void (*OUTPUT_FN)(const char *buf,int len,void *context); // as in sfnt.h
-#endif
EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode);
int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context); // returns number of bytes written
void emb_close(EMB_PARAMS *emb);
@@ -114,5 +112,6 @@
char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontfile_obj_ref);
char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWIDTHS *fwid,int fontdescr_obj_ref);
char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant_obj_ref);
+char *emb_pdf_simple_stdfont(EMB_PARAMS *emb);
#endif
Added: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/fontfile.c
==============================================================================
--- (empty file)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/fontfile.c Mon Aug 18 08:56:29 2008
@@ -0,0 +1,50 @@
+#include "fontfile.h"
+#include <assert.h>
+#include <string.h>
+
+//FONTFILE *fontfile_open(const char *filename);
+
+/*
+FONTFILE *fontfile_open(const char *filename)
+{
+ // TODO? check magic
+ if (...) {
+ }
+}
+*/
+
+FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
+{
+ if (!otf) {
+ assert(0);
+ return NULL;
+ }
+ FONTFILE *ret=calloc(1,sizeof(FONTFILE));
+
+ ret->sfnt=otf;
+
+ return ret;
+}
+// }}}
+
+FONTFILE *fontfile_open_std(const char *name) // {{{
+{
+ assert(name);
+ FONTFILE *ret=calloc(1,sizeof(FONTFILE));
+
+ ret->stdname=strdup(name);
+
+ return ret;
+}
+// }}}
+
+void fontfile_close(FONTFILE *ff) // {{{
+{
+ if (ff) {
+ otf_close(ff->sfnt);
+ // ??? cff_close(ff->cff);
+ free(ff->stdname);
+ free(ff);
+ }
+}
+// }}}
Added: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/fontfile.h
==============================================================================
--- (empty file)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/fontfile.h Mon Aug 18 08:56:29 2008
@@ -0,0 +1,22 @@
+#ifndef _FONTFILE_H
+#define _FONTFILE_H
+
+#include "sfnt.h"
+
+struct _FONTFILE {
+ OTF_FILE *sfnt;
+ // ??? *cff;
+ char *stdname;
+ union {
+ int fobj;
+ void *user;
+ };
+};
+
+typedef struct _FONTFILE FONTFILE;
+
+FONTFILE *fontfile_open_sfnt(OTF_FILE *otf);
+FONTFILE *fontfile_open_std(const char *name);
+void fontfile_close(FONTFILE *ff);
+
+#endif
Added: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/iofn.h
==============================================================================
--- (empty file)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/iofn.h Mon Aug 18 08:56:29 2008
@@ -0,0 +1,6 @@
+#ifndef _IOFN_H
+#define _IOFN_H
+
+typedef void (*OUTPUT_FN)(const char *buf,int len,void *context);
+
+#endif
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/main.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/main.c (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/main.c Mon Aug 18 08:56:29 2008
@@ -5,11 +5,6 @@
#include "embed.h"
-struct _FONTFILE {
- OTF_FILE *sfnt;
- // CFF *;
-};
-
#if 0
enum { TTF_OTF, TYPE1 } inputFile;
if (TTF_OTF) {
@@ -49,8 +44,8 @@
void example_write_fontdescr(OTF_FILE *otf,const char *outfile) // {{{
{
- struct _FONTFILE ff; ff.sfnt=otf; // TODO
- EMB_PARAMS *emb=emb_new(&ff,
+ FONTFILE *ff=fontfile_open_sfnt(otf);
+ EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PDF16,
// EMB_C_KEEP_T1
EMB_C_FORCE_MULTIBYTE
@@ -96,6 +91,7 @@
if (!f) {
fprintf(stderr,"Opening \"%s\" for writing failed: %m\n",outfile);
assert(0);
+ emb_close(emb);
return;
}
outlen=emb_embed(emb,example_outfn,f);
@@ -129,6 +125,13 @@
free(fdes);
free(fwid);
+ emb_close(emb);
+#if 1
+ free(ff); // TODO
+#else
+ ff->sfnt=NULL; // TODO
+ fontfile_close(ff);
+#endif
}
// }}}
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/sfnt.h
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/sfnt.h (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/sfnt.h Mon Aug 18 08:56:29 2008
@@ -1,6 +1,7 @@
#ifndef _SFNT_H
#define _SFNT_H
+#include <stdio.h>
#include "bitset.h"
typedef struct {
@@ -10,8 +11,6 @@
unsigned int length;
} OTF_DIRENT;
-typedef struct _IO_FILE FILE;
-
typedef struct {
FILE *f;
unsigned int numTTC,useTTC;
@@ -54,10 +53,9 @@
int otf_get_glyph(OTF_FILE *otf,unsigned short gid);
unsigned short otf_from_unicode(OTF_FILE *otf,int unicode);
-#ifndef OUTPUT_FN_DECLARED
-#define OUTPUT_FN_DECLARED
-typedef void (*OUTPUT_FN)(const char *buf,int len,void *context);
-#endif
+
+#include "iofn.h"
+
int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context);
int otf_ttc_extract(OTF_FILE *otf,OUTPUT_FN output,void *context);
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_pdf.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_pdf.c (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_pdf.c Mon Aug 18 08:56:29 2008
@@ -4,10 +4,6 @@
#include <stdio.h>
#include <stdlib.h>
-struct _FONTFILE { // TODO
- OTF_FILE *sfnt;
-};
-
static void example_outfn(const char *buf,int len,void *context) // {{{
{
FILE *f=(FILE *)context;
@@ -83,11 +79,11 @@
}
OTF_FILE *otf=otf_load(fn);
assert(otf);
- struct _FONTFILE ff; ff.sfnt=otf; // TODO
- EMB_PARAMS *emb=emb_new(&ff,
+ FONTFILE *ff=fontfile_open_sfnt(otf);
+ EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PDF16,
- EMB_C_FORCE_MULTIBYTE
-);
+ EMB_C_FORCE_MULTIBYTE|
+ EMB_C_TAKE_FONTFILE);
FILE *f=fopen("test.pdf","w");
assert(f);
@@ -216,7 +212,6 @@
fclose(f);
emb_close(emb);
- otf_close(otf);
return 0;
}
Added: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_ps.c
==============================================================================
--- (empty file)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/test_ps.c Mon Aug 18 08:56:29 2008
@@ -0,0 +1,92 @@
+#include "embed.h"
+#include "sfnt.h"
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+const char *emb_otf_get_fontname(OTF_FILE *otf); // TODO
+
+static void example_outfn(const char *buf,int len,void *context) // {{{
+{
+ FILE *f=(FILE *)context;
+ if (fwrite(buf,1,len,f)!=len) {
+ fprintf(stderr,"Short write: %m\n");
+ assert(0);
+ return;
+ }
+}
+// }}}
+
+static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
+{
+ assert(f);
+ assert(emb);
+ OTF_FILE *otf=emb->font->sfnt;
+ assert(otf);
+ int iA;
+
+ if (emb->plan&EMB_A_MULTIBYTE) {
+ putc('<',f);
+ for (iA=0;str[iA];iA++) {
+ const unsigned short gid=otf_from_unicode(otf,(unsigned char)str[iA]);
+ fprintf(f,"%04x",gid);
+ bit_set(emb->subset,gid);
+ }
+ putc('>',f);
+ } else {
+ putc('(',f);
+ for (iA=0;str[iA];iA++) {
+ bit_set(emb->subset,otf_from_unicode(otf,(unsigned char)str[iA])); // TODO: emb_set(...) encoding/unicode->gid
+ }
+ fprintf(f,"%s",str); // TODO
+ putc(')',f);
+ }
+}
+// }}}
+
+int main(int argc,char **argv)
+{
+ const char *fn="/usr/share/fonts/truetype/microsoft/ARIALN.TTF";
+ if (argc==2) {
+ fn=argv[1];
+ }
+ OTF_FILE *otf=otf_load(fn);
+ assert(otf);
+ FONTFILE *ff=fontfile_open_sfnt(otf);
+ EMB_PARAMS *emb=emb_new(ff,
+ EMB_DEST_PS,
+ EMB_C_FORCE_MULTIBYTE|
+ EMB_C_TAKE_FONTFILE);
+
+ FILE *f=fopen("test.ps","w");
+ assert(f);
+
+ assert(emb->subset);
+
+ fprintf(f,"%%!PS-Adobe-2.0\n");
+
+ char *str="Hallo";
+
+ bit_set(emb->subset,otf_from_unicode(otf,'a'));
+
+ int iA;
+ for (iA=0;str[iA];iA++) {
+ bit_set(emb->subset,otf_from_unicode(otf,(unsigned char)str[iA]));
+ }
+
+ emb_embed(emb,example_outfn,f);
+
+ // content
+ fprintf(f," 100 100 moveto\n" // content
+ " /%s findfont 10 scalefont setfont\n",emb_otf_get_fontname(emb->font->sfnt));
+ write_string(f,emb,"Hallo");
+ fprintf(f," show\n"
+ "showpage\n");
+
+ fprintf(f,"%%%%EOF\n");
+ fclose(f);
+
+ emb_close(emb);
+
+ return 0;
+}
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/pdfutils.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/pdfutils.c (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/pdfutils.c Mon Aug 18 08:56:29 2008
@@ -302,6 +302,20 @@
EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
if (!fdes) {
+ if (emb->intype==EMB_INPUT_STDFONT) { // std-14 font
+ const int f_obj=pdfOut_add_xref(pdf);
+ char *res=emb_pdf_simple_stdfont(emb);
+ if (!res) {
+ return 0;
+ }
+
+ pdfOut_printf(pdf,"%d 0 obj\n"
+ "%s"
+ "endobj\n"
+ ,f_obj,res);
+ free(res);
+ return f_obj;
+ }
return 0;
}
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/test_pdf2.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/test_pdf2.c (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/test_pdf2.c Mon Aug 18 08:56:29 2008
@@ -5,10 +5,6 @@
#include <stdio.h>
-struct _FONTFILE { // TODO
- OTF_FILE *sfnt;
-};
-
static inline void write_string(pdfOut *pdf,EMB_PARAMS *emb,const char *str) // {{{
{
assert(pdf);
@@ -57,10 +53,11 @@
*/
OTF_FILE *otf=otf_load(fn);
assert(otf);
- struct _FONTFILE ff; ff.sfnt=otf; // TODO
- EMB_PARAMS *emb=emb_new(&ff,
+ FONTFILE *ff=fontfile_open_sfnt(otf);
+ EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PDF16,
- EMB_C_FORCE_MULTIBYTE);
+ EMB_C_FORCE_MULTIBYTE|
+ EMB_C_TAKE_FONTFILE);
// test
const int PageWidth=595,PageLength=842;
@@ -104,5 +101,7 @@
pdfOut_free(pdf);
+ emb_close(emb);
+
return 0;
}
Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c (original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c Mon Aug 18 08:56:29 2008
@@ -34,11 +34,6 @@
#include <assert.h>
#include "fontembed/sfnt.h"
-// TODO:
-struct _FONTFILE { // TODO
- OTF_FILE *sfnt;
- int fobj; // TODO
-};
EMB_PARAMS *font_load(const char *datadir,const char *font);
static int bits_used(BITSET bits,int len) // {{{
@@ -65,10 +60,8 @@
// TODO: try /usr/share/fonts/*/*/%s.ttf
return NULL;
}
- struct _FONTFILE *ff=malloc(sizeof(struct _FONTFILE));
+ FONTFILE *ff=fontfile_open_sfnt(otf);
assert(ff);
- ff->sfnt=otf; // TODO
- ff->fobj=0; // TODO
EMB_PARAMS *emb=emb_new(ff,
EMB_DEST_PDF16,
EMB_C_FORCE_MULTIBYTE|
@@ -78,6 +71,17 @@
return emb;
}
+EMB_PARAMS *font_std(const char *name)
+{
+ FONTFILE *ff=fontfile_open_std(name);
+ assert(ff);
+ EMB_PARAMS *emb=emb_new(ff,
+ EMB_DEST_PDF16,
+ EMB_C_TAKE_FONTFILE);
+ assert(emb);
+ return emb;
+}
+
/*
* Globals...
*/
@@ -764,19 +768,10 @@
NumFonts = 1;
- Fonts[0][ATTR_NORMAL] = font_load(datadir,"Courier");
- if (!Fonts[0][ATTR_NORMAL]) {
- fprintf(stderr, _("ERROR: No usable font available\n"));
- exit(1);
- }
- Fonts[0][ATTR_BOLD] = font_load(datadir,"Courier-Bold");
- Fonts[0][ATTR_ITALIC] = font_load(datadir,"Courier-Oblique");
- Fonts[0][ATTR_BOLDITALIC] = font_load(datadir,"Courier-BoldOblique");
- for (j = 1; j < 4; j ++) {
- if (!Fonts[0][j]) {
- Fonts[0][j]=Fonts[0][0];
- }
- }
+ Fonts[0][ATTR_NORMAL] = font_std("Courier");
+ Fonts[0][ATTR_BOLD] = font_std("Courier-Bold");
+ Fonts[0][ATTR_ITALIC] = font_std("Courier-Oblique");
+ Fonts[0][ATTR_BOLDITALIC] = font_std("Courier-BoldOblique");
Widths[0] = 1;
Directions[0] = 1;
@@ -1088,8 +1083,13 @@
EMB_PARAMS *emb=Fonts[lastfont][fontid];
OTF_FILE *otf=emb->font->sfnt;
- pdfOut_printf(pdf," %.3f Tz\n",
- FontScaleX*600.0/(otf_get_width(otf,0)*1000.0/otf->unitsPerEm)*100.0/FontScaleY); // TODO?
+ if (otf) { // TODO?
+ pdfOut_printf(pdf," %.3f Tz\n",
+ FontScaleX*600.0/(otf_get_width(otf,0)*1000.0/otf->unitsPerEm)*100.0/FontScaleY); // TODO?
+ } else {
+ pdfOut_printf(pdf," %.3f Tz\n",
+ FontScaleX*100.0/FontScaleY); // TODO?
+ }
pdfOut_printf(pdf," /%s%02x %.3f Tf <",
names[fontid],lastfont,FontScaleY);
@@ -1101,17 +1101,21 @@
} else {
ch=Chars[str->ch];
}
- const unsigned short gid=otf_from_unicode(otf,ch);
font = Codes[ch];
if (lastfont != font) {
assert(0); // should never happen; TODO
break;
}
- pdfOut_printf(pdf,"%04x", gid);
-
- if (emb->subset) {
- bit_set(emb->subset,gid);
+ if (otf) { // TODO
+ const unsigned short gid=otf_from_unicode(otf,ch);
+ pdfOut_printf(pdf,"%04x", gid);
+
+ if (emb->subset) {
+ bit_set(emb->subset,gid);
+ }
+ } else { // std 14 font with 7-bit us-ascii uses single byte encoding, TODO
+ pdfOut_printf(pdf,"%02x",ch);
}
len --;
More information about the Pkg-cups-devel
mailing list