From cf1a80a111bfde8a75378c1f8af66b94e6f2a894 Mon Sep 17 00:00:00 2001 From: Till Kamppeter Date: Mon, 10 Oct 2022 20:34:12 +0200 Subject: [PATCH] libfontembed, libcupsfilters: Merge libfontembed into libcupsfilters libfontembed is only used by cups-filters, and here only by the cfFilterTextToPDF() filter function ("texttopdf" CUPS filter, also part of "universal" CUPS filter). It is also not used by any other package (at least of Ubuntu Main and Universe). To ease the separation of cups-filters into their components (similar to CUPDS 3.x we will separate, into libcupsfilters, libppd, cups-filters, and cups-browsed, to cleanly separate off the PPD file support) we merge the functionality of libfontembed into Libcupsfilters, to keep the cfFilterTextToPDF() filter function for plain text file printing support. --- Makefile.am | 134 +++---- configure.ac | 1 - cupsfilters/fontembed.h | 342 ++++++++++++++++++ {fontembed => cupsfilters/fontembed}/README | 18 +- .../fontembed}/aglfn13.c | 0 .../fontembed}/dynstring-private.h | 0 .../fontembed}/dynstring.c | 2 +- .../fontembed/embed-pdf-private.h | 0 .../fontembed}/embed-pdf.c | 11 +- .../fontembed/embed-sfnt-private.h | 3 +- .../fontembed}/embed-sfnt.c | 11 +- {fontembed => cupsfilters/fontembed}/embed.c | 6 +- .../fontembed}/fontfile.c | 4 +- .../fontembed}/frequent-private.h | 0 .../fontembed}/frequent.c | 2 +- .../fontembed}/macroman-private.h | 0 .../fontembed/sfnt-private.h | 0 .../fontembed}/sfnt-subset.c | 7 +- {fontembed => cupsfilters/fontembed}/sfnt.c | 6 +- .../fontembed}/test-analyze.c | 9 +- .../fontembed}/test-pdf.c | 5 +- .../fontembed}/test-ps.c | 5 +- cupsfilters/pdfutils.c | 4 +- cupsfilters/pdfutils.h | 2 +- cupsfilters/texttopdf.c | 12 +- filter/test_pdf2.c | 3 +- fontembed/bitset.h | 50 --- fontembed/debug-internal.h | 43 --- fontembed/embed-pdf.h | 62 ---- fontembed/embed.h | 119 ------ fontembed/fontfile.h | 24 -- fontembed/iofn.h | 6 - fontembed/sfnt.h | 72 ---- libfontembed.pc.in | 11 - 34 files changed, 446 insertions(+), 528 deletions(-) create mode 100644 cupsfilters/fontembed.h rename {fontembed => cupsfilters/fontembed}/README (76%) rename {fontembed => cupsfilters/fontembed}/aglfn13.c (100%) rename {fontembed => cupsfilters/fontembed}/dynstring-private.h (100%) rename {fontembed => cupsfilters/fontembed}/dynstring.c (97%) rename fontembed/embed-pdf-int-private.h => cupsfilters/fontembed/embed-pdf-private.h (100%) rename {fontembed => cupsfilters/fontembed}/embed-pdf.c (98%) rename fontembed/embed-sfnt-int-private.h => cupsfilters/fontembed/embed-sfnt-private.h (94%) rename {fontembed => cupsfilters/fontembed}/embed-sfnt.c (99%) rename {fontembed => cupsfilters/fontembed}/embed.c (98%) rename {fontembed => cupsfilters/fontembed}/fontfile.c (90%) rename {fontembed => cupsfilters/fontembed}/frequent-private.h (100%) rename {fontembed => cupsfilters/fontembed}/frequent.c (98%) rename {fontembed => cupsfilters/fontembed}/macroman-private.h (100%) rename fontembed/sfnt-int-private.h => cupsfilters/fontembed/sfnt-private.h (100%) rename {fontembed => cupsfilters/fontembed}/sfnt-subset.c (98%) rename {fontembed => cupsfilters/fontembed}/sfnt.c (99%) rename {fontembed => cupsfilters/fontembed}/test-analyze.c (97%) rename {fontembed => cupsfilters/fontembed}/test-pdf.c (98%) rename {fontembed => cupsfilters/fontembed}/test-ps.c (96%) delete mode 100644 fontembed/bitset.h delete mode 100644 fontembed/debug-internal.h delete mode 100644 fontembed/embed-pdf.h delete mode 100644 fontembed/embed.h delete mode 100644 fontembed/fontfile.h delete mode 100644 fontembed/iofn.h delete mode 100644 fontembed/sfnt.h delete mode 100644 libfontembed.pc.in diff --git a/Makefile.am b/Makefile.am index e56edf0d9..3d0909c50 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,8 +3,7 @@ ACLOCAL_AMFLAGS = -I m4 pkgconfdir = $(libdir)/pkgconfig pkgconf_DATA = \ libcupsfilters.pc \ - libppd.pc \ - libfontembed.pc + libppd.pc doc_DATA = \ ABOUT-NLS \ @@ -21,7 +20,6 @@ EXTRA_DIST = \ ln-srf \ libcupsfilters.pc.in \ libppd.pc.in \ - libfontembed.pc.in \ utils/cups-browsed.service \ utils/cups-browsed-upstart.conf \ utils/driverless-fax.in \ @@ -161,63 +159,9 @@ pkgcharset_DATA = \ EXTRA_DIST += $(pkgcharset_DATA) -# ================= -# Fontembed library -# ================= -pkgfontembedincludedir = $(includedir)/fontembed -pkgfontembedinclude_DATA = \ - fontembed/bitset.h \ - fontembed/embed.h \ - fontembed/embed-pdf.h \ - fontembed/fontfile.h \ - fontembed/iofn.h \ - fontembed/sfnt.h - -lib_LTLIBRARIES = libfontembed.la - -check_PROGRAMS = \ - test-analyze \ - test-pdf \ - test-ps -TESTS = \ - test-analyze \ - test-pdf \ - test-ps - -libfontembed_la_SOURCES = \ - fontembed/aglfn13.c \ - fontembed/dynstring.c \ - fontembed/dynstring-private.h \ - fontembed/debug-internal.h \ - fontembed/embed.c \ - fontembed/embed-sfnt.c \ - fontembed/embed-sfnt-int-private.h \ - fontembed/embed-pdf.c \ - fontembed/embed-pdf-int-private.h \ - fontembed/fontfile.c \ - fontembed/frequent.c \ - fontembed/frequent-private.h \ - fontembed/macroman-private.h \ - fontembed/sfnt.c \ - fontembed/sfnt-int-private.h \ - fontembed/sfnt-subset.c \ - $(pkgfontembedinclude_DATA) -libfontembed_la_LDFLAGS = \ - -no-undefined \ - -version-info 1 - -test_analyze_SOURCES = fontembed/test-analyze.c -test_analyze_LDADD = libfontembed.la - -test_pdf_SOURCES = fontembed/test-pdf.c -test_pdf_LDADD = libfontembed.la - -test_ps_SOURCES = fontembed/test-ps.c -test_ps_LDADD = libfontembed.la - -EXTRA_DIST += \ - $(pkgfontembedinclude_DATA) \ - fontembed/README +# ======= +# Filters +# ======= pkgfilter_PROGRAMS = pkgfilterdir = $(CUPS_SERVERBIN)/filter @@ -233,6 +177,7 @@ pkgfiltersinclude_DATA = \ cupsfilters/colormanager.h \ cupsfilters/driver.h \ cupsfilters/filter.h \ + cupsfilters/fontembed.h \ cupsfilters/ieee1284.h \ cupsfilters/image.h \ cupsfilters/ipp.h \ @@ -241,16 +186,23 @@ pkgfiltersinclude_DATA = \ cupsfilters/pdfutils.h \ cupsfilters/raster.h -lib_LTLIBRARIES += libcupsfilters.la +lib_LTLIBRARIES = libcupsfilters.la -check_PROGRAMS += \ +check_PROGRAMS = \ testcmyk \ testdither \ testimage \ testrgb \ - test1284 -TESTS += \ - testdither + test1284 \ + test-analyze \ + test-pdf \ + test-ps +TESTS = \ + testdither \ + test-analyze \ + test-pdf \ + test-ps + # testcmyk # fails as it opens some image.ppm which is nowerhe to be found. # testimage # requires also some ppm file as argument # testrgb # same error @@ -280,6 +232,21 @@ libcupsfilters_la_SOURCES = \ cupsfilters/debug-internal.h \ cupsfilters/dither.c \ cupsfilters/filter.c \ + cupsfilters/fontembed/aglfn13.c \ + cupsfilters/fontembed/dynstring.c \ + cupsfilters/fontembed/dynstring-private.h \ + cupsfilters/fontembed/embed.c \ + cupsfilters/fontembed/embed-sfnt.c \ + cupsfilters/fontembed/embed-sfnt-private.h \ + cupsfilters/fontembed/embed-pdf.c \ + cupsfilters/fontembed/embed-pdf-private.h \ + cupsfilters/fontembed/fontfile.c \ + cupsfilters/fontembed/frequent.c \ + cupsfilters/fontembed/frequent-private.h \ + cupsfilters/fontembed/macroman-private.h \ + cupsfilters/fontembed/sfnt.c \ + cupsfilters/fontembed/sfnt-private.h \ + cupsfilters/fontembed/sfnt-subset.c \ cupsfilters/ghostscript.c \ cupsfilters/ieee1284.c \ cupsfilters/image.c \ @@ -330,10 +297,7 @@ libcupsfilters_la_SOURCES = \ cupsfilters/universal.c \ $(pkgfiltersinclude_DATA) libcupsfilters_la_LIBADD = \ - libfontembed.la \ $(FONTCONFIG_LIBS) \ - $(GETLINE) \ - $(STRCASESTR) \ $(CUPS_LIBS) \ $(LCMS_LIBS) \ $(LIBQPDF_LIBS) \ @@ -344,7 +308,7 @@ libcupsfilters_la_LIBADD = \ $(POPPLER_LIBS) \ -lm libcupsfilters_la_CFLAGS = \ - -I$(srcdir)/fontembed/ \ + -I$(srcdir)/cupsfilters/fontembed/ \ $(FONTCONFIG_CFLAGS) \ $(CUPS_CFLAGS) \ $(LCMS_CFLAGS) \ @@ -361,10 +325,6 @@ libcupsfilters_la_CFLAGS += $(DBUS_CFLAGS) -DHAVE_DBUS libcupsfilters_CXXFLAGS = -std=c++0x $(libcupsfilters_CFLAGS) # -std=c++11 libcupsfilters_la_LIBADD += $(DBUS_LIBS) endif -libcupsfilters_la_DEPENDENCIES = \ - libfontembed.la \ - $(GETLINE) \ - $(STRCASESTR) testcmyk_SOURCES = \ cupsfilters/testcmyk.c \ @@ -401,10 +361,20 @@ testrgb_LDADD = \ libcupsfilters.la \ -lm +test_analyze_SOURCES = cupsfilters/fontembed/test-analyze.c +test_analyze_LDADD = libcupsfilters.la + +test_pdf_SOURCES = cupsfilters/fontembed/test-pdf.c +test_pdf_LDADD = libcupsfilters.la + +test_ps_SOURCES = cupsfilters/fontembed/test-ps.c +test_ps_LDADD = libcupsfilters.la + EXTRA_DIST += \ $(pkgfiltersinclude_DATA) \ cupsfilters/image.pgm \ - cupsfilters/image.ppm + cupsfilters/image.ppm \ + cupsfilters/fontembed/README test1284_SOURCES = \ cupsfilters/test1284.c @@ -1167,20 +1137,20 @@ rastertopclx_LDADD = \ test_pdf1_SOURCES = \ filter/test_pdf1.c \ - fontembed/embed.h \ - fontembed/sfnt.h -test_pdf1_CFLAGS = -I$(srcdir)/fontembed/ \ + cupsfilters/fontembed.h +test_pdf1_CFLAGS = \ + -I$(srcdir)/cupsfilters/fontembed/ \ -I$(srcdir)/cupsfilters/ -test_pdf1_LDADD = libfontembed.la \ +test_pdf1_LDADD = \ libcupsfilters.la test_pdf2_SOURCES = \ filter/test_pdf2.c \ - fontembed/embed.h \ - fontembed/sfnt.h -test_pdf2_CFLAGS = -I$(srcdir)/fontembed/ \ + cupsfilters/fontembed.h +test_pdf2_CFLAGS = \ + -I$(srcdir)/cupsfilters/fontembed/ \ -I$(srcdir)/cupsfilters/ -test_pdf2_LDADD = libfontembed.la \ +test_pdf2_LDADD = \ libcupsfilters.la universal_SOURCES = \ diff --git a/configure.ac b/configure.ac index 5fcab1378..c4775bea6 100644 --- a/configure.ac +++ b/configure.ac @@ -981,7 +981,6 @@ AS_IF([test "x$FREQUENT_NETIF_UPDATE" != "xno"], AC_CONFIG_FILES([ libcupsfilters.pc libppd.pc - libfontembed.pc Makefile utils/cups-browsed utils/cups-browsed.conf diff --git a/cupsfilters/fontembed.h b/cupsfilters/fontembed.h new file mode 100644 index 000000000..0faf70c23 --- /dev/null +++ b/cupsfilters/fontembed.h @@ -0,0 +1,342 @@ +#ifndef _CUPSFILTERS_FONTEMBED_H_ +#define _CUPSFILTERS_FONTEMBED_H_ + + +// +// Include necessary headers... +// + +#include +#include + + +// +// Constants and macros... +// + +#define OTF_F_FMT_CFF 0x10000 +#define OTF_F_DO_CHECKSUM 0x40000 + +#define OTF_TAG(a, b, c, d) (unsigned int)(((a) << 24) | ((b) << 16) | \ + ((c) << 8) | (d)) +#define OTF_UNTAG(a) (((unsigned int)(a) >> 24) & 0xff), \ + (((unsigned int)(a) >> 16) & 0xff), \ + (((unsigned int)(a) >> 8) & 0xff), \ + (((unsigned int)(a)) & 0xff) + + +// +// Types and structures... +// + +// OpenType Font (OTF) handling + +typedef struct +{ + unsigned int tag; + unsigned int checkSum; + unsigned int offset; + unsigned int length; +} OTF_DIRENT; + +typedef struct +{ + FILE *f; + unsigned int numTTC, useTTC; + unsigned int version; + + unsigned short numTables; + OTF_DIRENT *tables; + + int flags; + unsigned short unitsPerEm; + unsigned short indexToLocFormat; // 0=short, 1=long + unsigned short numGlyphs; + + // optionally loaded data + unsigned int *glyphOffsets; + unsigned short numberOfHMetrics; + char *hmtx, *name, *cmap; + const char *unimap; // ptr to (3,1) or (3,0) cmap start + + // single glyf buffer, allocated large enough by otf_load_more() + char *gly; + OTF_DIRENT *glyfTable; + +} OTF_FILE; + +// SFNT Font files + +struct _FONTFILE +{ + OTF_FILE *sfnt; + // ??? *cff; + char *stdname; + union + { + int fobj; + void *user; + }; +}; + +typedef struct _FONTFILE FONTFILE; + +// Output callback function type + +typedef void (*OUTPUT_FN)(const char *buf, int len, void *context); + +// Bit manipulation + +typedef int* BITSET; + +// General font embedding + +typedef enum +{ + EMB_FMT_T1, // type1, with AFM/PFM,PFA/PFB + EMB_FMT_TTF, // sfnt, for TTF(glyf) + EMB_FMT_OTF, // sfnt+cff, for OTF(cff) + EMB_FMT_CFF, // cff, for raw CFF + EMB_FMT_STDFONT // don't embed (already present) +} EMB_FORMAT; + +typedef enum +{ + EMB_DEST_NATIVE, // just subsetting/conversion + EMB_DEST_PS, +//EMB_DEST_PS2, +//EMB_DEST_PDF13, + EMB_DEST_PDF16 +} EMB_DESTINATION; + +typedef enum +{ + EMB_RIGHT_FULL = 0, + EMB_RIGHT_NONE = 0x02, + EMB_RIGHT_READONLY = 0x04, + EMB_RIGHT_NO_SUBSET = 0x0100, + EMB_RIGHT_BITMAPONLY = 0x0200 +} EMB_RIGHT_TYPE; + +typedef enum +{ + EMB_A_MULTIBYTE = 0x01, // embedd as multibyte font? + EMB_A_SUBSET = 0x02, // do subsetting? + EMB_A_T1_TO_CFF = 0x04, // convert Type1 to CFF? + EMB_A_CFF_TO_OTF = 0x08, // wrap CFF(from input or T1+CONVERT_CFF) in sfnt? + // (OTF) + EMB_A_OTF_TO_CFF = 0x10, // unwrap CFF + + EMB_A_CLOSE_FONTFILE = 0x8000 +} EMB_ACTIONS; + +typedef enum +{ + EMB_C_MUST_SUBSET = 0x01, // (fail, when not possible) + EMB_C_EDITABLE_SUBSET = 0x02, // (...) + EMB_C_NEVER_SUBSET = 0x04, // (...) + + EMB_C_FORCE_MULTIBYTE = 0x08, // always use multibyte fonts + + EMB_C_PDF_OT = 0x10, // output TTF/OTF (esp. CFF to OTF) + EMB_C_KEEP_T1 = 0x20, // don't convert T1 to CFF + + EMB_C_TAKE_FONTFILE = 0x8000 // take ownership of fontfile +} EMB_CONSTRAINTS; + +typedef struct _EMB_PARAMS +{ + EMB_FORMAT intype; + EMB_FORMAT outtype; + EMB_DESTINATION dest; + + EMB_ACTIONS plan; + + // font infos + FONTFILE *font; + EMB_RIGHT_TYPE rights; +// public: + BITSET subset; +} EMB_PARAMS; + +// PDF file font embedding +typedef struct +{ + char *fontname; + unsigned int flags; + + // for the following: 0 = not set/invalid + int bbxmin, bbymin, bbxmax, bbymax; + int italicAngle; // >= 90: not set/invalid + int ascent; + int descent; + int capHeight; + int stemV; + // optional, default = 0: + int xHeight; + int avgWidth; + + // CID-additions: + char *panose; // 12 bytes + char *registry, *ordering; + int supplement; + + char data[1]; // used for storing e.g. > fontname +} EMB_PDF_FONTDESCR; + +typedef struct +{ + // normal font + int first, last; + int *widths; + + // multibyte font + int default_width; + int *warray; // format: (len c w ... w)* + // if (len < 0) { c1 (c2 = c1 + (-len)) w } else { c w[len] }, + // terminated by len == 0 + + int data[1]; +} EMB_PDF_FONTWIDTHS; + + +// +// Prototypes... +// + +// OpenType Font (OTF) handling + +// To load TTC collections: append e.g. "/3" for the third font in the file. +OTF_FILE *otf_load(const char *file); +void otf_close(OTF_FILE *otf); + +char *otf_get_table(OTF_FILE *otf, unsigned int tag, int *ret_len); + +int otf_get_width(OTF_FILE *otf, unsigned short gid); +const char *otf_get_name(OTF_FILE *otf, int platformID, int encodingID, + int languageID, int nameID, int *ret_len); +int otf_get_glyph(OTF_FILE *otf, unsigned short gid); +unsigned short otf_from_unicode(OTF_FILE *otf, int unicode); + +// TODO?! allow glyphs==NULL for non-subsetting table reduction? +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); +int otf_subset_cff(OTF_FILE *otf, BITSET glyphs, OUTPUT_FN output, + void *context); +int otf_cff_extract(OTF_FILE *otf, OUTPUT_FN output, void *context); + +// SFNT Font files + +FONTFILE *fontfile_open_sfnt(OTF_FILE *otf); +FONTFILE *fontfile_open_std(const char *name); +void fontfile_close(FONTFILE *ff); + +// General font embedding + +EMB_PARAMS *emb_new(FONTFILE *font, EMB_DESTINATION dest, EMB_CONSTRAINTS mode); +// emb_embed does only the "binary" part +int emb_embed(EMB_PARAMS *emb, OUTPUT_FN output, void *context); + // returns number of bytes written +void emb_close(EMB_PARAMS *emb); + +// PDF file font embedding + +const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb); +const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb); +const char *emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb); + +EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb); +EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb); + +/** TODO elsewhere **/ +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); + + +// +// Inline functions... +// + +// Bit manipulation + +static inline void +bit_set(BITSET bs, + int num) +{ + bs[num / (8 * sizeof(int))] |= 1 << (num % (8 * sizeof(int))); +} + + +static inline int +bit_check(BITSET bs, + int num) +{ + return bs [num / (8 * sizeof(int))] & 1 << (num % (8 * sizeof(int))); +} + + +// Use free() when done. returns NULL on bad_alloc +static inline BITSET +bitset_new(int size) +{ + return (BITSET)calloc(1, ((size + 8 * sizeof(int) - 1) & + ~(8 * sizeof(int) - 1)) / 8); +} + + +static inline int +bits_used(BITSET bits, + int size) // {{{ returns true if any bit is used +{ + size = (size + 8 * sizeof(int) - 1) / (8 * sizeof(int)); + while (size > 0) + { + if (*bits) + return (1); + bits ++; + size --; + } + return (0); +} +// }}} + +// General font embedding + +// TODO: encoding, TODO: ToUnicode +static inline void +emb_set(EMB_PARAMS *emb, + int unicode, + unsigned short gid) // {{{ +{ + if (emb->subset) + { + if (emb->plan & EMB_A_MULTIBYTE) + { + bit_set(emb->subset, gid); + // ToUnicode.add(gid, unicode); + } + else + { + // TODO ... encoding + } + } +} +// }}} + +// TODO: encoding?, TODO: non-sfnt +static inline unsigned short +emb_get(EMB_PARAMS *emb, int unicode) // {{{ gid +{ + const unsigned short gid = otf_from_unicode(emb->font->sfnt, unicode); + emb_set(emb, unicode, gid); + return (gid); +} +// }}} + + +#endif // !_CUPSFILTERS_FONTEMBED_H_ diff --git a/fontembed/README b/cupsfilters/fontembed/README similarity index 76% rename from fontembed/README rename to cupsfilters/fontembed/README index f84bd617b..bd4b5c962 100644 --- a/fontembed/README +++ b/cupsfilters/fontembed/README @@ -1,9 +1,13 @@ -libfontembed - font embedding and subsetting library ----------------------------------------------------- +fontembed/ - font embedding and subsetting functions in libcupsfilters +---------------------------------------------------------------------- -This library implements all the stuff required to +Currently used for the cfFilterTextToPDF() filter function (files +cupsfilters/texttopdf.c, cupsfilters/pdfutils.c, +cupsfilters/pdfutils.h). + +These functions implement all the stuff required to embed and subset TrueType fonts, as for example -required in PDF files. It is completely self-contained, +required in PDF files. There are completely self-contained, although a FreeType binding might come sometime in the future. Currently glyf-flavored TrueType is fully supported, @@ -19,10 +23,10 @@ which requires ToUnicode support; some preparation is already done. Usage ----- -(TODO)... see test_pdf.c ... +(TODO)... see cupsfilters/fontembed/test-pdf.c ... + + * for direct sfnt access and for embedding use - * for direct sfnt access: use - * for embedding: use (which includes ) License (MIT) ------------- diff --git a/fontembed/aglfn13.c b/cupsfilters/fontembed/aglfn13.c similarity index 100% rename from fontembed/aglfn13.c rename to cupsfilters/fontembed/aglfn13.c diff --git a/fontembed/dynstring-private.h b/cupsfilters/fontembed/dynstring-private.h similarity index 100% rename from fontembed/dynstring-private.h rename to cupsfilters/fontembed/dynstring-private.h diff --git a/fontembed/dynstring.c b/cupsfilters/fontembed/dynstring.c similarity index 97% rename from fontembed/dynstring.c rename to cupsfilters/fontembed/dynstring.c index 5dbdceea0..acee65867 100644 --- a/fontembed/dynstring.c +++ b/cupsfilters/fontembed/dynstring.c @@ -1,5 +1,5 @@ #include "dynstring-private.h" -#include "debug-internal.h" +#include #include #include #include diff --git a/fontembed/embed-pdf-int-private.h b/cupsfilters/fontembed/embed-pdf-private.h similarity index 100% rename from fontembed/embed-pdf-int-private.h rename to cupsfilters/fontembed/embed-pdf-private.h diff --git a/fontembed/embed-pdf.c b/cupsfilters/fontembed/embed-pdf.c similarity index 98% rename from fontembed/embed-pdf.c rename to cupsfilters/fontembed/embed-pdf.c index e3ed50fb6..179caed1e 100644 --- a/fontembed/embed-pdf.c +++ b/cupsfilters/fontembed/embed-pdf.c @@ -1,12 +1,11 @@ -#include "embed.h" -#include "embed-pdf.h" // already included fron embed.h ... -#include "embed-pdf-int-private.h" -#include "embed-sfnt-int-private.h" -#include "debug-internal.h" +#include +#include +#include "embed-pdf-private.h" +#include "embed-sfnt-private.h" +#include "frequent-private.h" #include #include #include -#include "frequent-private.h" // NOTE: these must be in sync with the EMB_FORMAT enum diff --git a/fontembed/embed-sfnt-int-private.h b/cupsfilters/fontembed/embed-sfnt-private.h similarity index 94% rename from fontembed/embed-sfnt-int-private.h rename to cupsfilters/fontembed/embed-sfnt-private.h index e1f1553bb..0410741ad 100644 --- a/fontembed/embed-sfnt-int-private.h +++ b/cupsfilters/fontembed/embed-sfnt-private.h @@ -1,8 +1,7 @@ #ifndef _FONTEMBED_EMBED_SFNT_INT_H_ #define _FONTEMBED_EMBED_SFNT_INT_H_ -#include "sfnt.h" -#include "embed-pdf.h" +#include EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf); diff --git a/fontembed/embed-sfnt.c b/cupsfilters/fontembed/embed-sfnt.c similarity index 99% rename from fontembed/embed-sfnt.c rename to cupsfilters/fontembed/embed-sfnt.c index 249c95dca..e67ea25c5 100644 --- a/fontembed/embed-sfnt.c +++ b/cupsfilters/fontembed/embed-sfnt.c @@ -1,9 +1,8 @@ -#include "embed.h" -#include "embed-pdf-int-private.h" -#include "embed-sfnt-int-private.h" -#include "sfnt.h" -#include "sfnt-int-private.h" -#include "debug-internal.h" +#include +#include +#include "embed-pdf-private.h" +#include "embed-sfnt-private.h" +#include "sfnt-private.h" #include #include #include diff --git a/fontembed/embed.c b/cupsfilters/fontembed/embed.c similarity index 98% rename from fontembed/embed.c rename to cupsfilters/fontembed/embed.c index 142f29fd7..c7e0853db 100644 --- a/fontembed/embed.c +++ b/cupsfilters/fontembed/embed.c @@ -1,6 +1,6 @@ -#include "embed.h" -#include "embed-sfnt-int-private.h" -#include "debug-internal.h" +#include +#include "embed-sfnt-private.h" +#include #include #include #include diff --git a/fontembed/fontfile.c b/cupsfilters/fontembed/fontfile.c similarity index 90% rename from fontembed/fontfile.c rename to cupsfilters/fontembed/fontfile.c index 6b923dca5..a97f80770 100644 --- a/fontembed/fontfile.c +++ b/cupsfilters/fontembed/fontfile.c @@ -1,5 +1,5 @@ -#include "fontfile.h" -#include "debug-internal.h" +#include +#include #include diff --git a/fontembed/frequent-private.h b/cupsfilters/fontembed/frequent-private.h similarity index 100% rename from fontembed/frequent-private.h rename to cupsfilters/fontembed/frequent-private.h diff --git a/fontembed/frequent.c b/cupsfilters/fontembed/frequent.c similarity index 98% rename from fontembed/frequent.c rename to cupsfilters/fontembed/frequent.c index bb978b4da..784e9c2e5 100644 --- a/fontembed/frequent.c +++ b/cupsfilters/fontembed/frequent.c @@ -1,5 +1,5 @@ #include "frequent-private.h" -#include "debug-internal.h" +#include #include diff --git a/fontembed/macroman-private.h b/cupsfilters/fontembed/macroman-private.h similarity index 100% rename from fontembed/macroman-private.h rename to cupsfilters/fontembed/macroman-private.h diff --git a/fontembed/sfnt-int-private.h b/cupsfilters/fontembed/sfnt-private.h similarity index 100% rename from fontembed/sfnt-int-private.h rename to cupsfilters/fontembed/sfnt-private.h diff --git a/fontembed/sfnt-subset.c b/cupsfilters/fontembed/sfnt-subset.c similarity index 98% rename from fontembed/sfnt-subset.c rename to cupsfilters/fontembed/sfnt-subset.c index bf5bcd10d..cb8d7502a 100644 --- a/fontembed/sfnt-subset.c +++ b/cupsfilters/fontembed/sfnt-subset.c @@ -1,7 +1,6 @@ -#include "sfnt.h" -#include "sfnt-int-private.h" -#include "bitset.h" -#include "debug-internal.h" +#include +#include +#include "sfnt-private.h" #include #include #include diff --git a/fontembed/sfnt.c b/cupsfilters/fontembed/sfnt.c similarity index 99% rename from fontembed/sfnt.c rename to cupsfilters/fontembed/sfnt.c index 0616e52f6..7beee4216 100644 --- a/fontembed/sfnt.c +++ b/cupsfilters/fontembed/sfnt.c @@ -1,6 +1,6 @@ -#include "sfnt.h" -#include "sfnt-int-private.h" -#include "debug-internal.h" +#include +#include +#include "sfnt-private.h" #include #include #include diff --git a/fontembed/test-analyze.c b/cupsfilters/fontembed/test-analyze.c similarity index 97% rename from fontembed/test-analyze.c rename to cupsfilters/fontembed/test-analyze.c index 2870195c0..36155cda0 100644 --- a/fontembed/test-analyze.c +++ b/cupsfilters/fontembed/test-analyze.c @@ -1,9 +1,8 @@ -#include "sfnt.h" -#include "sfnt-int-private.h" -#include "embed.h" +#include +#include +#include "embed-sfnt-private.h" +#include "sfnt-private.h" #include "config.h" -#include "embed-sfnt-int-private.h" -#include "debug-internal.h" #include #include diff --git a/fontembed/test-pdf.c b/cupsfilters/fontembed/test-pdf.c similarity index 98% rename from fontembed/test-pdf.c rename to cupsfilters/fontembed/test-pdf.c index 197ee5791..6e6c224f6 100644 --- a/fontembed/test-pdf.c +++ b/cupsfilters/fontembed/test-pdf.c @@ -1,7 +1,6 @@ -#include "embed.h" +#include +#include #include "config.h" -#include "sfnt.h" -#include "debug-internal.h" #include #include diff --git a/fontembed/test-ps.c b/cupsfilters/fontembed/test-ps.c similarity index 96% rename from fontembed/test-ps.c rename to cupsfilters/fontembed/test-ps.c index fa593fc82..770fb6d8f 100644 --- a/fontembed/test-ps.c +++ b/cupsfilters/fontembed/test-ps.c @@ -1,7 +1,6 @@ -#include "embed.h" +#include +#include #include "config.h" -#include "sfnt.h" -#include "debug-internal.h" #include #include diff --git a/cupsfilters/pdfutils.c b/cupsfilters/pdfutils.c index 0e41abf4d..7e18766e7 100644 --- a/cupsfilters/pdfutils.c +++ b/cupsfilters/pdfutils.c @@ -8,13 +8,13 @@ // #include -#include "debug-internal.h" #include #include #include #include #include "pdfutils.h" -#include "fontembed/embed.h" +#include "fontembed.h" +#include "debug-internal.h" // diff --git a/cupsfilters/pdfutils.h b/cupsfilters/pdfutils.h index b96d9a604..792cf1e8c 100644 --- a/cupsfilters/pdfutils.h +++ b/cupsfilters/pdfutils.h @@ -20,7 +20,7 @@ extern "C" { // #include -#include +#include // diff --git a/cupsfilters/texttopdf.c b/cupsfilters/texttopdf.c index cf53ddd98..f943fc929 100644 --- a/cupsfilters/texttopdf.c +++ b/cupsfilters/texttopdf.c @@ -15,17 +15,15 @@ // Include necessary headers... // -#include "debug-internal.h" #include -#include "cupsfilters/pdfutils.h" -#include "cupsfilters/raster.h" +#include "pdfutils.h" +#include "debug-internal.h" +#include "filter.h" +#include "raster.h" +#include "fontembed.h" #include #include -#include "filter.h" #include "fontconfig/fontconfig.h" -#include "fontembed/embed.h" -#include "fontembed/sfnt.h" -#include "fontembed/fontfile.h" // diff --git a/filter/test_pdf2.c b/filter/test_pdf2.c index 8eaef3892..46414c31d 100644 --- a/filter/test_pdf2.c +++ b/filter/test_pdf2.c @@ -1,8 +1,7 @@ #include "pdfutils.h" #include "config.h" #include "debug-internal.h" -#include "fontembed/embed.h" -#include "fontembed/sfnt.h" +#include "cupsfilters/fontembed.h" #include diff --git a/fontembed/bitset.h b/fontembed/bitset.h deleted file mode 100644 index f7766e0ed..000000000 --- a/fontembed/bitset.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _FONTEMBED_BITSET_H_ -#define _FONTEMBED_BITSET_H_ - -#include - -typedef int* BITSET; - - -static inline void -bit_set(BITSET bs, - int num) -{ - bs[num / (8 * sizeof(int))] |= 1 << (num % (8 * sizeof(int))); -} - - -static inline int -bit_check(BITSET bs, - int num) -{ - return bs [num / (8 * sizeof(int))] & 1 << (num % (8 * sizeof(int))); -} - - -// Use free() when done. returns NULL on bad_alloc -static inline BITSET -bitset_new(int size) -{ - return (BITSET)calloc(1, ((size + 8 * sizeof(int) - 1) & - ~(8 * sizeof(int) - 1)) / 8); -} - - -static inline int -bits_used(BITSET bits, - int size) // {{{ returns true if any bit is used -{ - size = (size + 8 * sizeof(int) - 1) / (8 * sizeof(int)); - while (size > 0) - { - if (*bits) - return (1); - bits ++; - size --; - } - return (0); -} -// }}} - -#endif // !_FONTEMBED_BITSET_H_ diff --git a/fontembed/debug-internal.h b/fontembed/debug-internal.h deleted file mode 100644 index 5e4eaf3c4..000000000 --- a/fontembed/debug-internal.h +++ /dev/null @@ -1,43 +0,0 @@ -// -// Internal debugging macros for libfontembed. -// -// Copyright © 2007-2018 by Apple Inc. -// Copyright © 1997-2005 by Easy Software Products. -// -// Licensed under Apache License v2.0. See the file "LICENSE" for more -// information. -// - -#ifndef _FONTEMBED_DEBUG_INTERNAL_H_ -# define _FONTEMBED_DEBUG_INTERNAL_H_ - - -// -// C++ magic... -// - -# ifdef __cplusplus -extern "C" { -# endif // __cplusplus - - -// -// The debug macros are used if you compile with DEBUG defined. -// -// Usage: -// -// DEBUG_assert(boolean expression); -// - -# ifdef DEBUG -# include -# define DEBUG_assert(x) assert(x) -# else -# define DEBUG_assert(x) -# endif // DEBUG - -# ifdef __cplusplus -} -# endif // __cplusplus - -#endif // !_FONTEMBED_DEBUG_INTERNAL_H_ diff --git a/fontembed/embed-pdf.h b/fontembed/embed-pdf.h deleted file mode 100644 index 0df8f42c0..000000000 --- a/fontembed/embed-pdf.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _FONTEMBED_EMBED_PDF_H_ -#define _FONTEMBED_EMBED_PDF_H_ - - -// all the necessary information for PDF font embedding -typedef struct -{ - char *fontname; - unsigned int flags; - - // for the following: 0 = not set/invalid - int bbxmin, bbymin, bbxmax, bbymax; - int italicAngle; // >= 90: not set/invalid - int ascent; - int descent; - int capHeight; - int stemV; - // optional, default = 0: - int xHeight; - int avgWidth; - - // CID-additions: - char *panose; // 12 bytes - char *registry, *ordering; - int supplement; - - char data[1]; // used for storing e.g. > fontname -} EMB_PDF_FONTDESCR; - -typedef struct -{ - // normal font - int first, last; - int *widths; - - // multibyte font - int default_width; - int *warray; // format: (len c w ... w)* - // if (len < 0) { c1 (c2 = c1 + (-len)) w } else { c w[len] }, - // terminated by len == 0 - - int data[1]; -} EMB_PDF_FONTWIDTHS; - - -const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb); -const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb); -const char *emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb); - -EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb); -EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb); - -/** TODO elsewhere **/ -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 // !_FONTEMBED_EMBED_PDF_H_ diff --git a/fontembed/embed.h b/fontembed/embed.h deleted file mode 100644 index a08d22774..000000000 --- a/fontembed/embed.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef _FONTEMBED_EMBED_H_ -#define _FONTEMBED_EMBED_H_ - -#include "bitset.h" -#include "fontfile.h" -#include "iofn.h" - - -typedef enum -{ - EMB_FMT_T1, // type1, with AFM/PFM,PFA/PFB - EMB_FMT_TTF, // sfnt, for TTF(glyf) - EMB_FMT_OTF, // sfnt+cff, for OTF(cff) - EMB_FMT_CFF, // cff, for raw CFF - EMB_FMT_STDFONT // don't embed (already present) -} EMB_FORMAT; - -typedef enum -{ - EMB_DEST_NATIVE, // just subsetting/conversion - EMB_DEST_PS, -// EMB_DEST_PS2, -// EMB_DEST_PDF13, - EMB_DEST_PDF16 -} EMB_DESTINATION; - -typedef enum -{ - EMB_RIGHT_FULL = 0, - EMB_RIGHT_NONE = 0x02, - EMB_RIGHT_READONLY = 0x04, - EMB_RIGHT_NO_SUBSET = 0x0100, - EMB_RIGHT_BITMAPONLY = 0x0200 -} EMB_RIGHT_TYPE; - -typedef enum -{ - EMB_A_MULTIBYTE = 0x01, // embedd as multibyte font? - EMB_A_SUBSET = 0x02, // do subsetting? - EMB_A_T1_TO_CFF = 0x04, // convert Type1 to CFF? - EMB_A_CFF_TO_OTF = 0x08, // wrap CFF(from input or T1+CONVERT_CFF) in sfnt? - // (OTF) - EMB_A_OTF_TO_CFF = 0x10, // unwrap CFF - - EMB_A_CLOSE_FONTFILE = 0x8000 -} EMB_ACTIONS; - -typedef enum -{ - EMB_C_MUST_SUBSET = 0x01, // (fail, when not possible) - EMB_C_EDITABLE_SUBSET = 0x02, // (...) - EMB_C_NEVER_SUBSET = 0x04, // (...) - - EMB_C_FORCE_MULTIBYTE = 0x08, // always use multibyte fonts - - EMB_C_PDF_OT = 0x10, // output TTF/OTF (esp. CFF to OTF) - EMB_C_KEEP_T1 = 0x20, // don't convert T1 to CFF - - EMB_C_TAKE_FONTFILE = 0x8000 // take ownership of fontfile -} EMB_CONSTRAINTS; - -typedef struct _EMB_PARAMS -{ - EMB_FORMAT intype; - EMB_FORMAT outtype; - EMB_DESTINATION dest; - - EMB_ACTIONS plan; - - // font infos - FONTFILE *font; - EMB_RIGHT_TYPE rights; -// public: - BITSET subset; -} EMB_PARAMS; - - -EMB_PARAMS *emb_new(FONTFILE *font, EMB_DESTINATION dest, EMB_CONSTRAINTS mode); -// emb_embed does only the "binary" part -int emb_embed(EMB_PARAMS *emb, OUTPUT_FN output, void *context); - // returns number of bytes written -void emb_close(EMB_PARAMS *emb); - - -// TODO: encoding, TODO: ToUnicode -static inline void -emb_set(EMB_PARAMS *emb, - int unicode, - unsigned short gid) // {{{ -{ - if (emb->subset) - { - if (emb->plan & EMB_A_MULTIBYTE) - { - bit_set(emb->subset, gid); - // ToUnicode.add(gid, unicode); - } - else - { - // TODO ... encoding - } - } -} -// }}} - - -// TODO: encoding?, TODO: non-sfnt -static inline unsigned short -emb_get(EMB_PARAMS *emb, int unicode) // {{{ gid -{ - const unsigned short gid = otf_from_unicode(emb->font->sfnt, unicode); - emb_set(emb, unicode, gid); - return (gid); -} -// }}} - -#include "embed-pdf.h" - -#endif // !_FONTEMBED_EMBED_H_ diff --git a/fontembed/fontfile.h b/fontembed/fontfile.h deleted file mode 100644 index 7a50a8b3a..000000000 --- a/fontembed/fontfile.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _FONTEMBED_FONTFILE_H_ -#define _FONTEMBED_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 // !_FONTEMBED_FONTFILE_H_ diff --git a/fontembed/iofn.h b/fontembed/iofn.h deleted file mode 100644 index b361f6430..000000000 --- a/fontembed/iofn.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _FONTEMBED_IOFN_H_ -#define _FONTEMBED_IOFN_H_ - -typedef void (*OUTPUT_FN)(const char *buf, int len, void *context); - -#endif // !_FONTEMBED_IOFN_H_ diff --git a/fontembed/sfnt.h b/fontembed/sfnt.h deleted file mode 100644 index f9c9141a7..000000000 --- a/fontembed/sfnt.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef _FONTEMBED_SFNT_H_ -#define _FONTEMBED_SFNT_H_ - -#include - -typedef struct -{ - unsigned int tag; - unsigned int checkSum; - unsigned int offset; - unsigned int length; -} OTF_DIRENT; - -typedef struct -{ - FILE *f; - unsigned int numTTC, useTTC; - unsigned int version; - - unsigned short numTables; - OTF_DIRENT *tables; - - int flags; - unsigned short unitsPerEm; - unsigned short indexToLocFormat; // 0=short, 1=long - unsigned short numGlyphs; - - // optionally loaded data - unsigned int *glyphOffsets; - unsigned short numberOfHMetrics; - char *hmtx, *name, *cmap; - const char *unimap; // ptr to (3,1) or (3,0) cmap start - - // single glyf buffer, allocated large enough by otf_load_more() - char *gly; - OTF_DIRENT *glyfTable; - -} OTF_FILE; - -#define OTF_F_FMT_CFF 0x10000 -#define OTF_F_DO_CHECKSUM 0x40000 - -// to load TTC collections: append e.g. "/3" for the third font in the file. -OTF_FILE *otf_load(const char *file); -void otf_close(OTF_FILE *otf); - -#define OTF_TAG(a, b, c, d) (unsigned int)(((a) << 24) | ((b) << 16) | \ - ((c) << 8) | (d)) -#define OTF_UNTAG(a) (((unsigned int)(a) >> 24) & 0xff), \ - (((unsigned int)(a) >> 16) & 0xff), \ - (((unsigned int)(a) >> 8) & 0xff), \ - (((unsigned int)(a)) & 0xff) - -char *otf_get_table(OTF_FILE *otf, unsigned int tag, int *ret_len); - -int otf_get_width(OTF_FILE *otf, unsigned short gid); -const char *otf_get_name(OTF_FILE *otf, int platformID, int encodingID, - int languageID, int nameID, int *ret_len); -int otf_get_glyph(OTF_FILE *otf, unsigned short gid); -unsigned short otf_from_unicode(OTF_FILE *otf, int unicode); - -#include "bitset.h" -#include "iofn.h" - -// TODO?! allow glyphs==NULL for non-subsetting table reduction? -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); -int otf_subset_cff(OTF_FILE *otf, BITSET glyphs, OUTPUT_FN output, - void *context); -int otf_cff_extract(OTF_FILE *otf, OUTPUT_FN output, void *context); - -#endif // !_FONTEMBED_SFNT_H_ diff --git a/libfontembed.pc.in b/libfontembed.pc.in deleted file mode 100644 index 187cc1863..000000000 --- a/libfontembed.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libfontembed -Description: Library for de/embedding fonts to PDF files -Version: @VERSION@ - -Libs: -L${libdir} -lfontembed -Cflags: -I${includedir}/fontembed -- 2.47.3