]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libfontembed, libcupsfilters: Merge libfontembed into libcupsfilters
authorTill Kamppeter <till.kamppeter@gmail.com>
Mon, 10 Oct 2022 18:34:12 +0000 (20:34 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Mon, 10 Oct 2022 18:34:12 +0000 (20:34 +0200)
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.

34 files changed:
Makefile.am
configure.ac
cupsfilters/fontembed.h [new file with mode: 0644]
cupsfilters/fontembed/README [moved from fontembed/README with 76% similarity]
cupsfilters/fontembed/aglfn13.c [moved from fontembed/aglfn13.c with 100% similarity]
cupsfilters/fontembed/dynstring-private.h [moved from fontembed/dynstring-private.h with 100% similarity]
cupsfilters/fontembed/dynstring.c [moved from fontembed/dynstring.c with 97% similarity]
cupsfilters/fontembed/embed-pdf-private.h [moved from fontembed/embed-pdf-int-private.h with 100% similarity]
cupsfilters/fontembed/embed-pdf.c [moved from fontembed/embed-pdf.c with 98% similarity]
cupsfilters/fontembed/embed-sfnt-private.h [moved from fontembed/embed-sfnt-int-private.h with 94% similarity]
cupsfilters/fontembed/embed-sfnt.c [moved from fontembed/embed-sfnt.c with 99% similarity]
cupsfilters/fontembed/embed.c [moved from fontembed/embed.c with 98% similarity]
cupsfilters/fontembed/fontfile.c [moved from fontembed/fontfile.c with 90% similarity]
cupsfilters/fontembed/frequent-private.h [moved from fontembed/frequent-private.h with 100% similarity]
cupsfilters/fontembed/frequent.c [moved from fontembed/frequent.c with 98% similarity]
cupsfilters/fontembed/macroman-private.h [moved from fontembed/macroman-private.h with 100% similarity]
cupsfilters/fontembed/sfnt-private.h [moved from fontembed/sfnt-int-private.h with 100% similarity]
cupsfilters/fontembed/sfnt-subset.c [moved from fontembed/sfnt-subset.c with 98% similarity]
cupsfilters/fontembed/sfnt.c [moved from fontembed/sfnt.c with 99% similarity]
cupsfilters/fontembed/test-analyze.c [moved from fontembed/test-analyze.c with 97% similarity]
cupsfilters/fontembed/test-pdf.c [moved from fontembed/test-pdf.c with 98% similarity]
cupsfilters/fontembed/test-ps.c [moved from fontembed/test-ps.c with 96% similarity]
cupsfilters/pdfutils.c
cupsfilters/pdfutils.h
cupsfilters/texttopdf.c
filter/test_pdf2.c
fontembed/bitset.h [deleted file]
fontembed/debug-internal.h [deleted file]
fontembed/embed-pdf.h [deleted file]
fontembed/embed.h [deleted file]
fontembed/fontfile.h [deleted file]
fontembed/iofn.h [deleted file]
fontembed/sfnt.h [deleted file]
libfontembed.pc.in [deleted file]

index e56edf0d9fba90e821e64759a6464440f3d6e27e..3d0909c5002e843032e7e51913a253e9b904fbf4 100644 (file)
@@ -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 = \
index 5fcab1378b72ed6b7f92d97c37841fed299d7c0f..c4775bea679b4ee5e8ecf42b64f7db498173f6cc 100644 (file)
@@ -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 (file)
index 0000000..0faf70c
--- /dev/null
@@ -0,0 +1,342 @@
+#ifndef _CUPSFILTERS_FONTEMBED_H_
+#define _CUPSFILTERS_FONTEMBED_H_
+
+
+//
+// Include necessary headers...
+//
+
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//
+// 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_
similarity index 76%
rename from fontembed/README
rename to cupsfilters/fontembed/README
index f84bd617b2a14f0be7c47b7a891119d0d75659aa..bd4b5c962e982a7c85be3b48177ca8d5f6a51d53 100644 (file)
@@ -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 <cupsfilters/fontembed.h>
 
- * for direct sfnt access: use <sfnt.h>
- * for embedding: use <embed.h>  (which includes <fontfile.h>)
 
 License (MIT)
 -------------
similarity index 97%
rename from fontembed/dynstring.c
rename to cupsfilters/fontembed/dynstring.c
index 5dbdceea0f22852d3d9b8f444a4a3817ab54f8c9..acee658679d808df5f1d96be7028d988a44b9236 100644 (file)
@@ -1,5 +1,5 @@
 #include "dynstring-private.h"
-#include "debug-internal.h"
+#include <cupsfilters/debug-internal.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
similarity index 98%
rename from fontembed/embed-pdf.c
rename to cupsfilters/fontembed/embed-pdf.c
index e3ed50fb6dc6d8f6895a075d74ac4be9b4491b66..179caed1e1a8ebddaade894cef29e76cfb75c30d 100644 (file)
@@ -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 <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
+#include "embed-pdf-private.h"
+#include "embed-sfnt-private.h"
+#include "frequent-private.h"
 #include <errno.h>
 #include <string.h>
 #include <time.h>
-#include "frequent-private.h"
 
 
 // NOTE: these must be in sync with the EMB_FORMAT enum
similarity index 94%
rename from fontembed/embed-sfnt-int-private.h
rename to cupsfilters/fontembed/embed-sfnt-private.h
index e1f1553bbf27fdd9fd260b72b1e1d372e74fd2c8..0410741ad0e0ed0faac2ed23e7ea3dfa47682a2b 100644 (file)
@@ -1,8 +1,7 @@
 #ifndef _FONTEMBED_EMBED_SFNT_INT_H_
 #define _FONTEMBED_EMBED_SFNT_INT_H_
 
-#include "sfnt.h"
-#include "embed-pdf.h"
+#include <cupsfilters/fontembed.h>
 
 
 EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf);
similarity index 99%
rename from fontembed/embed-sfnt.c
rename to cupsfilters/fontembed/embed-sfnt.c
index 249c95dca7f6fec79bf4547ae2e0fef894594137..e67ea25c5367072bb699e3322106bce0e24b8dd5 100644 (file)
@@ -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 <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
+#include "embed-pdf-private.h"
+#include "embed-sfnt-private.h"
+#include "sfnt-private.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
similarity index 98%
rename from fontembed/embed.c
rename to cupsfilters/fontembed/embed.c
index 142f29fd7a67070508182685bf164e3d75708783..c7e0853dbe5687985117e8a6e973b123b9991ba9 100644 (file)
@@ -1,6 +1,6 @@
-#include "embed.h"
-#include "embed-sfnt-int-private.h"
-#include "debug-internal.h"
+#include <cupsfilters/fontembed.h>
+#include "embed-sfnt-private.h"
+#include <cupsfilters/debug-internal.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
similarity index 90%
rename from fontembed/fontfile.c
rename to cupsfilters/fontembed/fontfile.c
index 6b923dca578ccbcbdeb76b66015eb6fc0b86c28c..a97f80770bdec1a05a75f12b3bdcf951ed6ceeef 100644 (file)
@@ -1,5 +1,5 @@
-#include "fontfile.h"
-#include "debug-internal.h"
+#include <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
 #include <string.h>
 
 
similarity index 98%
rename from fontembed/frequent.c
rename to cupsfilters/fontembed/frequent.c
index bb978b4da316e1b66bf4ce611f6589c5dc3142ee..784e9c2e5f2cc577ec1ef7ba9193f99fe1cbf888 100644 (file)
@@ -1,5 +1,5 @@
 #include "frequent-private.h"
-#include "debug-internal.h"
+#include <cupsfilters/debug-internal.h>
 #include <stdlib.h>
 
 
similarity index 98%
rename from fontembed/sfnt-subset.c
rename to cupsfilters/fontembed/sfnt-subset.c
index bf5bcd10dbd6037725685e3046adc0131209a37f..cb8d7502a03bc51d5adc01cdca2006a8fe9c200e 100644 (file)
@@ -1,7 +1,6 @@
-#include "sfnt.h"
-#include "sfnt-int-private.h"
-#include "bitset.h"
-#include "debug-internal.h"
+#include <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
+#include "sfnt-private.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
similarity index 99%
rename from fontembed/sfnt.c
rename to cupsfilters/fontembed/sfnt.c
index 0616e52f6a61918da44179d2f05b7ba7550161cb..7beee4216a280d8cd1faea78fd31417951d6817d 100644 (file)
@@ -1,6 +1,6 @@
-#include "sfnt.h"
-#include "sfnt-int-private.h"
-#include "debug-internal.h"
+#include <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
+#include "sfnt-private.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
similarity index 97%
rename from fontembed/test-analyze.c
rename to cupsfilters/fontembed/test-analyze.c
index 2870195c090f71eb9996c8c135a2408fe25c6fed..36155cda08cfa1d821750246fffa8b8121d894eb 100644 (file)
@@ -1,9 +1,8 @@
-#include "sfnt.h"
-#include "sfnt-int-private.h"
-#include "embed.h"
+#include <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
+#include "embed-sfnt-private.h"
+#include "sfnt-private.h"
 #include "config.h"
-#include "embed-sfnt-int-private.h"
-#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
similarity index 98%
rename from fontembed/test-pdf.c
rename to cupsfilters/fontembed/test-pdf.c
index 197ee5791d1c28f2bb2a328e8a2a8e051899a91e..6e6c224f6636e163903be2fc9e2f5e459734c4ac 100644 (file)
@@ -1,7 +1,6 @@
-#include "embed.h"
+#include <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
 #include "config.h"
-#include "sfnt.h"
-#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
similarity index 96%
rename from fontembed/test-ps.c
rename to cupsfilters/fontembed/test-ps.c
index fa593fc82c623e11b87e5cbf780230695e458e71..770fb6d8facc977df4c0993e314e944b2d54dae3 100644 (file)
@@ -1,7 +1,6 @@
-#include "embed.h"
+#include <cupsfilters/fontembed.h>
+#include <cupsfilters/debug-internal.h>
 #include "config.h"
-#include "sfnt.h"
-#include "debug-internal.h"
 #include <stdio.h>
 #include <stdlib.h>
 
index 0e41abf4d339d857f401e3f9633c6620855aa616..7e18766e7c9046dcc709b176e93d4296dca8f5ac 100644 (file)
@@ -8,13 +8,13 @@
 //
 
 #include <stdio.h>
-#include "debug-internal.h"
 #include <stdarg.h>
 #include <memory.h>
 #include <stdlib.h>
 #include <string.h>
 #include "pdfutils.h"
-#include "fontembed/embed.h"
+#include "fontembed.h"
+#include "debug-internal.h"
 
 
 //
index b96d9a6042e7179bc706e2cbce1eec46d575bb79..792cf1e8c715ae75bf69a60a5ee585aeac6b0400 100644 (file)
@@ -20,7 +20,7 @@ extern "C" {
 //
 
 #include <time.h>
-#include <fontembed/embed.h>
+#include <cupsfilters/fontembed.h>
 
 
 //
index cf53ddd98811d9db702afa397d4a92df39427434..f943fc9296eee77751b212e86d634e97c259fc59 100644 (file)
 // Include necessary headers...
 //
 
-#include "debug-internal.h"
 #include <config.h>
-#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 <ctype.h>
 #include <errno.h>
-#include "filter.h"
 #include "fontconfig/fontconfig.h"
-#include "fontembed/embed.h"
-#include "fontembed/sfnt.h"
-#include "fontembed/fontfile.h"
 
 
 //
index 8eaef38923c07c91b6cdbcf099a324b7f697d616..46414c31d48bbc990e2d4d836a318023a967fef7 100644 (file)
@@ -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 <stdio.h>
 
diff --git a/fontembed/bitset.h b/fontembed/bitset.h
deleted file mode 100644 (file)
index f7766e0..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef _FONTEMBED_BITSET_H_
-#define _FONTEMBED_BITSET_H_
-
-#include <stdlib.h>
-
-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 (file)
index 5e4eaf3..0000000
+++ /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 <assert.h>
-#    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 (file)
index 0df8f42..0000000
+++ /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 (file)
index a08d227..0000000
+++ /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 (file)
index 7a50a8b..0000000
+++ /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 (file)
index b361f64..0000000
+++ /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 (file)
index f9c9141..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef _FONTEMBED_SFNT_H_
-#define _FONTEMBED_SFNT_H_
-
-#include <stdio.h>
-
-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 (file)
index 187cc18..0000000
+++ /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