]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Renamed functions and types in fontembed code
authorTill Kamppeter <till.kamppeter@gmail.com>
Tue, 11 Oct 2022 06:49:40 +0000 (08:49 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Tue, 11 Oct 2022 06:49:40 +0000 (08:49 +0200)
Renamed all functions and types in the source files in the fontembed/
subdirectory tofollow the rules of DEVELOPING.md of CUPS.

To distinguish functions and types internal to only fontembed/ and
internal to the whole libcupsfilters, the ones internal to fontembed/
have two underscores in the beginning of their names now
("__cfFontEmbed...", "__cf_fontembed_...") while the ones which form
the internal API to libcupsfilters have only one ("_cfFontEmbed...",
"_cf_fontembed_...").

Also considered the API of fontembed as internal to
libcupsfilters. Therefore renamed cupsfilters/fontembed.h to
cupsfilters/fontembed-private.h and not installing it into
/usr/include.

25 files changed:
Makefile.am
cupsfilters/fontembed-private.h [new file with mode: 0644]
cupsfilters/fontembed.h [deleted file]
cupsfilters/fontembed/README
cupsfilters/fontembed/dynstring-private.h
cupsfilters/fontembed/dynstring.c
cupsfilters/fontembed/embed-pdf-private.h
cupsfilters/fontembed/embed-pdf.c
cupsfilters/fontembed/embed-sfnt-private.h
cupsfilters/fontembed/embed-sfnt.c
cupsfilters/fontembed/embed.c
cupsfilters/fontembed/fontfile.c
cupsfilters/fontembed/frequent-private.h
cupsfilters/fontembed/frequent.c
cupsfilters/fontembed/macroman-private.h
cupsfilters/fontembed/sfnt-private.h
cupsfilters/fontembed/sfnt-subset.c
cupsfilters/fontembed/sfnt.c
cupsfilters/fontembed/test-analyze.c
cupsfilters/fontembed/test-pdf.c
cupsfilters/fontembed/test-ps.c
cupsfilters/pdfutils.c
cupsfilters/pdfutils.h
cupsfilters/texttopdf.c
filter/test_pdf2.c

index 3d0909c5002e843032e7e51913a253e9b904fbf4..b2bd76429edfd019ea6f9d77a1b09dcc215cc49c 100644 (file)
@@ -177,7 +177,6 @@ pkgfiltersinclude_DATA = \
        cupsfilters/colormanager.h \
        cupsfilters/driver.h \
        cupsfilters/filter.h \
-       cupsfilters/fontembed.h \
        cupsfilters/ieee1284.h \
        cupsfilters/image.h \
        cupsfilters/ipp.h \
@@ -232,6 +231,7 @@ libcupsfilters_la_SOURCES = \
        cupsfilters/debug-internal.h \
        cupsfilters/dither.c \
        cupsfilters/filter.c \
+       cupsfilters/fontembed-private.h \
        cupsfilters/fontembed/aglfn13.c \
        cupsfilters/fontembed/dynstring.c \
        cupsfilters/fontembed/dynstring-private.h \
diff --git a/cupsfilters/fontembed-private.h b/cupsfilters/fontembed-private.h
new file mode 100644 (file)
index 0000000..741ef87
--- /dev/null
@@ -0,0 +1,366 @@
+#ifndef _CUPSFILTERS_FONTEMBED_H_
+#define _CUPSFILTERS_FONTEMBED_H_
+
+
+//
+// Include necessary headers...
+//
+
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//
+// Constants and macros...
+//
+
+#define _CF_FONTEMBED_OTF_F_FMT_CFF      0x10000
+#define _CF_FONTEMBED_OTF_F_DO_CHECKSUM  0x40000
+
+#define _CF_FONTEMBED_OTF_TAG(a, b, c, d) (unsigned int)(((a) << 24) | \
+                                                        ((b) << 16) | \
+                                                        ((c) << 8) | (d))
+#define _CF_FONTEMBED_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;
+} _cf_fontembed_otf_dir_ent_t;
+
+typedef struct
+{
+  FILE *f;
+  unsigned int numTTC, useTTC;
+  unsigned int version;
+
+  unsigned short numTables;
+  _cf_fontembed_otf_dir_ent_t *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 __cfFontEmbedOTFLoadMore()
+  char *gly;
+  _cf_fontembed_otf_dir_ent_t *glyfTable;
+
+} _cf_fontembed_otf_file_t;
+
+// SFNT Font files
+
+struct _cf_fontembed_fontfile_s
+{
+  _cf_fontembed_otf_file_t *sfnt;
+  // ??? *cff;
+  char *stdname;
+  union
+  {
+    int fobj;
+    void *user;
+  };
+};
+
+typedef struct _cf_fontembed_fontfile_s _cf_fontembed_fontfile_t;
+
+// Output callback function type
+
+typedef void (*_cf_fontembed_output_fn_t)(const char *buf, int len,
+                                         void *context);
+
+// Bit manipulation
+
+typedef int* _cf_fontembed_bit_set_t;
+
+// General font embedding
+
+typedef enum
+{
+  _CF_FONTEMBED_EMB_FMT_T1,       // type1, with AFM/PFM,PFA/PFB
+  _CF_FONTEMBED_EMB_FMT_TTF,      // sfnt, for TTF(glyf)
+  _CF_FONTEMBED_EMB_FMT_OTF,      // sfnt+cff, for OTF(cff)
+  _CF_FONTEMBED_EMB_FMT_CFF,      // cff, for raw CFF
+  _CF_FONTEMBED_EMB_FMT_STDFONT   // don't embed (already present)
+} _cf_fontembed_emb_format_t;
+
+typedef enum
+{
+  _CF_FONTEMBED_EMB_DEST_NATIVE,  // just subsetting/conversion
+  _CF_FONTEMBED_EMB_DEST_PS,
+//_CF_FONTEMBED_EMB_DEST_PS2,
+//_CF_FONTEMBED_EMB_DEST_PDF13,
+  _CF_FONTEMBED_EMB_DEST_PDF16
+} _cf_fontembed_emb_dest_t;
+
+typedef enum
+{
+  _CF_FONTEMBED_EMB_RIGHT_FULL = 0,
+  _CF_FONTEMBED_EMB_RIGHT_NONE = 0x02,
+  _CF_FONTEMBED_EMB_RIGHT_READONLY = 0x04,
+  _CF_FONTEMBED_EMB_RIGHT_NO_SUBSET = 0x0100,
+  _CF_FONTEMBED_EMB_RIGHT_BITMAPONLY = 0x0200
+} _cf_fontembed_emb_right_t;
+
+typedef enum
+{
+  _CF_FONTEMBED_EMB_A_MULTIBYTE = 0x01,    // embedd as multibyte font?
+  _CF_FONTEMBED_EMB_A_SUBSET = 0x02,       // do subsetting?
+  _CF_FONTEMBED_EMB_A_T1_TO_CFF = 0x04,    // convert Type1 to CFF?
+  _CF_FONTEMBED_EMB_A_CFF_TO_OTF = 0x08,   // wrap CFF(from input or
+                                           // T1+CONVERT_CFF) in sfnt? (OTF)
+  _CF_FONTEMBED_EMB_A_OTF_TO_CFF = 0x10,   // unwrap CFF
+
+  _CF_FONTEMBED_EMB_A_CLOSE_FONTFILE = 0x8000
+} _cf_fontembed_emb_action_t;
+
+typedef enum
+{
+  _CF_FONTEMBED_EMB_C_MUST_SUBSET = 0x01,     // (fail, when not possible)
+  _CF_FONTEMBED_EMB_C_EDITABLE_SUBSET = 0x02, // (...)
+  _CF_FONTEMBED_EMB_C_NEVER_SUBSET = 0x04,    // (...)
+
+  _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE = 0x08, // always use multibyte fonts
+
+  _CF_FONTEMBED_EMB_C_PDF_OT = 0x10,          // output TTF/OTF (esp. CFF to
+                                              // OTF)
+  _CF_FONTEMBED_EMB_C_KEEP_T1 = 0x20,         // don't convert T1 to CFF
+
+  _CF_FONTEMBED_EMB_C_TAKE_FONTFILE = 0x8000  // take ownership of fontfile
+} _cf_fontembed_emb_constraint_t;
+
+typedef struct _cf_fontembed_emb_params_s
+{
+  _cf_fontembed_emb_format_t intype;
+  _cf_fontembed_emb_format_t outtype;
+  _cf_fontembed_emb_dest_t dest;
+
+  _cf_fontembed_emb_action_t plan;
+
+  // font infos
+  _cf_fontembed_fontfile_t *font;
+  _cf_fontembed_emb_right_t rights;
+// public:
+  _cf_fontembed_bit_set_t subset;
+} _cf_fontembed_emb_params_t;
+
+// 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
+} _cf_fontembed_emb_pdf_font_descr_t;
+
+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];
+} _cf_fontembed_emb_pdf_font_widths_t;
+
+
+//
+// Prototypes...
+//
+
+// OpenType Font (OTF) handling
+
+// To load TTC collections: append e.g. "/3" for the third font in the file.
+_cf_fontembed_otf_file_t *_cfFontEmbedOTFLoad(const char *file);
+void _cfFontEmbedOTFClose(_cf_fontembed_otf_file_t *otf);
+
+char *_cfFontEmbedOTFGetTable(_cf_fontembed_otf_file_t *otf, unsigned int tag,
+                             int *ret_len);
+
+int _cfFontEmbedOTFGetWidth(_cf_fontembed_otf_file_t *otf, unsigned short gid);
+const char *_cfFontEmbedOTFGetName(_cf_fontembed_otf_file_t *otf,
+                                  int platformID, int encodingID,
+                                  int languageID, int nameID, int *ret_len);
+int _cfFontEmbedOTFGetGlyph(_cf_fontembed_otf_file_t *otf, unsigned short gid);
+unsigned short _cfFontEmbedOTFFromUnicode(_cf_fontembed_otf_file_t *otf,
+                                         int unicode);
+
+// TODO?! allow glyphs==NULL for non-subsetting table reduction?
+int _cfFontEmbedOTFSubSet(_cf_fontembed_otf_file_t *otf,
+                         _cf_fontembed_bit_set_t glyphs,
+                         _cf_fontembed_output_fn_t output, void *context);
+int _cfFontEmbedOTFTTCExtract(_cf_fontembed_otf_file_t *otf,
+                             _cf_fontembed_output_fn_t output, void *context);
+int _cfFontEmbedOTFSubSetCFF(_cf_fontembed_otf_file_t *otf,
+                            _cf_fontembed_bit_set_t glyphs,
+                            _cf_fontembed_output_fn_t output, void *context);
+int _cfFontEmbedOTFCFFExtract(_cf_fontembed_otf_file_t *otf,
+                             _cf_fontembed_output_fn_t output, void *context);
+
+// SFNT Font files
+
+_cf_fontembed_fontfile_t
+              *_cfFontEmbedFontFileOpenSFNT(_cf_fontembed_otf_file_t *otf);
+_cf_fontembed_fontfile_t *_cfFontEmbedFontFileOpenStd(const char *name);
+void _cfFontEmbedFontFileClose(_cf_fontembed_fontfile_t *ff);
+
+// General font embedding
+
+_cf_fontembed_emb_params_t
+              *_cfFontEmbedEmbNew(_cf_fontembed_fontfile_t *font,
+                                 _cf_fontembed_emb_dest_t dest,
+                                 _cf_fontembed_emb_constraint_t mode);
+// _cfFontEmbedEmbEmbed does only the "binary" part
+int _cfFontEmbedEmbEmbed(_cf_fontembed_emb_params_t *emb,
+                        _cf_fontembed_output_fn_t output, void *context);
+                                            // returns number of bytes written
+void _cfFontEmbedEmbClose(_cf_fontembed_emb_params_t *emb);
+
+// PDF file font embedding
+
+const char *_cfFontEmbedEmbPDFGetFontSubType(_cf_fontembed_emb_params_t *emb);
+const char *_cfFontEmbedEmbPDFGetFontFileKey(_cf_fontembed_emb_params_t *emb);
+const char
+       *_cfFontEmbedEmbPDFGetFontFileSubType(_cf_fontembed_emb_params_t *emb);
+
+_cf_fontembed_emb_pdf_font_descr_t
+       *_cfFontEmbedEmbPDFFontDescr(_cf_fontembed_emb_params_t *emb);
+_cf_fontembed_emb_pdf_font_widths_t
+       *_cfFontEmbedEmbPDFFontWidths(_cf_fontembed_emb_params_t *emb);
+
+/** TODO elsewhere **/
+char *_cfFontEmbedEmbPDFSimpleFontDescr(_cf_fontembed_emb_params_t *emb,
+                                      _cf_fontembed_emb_pdf_font_descr_t *fdes,
+                                      int fontfile_obj_ref);
+char *_cfFontEmbedEmbPDFSimpleFont(_cf_fontembed_emb_params_t *emb,
+                                  _cf_fontembed_emb_pdf_font_descr_t *fdes,
+                                  _cf_fontembed_emb_pdf_font_widths_t *fwid,
+                                  int fontdescr_obj_ref);
+char *_cfFontEmbedEmbPDFSimpleCIDFont(_cf_fontembed_emb_params_t *emb,
+                                     const char *fontname,
+                                     int descendant_obj_ref);
+char *_cfFontEmbedEmbPDFSimpleStdFont(_cf_fontembed_emb_params_t *emb);
+
+
+//
+// Inline functions...
+//
+
+// Bit manipulation
+
+static inline void
+_cfFontEmbedBitSet(_cf_fontembed_bit_set_t bs,
+                  int num)
+{
+  bs[num / (8 * sizeof(int))] |= 1 << (num % (8 * sizeof(int)));
+}
+
+
+static inline int
+_cfFontEmbedBitCheck(_cf_fontembed_bit_set_t 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 _cf_fontembed_bit_set_t
+_cfFontEmbedBitSetNew(int size)
+{
+  return (_cf_fontembed_bit_set_t)calloc(1, ((size + 8 * sizeof(int) - 1) &
+                                            ~(8 * sizeof(int) - 1)) / 8);
+}
+
+
+static inline int
+_cfFontEmbedBitsUsed(_cf_fontembed_bit_set_t 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
+_cfFontEmbedEmbSet(_cf_fontembed_emb_params_t *emb,
+                  int unicode,
+                  unsigned short gid) // {{{
+{
+  if (emb->subset)
+  {
+    if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE)
+    {
+      _cfFontEmbedBitSet(emb->subset, gid);
+      // ToUnicode.add(gid, unicode);
+    }
+    else
+    {
+      // TODO ... encoding
+    }
+  }
+}
+// }}}
+
+// TODO: encoding?, TODO: non-sfnt
+static inline unsigned short
+_cfFontEmbedEmbGet(_cf_fontembed_emb_params_t *emb, int unicode) // {{{ gid
+{
+  const unsigned short gid = _cfFontEmbedOTFFromUnicode(emb->font->sfnt,
+                                                       unicode);
+  _cfFontEmbedEmbSet(emb, unicode, gid);
+  return (gid);
+}
+// }}}
+
+
+#endif // !_CUPSFILTERS_FONTEMBED_H_
diff --git a/cupsfilters/fontembed.h b/cupsfilters/fontembed.h
deleted file mode 100644 (file)
index 0faf70c..0000000
+++ /dev/null
@@ -1,342 +0,0 @@
-#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_
index bd4b5c962e982a7c85be3b48177ca8d5f6a51d53..a0e30932b9fbbbf4e26efccf788e1bcfe8435ecf 100644 (file)
@@ -25,7 +25,8 @@ Usage
 -----
 (TODO)... see cupsfilters/fontembed/test-pdf.c ...
 
- * for direct sfnt access and for embedding use <cupsfilters/fontembed.h>
+ * for direct sfnt access and for embedding use
+   <cupsfilters/fontembed-private.h>
 
 
 License (MIT)
index 69691cb0d45e76d8ab802a322094da821a05d8a6..0548eb610744e74ab486ce0ed842a08daee5f7c3 100644 (file)
@@ -5,12 +5,14 @@ typedef struct
 {
   int len, alloc;
   char *buf;
-} DYN_STRING;
+} __cf_fontembed_dyn_string_t;
 
-int dyn_init(DYN_STRING *ds, int reserve_size); // -1 on error
-void dyn_free(DYN_STRING *ds);
-int dyn_ensure(DYN_STRING *ds, int free_space);
-int dyn_printf(DYN_STRING *ds, const char *fmt, ...) // appends
+int __cfFontEmbedDynInit(__cf_fontembed_dyn_string_t *ds,
+                        int reserve_size); // -1 on error
+void __cfFontEmbedDynFree(__cf_fontembed_dyn_string_t *ds);
+int __cfFontEmbedDynEnsure(__cf_fontembed_dyn_string_t *ds, int free_space);
+int __cfFontEmbedDynPrintF(__cf_fontembed_dyn_string_t *ds,
+                          const char *fmt, ...) // appends
   __attribute__((format(printf, 2, 3)));
 
 #endif // !_FONTEMBED_DYNSTRING_H_
index acee658679d808df5f1d96be7028d988a44b9236..a77693f2782d3100090f3d3b27219a584d54e1e8 100644 (file)
@@ -8,8 +8,8 @@
 
 
 int
-dyn_init(DYN_STRING *ds,
-        int reserve_size) // {{{
+__cfFontEmbedDynInit(__cf_fontembed_dyn_string_t *ds,
+                    int reserve_size) // {{{
 {
   DEBUG_assert(ds);
   DEBUG_assert(reserve_size > 0);
@@ -30,7 +30,7 @@ dyn_init(DYN_STRING *ds,
 
 
 void
-dyn_free(DYN_STRING *ds) // {{{
+__cfFontEmbedDynFree(__cf_fontembed_dyn_string_t *ds) // {{{
 {
   DEBUG_assert(ds);
 
@@ -43,8 +43,8 @@ dyn_free(DYN_STRING *ds) // {{{
 
 
 int
-dyn_ensure(DYN_STRING *ds,
-          int free_space) // {{{
+__cfFontEmbedDynEnsure(__cf_fontembed_dyn_string_t *ds,
+                      int free_space) // {{{
 {
   DEBUG_assert(ds);
   DEBUG_assert(free_space);
@@ -68,8 +68,8 @@ dyn_ensure(DYN_STRING *ds,
 // }}}
 
 
-int
-dyn_vprintf(DYN_STRING *ds,
+static int
+dyn_vprintf(__cf_fontembed_dyn_string_t *ds,
            const char *fmt,
            va_list ap) // {{{
 {
@@ -78,7 +78,7 @@ dyn_vprintf(DYN_STRING *ds,
   int need, len = strlen(fmt) + 100;
   va_list va;
 
-  if (dyn_ensure(ds, len) == -1)
+  if (__cfFontEmbedDynEnsure(ds, len) == -1)
     return (-1);
 
   while (1)
@@ -94,7 +94,7 @@ dyn_vprintf(DYN_STRING *ds,
       ds->len += need;
       break;
     }
-    if (dyn_ensure(ds, len) == -1)
+    if (__cfFontEmbedDynEnsure(ds, len) == -1)
       return (-1);
   }
   return (0);
@@ -102,9 +102,9 @@ dyn_vprintf(DYN_STRING *ds,
 // }}}
 
 int
-dyn_printf(DYN_STRING *ds,
-          const char *fmt,
-          ...) // {{{
+__cfFontEmbedDynPrintF(__cf_fontembed_dyn_string_t *ds,
+                      const char *fmt,
+                      ...) // {{{
 {
   va_list va;
   int ret;
index 523399e148d0dbf70cb6e7547a0ef1e6bb992412..b276ea1de1d94273de00ea3a7f7743f483904701 100644 (file)
@@ -1,14 +1,14 @@
 #ifndef _FONTEMBED_EMBED_PDF_INT_H_
 #define _FONTEMBED_EMBED_PDF_INT_H_
 
-EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize);
+_cf_fontembed_emb_pdf_font_widths_t *__cfFontEmbedEmbPDFFWNew(int datasize);
 
 // if default_width == -1: default_width will be estimated
 // glyphs == NULL -> output all
-EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,
-                                        int len, int default_width,
-                                        int (*getGlyphWidth)
-                                          (void *context,int gid),
-                                        void *context);
+_cf_fontembed_emb_pdf_font_widths_t
+  *__cfFontEmbedEmbPDFFWCIDWidths(const _cf_fontembed_bit_set_t glyphs,
+                                 int len, int default_width,
+                                 int (*getGlyphWidth)(void *context, int gid),
+                                 void *context);
 
 #endif // !_FONTEMBED_EMBED_PDF_INT_H_
index 179caed1e1a8ebddaade894cef29e76cfb75c30d..26f9b9798be2c88ccf0fe2890b07d3107bb3d517 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "embed-pdf-private.h"
 #include "embed-sfnt-private.h"
@@ -8,7 +8,7 @@
 #include <time.h>
 
 
-// NOTE: these must be in sync with the EMB_FORMAT enum
+// NOTE: these must be in sync with the _cf_fontembed_emb_format_t enum
 static const char *emb_pdf_font_subtype[][2] =
 { // {{{ (output_format, multibyte)
   {"Type1", NULL},
@@ -39,9 +39,9 @@ static const char *emb_pdf_fontfile_subtype[][2] =
 
 
 static inline int
-emb_multibyte(EMB_PARAMS *emb) // {{{
+emb_multibyte(_cf_fontembed_emb_params_t *emb) // {{{
 {
-  return ((emb->plan & EMB_A_MULTIBYTE) ? 1 : 0);
+  return ((emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE) ? 1 : 0);
 }
 // }}}
 
@@ -80,7 +80,7 @@ static const char
 // this is in the font dict
 
 const char *
-emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
+_cfFontEmbedEmbPDFGetFontSubType(_cf_fontembed_emb_params_t *emb) // {{{
 {
   DEBUG_assert(emb);
   return (emb_pdf_font_subtype[emb->outtype][emb_multibyte(emb)]);
@@ -91,7 +91,7 @@ emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
 // in font descriptor
 
 const char *
-emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
+_cfFontEmbedEmbPDFGetFontFileKey(_cf_fontembed_emb_params_t *emb) // {{{
 {
   DEBUG_assert(emb);
   return (emb_pdf_fontfile_key[emb->outtype]);
@@ -102,7 +102,7 @@ emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
 // this is what to put in the font-stream dict
 
 const char *
-emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb) // {{{
+_cfFontEmbedEmbPDFGetFontFileSubType(_cf_fontembed_emb_params_t *emb) // {{{
 {
   DEBUG_assert(emb);
   return (emb_pdf_fontfile_subtype[emb->outtype][emb_multibyte(emb)]);
@@ -110,11 +110,11 @@ emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb) // {{{
 // }}}
 
 
-// {{{ static EMB_PDF_FONTDESCR *
+// {{{ static _cf_fontembed_emb_pdf_font_descr_t *
 //     emb_pdf_fd_new(fontname, subset_tag, cid_registry, cid_ordering,
 //                    cid_supplement, panose)
 
-static EMB_PDF_FONTDESCR *
+static _cf_fontembed_emb_pdf_font_descr_t *
 emb_pdf_fd_new(const char *fontname,
               const char *subset_tag,
               const char *cid_registry, // or supplement==-1
@@ -122,9 +122,9 @@ emb_pdf_fd_new(const char *fontname,
               int cid_supplement) // -1 for non-cid
 {
   DEBUG_assert(fontname);
-  EMB_PDF_FONTDESCR *ret;
+  _cf_fontembed_emb_pdf_font_descr_t *ret;
 
-  int len = sizeof(EMB_PDF_FONTDESCR);
+  int len = sizeof(_cf_fontembed_emb_pdf_font_descr_t);
   if (subset_tag)
   {
     DEBUG_assert(strlen(subset_tag) == 6);
@@ -182,8 +182,9 @@ emb_pdf_fd_new(const char *fontname,
 // }}}
 
 
-EMB_PDF_FONTDESCR *
-emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
+_cf_fontembed_emb_pdf_font_descr_t *
+_cfFontEmbedEmbPDFFontDescr(_cf_fontembed_emb_params_t *emb) // {{{
+                                                    // -  to be freed by user
 {
   DEBUG_assert(emb);
 
@@ -195,7 +196,7 @@ emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
 
   char subtag[7];
   subtag[6] = 0;
-  if (emb->plan & EMB_A_SUBSET)
+  if (emb->plan & _CF_FONTEMBED_EMB_A_SUBSET)
   {
     int iA;
     for (iA = 0; iA < 6; iA ++)
@@ -208,12 +209,13 @@ emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
   // }}}
 
   const char *fontname = NULL;
-  if ((emb->intype == EMB_FMT_TTF) || (emb->intype == EMB_FMT_OTF))
+  if ((emb->intype == _CF_FONTEMBED_EMB_FMT_TTF) ||
+      (emb->intype == _CF_FONTEMBED_EMB_FMT_OTF))
   { // TODO? use fontinfo from CFF when outtype==CFT, etc.?
     DEBUG_assert(emb->font->sfnt);
-    fontname = emb_otf_get_fontname(emb->font->sfnt);
+    fontname = __cfFontEmbedEmbOTFGetFontName(emb->font->sfnt);
   }
-  else if (emb->outtype == EMB_FMT_STDFONT)
+  else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_STDFONT)
     return (NULL);
   else
   {
@@ -222,8 +224,8 @@ emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
     return (NULL);
   }
 
-  EMB_PDF_FONTDESCR *ret;
-  if (emb->plan & EMB_A_MULTIBYTE) // multibyte
+  _cf_fontembed_emb_pdf_font_descr_t *ret;
+  if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE) // multibyte
     ret = emb_pdf_fd_new(fontname, subset_tag, "Adobe", "Identity", 0);
                                                       // TODO other /ROS ?
   else
@@ -231,8 +233,9 @@ emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
   if (!ret)
     return (NULL);
 
-  if ((emb->intype == EMB_FMT_TTF) || (emb->intype == EMB_FMT_OTF))
-    emb_otf_get_pdf_fontdescr(emb->font->sfnt, ret);
+  if ((emb->intype == _CF_FONTEMBED_EMB_FMT_TTF) ||
+      (emb->intype == _CF_FONTEMBED_EMB_FMT_OTF))
+    __cfFontEmbedEmbOTFGetPDFFontDescr(emb->font->sfnt, ret);
   else
     DEBUG_assert(0);
   return (ret);
@@ -240,15 +243,16 @@ emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ -  to be freed by user
 // }}}
 
 
-EMB_PDF_FONTWIDTHS *
-emb_pdf_fw_new(int datasize) // {{{
+_cf_fontembed_emb_pdf_font_widths_t *
+__cfFontEmbedEmbPDFFWNew(int datasize) // {{{
 {
   DEBUG_assert(datasize >= 0);
-  EMB_PDF_FONTWIDTHS *ret =
-    calloc(1, sizeof(EMB_PDF_FONTWIDTHS) + datasize * sizeof(int));
+  _cf_fontembed_emb_pdf_font_widths_t *ret =
+    calloc(1, sizeof(_cf_fontembed_emb_pdf_font_widths_t) +
+          datasize * sizeof(int));
   if (!ret)
   {
-    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+    fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
     DEBUG_assert(0);
     return (NULL);
   }
@@ -259,18 +263,19 @@ emb_pdf_fw_new(int datasize) // {{{
 
 // if default_width == -1: default_width will be estimated
 
-EMB_PDF_FONTWIDTHS *
-emb_pdf_fw_cidwidths(const BITSET glyphs,
-                    int len,
-                    int default_width,
-                    int (*getGlyphWidth)(void *context, int gid),
-                    void *context) // {{{ glyphs == NULL -> output all
+_cf_fontembed_emb_pdf_font_widths_t *
+__cfFontEmbedEmbPDFFWCIDWidths(const _cf_fontembed_bit_set_t glyphs,
+                              int len,
+                              int default_width,
+                              int (*getGlyphWidth)(void *context, int gid),
+                              void *context) // {{{ glyphs == NULL ->
+                                              //                 output all
 {
   DEBUG_assert(getGlyphWidth);
 
-  FREQUENT *freq = NULL;
+  __cf_fontembed_frequent_t *freq = NULL;
   if (default_width < 0)
-    freq = frequent_new(3);
+    freq = __cfFontEmbedFrequentNew(3);
 
   int iA, b, c;
   int size = 0,
@@ -289,7 +294,7 @@ emb_pdf_fw_cidwidths(const BITSET glyphs,
       if (freq)
       {
         const int w = (*getGlyphWidth)(context, iA);
-        frequent_add(freq, w);
+        __cfFontEmbedFrequentAdd(freq, w);
       }
       if (in_region)
         in_region ++;
@@ -311,13 +316,13 @@ emb_pdf_fw_cidwidths(const BITSET glyphs,
 
   if (freq)
   {
-    default_width = frequent_get(freq, 0);
+    default_width = __cfFontEmbedFrequentGet(freq, 0);
     free(freq);
   }
   DEBUG_assert(default_width > 0);
 
   // now create the array
-  EMB_PDF_FONTWIDTHS *ret = emb_pdf_fw_new(size + 1);
+  _cf_fontembed_emb_pdf_font_widths_t *ret = __cfFontEmbedEmbPDFFWNew(size + 1);
   if (!ret)
     return (NULL);
   ret->default_width = default_width;
@@ -412,25 +417,27 @@ emb_pdf_fw_cidwidths(const BITSET glyphs,
 // }}}
 
 
-// TODO: encoding into EMB_PARAMS (emb_new_enc(..., encoding, len, to_unicode));
-//   -> will then change interpretation of BITSET...(?really?); can we allow
-//      dynamic encoding map generation?
-//   -> encoding has a "len";  len<256
+// TODO: Encoding into _cf_fontembed_emb_params_t (emb_new_enc(..., encoding,
+//       len, to_unicode));
+//   -> will then change interpretation of _cf_fontembed_bit_set_t...
+//        (?really?); can we allow dynamic encoding map generation?
+//   -> encoding has a "len";  len < 256
 
-EMB_PDF_FONTWIDTHS *
-emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
+_cf_fontembed_emb_pdf_font_widths_t *
+_cfFontEmbedEmbPDFFontWidths(_cf_fontembed_emb_params_t *emb) // {{{
 {
   DEBUG_assert(emb);
 
-  if ((emb->intype == EMB_FMT_TTF) || (emb->intype == EMB_FMT_OTF))
+  if ((emb->intype == _CF_FONTEMBED_EMB_FMT_TTF) ||
+      (emb->intype == _CF_FONTEMBED_EMB_FMT_OTF))
   {
     DEBUG_assert(emb->font->sfnt);
-    if (emb->plan & EMB_A_MULTIBYTE)
-      return (emb_otf_get_pdf_cidwidths(emb->font->sfnt,emb->subset));
+    if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE)
+      return (__cfFontEmbedEmbOTFGetPDFCIDWidths(emb->font->sfnt, emb->subset));
     else
-      return (emb_otf_get_pdf_widths(emb->font->sfnt, /*encoding*/NULL,
-                                    emb->font->sfnt->numGlyphs,
-                                    emb->subset)); // TODO: encoding
+      return (__cfFontEmbedEmbOTFGetPDFWidths(emb->font->sfnt, /*encoding*/NULL,
+                                             emb->font->sfnt->numGlyphs,
+                                             emb->subset)); // TODO: encoding
   }
   else
   {
@@ -460,9 +467,10 @@ emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
 // would be nice...
 
 char *
-emb_pdf_simple_fontdescr(EMB_PARAMS *emb,
-                        EMB_PDF_FONTDESCR *fdes,
-                        int fontfile_obj_ref) // {{{ - to be freed by user
+_cfFontEmbedEmbPDFSimpleFontDescr(_cf_fontembed_emb_params_t *emb,
+                                 _cf_fontembed_emb_pdf_font_descr_t *fdes,
+                                 int fontfile_obj_ref) // {{{ - to be freed
+                                                        //       by user
 {
   DEBUG_assert(emb);
   DEBUG_assert(fdes);
@@ -532,11 +540,12 @@ emb_pdf_simple_fontdescr(EMB_PARAMS *emb,
     len = snprintf(pos, size, "> >>\n");
     NEXT;
   }
-  // TODO (for Type0)? CIDSet  -> simply our glyphs BITSET  (ok. endianess?)
+  // TODO (for Type0)? CIDSet  -> simply our glyphs _cf_fontembed_bit_set_t
+  // (ok. endianess?)
   len = snprintf(pos, size,
                 "  /%s %d 0 R\n"
                 ">>\n",
-                emb_pdf_get_fontfile_key(emb),
+                _cfFontEmbedEmbPDFGetFontFileKey(emb),
                 fontfile_obj_ref);
   NEXT;
 
@@ -546,93 +555,96 @@ emb_pdf_simple_fontdescr(EMB_PARAMS *emb,
 
 
 char *
-emb_pdf_simple_font(EMB_PARAMS *emb,
-                   EMB_PDF_FONTDESCR *fdes,
-                   EMB_PDF_FONTWIDTHS *fwid,
-                   int fontdescr_obj_ref) // {{{ - to be freed by user
+_cfFontEmbedEmbPDFSimpleFont(_cf_fontembed_emb_params_t *emb,
+                            _cf_fontembed_emb_pdf_font_descr_t *fdes,
+                            _cf_fontembed_emb_pdf_font_widths_t *fwid,
+                            int fontdescr_obj_ref) // {{{ - to be freed by user
 {
   DEBUG_assert(emb);
   DEBUG_assert(fdes);
   DEBUG_assert(fwid);
 
   int iA, iB;
-  DYN_STRING ret;
+  __cf_fontembed_dyn_string_t ret;
 
-  if (dyn_init(&ret, 500) == -1)
+  if (__cfFontEmbedDynInit(&ret, 500) == -1)
     return (NULL);
 
-  dyn_printf(&ret, "<</Type /Font\n"
-                   "  /Subtype /%s\n"
-                   "  /BaseFont /%s\n"
-                   "  /FontDescriptor %d 0 R\n",
-            emb_pdf_get_font_subtype(emb),
-            emb_pdf_escape_name(fdes->fontname,-1),
-            fontdescr_obj_ref);
+  __cfFontEmbedDynPrintF(&ret,
+                        "<</Type /Font\n"
+                        "  /Subtype /%s\n"
+                        "  /BaseFont /%s\n"
+                        "  /FontDescriptor %d 0 R\n",
+                        _cfFontEmbedEmbPDFGetFontSubType(emb),
+                        emb_pdf_escape_name(fdes->fontname,-1),
+                        fontdescr_obj_ref);
 
-  if (emb->plan & EMB_A_MULTIBYTE)
+  if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE)
   {
     // multibyte
     DEBUG_assert(fwid->warray);
-    dyn_printf(&ret, "  /CIDSystemInfo <<\n"
-                     "    /Registry (%s)\n"
-                     "    /Ordering (%s)\n"
-                     "    /Supplement %d\n"
-                     "  >>\n"
-                     "  /DW %d\n",
-//                   "  /CIDToGIDMap /Id...\n" // TrueType only, default
-                                              // Identity  [optional?  which
-                                              // PDF version says what?]
-              fdes->registry,
-              fdes->ordering,
-              fdes->supplement,
-              fwid->default_width);
+    __cfFontEmbedDynPrintF(&ret,
+                          "  /CIDSystemInfo <<\n"
+                          "    /Registry (%s)\n"
+                          "    /Ordering (%s)\n"
+                          "    /Supplement %d\n"
+                          "  >>\n"
+                          "  /DW %d\n",
+                          //"  /CIDToGIDMap /Id...\n" // TrueType only, default
+                          // Identity  [optional?  which
+                          // PDF version says what?]
+                          fdes->registry,
+                          fdes->ordering,
+                          fdes->supplement,
+                          fwid->default_width);
 
     if (fwid->warray[0])
     {
-      dyn_printf(&ret, "  /W [");
+      __cfFontEmbedDynPrintF(&ret, "  /W [");
       for (iA = 0; fwid->warray[iA];)
       {
         if (fwid->warray[iA] < 0)
        {
          // c1 (c1-len) w
-          dyn_printf(&ret, " %d %d %d",
-                    fwid->warray[iA + 1],
-                    fwid->warray[iA + 1] - fwid->warray[iA],
-                    fwid->warray[iA + 2]);
+          __cfFontEmbedDynPrintF(&ret, " %d %d %d",
+                                fwid->warray[iA + 1],
+                                fwid->warray[iA + 1] - fwid->warray[iA],
+                                fwid->warray[iA + 2]);
           iA += 3;
         }
        else
        {
          // c [w ... w]
           iB = fwid->warray[iA ++]; // len
-          dyn_printf(&ret, " %d [", fwid->warray[iA ++]); // c
+          __cfFontEmbedDynPrintF(&ret, " %d [", fwid->warray[iA ++]); // c
           for (; iB > 0; iB --)
-            dyn_printf(&ret, " %d", fwid->warray[iA ++]);
-          dyn_printf(&ret, "]");
+            __cfFontEmbedDynPrintF(&ret, " %d", fwid->warray[iA ++]);
+          __cfFontEmbedDynPrintF(&ret, "]");
         }
       }
-      dyn_printf(&ret, "]\n");
+      __cfFontEmbedDynPrintF(&ret, "]\n");
     }
   }
   else
   {
     // "not std14"
     DEBUG_assert(fwid->widths);
-    dyn_printf(&ret, "  /Encoding /MacRomanEncoding\n"  // optional; TODO!!!!!
-//                   "  /ToUnicode ?\n"  // optional
-                     "  /FirstChar %d\n"
-                     "  /LastChar %d\n"
-                     "  /Widths [",
-              fwid->first,
-              fwid->last);
+    __cfFontEmbedDynPrintF(&ret,
+                          "  /Encoding /MacRomanEncoding\n"// optional; TODO!
+                          //"  /ToUnicode ?\n"  // optional
+                          "  /FirstChar %d\n"
+                          "  /LastChar %d\n"
+                          "  /Widths [",
+                          fwid->first,
+                          fwid->last);
     for (iA = 0, iB = fwid->first; iB <= fwid->last; iA ++, iB ++)
-      dyn_printf(&ret, " %d", fwid->widths[iA]);
-    dyn_printf(&ret, "]\n");
+      __cfFontEmbedDynPrintF(&ret, " %d", fwid->widths[iA]);
+    __cfFontEmbedDynPrintF(&ret, "]\n");
   }
-  dyn_printf(&ret, ">>\n");
+  __cfFontEmbedDynPrintF(&ret, ">>\n");
   if (ret.len == -1)
   {
-    dyn_free(&ret);
+    __cfFontEmbedDynFree(&ret);
     DEBUG_assert(0);
     return (NULL);
   }
@@ -647,10 +659,10 @@ emb_pdf_simple_font(EMB_PARAMS *emb,
 // (TODO?? fontname here without subset-tag [_some_ pdfs out there seem
 //  to be that way])
 // TODO? don't do the CidType0 check here?
-// NOTE: this is _additionally_ to emb_pdf_simple_font()!
+// NOTE: this is _additionally_ to _cfFontEmbedEmbPDFSimpleFont()!
 
 char *
-emb_pdf_simple_cidfont(EMB_PARAMS *emb,
+_cfFontEmbedEmbPDFSimpleCIDFont(_cf_fontembed_emb_params_t *emb,
                       const char *fontname,
                       int descendant_obj_ref) // {{{ - to be freed by user
 {
@@ -670,7 +682,7 @@ emb_pdf_simple_cidfont(EMB_PARAMS *emb,
   // for CFF: one of:
   // UniGB-UCS2-H, UniCNS-UCS2-H, UniJIS-UCS2-H, UniKS-UCS2-H
   const char *encoding = "Identity-H", *addenc = "-";
-  if (emb->outtype == EMB_FMT_TTF)
+  if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
     // !=CidType0
     addenc = "";
 
@@ -696,7 +708,8 @@ emb_pdf_simple_cidfont(EMB_PARAMS *emb,
 
 
 char *
-emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
+_cfFontEmbedEmbPDFSimpleStdFont(_cf_fontembed_emb_params_t *emb)
+                                                 // {{{ - to be freed by user
 {
   DEBUG_assert(emb);
   DEBUG_assert(emb->font->stdname);
@@ -717,7 +730,7 @@ emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
                 "  /Subtype /Type1\n"
                 "  /BaseFont /%s\n"
                 ">>\n",
-//               emb_pdf_get_font_subtype(emb),
+//               _cfFontEmbedEmbPDFGetFontSubType(emb),
                 emb->font->stdname);
   NEXT;
 
index 0410741ad0e0ed0faac2ed23e7ea3dfa47682a2b..a392c59111a361ca9c5685ce1f7c264fd934a012 100644 (file)
@@ -1,22 +1,30 @@
 #ifndef _FONTEMBED_EMBED_SFNT_INT_H_
 #define _FONTEMBED_EMBED_SFNT_INT_H_
 
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 
 
-EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf);
+_cf_fontembed_emb_right_t
+  __cfFontEmbedEmbOTFGetRights(_cf_fontembed_otf_file_t *otf);
 
 // NOTE: statically allocated buffer
-const char *emb_otf_get_fontname(OTF_FILE *otf);
+const char *__cfFontEmbedEmbOTFGetFontName(_cf_fontembed_otf_file_t *otf);
 
-void emb_otf_get_pdf_fontdescr(OTF_FILE *otf, EMB_PDF_FONTDESCR *ret);
-EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,
-                                          const unsigned short *encoding,
-                                          int len, const BITSET glyphs);
-EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,
-                                             const BITSET glyph);
+void
+  __cfFontEmbedEmbOTFGetPDFFontDescr(_cf_fontembed_otf_file_t *otf,
+                                    _cf_fontembed_emb_pdf_font_descr_t *ret);
+_cf_fontembed_emb_pdf_font_widths_t
+  *__cfFontEmbedEmbOTFGetPDFWidths(_cf_fontembed_otf_file_t *otf,
+                                  const unsigned short *encoding,
+                                  int len,
+                                  const _cf_fontembed_bit_set_t glyphs);
+_cf_fontembed_emb_pdf_font_widths_t
+  *__cfFontEmbedEmbOTFGetPDFCIDWidths(_cf_fontembed_otf_file_t *otf,
+                                     const _cf_fontembed_bit_set_t glyph);
 
-int emb_otf_ps(OTF_FILE *otf, unsigned short *encoding, int len,
-              unsigned short *to_unicode, OUTPUT_FN output, void *context);
+int __cfFontEmbedEmbOTFPS(_cf_fontembed_otf_file_t *otf,
+                         unsigned short *encoding, int len,
+                         unsigned short *to_unicode,
+                         _cf_fontembed_output_fn_t output, void *context);
 
 #endif // !_FONTEMBED_EMBED_SFNT_INT_H_
index e67ea25c5367072bb699e3322106bce0e24b8dd5..3120ecc0c1622c46867d402617864f9ff41c761e 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "embed-pdf-private.h"
 #include "embed-sfnt-private.h"
@@ -8,16 +8,18 @@
 #include <string.h>
 
 
-EMB_RIGHT_TYPE
-emb_otf_get_rights(OTF_FILE *otf) // {{{
+_cf_fontembed_emb_right_t
+__cfFontEmbedEmbOTFGetRights(_cf_fontembed_otf_file_t *otf) // {{{
 {
-  EMB_RIGHT_TYPE ret = EMB_RIGHT_FULL;
+  _cf_fontembed_emb_right_t ret = _CF_FONTEMBED_EMB_RIGHT_FULL;
 
   int len;
-  char *os2 = otf_get_table(otf, OTF_TAG('O', 'S', '/', '2'), &len);
+  char *os2 =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('O', 'S', '/', '2'),
+                           &len);
   if (os2)
   {
-    const unsigned short os2_version = get_USHORT(os2);
+    const unsigned short os2_version = __cfFontEmbedGetUShort(os2);
     // check len
     DEBUG_assert((os2_version != 0x0000) || (len == 78));
     DEBUG_assert((os2_version != 0x0001) || (len == 86));
@@ -26,15 +28,16 @@ emb_otf_get_rights(OTF_FILE *otf) // {{{
     if (os2_version <= 0x0004)
     {
       // get rights
-      unsigned short fsType = get_USHORT(os2 + 8);
+      unsigned short fsType = __cfFontEmbedGetUShort(os2 + 8);
       // from Adobe's Fontpolicies_v9.pdf, pg 13:
       if (fsType == 0x0002)
-        ret = EMB_RIGHT_NONE;
+        ret = _CF_FONTEMBED_EMB_RIGHT_NONE;
       else
       {
-        ret = fsType & 0x0300; // EMB_RIGHT_BITMAPONLY, EMB_RIGHT_NO_SUBSET
+        ret = fsType & 0x0300; // _CF_FONTEMBED_EMB_RIGHT_BITMAPONLY,
+                              // _CF_FONTEMBED_EMB_RIGHT_NO_SUBSET
         if ((fsType & 0x000c) == 0x0004)
-          ret |= EMB_RIGHT_READONLY;
+          ret |= _CF_FONTEMBED_EMB_RIGHT_READONLY;
       }
     }
     free(os2);
@@ -47,12 +50,13 @@ emb_otf_get_rights(OTF_FILE *otf) // {{{
 // NOTE: statically allocated buffer
 
 const char *
-emb_otf_get_fontname(OTF_FILE *otf) // {{{
+__cfFontEmbedEmbOTFGetFontName(_cf_fontembed_otf_file_t *otf) // {{{
 {
   static char fontname[64];
 
   int len;
-  const char *fname = otf_get_name(otf, 3, 1, 0x409, 6, &len); // Microsoft
+  const char *fname = _cfFontEmbedOTFGetName(otf, 3, 1, 0x409, 6, &len);
+                                                                // Microsoft
   if (fname)
   {
     int iA, iB = 0;
@@ -65,7 +69,7 @@ emb_otf_get_fontname(OTF_FILE *otf) // {{{
     }
     fontname[iB] = 0;
   }
-  else if ((fname = otf_get_name(otf, 1, 0, 0, 6, &len))) // Mac
+  else if ((fname = _cfFontEmbedOTFGetName(otf, 1, 0, 0, 6, &len))) // Mac
   {
     int iA, iB = 0;
     for (iA = 0; (iA < 63) && (iA < len); iA ++)
@@ -91,25 +95,30 @@ emb_otf_get_fontname(OTF_FILE *otf) // {{{
 // TODO? use PCLT table? (esp. CFF, as table dircouraged for glyf fonts)
 
 void
-emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
-                         EMB_PDF_FONTDESCR *ret) // {{{
+__cfFontEmbedEmbOTFGetPDFFontDescr(_cf_fontembed_otf_file_t *otf,
+                                  _cf_fontembed_emb_pdf_font_descr_t *ret)
+                                                                        // {{{
 {
   int len;
 
 //  TODO
 //  ... fill in struct
-  char *head = otf_get_table(otf, OTF_TAG('h', 'e', 'a', 'd'), &len);
-  DEBUG_assert(head); // version is 1.0 from otf_load
-  ret->bbxmin = get_SHORT(head + 36) * 1000 / otf->unitsPerEm;
-  ret->bbymin = get_SHORT(head + 38) * 1000 / otf->unitsPerEm;
-  ret->bbxmax = get_SHORT(head + 40) * 1000 / otf->unitsPerEm;
-  ret->bbymax = get_SHORT(head + 42) * 1000 / otf->unitsPerEm;
-  const int macStyle = get_USHORT(head + 44);
+  char *head =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'),
+                           &len);
+  DEBUG_assert(head); // version is 1.0 from _cfFontEmbedOTFLoad
+  ret->bbxmin = __cfFontEmbedGetShort(head + 36) * 1000 / otf->unitsPerEm;
+  ret->bbymin = __cfFontEmbedGetShort(head + 38) * 1000 / otf->unitsPerEm;
+  ret->bbxmax = __cfFontEmbedGetShort(head + 40) * 1000 / otf->unitsPerEm;
+  ret->bbymax = __cfFontEmbedGetShort(head + 42) * 1000 / otf->unitsPerEm;
+  const int macStyle = __cfFontEmbedGetUShort(head + 44);
   free(head);
 
-  char *post = otf_get_table(otf, OTF_TAG('p', 'o', 's', 't'), &len);
+  char *post =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('p', 'o', 's', 't'),
+                           &len);
   DEBUG_assert(post);
-  const unsigned int post_version = get_ULONG(post);
+  const unsigned int post_version = __cfFontEmbedGetULong(post);
   // check length
   DEBUG_assert((post_version != 0x00010000) || (len == 32));
   DEBUG_assert((post_version != 0x00020000) ||
@@ -117,9 +126,9 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
   DEBUG_assert((post_version != 0x00025000) || (len == 35 + otf->numGlyphs));
   DEBUG_assert((post_version != 0x00030000) || (len == 32));
   DEBUG_assert((post_version != 0x00020000) ||
-              (get_USHORT(post + 32) == otf->numGlyphs)); // v4?
+              (__cfFontEmbedGetUShort(post + 32) == otf->numGlyphs)); // v4?
   // DEBUG_assert((post_version == 0x00030000) ==
-  //              (!!(otf->flags&OTF_F_FMT_CFF)));
+  //              (!!(otf->flags&_CF_FONTEMBED_OTF_F_FMT_CFF)));
   //                                     // Ghostscript embedding does this..
   // TODO: v4 (apple) :  uint16 reencoding[numGlyphs]
   if ((post_version == 0x00010000) ||
@@ -128,18 +137,20 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
       (post_version == 0x00030000) ||
       (post_version == 0x00040000))
   {
-    ret->italicAngle = get_LONG(post + 4) >> 16;
-    if (get_ULONG(post + 12) > 0) // monospaced
+    ret->italicAngle = __cfFontEmbedGetLong(post + 4) >> 16;
+    if (__cfFontEmbedGetULong(post + 12) > 0) // monospaced
       ret->flags |= 1;
   }
   else
     fprintf(stderr, "WARNING: no italicAngle, no monospaced flag\n");
   free(post);
 
-  char *os2 = otf_get_table(otf, OTF_TAG('O', 'S', '/', '2'), &len);
+  char *os2 =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('O', 'S', '/', '2'),
+                           &len);
   if (os2)
   {
-    const unsigned short os2_version = get_USHORT(os2);
+    const unsigned short os2_version = __cfFontEmbedGetUShort(os2);
     // check len
     DEBUG_assert((os2_version != 0x0000) || (len == 78));
     DEBUG_assert((os2_version != 0x0001) || (len == 86));
@@ -148,7 +159,7 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
     if (os2_version <= 0x0004)
     {
       // from PDF14Deltas.pdf, pg 113
-      const int weightClass = get_USHORT(os2 + 4);
+      const int weightClass = __cfFontEmbedGetUShort(os2 + 4);
       ret->stemV = 50 + weightClass * weightClass / (65 * 65);
                                                      // TODO, really bad
       //printf("a %d\n", weightClass);
@@ -158,14 +169,14 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
         ret->panose = ret->data;
         memcpy(ret->panose, os2 + 30, 12); // sFamilyClass + panose
       }
-      const unsigned short fsSelection = get_USHORT(os2 + 62);
+      const unsigned short fsSelection = __cfFontEmbedGetUShort(os2 + 62);
       if (fsSelection & 0x01)
        // italic
         ret->flags |= 0x0040;
       if ((fsSelection & 0x10) && (weightClass > 600))
        // force bold
         ret->flags |= 0x0400;
-      const unsigned char family_class = get_USHORT(os2 + 30) >> 8;
+      const unsigned char family_class = __cfFontEmbedGetUShort(os2 + 30) >> 8;
       if (family_class == 10)
        // script
         ret->flags |= 0x0008;
@@ -173,13 +184,14 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
        // not sans-serif
         ret->flags |= 0x0002;
 
-      ret->avgWidth = get_SHORT(os2 + 2) * 1000 / otf->unitsPerEm;
-      ret->ascent = get_SHORT(os2 + 68) * 1000 / otf->unitsPerEm;
-      ret->descent = get_SHORT(os2 + 70) * 1000 / otf->unitsPerEm;
+      ret->avgWidth = __cfFontEmbedGetShort(os2 + 2) * 1000 / otf->unitsPerEm;
+      ret->ascent = __cfFontEmbedGetShort(os2 + 68) * 1000 / otf->unitsPerEm;
+      ret->descent = __cfFontEmbedGetShort(os2 + 70) * 1000 / otf->unitsPerEm;
       if (os2_version >= 0x0002)
       {
-        ret->xHeight = get_SHORT(os2 + 86) * 1000 / otf->unitsPerEm;
-        ret->capHeight = get_SHORT(os2 + 88) * 1000 / otf->unitsPerEm;
+        ret->xHeight = __cfFontEmbedGetShort(os2 + 86) * 1000 / otf->unitsPerEm;
+        ret->capHeight = __cfFontEmbedGetShort(os2 + 88) * 1000 /
+         otf->unitsPerEm;
       } // else capHeight fixed later
     }
     else
@@ -208,24 +220,27 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
   // Fallbacks
   if ((!ret->ascent) || (!ret->descent))
   {
-    char *hhea = otf_get_table(otf, OTF_TAG('h', 'h', 'e', 'a'), &len);
+    char *hhea =
+      _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'h', 'e', 'a'),
+                             &len);
     if (hhea)
     {
-      ret->ascent = get_SHORT(hhea + 4) * 1000 / otf->unitsPerEm;
-      ret->descent = get_SHORT(hhea + 6) * 1000 / otf->unitsPerEm;
+      ret->ascent = __cfFontEmbedGetShort(hhea + 4) * 1000 / otf->unitsPerEm;
+      ret->descent = __cfFontEmbedGetShort(hhea + 6) * 1000 / otf->unitsPerEm;
     }
     free(hhea);
   }
   if (!ret->stemV)
   {
     // TODO? use name
-    const unsigned short d_gid = otf_from_unicode(otf, '.');
+    const unsigned short d_gid = _cfFontEmbedOTFFromUnicode(otf, '.');
     if (d_gid)
     {
       // stemV=bbox['.'].width;
-      len = otf_get_glyph(otf, d_gid);
+      len = _cfFontEmbedOTFGetGlyph(otf, d_gid);
       DEBUG_assert(len >= 10);
-      ret->stemV = (get_SHORT(otf->gly + 6) - get_SHORT(otf->gly + 2)) * 1000 /
+      ret->stemV = (__cfFontEmbedGetShort(otf->gly + 6) -
+                   __cfFontEmbedGetShort(otf->gly + 2)) * 1000 /
        otf->unitsPerEm;
     }
     else
@@ -259,11 +274,12 @@ emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
 //    'symbol' + custom(1, 0) / (3, 0)
 // HINT: caller sets len == otf->numGlyphs   (only when not using encoding...)
 
-EMB_PDF_FONTWIDTHS *
-emb_otf_get_pdf_widths(OTF_FILE *otf,
-                      const unsigned short *encoding,
-                      int len,
-                      const BITSET glyphs) // {{{ glyphs == NULL ->
+_cf_fontembed_emb_pdf_font_widths_t *
+__cfFontEmbedEmbOTFGetPDFWidths(_cf_fontembed_otf_file_t *otf,
+                               const unsigned short *encoding,
+                               int len,
+                               const _cf_fontembed_bit_set_t glyphs)
+                                            // {{{ glyphs == NULL ->
                                             //        all from 0 to len
 {
   DEBUG_assert(otf);
@@ -276,8 +292,8 @@ emb_otf_get_pdf_widths(OTF_FILE *otf,
     for (iA = 0; iA < len; iA ++) // iA is a "gid" when in multi_byte mode...
     {
       const int gid = (encoding) ?
-       encoding[iA] : otf_from_unicode(otf, iA); // TODO
-      if (bit_check(glyphs, gid))
+       encoding[iA] : _cfFontEmbedOTFFromUnicode(otf, iA); // TODO
+      if (_cfFontEmbedBitCheck(glyphs, gid))
       {
         if (first > iA)
          // first is a character index
@@ -302,7 +318,7 @@ emb_otf_get_pdf_widths(OTF_FILE *otf,
   // ensure hmtx is there
   if (!otf -> hmtx)
   {
-    if (otf_load_more(otf) != 0)
+    if (__cfFontEmbedOTFLoadMore(otf) != 0)
     {
       fprintf(stderr, "Unsupported OTF font / cmap table \n");
       return (NULL);
@@ -310,7 +326,8 @@ emb_otf_get_pdf_widths(OTF_FILE *otf,
   }
 
   // now create the array
-  EMB_PDF_FONTWIDTHS *ret = emb_pdf_fw_new(last - first + 1);
+  _cf_fontembed_emb_pdf_font_widths_t *ret =
+    __cfFontEmbedEmbPDFFWNew(last - first + 1);
   if (!ret)
     return (NULL);
   ret->first = first;
@@ -319,7 +336,7 @@ emb_otf_get_pdf_widths(OTF_FILE *otf,
   for (iA = 0; first <= last; iA ++, first ++)
   {
     const int gid = (encoding) ?
-      encoding[first] : otf_from_unicode(otf, first); // TODO
+      encoding[first] : _cfFontEmbedOTFFromUnicode(otf, first); // TODO
     if (gid >= otf->numGlyphs)
     {
       fprintf(stderr, "Bad glyphid\n");
@@ -327,8 +344,9 @@ emb_otf_get_pdf_widths(OTF_FILE *otf,
       free(ret);
       return (NULL);
     }
-    if ((!glyphs) || (bit_check(glyphs, gid)))
-      ret->widths[iA] = get_width_fast(otf, gid) * 1000 / otf->unitsPerEm;
+    if ((!glyphs) || (_cfFontEmbedBitCheck(glyphs, gid)))
+      ret->widths[iA] =
+       __cfFontEmbedGetWidthFast(otf, gid) * 1000 / otf->unitsPerEm;
       // else 0 from calloc
   }
 
@@ -342,15 +360,15 @@ emb_otf_get_pdf_widths(OTF_FILE *otf,
 static int
 emb_otf_pdf_glyphwidth(void *context, int gid) // {{{
 {
-  OTF_FILE *otf = (OTF_FILE *)context;
-  return (get_width_fast(otf, gid) * 1000 / otf->unitsPerEm);
+  _cf_fontembed_otf_file_t *otf = (_cf_fontembed_otf_file_t *)context;
+  return (__cfFontEmbedGetWidthFast(otf, gid) * 1000 / otf->unitsPerEm);
 }
 // }}}
 
 
-EMB_PDF_FONTWIDTHS *
-emb_otf_get_pdf_cidwidths(OTF_FILE *otf,
-                         const BITSET glyphs) // {{{
+_cf_fontembed_emb_pdf_font_widths_t *
+__cfFontEmbedEmbOTFGetPDFCIDWidths(_cf_fontembed_otf_file_t *otf,
+                                  const _cf_fontembed_bit_set_t glyphs) // {{{
                                                // glyphs == NULL -> output all
 {
   DEBUG_assert(otf);
@@ -358,7 +376,7 @@ emb_otf_get_pdf_cidwidths(OTF_FILE *otf,
   // ensure hmtx is there
   if (!otf->hmtx)
   {
-    if (otf_load_more(otf) != 0)
+    if (__cfFontEmbedOTFLoadMore(otf) != 0)
     {
       fprintf(stderr, "Unsupported OTF font / cmap table \n");
       return NULL;
@@ -367,8 +385,8 @@ emb_otf_get_pdf_cidwidths(OTF_FILE *otf,
   // int dw = emb_otf_pdf_glyphwidth(otf, 0); // e.g.
   int dw = -1; // let them estimate
 
-  return (emb_pdf_fw_cidwidths(glyphs, otf->numGlyphs, dw,
-                              emb_otf_pdf_glyphwidth, otf));
+  return (__cfFontEmbedEmbPDFFWCIDWidths(glyphs, otf->numGlyphs, dw,
+                                        emb_otf_pdf_glyphwidth, otf));
 }
 // }}}
 
@@ -390,24 +408,26 @@ emb_otf_get_post_name(const char *post,
 {
   if (!post)
     return (NULL);
-  const unsigned int post_version = get_ULONG(post);
+  const unsigned int post_version = __cfFontEmbedGetULong(post);
   if (post_version == 0x00010000) // font has only 258 chars...
                                   // font cannot be used on windows
   {
-    if (gid < sizeof(macRoman) / sizeof(macRoman[0]))
-      return (macRoman[gid]);
+    if (gid < sizeof(__cf_fontembed_mac_roman) /
+       sizeof(__cf_fontembed_mac_roman[0]))
+      return (__cf_fontembed_mac_roman[gid]);
   }
   else if (post_version == 0x00020000)
   {
-    const unsigned short num_glyphs = get_USHORT(post + 32);
+    const unsigned short num_glyphs = __cfFontEmbedGetUShort(post + 32);
     // DEBUG_assert(num_glyphs == otf->numGlyphs);
     if (gid < num_glyphs)
     {
-      unsigned short idx = get_USHORT(post + 34 + 2 * gid);
+      unsigned short idx = __cfFontEmbedGetUShort(post + 34 + 2 * gid);
       if (idx < 258)
       {
-        if (idx < sizeof(macRoman) / sizeof(macRoman[0]))
-          return (macRoman[idx]);
+        if (idx < sizeof(__cf_fontembed_mac_roman) /
+           sizeof(__cf_fontembed_mac_roman[0]))
+          return (__cf_fontembed_mac_roman[idx]);
       }
       else if (idx < 32768)
       {
@@ -426,12 +446,13 @@ emb_otf_get_post_name(const char *post,
   else if (post_version == 0x00025000)
   {
     // similiar to 0x00010000, deprecated
-    const unsigned short num_glyphs = get_USHORT(post + 32);
+    const unsigned short num_glyphs = __cfFontEmbedGetUShort(post + 32);
     if (gid < num_glyphs)
     {
       const unsigned short idx = post[34 + gid] + gid; // post is signed char *
-      if (idx < sizeof(macRoman) / sizeof(macRoman[0]))
-        return (macRoman[idx]);
+      if (idx < sizeof(__cf_fontembed_mac_roman) /
+         sizeof(__cf_fontembed_mac_roman[0]))
+        return (__cf_fontembed_mac_roman[idx]);
     }
   }
   else if (post_version == 0x00030000)
@@ -444,7 +465,8 @@ emb_otf_get_post_name(const char *post,
 // }}}
 
 
-// TODO!? to_unicode should be able to represent more than one unicode character?
+// TODO!? to_unicode should be able to represent more than one unicode
+//        character?
 // NOTE: statically allocated string
 
 static const char *
@@ -483,7 +505,7 @@ get_glyphname(const char *post,
 
 struct OUTFILTER_PS
 {
-  OUTPUT_FN out;
+  _cf_fontembed_output_fn_t out;
   void *ctx;
   int len;
 };
@@ -499,7 +521,7 @@ outfilter_ascii_ps(const char *buf,
                   void *context)  // {{{
 {
   struct OUTFILTER_PS *of = context;
-  OUTPUT_FN out = of->out;
+  _cf_fontembed_output_fn_t out = of->out;
   int iA;
 
   (*out)("<", 1, of->ctx);
@@ -544,7 +566,7 @@ outfilter_binary_ps(const char *buf,
                    void *context)  // {{{
 {
   struct OUTFILTER_PS *of = context;
-  OUTPUT_FN out = of->out;
+  _cf_fontembed_output_fn_t out = of->out;
 
   char tmp[100];
   while (len > 0)
@@ -587,8 +609,8 @@ outfilter_binary_ps(const char *buf,
 //    just map to gids, but only to names, which acro will then cmap(3, 1)
 //    to gids)
 //
-//  => problem with subsetting BITSET (keyed by gid); we want BITSET keyed
-//     by 0..255 (via encoding)
+//  => problem with subsetting _cf_fontembed_bit_set_t (keyed by gid); we want
+//     _cf_fontembed_bit_set_t keyed by 0..255 (via encoding)
 //
 //   TODO: a) multi font encoding
 //   TODO: b) cid/big font encoding (PS >= 2015) [/CIDFontType 2] : CMap does
@@ -613,12 +635,12 @@ outfilter_binary_ps(const char *buf,
 //
 
 int
-emb_otf_ps(OTF_FILE *otf,
-          unsigned short *encoding,
-          int len,
-          unsigned short *to_unicode,
-          OUTPUT_FN output,
-          void *context) // {{{
+__cfFontEmbedEmbOTFPS(_cf_fontembed_otf_file_t *otf,
+                     unsigned short *encoding,
+                     int len,
+                     unsigned short *to_unicode,
+                     _cf_fontembed_output_fn_t output,
+                     void *context) // {{{
 {
   const int binary = 0; // binary format? // TODO
   if (len > 256)
@@ -636,26 +658,30 @@ emb_otf_ps(OTF_FILE *otf,
 
   int iA, ret=0;
 
-  DYN_STRING ds;
-  if (dyn_init(&ds, 1024) == -1)
+  __cf_fontembed_dyn_string_t ds;
+  if (__cfFontEmbedDynInit(&ds, 1024) == -1)
     return (-1);
 
   int rlen = 0;
-  char *head = otf_get_table(otf, OTF_TAG('h', 'e', 'a', 'd'), &rlen);
+  char *head =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'),
+                           &rlen);
   if (!head)
   {
     free(ds.buf);
     return (-1);
   }
-  dyn_printf(&ds, "%%!PS-TrueTypeFont-%d-%d\n",
-            otf->version, get_ULONG(head + 4));
-  const int bbxmin = get_SHORT(head + 36) * 1000 / otf->unitsPerEm,
-            bbymin = get_SHORT(head + 38) * 1000 / otf->unitsPerEm,
-            bbxmax = get_SHORT(head + 40) * 1000 / otf->unitsPerEm,
-            bbymax = get_SHORT(head + 42) * 1000 / otf->unitsPerEm;
+  __cfFontEmbedDynPrintF(&ds, "%%!PS-TrueTypeFont-%d-%d\n",
+            otf->version, __cfFontEmbedGetULong(head + 4));
+  const int bbxmin = __cfFontEmbedGetShort(head + 36) * 1000 / otf->unitsPerEm,
+            bbymin = __cfFontEmbedGetShort(head + 38) * 1000 / otf->unitsPerEm,
+            bbxmax = __cfFontEmbedGetShort(head + 40) * 1000 / otf->unitsPerEm,
+            bbymax = __cfFontEmbedGetShort(head + 42) * 1000 / otf->unitsPerEm;
   free(head);
 
-  char *post = otf_get_table(otf, OTF_TAG('p', 'o', 's', 't'), &rlen);
+  char *post =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('p', 'o', 's', 't'),
+                           &rlen);
   if ((!post) && (rlen != -1)) // other error than "not found"
   {
     free(ds.buf);
@@ -663,56 +689,63 @@ emb_otf_ps(OTF_FILE *otf,
   }
   if (post)
   {
-    const unsigned int minMem = get_ULONG(post + 16),
-                       maxMem = get_ULONG(post + 20);
+    const unsigned int minMem = __cfFontEmbedGetULong(post + 16),
+                       maxMem = __cfFontEmbedGetULong(post + 20);
     if (minMem)
-      dyn_printf(&ds, "%%VMusage: %d %d\n", minMem, maxMem);
+      __cfFontEmbedDynPrintF(&ds, "%%VMusage: %d %d\n", minMem, maxMem);
   }
 
   // don't forget the coordinate scaling...
-  dyn_printf(&ds, "11 dict begin\n"
-                 "/FontName /%s def\n"
-                  "/FontType 42 def\n"
-                  "/FontMatrix [1 0 0 1 0 0] def\n"
-                  "/FontBBox [%f %f %f %f] def\n"
-                  "/PaintType 0 def\n",
-//                "/XUID [42 16#%X 16#%X 16#%X 16#%X] def\n"
-//                          // TODO?!? (md5 of font data)  (16# means base16)
-            emb_otf_get_fontname(otf),
-            bbxmin / 1000.0, bbymin / 1000.0,
-            bbxmax / 1000.0, bbymax / 1000.0);
+  __cfFontEmbedDynPrintF(&ds, "11 dict begin\n"
+                        "/FontName /%s def\n"
+                        "/FontType 42 def\n"
+                        "/FontMatrix [1 0 0 1 0 0] def\n"
+                        "/FontBBox [%f %f %f %f] def\n"
+                        "/PaintType 0 def\n",
+                        //"/XUID [42 16#%X 16#%X 16#%X 16#%X] def\n"
+                        //   // TODO?!? (md5 of font data)  (16# means base16)
+                        __cfFontEmbedEmbOTFGetFontName(otf),
+                        bbxmin / 1000.0, bbymin / 1000.0,
+                        bbxmax / 1000.0, bbymax / 1000.0);
   if (post)
-    dyn_printf(&ds,"/FontInfo 4 dict dup begin\n"
-                   // TODO? [even non-post]:
-                  // /version|/Notice|/Copyright|/FullName|/FamilyName|/Weight
-                  //   () readonly def\n   from name table: 5 7 0 4 1 2
-                   // using: otf_get_name(otf, 3, 1, 0x409, ?, &len) /
-                  //        otf_get_name(otf, 1, 0, 0, ?, &len)   + encoding
-                   "  /ItalicAngle %d def\n"
-                   "  /isFixedPitch %s def\n"
-                   "  /UnderlinePosition %f def\n"
-                   "  /UnderlineThickness %f def\n"
-                   "end readonly def\n",
-              get_LONG(post + 4) >> 16,
-              (get_ULONG(post + 12) ? "true" : "false"),
-              (get_SHORT(post + 8) - get_SHORT(post + 10) / 2) /
-                (float)otf->unitsPerEm,
-              get_SHORT(post + 10) / (float)otf->unitsPerEm);
-  dyn_printf(&ds, "/Encoding 256 array\n"
-                  "0 1 255 { 1 index exch /.notdef put } for\n");
+    __cfFontEmbedDynPrintF(&ds,"/FontInfo 4 dict dup begin\n"
+                           // TODO? [even non-post]:
+                          // /version | /Notice | /Copyright | /FullName |
+                          // /FamilyName| /Weight
+                          //   () readonly def\n   from name table: 5 7 0 4 1 2
+                          // using:
+                          // _cfFontEmbedOTFGetName(otf, 3, 1, 0x409, ?,&len) /
+                          // _cfFontEmbedOTFGetName(otf, 1, 0, 0, ?, &len) +
+                          //   encoding
+                          "  /ItalicAngle %d def\n"
+                          "  /isFixedPitch %s def\n"
+                          "  /UnderlinePosition %f def\n"
+                          "  /UnderlineThickness %f def\n"
+                          "end readonly def\n",
+                          __cfFontEmbedGetLong(post + 4) >> 16,
+                          (__cfFontEmbedGetULong(post + 12) ?
+                           "true" : "false"),
+                          (__cfFontEmbedGetShort(post + 8) -
+                           __cfFontEmbedGetShort(post + 10) / 2) /
+                          (float)otf->unitsPerEm,
+                          __cfFontEmbedGetShort(post + 10) /
+                          (float)otf->unitsPerEm);
+  __cfFontEmbedDynPrintF(&ds, "/Encoding 256 array\n"
+                        "0 1 255 { 1 index exch /.notdef put } for\n");
   for (iA = 0; iA < len; iA ++) // encoding data: 0...255 -> /glyphname
   {
-    const int gid = (encoding) ? encoding[iA] : otf_from_unicode(otf, iA);
+    const int gid =
+      (encoding) ? encoding[iA] : _cfFontEmbedOTFFromUnicode(otf, iA);
     if (gid != 0)
-      dyn_printf(&ds, "dup %d /%s put\n",
-                iA, get_glyphname(post, to_unicode, iA, gid));
+      __cfFontEmbedDynPrintF(&ds, "dup %d /%s put\n",
+                            iA, get_glyphname(post, to_unicode, iA, gid));
   }
-  dyn_printf(&ds, "readonly def\n");
+  __cfFontEmbedDynPrintF(&ds, "readonly def\n");
 
   if (binary)
-    dyn_printf(&ds,
-              "/RD { string currentfile exch readstring pop } executeonly def\n");
-  dyn_printf(&ds, "/sfnts[\n");
+    __cfFontEmbedDynPrintF(&ds,
+         "/RD { string currentfile exch readstring pop } executeonly def\n");
+  __cfFontEmbedDynPrintF(&ds, "/sfnts[\n");
 
   if (ds.len < 0)
   {
@@ -724,16 +757,17 @@ emb_otf_ps(OTF_FILE *otf,
   ret += ds.len;
   ds.len = 0;
 
-  // TODO: only tables as in otf_subset
+  // TODO: only tables as in _cfFontEmbedOTFSubSet
   // TODO:  somehow communicate table boundaries:
-  //   otf_action_copy  does exactly one output call (per table)
-  //   only otf_action_replace might do two (padding)
+  //   __cfFontEmbedOTFActionCopy  does exactly one output call (per table)
+  //   only __cfFontEmbedOTFActionReplace might do two (padding)
   // {{{ copy tables verbatim (does not affect ds .len)
 
-  struct _OTF_WRITE *otfree = NULL;
+  struct __cf_fontembed_otf_write_s *otfree = NULL;
 #if 0
-  struct _OTF_WRITE *otw;
-  otwfree = otw = malloc(sizeof(struct _OTF_WRITE) * otf->numTables);
+  struct __cf_fontembed_otf_write_s *otw;
+  otwfree = otw =
+    malloc(sizeof(struct __cf_fontembed_otf_write_s) * otf->numTables);
   if (!otw)
   {
     fprintf(stderr, "Bad alloc: %m\n");
@@ -745,28 +779,39 @@ emb_otf_ps(OTF_FILE *otf,
   for (iA = 0; iA < otf->numTables; iA ++)
   {
     otw[iA].tag = otf->tables[iA].tag;
-    otw[iA].action = otf_action_copy;
+    otw[iA].action = __cfFontEmbedOTFActionCopy;
     otw[iA].param = otf;
     otw[iA].length = iA;
   }
   int numTables = otf->numTables;
 #else
-  struct _OTF_WRITE otw[] = // sorted
-  {
-    {OTF_TAG('c', 'm', 'a', 'p'), otf_action_copy, otf,},
-    {OTF_TAG('c', 'v', 't', ' '), otf_action_copy, otf,},
-    {OTF_TAG('f', 'p', 'g', 'm'), otf_action_copy, otf,},
-    {OTF_TAG('g', 'l', 'y', 'f'), otf_action_copy, otf,},
-    {OTF_TAG('h', 'e', 'a', 'd'), otf_action_copy, otf,},
-    {OTF_TAG('h', 'h', 'e', 'a'), otf_action_copy, otf,},
-    {OTF_TAG('h', 'm', 't', 'x'), otf_action_copy, otf,},
-    {OTF_TAG('l', 'o', 'c', 'a'), otf_action_copy, otf,},
-    {OTF_TAG('m', 'a', 'x', 'p'), otf_action_copy, otf,},
-    {OTF_TAG('n', 'a', 'm', 'e'), otf_action_copy, otf,},
-    {OTF_TAG('p', 'r', 'e', 'p'), otf_action_copy, otf,},
+  struct __cf_fontembed_otf_write_s otw[] = // sorted
+  {
+    {_CF_FONTEMBED_OTF_TAG('c', 'm', 'a', 'p'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('c', 'v', 't', ' '),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('f', 'p', 'g', 'm'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('g', 'l', 'y', 'f'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('h', 'h', 'e', 'a'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('h', 'm', 't', 'x'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('l', 'o', 'c', 'a'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('m', 'a', 'x', 'p'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('n', 'a', 'm', 'e'),
+     __cfFontEmbedOTFActionCopy, otf,},
+    {_CF_FONTEMBED_OTF_TAG('p', 'r', 'e', 'p'),
+     __cfFontEmbedOTFActionCopy, otf,},
     // vhea vmtx (never used in PDF, but possible in PS >= 3011)
     {0,0,0,0}};
-  int numTables = otf_intersect_tables(otf, otw);
+  int numTables = __cfFontEmbedOTFIntersectTables(otf, otw);
 #endif
 
   struct OUTFILTER_PS of;
@@ -774,9 +819,11 @@ emb_otf_ps(OTF_FILE *otf,
   of.ctx = context;
   of.len = 0;
   if (binary)
-    iA = otf_write_sfnt(otw, otf->version, numTables, outfilter_binary_ps, &of);
+    iA = __cfFontEmbedOTFWriteSFNT(otw, otf->version, numTables,
+                                  outfilter_binary_ps, &of);
   else
-    iA = otf_write_sfnt(otw, otf->version, numTables, outfilter_ascii_ps, &of);
+    iA = __cfFontEmbedOTFWriteSFNT(otw, otf->version, numTables,
+                                  outfilter_ascii_ps, &of);
   free(otfree);
   if (iA == -1)
   {
@@ -787,20 +834,21 @@ emb_otf_ps(OTF_FILE *otf,
   ret += of.len;
   // }}} done copying
 
-  dyn_printf(&ds, "] def\n");
+  __cfFontEmbedDynPrintF(&ds, "] def\n");
 
-  dyn_printf(&ds, "/CharStrings %d dict dup begin\n"
-                  "/.notdef 0 def\n", len);
+  __cfFontEmbedDynPrintF(&ds, "/CharStrings %d dict dup begin\n"
+                        "/.notdef 0 def\n", len);
   for (iA = 0; iA < len; iA ++) // charstrings data: /glyphname -> gid
   {
-    const int gid = (encoding) ? encoding[iA] : otf_from_unicode(otf, iA);
+    const int gid =
+      (encoding) ? encoding[iA] : _cfFontEmbedOTFFromUnicode(otf, iA);
     if (gid)
-      dyn_printf(&ds, "/%s %d def\n",
-                get_glyphname(post, to_unicode, iA, gid), gid);
+      __cfFontEmbedDynPrintF(&ds, "/%s %d def\n",
+                            get_glyphname(post, to_unicode, iA, gid), gid);
     // (respecting subsetting...)
   }
-  dyn_printf(&ds, "end readonly def\n");
-  dyn_printf(&ds, "FontName currentdict end definefont pop\n");
+  __cfFontEmbedDynPrintF(&ds, "end readonly def\n");
+  __cfFontEmbedDynPrintF(&ds, "FontName currentdict end definefont pop\n");
   free(post);
 
   if (ds.len < 0)
index c7e0853dbe5687985117e8a6e973b123b9991ba9..316985956154db0446126fb975b65102ec78e27d 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include "embed-sfnt-private.h"
 #include <cupsfilters/debug-internal.h>
 #include <errno.h>
@@ -9,7 +9,7 @@
 
 static inline int
 copy_file(FILE *f,
-         OUTPUT_FN output,
+         _cf_fontembed_output_fn_t output,
          void *context) // {{{
 {
   DEBUG_assert(f);
@@ -33,7 +33,8 @@ copy_file(FILE *f,
 
 
 //
-// certain profiles: (=> constraints to be auto-applied in emb_new via >dest)
+// certain profiles: (=> constraints to be auto-applied in
+// _cfFontEmbedEmbNew via >dest)
 // PSold: T1->T1, TTF->T1, OTF->CFF->T1, STD->STD // output limit: T1
 //                                                // (maybe length,
 //                                                //  binary/text, ... limit)
@@ -54,54 +55,57 @@ copy_file(FILE *f,
 // output modes:
 // subset,CID(multibyte),(PS:)text/binary,(PS:)incremental
 //
-// TODO: remove dest from emb_new, replace with EMB_ACTIONS constraints:
+// TODO: remove dest from _cfFontEmbedEmbNew, replace with
+//       _cf_fontembed_emb_action_t constraints:
 //    - bitfield mask which ACTIONS are allowed. (problem: we want to force
 //      certain ones, e.g. MULTIBYTE)
-//    - e.g. currently EMB_C_PDF_OT has to functions
+//    - e.g. currently _CF_FONTEMBED_EMB_C_PDF_OT has to functions
 //    - the only (other) 'difference' to now is the subsetting spec
 //    - another issue is, that emb_pdf_ might want some pdf version
 //      informatino (-> extra flag?)
 //      and funtion to determine appropriate mask for certain destination
-//      EMB_ACTIONS emb_mask_for_dest(EMB_DESTINATION)
-// TODO? determine viability before trying emb_embed
-//   (idea: use emb_embed(, NULL) -> will just return true/false  [same
-//    codepath!])
+//      _cf_fontembed_emb_action_t emb_mask_for_dest(_cf_fontembed_emb_dest_t)
+// TODO? determine viability before trying _cfFontEmbedEmbEmbed
+//   (idea: use _cfFontEmbedEmbEmbed(, NULL) -> will just return true/false
+//          [same codepath!])
 //
 // TODO?! "always subset CJK"
 //
 
 
-EMB_PARAMS *
-emb_new(FONTFILE *font,
-       EMB_DESTINATION dest,
-       EMB_CONSTRAINTS mode) // {{{
+_cf_fontembed_emb_params_t *
+_cfFontEmbedEmbNew(_cf_fontembed_fontfile_t *font,
+                  _cf_fontembed_emb_dest_t dest,
+                  _cf_fontembed_emb_constraint_t mode) // {{{
 {
   DEBUG_assert(font);
 
-  EMB_PARAMS *ret = calloc(1, sizeof(EMB_PARAMS));
+  _cf_fontembed_emb_params_t *ret =
+    calloc(1, sizeof(_cf_fontembed_emb_params_t));
   if (!ret)
   {
     fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
-    if (mode & EMB_C_TAKE_FONTFILE)
-      fontfile_close(font);
+    if (mode & _CF_FONTEMBED_EMB_C_TAKE_FONTFILE)
+      _cfFontEmbedFontFileClose(font);
     return (NULL);
   }
   ret->dest = dest;
   ret->font = font;
-  if (mode & EMB_C_TAKE_FONTFILE)
-    ret->plan |= EMB_A_CLOSE_FONTFILE;
+  if (mode & _CF_FONTEMBED_EMB_C_TAKE_FONTFILE)
+    ret->plan |= _CF_FONTEMBED_EMB_A_CLOSE_FONTFILE;
 
   // check parameters
-  if ((mode & EMB_C_KEEP_T1) && (mode & EMB_C_FORCE_MULTIBYTE))
+  if ((mode & _CF_FONTEMBED_EMB_C_KEEP_T1) &&
+      (mode & _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE))
   {
     fprintf(stderr, "Incompatible mode: KEEP_T1 and FORCE_MULTIBYTE\n");
-    emb_close(ret);
+    _cfFontEmbedEmbClose(ret);
     return (NULL);
   }
   if ((mode & 0x07) > 5)
   {
     fprintf(stderr, "Bad subset specification\n");
-    emb_close(ret);
+    _cfFontEmbedEmbClose(ret);
     return (NULL);
   }
 
@@ -109,97 +113,99 @@ emb_new(FONTFILE *font,
   int numGlyphs = 0;
   if (font->sfnt)
   {
-    if (font->sfnt->flags & OTF_F_FMT_CFF)
-      ret->intype = EMB_FMT_OTF;
+    if (font->sfnt->flags & _CF_FONTEMBED_OTF_F_FMT_CFF)
+      ret->intype = _CF_FONTEMBED_EMB_FMT_OTF;
     else
-      ret->intype = EMB_FMT_TTF;
-    ret->rights = emb_otf_get_rights(ret->font->sfnt);
+      ret->intype = _CF_FONTEMBED_EMB_FMT_TTF;
+    ret->rights = __cfFontEmbedEmbOTFGetRights(ret->font->sfnt);
     numGlyphs = ret->font->sfnt->numGlyphs; // TODO
   }
   else if (font->stdname)
   {
-    ret->intype = EMB_FMT_STDFONT;
-    ret->rights = EMB_RIGHT_NONE;
+    ret->intype = _CF_FONTEMBED_EMB_FMT_STDFONT;
+    ret->rights = _CF_FONTEMBED_EMB_RIGHT_NONE;
   } else
     DEBUG_assert(0);
 
 #if 0
-  if ((ret->intype == EMB_FMT_CFF) &&
+  if ((ret->intype == _CF_FONTEMBED_EMB_FMT_CFF) &&
       (ret->cffFont.is_cid()))
   {
-     ?= || ((ret->intype == EMB_FMT_OTF) &&
+     ?= || ((ret->intype == _CF_FONTEMBED_EMB_FMT_OTF) &&
            (ret->sfnt->cffFont.is_cid())) // TODO?
-      ret->plan |= EMB_A_MULTIBYTE;
+      ret->plan |= _CF_FONTEMBED_EMB_A_MULTIBYTE;
   }
 #endif // 0
 
   // determine outtype
-  if (ret->intype == EMB_FMT_STDFONT)
+  if (ret->intype == _CF_FONTEMBED_EMB_FMT_STDFONT)
   {
     ret->outtype = ret->intype;
-    if (mode & EMB_C_FORCE_MULTIBYTE)
+    if (mode & _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE)
     {
       fprintf(stderr, "Multibyte stdfonts are not possible\n");
-      emb_close(ret);
+      _cfFontEmbedEmbClose(ret);
       return (NULL);
     }
     return (ret); // never subset, no multibyte
   }
-  else if (ret->intype == EMB_FMT_T1)
+  else if (ret->intype == _CF_FONTEMBED_EMB_FMT_T1)
   {
-    if (mode & EMB_C_KEEP_T1)
-      ret->outtype = EMB_FMT_T1;
+    if (mode & _CF_FONTEMBED_EMB_C_KEEP_T1)
+      ret->outtype = _CF_FONTEMBED_EMB_FMT_T1;
     else {
-      ret->plan |= EMB_A_T1_TO_CFF;
-      ret->outtype = EMB_FMT_CFF;
+      ret->plan |= _CF_FONTEMBED_EMB_A_T1_TO_CFF;
+      ret->outtype = _CF_FONTEMBED_EMB_FMT_CFF;
     }
   }
   else
     ret->outtype = ret->intype;
-  if (ret->outtype == EMB_FMT_CFF)
+  if (ret->outtype == _CF_FONTEMBED_EMB_FMT_CFF)
   {
-    if (mode & EMB_C_PDF_OT)
+    if (mode & _CF_FONTEMBED_EMB_C_PDF_OT)
     {
-      ret->outtype = EMB_FMT_OTF;
-      ret->plan |= EMB_A_CFF_TO_OTF;
+      ret->outtype = _CF_FONTEMBED_EMB_FMT_OTF;
+      ret->plan |= _CF_FONTEMBED_EMB_A_CFF_TO_OTF;
     }
   }
-  else if (ret->outtype == EMB_FMT_OTF)
+  else if (ret->outtype == _CF_FONTEMBED_EMB_FMT_OTF)
   {
     // TODO: no support yet;  but we want to get the FontDescriptor/Name right
-    mode |= EMB_C_NEVER_SUBSET;
-    if (!(mode & EMB_C_PDF_OT))
+    mode |= _CF_FONTEMBED_EMB_C_NEVER_SUBSET;
+    if (!(mode & _CF_FONTEMBED_EMB_C_PDF_OT))
     { // TODO!?!
-      ret->outtype = EMB_FMT_CFF;
-      ret->plan |= EMB_A_OTF_TO_CFF;
+      ret->outtype = _CF_FONTEMBED_EMB_FMT_CFF;
+      ret->plan |= _CF_FONTEMBED_EMB_A_OTF_TO_CFF;
     }
   }
 
-  if (mode & EMB_C_FORCE_MULTIBYTE)
-    ret->plan |= EMB_A_MULTIBYTE;
+  if (mode & _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE)
+    ret->plan |= _CF_FONTEMBED_EMB_A_MULTIBYTE;
 
   // check rights (for subsetting)
-  if ((ret->rights & EMB_RIGHT_NONE) ||
-      (ret->rights & EMB_RIGHT_BITMAPONLY) ||
-      ((ret->rights & EMB_RIGHT_READONLY) && (mode & EMB_C_EDITABLE_SUBSET)) ||
-      ((ret->rights & EMB_RIGHT_NO_SUBSET) && (mode & EMB_C_MUST_SUBSET)))
+  if ((ret->rights & _CF_FONTEMBED_EMB_RIGHT_NONE) ||
+      (ret->rights & _CF_FONTEMBED_EMB_RIGHT_BITMAPONLY) ||
+      ((ret->rights & _CF_FONTEMBED_EMB_RIGHT_READONLY) &&
+       (mode & _CF_FONTEMBED_EMB_C_EDITABLE_SUBSET)) ||
+      ((ret->rights & _CF_FONTEMBED_EMB_RIGHT_NO_SUBSET) &&
+       (mode & _CF_FONTEMBED_EMB_C_MUST_SUBSET)))
   {
     fprintf(stderr, "The font does not permit the requested embedding\n");
-    emb_close(ret);
+    _cfFontEmbedEmbClose(ret);
     return (NULL);
   }
-  else if ((!(ret->rights & EMB_RIGHT_NO_SUBSET)) &&
-          (!(mode & EMB_C_NEVER_SUBSET)))
-    ret->plan |= EMB_A_SUBSET;
+  else if ((!(ret->rights & _CF_FONTEMBED_EMB_RIGHT_NO_SUBSET)) &&
+          (!(mode & _CF_FONTEMBED_EMB_C_NEVER_SUBSET)))
+    ret->plan |= _CF_FONTEMBED_EMB_A_SUBSET;
 
   // alloc subset
-  if (ret->plan & EMB_A_SUBSET)
+  if (ret->plan & _CF_FONTEMBED_EMB_A_SUBSET)
   {
-    ret->subset = bitset_new(numGlyphs);
+    ret->subset = _cfFontEmbedBitSetNew(numGlyphs);
     if (!ret->subset)
     {
       fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
-      emb_close(ret);
+      _cfFontEmbedEmbClose(ret);
       return (NULL);
     }
   }
@@ -210,35 +216,37 @@ emb_new(FONTFILE *font,
 
 
 int
-emb_embed(EMB_PARAMS *emb,
-         OUTPUT_FN output,
-         void *context) // {{{
+_cfFontEmbedEmbEmbed(_cf_fontembed_emb_params_t *emb,
+                    _cf_fontembed_output_fn_t output,
+                    void *context) // {{{
 {
   DEBUG_assert(emb);
 
-  if (emb->dest == EMB_DEST_NATIVE)
+  if (emb->dest == _CF_FONTEMBED_EMB_DEST_NATIVE)
   {
   }
-  else if (emb->dest <= EMB_DEST_PS)
+  else if (emb->dest <= _CF_FONTEMBED_EMB_DEST_PS)
   {
     int ret =- 2;
-    const char *fontname = emb_otf_get_fontname(emb->font->sfnt); // TODO!!
+    const char *fontname =
+      __cfFontEmbedEmbOTFGetFontName(emb->font->sfnt); // TODO!!
     (*output)("%%BeginFont: ", 13, context);
     (*output)(fontname, strlen(fontname), context);
     (*output)("\n", 1, context);
-    if (emb->outtype == EMB_FMT_T1)
+    if (emb->outtype == _CF_FONTEMBED_EMB_FMT_T1)
     {
     }
-    else if (emb->outtype == EMB_FMT_TTF) { // emb->outtype==EMB_OUTPUT_OTF
+    else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
+    { // emb->outtype==EMB_OUTPUT_OTF
                                             // is stupid (?)
                                             // do Type42
-      ret = emb_otf_ps(emb->font->sfnt, NULL, 256, NULL, output, context);
-                                                                    // TODO?
+      ret = __cfFontEmbedEmbOTFPS(emb->font->sfnt, NULL, 256, NULL, output,
+                                 context); // TODO?
     }
-    else if (emb->outtype == EMB_FMT_CFF)
+    else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_CFF)
     {
     }
-    else if (emb->outtype == EMB_FMT_STDFONT)
+    else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_STDFONT)
     {
     }
     if (ret != -2)
@@ -250,23 +258,24 @@ emb_embed(EMB_PARAMS *emb,
       return (ret);
     }
   }
-  else if (emb->dest <= EMB_DEST_PDF16)
+  else if (emb->dest <= _CF_FONTEMBED_EMB_DEST_PDF16)
   {
-    if (emb->outtype == EMB_FMT_TTF)
+    if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
     {
       DEBUG_assert(emb->font->sfnt);
-      if (emb->plan & EMB_A_SUBSET)
-        return (otf_subset(emb->font->sfnt, emb->subset, output, context));
+      if (emb->plan & _CF_FONTEMBED_EMB_A_SUBSET)
+        return (_cfFontEmbedOTFSubSet(emb->font->sfnt, emb->subset, output,
+                                     context));
       else if (emb->font->sfnt->numTTC)
-        return (otf_ttc_extract(emb->font->sfnt, output, context));
+        return (_cfFontEmbedOTFTTCExtract(emb->font->sfnt, output, context));
       else // copy verbatim
         return (copy_file(emb->font->sfnt->f, output, context));
     }
-    else if (emb->outtype == EMB_FMT_OTF)
+    else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_OTF)
     {
-      if (emb->plan&EMB_A_CFF_TO_OTF)
+      if (emb->plan & _CF_FONTEMBED_EMB_A_CFF_TO_OTF)
       {
-        if (emb->plan&EMB_A_T1_TO_CFF)
+        if (emb->plan & _CF_FONTEMBED_EMB_A_T1_TO_CFF)
        {
           // TODO
         }
@@ -279,25 +288,25 @@ emb_embed(EMB_PARAMS *emb,
       else
       {
         DEBUG_assert(emb->font->sfnt);
-        if (emb->plan & EMB_A_SUBSET)
-          return (otf_subset_cff(emb->font->sfnt, emb->subset, output,
+        if (emb->plan & _CF_FONTEMBED_EMB_A_SUBSET)
+          return (_cfFontEmbedOTFSubSetCFF(emb->font->sfnt, emb->subset, output,
                                 context));
         else
           return (copy_file(emb->font->sfnt->f, output, context));
       }
     }
-    else if (emb->outtype == EMB_FMT_CFF)
+    else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_CFF)
     {
-      if (emb->plan & EMB_A_OTF_TO_CFF)
+      if (emb->plan & _CF_FONTEMBED_EMB_A_OTF_TO_CFF)
       {
         DEBUG_assert(emb->font->sfnt);
-        if (emb->plan & EMB_A_SUBSET)
+        if (emb->plan & _CF_FONTEMBED_EMB_A_SUBSET)
        {
           // TODO
         }
        else
        {
-          return (otf_cff_extract(emb->font->sfnt, output, context));
+          return (_cfFontEmbedOTFCFFExtract(emb->font->sfnt, output, context));
         }
       }
       else
@@ -315,13 +324,13 @@ emb_embed(EMB_PARAMS *emb,
 
 
 void
-emb_close(EMB_PARAMS *emb) // {{{
+_cfFontEmbedEmbClose(_cf_fontembed_emb_params_t *emb) // {{{
 {
   if (emb)
   {
     free(emb->subset);
-    if (emb->plan & EMB_A_CLOSE_FONTFILE)
-      fontfile_close(emb->font);
+    if (emb->plan & _CF_FONTEMBED_EMB_A_CLOSE_FONTFILE)
+      _cfFontEmbedFontFileClose(emb->font);
     free(emb);
   }
 }
index a97f80770bdec1a05a75f12b3bdcf951ed6ceeef..1c8c24687db6db576023b699cb7dd2902de1b360 100644 (file)
@@ -1,12 +1,13 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include <string.h>
 
 
-//FONTFILE *fontfile_open(const char *filename);
+//_cf_fontembed_fontfile_t *_cfFontEmbedFontFileOpen(const char *filename);
 
 #if 0
-FONTFILE *fontfile_open(const char *filename)
+_cf_fontembed_fontfile_t *
+_cfFontEmbedFontFileOpen(const char *filename)
 {
   // TODO? check magic
   if (...) {
@@ -15,14 +16,15 @@ FONTFILE *fontfile_open(const char *filename)
 #endif // 0
 
 
-FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
+_cf_fontembed_fontfile_t *
+_cfFontEmbedFontFileOpenSFNT(_cf_fontembed_otf_file_t *otf) // {{{
 {
   if (!otf)
   {
     DEBUG_assert(0);
     return (NULL);
   }
-  FONTFILE *ret = calloc(1, sizeof(FONTFILE));
+  _cf_fontembed_fontfile_t *ret = calloc(1, sizeof(_cf_fontembed_fontfile_t));
 
   ret->sfnt = otf;
 
@@ -31,11 +33,11 @@ FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
 // }}}
 
 
-FONTFILE *
-fontfile_open_std(const char *name) // {{{
+_cf_fontembed_fontfile_t *
+_cfFontEmbedFontFileOpenStd(const char *name) // {{{
 {
   DEBUG_assert(name);
-  FONTFILE *ret = calloc(1, sizeof(FONTFILE));
+  _cf_fontembed_fontfile_t *ret = calloc(1, sizeof(_cf_fontembed_fontfile_t));
 
   ret->stdname = strdup(name);
 
@@ -44,11 +46,11 @@ fontfile_open_std(const char *name) // {{{
 // }}}
 
 
-void fontfile_close(FONTFILE *ff) // {{{
+void _cfFontEmbedFontFileClose(_cf_fontembed_fontfile_t *ff) // {{{
 {
   if (ff)
   {
-    otf_close(ff->sfnt);
+    _cfFontEmbedOTFClose(ff->sfnt);
     // ??? cff_close(ff->cff);
     free(ff->stdname);
     free(ff);
index 5b091a205a0f7858d94bfb93803dd73d331aeb8a..2d71d74496580a686437aa3406f88d1a707f3144 100644 (file)
@@ -3,16 +3,18 @@
 
 #include <stdint.h>
 
-typedef struct _FREQUENT FREQUENT;
+typedef struct __cf_fontembed_frequent_s __cf_fontembed_frequent_t;
 
 // size is the precision/return size: it will find at most >size
 // elements (i.e. all, if there) with frequency > 1 / (size + 1)
-FREQUENT *frequent_new(int size); // - just free() it
+__cf_fontembed_frequent_t *__cfFontEmbedFrequentNew(int size);
+                                                       // - just free() it
 
-void frequent_add(FREQUENT *freq, intptr_t key);
+void __cfFontEmbedFrequentAdd(__cf_fontembed_frequent_t *freq, intptr_t key);
 
 // might return INTPTR_MIN, if not populated
 // this is only an approximation!
-intptr_t frequent_get(FREQUENT *freq, int pos); // 0 is "most frequent"
+intptr_t __cfFontEmbedFrequentGet(__cf_fontembed_frequent_t *freq, int pos);
+                                                       // 0 is "most frequent"
 
 #endif // !_FONTEMBED_FREQUENT_H_
index 784e9c2e5f2cc577ec1ef7ba9193f99fe1cbf888..d4404c38fbf604d671fdc6fcd49de2819a9984a2 100644 (file)
@@ -6,7 +6,7 @@
 // misra-gries
 // http://www2.research.att.com/~marioh/papers/vldb08-2.pdf
 
-struct _FREQUENT
+struct __cf_fontembed_frequent_s
 {
   int size, czero;
   char sorted;
@@ -20,13 +20,14 @@ struct _FREQUENT
 
 
 // size is the precision/return size: in sequence with n _add(),
-// it will find at most >size elements with occurence > n/(size+1) times
+// it will find at most >size elements with occurence > n / (size + 1) times
 
-FREQUENT *
-frequent_new(int size) // {{{ - just free() it
+__cf_fontembed_frequent_t *
+__cfFontEmbedFrequentNew(int size) // {{{ - just free() it
 {
   DEBUG_assert(size>0);
-  FREQUENT *ret = malloc(sizeof(ret[0]) + sizeof(ret->pair[0]) * size);
+  __cf_fontembed_frequent_t *ret =
+    malloc(sizeof(ret[0]) + sizeof(ret->pair[0]) * size);
   if (!ret)
     return (NULL);
   ret->size = size;
@@ -46,8 +47,8 @@ frequent_new(int size) // {{{ - just free() it
 
 
 void
-frequent_add(FREQUENT *freq,
-            intptr_t key) // {{{
+__cfFontEmbedFrequentAdd(__cf_fontembed_frequent_t *freq,
+                        intptr_t key) // {{{
 {
   DEBUG_assert(freq);
   int iA, zero = -1;
@@ -79,8 +80,8 @@ frequent_add(FREQUENT *freq,
 static int
 frequent_cmp(const void *a, const void *b) // {{{
 {
-  const typeof(((FREQUENT *)0)->pair[0]) *aa = a;
-  const typeof(((FREQUENT *)0)->pair[0]) *bb = b;
+  const typeof(((__cf_fontembed_frequent_t *)0)->pair[0]) *aa = a;
+  const typeof(((__cf_fontembed_frequent_t *)0)->pair[0]) *bb = b;
   return ((bb->count - bb->zero) - (aa->count - aa->zero));
 }
 // }}}
@@ -88,7 +89,9 @@ frequent_cmp(const void *a, const void *b) // {{{
 
 // true frequency is somewhere between (count-zero) and count
 
-intptr_t frequent_get(FREQUENT *freq, int pos) // {{{
+intptr_t
+__cfFontEmbedFrequentGet(__cf_fontembed_frequent_t *freq,
+                        int pos) // {{{
 {
   DEBUG_assert(freq);
   if (!freq->sorted)
index 86baf90eb419d2553410f411d8af3c6b123f3a32..8460d40b4d2762b2b1272a9657cfceaeb598c2ff 100644 (file)
@@ -3,7 +3,7 @@
 #define _FONTEMBED_MACROMAN_PRIVATE_H_
 
 #ifdef WITH_MACROMAN
-static const char *macRoman[] =
+static const char *__cf_fontembed_mac_roman[] =
 {
   ".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand",
   "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero",
@@ -33,7 +33,7 @@ static const char *macRoman[] =
   "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat"
 };
 #else
-static const char *macRoman[] =
+static const char *__cf_fontembed_mac_roman[] =
 {
   NULL
 };
index 34013e7c3d0e1d71e59c8edada5d49a5042bfcfa..a8f00787618c64666f7a0fddf8e86cd4bc218450 100644 (file)
@@ -2,8 +2,28 @@
 #define _FONTEMBED_SFNT_INT_H_
 
 
+//
+// Types and structures...
+//
+
+struct __cf_fontembed_otf_write_s
+{
+  unsigned long tag;
+  int (*action)(void *param, int length, _cf_fontembed_output_fn_t output,
+               void *context);
+         // -1 on error, num_bytes_written on success; if >output == NULL
+         // return checksum in (unsigned int *)context  instead.
+  void *param;
+  int length;
+};
+
+
+//
+// Inline functions...
+//
+
 static inline unsigned short
-get_USHORT(const char *buf) // {{{
+__cfFontEmbedGetUShort(const char *buf) // {{{
 {
   return (((unsigned char)buf[0] << 8) | ((unsigned char)buf[1]));
 }
@@ -11,7 +31,7 @@ get_USHORT(const char *buf) // {{{
 
 
 static inline short
-get_SHORT(const char *buf) // {{{
+__cfFontEmbedGetShort(const char *buf) // {{{
 {
   return ((buf[0] << 8) | ((unsigned char)buf[1]));
 }
@@ -19,7 +39,7 @@ get_SHORT(const char *buf) // {{{
 
 
 static inline unsigned int
-get_UINT24(const char *buf) // {{{
+__cfFontEmbedGetUInt24(const char *buf) // {{{
 {
   return (((unsigned char)buf[0] << 16) |
          ((unsigned char)buf[1] << 8 )|
@@ -29,7 +49,7 @@ get_UINT24(const char *buf) // {{{
 
 
 static inline unsigned int
-get_ULONG(const char *buf) // {{{
+__cfFontEmbedGetULong(const char *buf) // {{{
 {
   return (((unsigned char)buf[0] << 24) |
          ((unsigned char)buf[1] << 16) |
@@ -40,7 +60,7 @@ get_ULONG(const char *buf) // {{{
 
 
 static inline int
-get_LONG(const char *buf) // {{{
+__cfFontEmbedGetLong(const char *buf) // {{{
 {
   return ((buf[0] << 24) |
          ((unsigned char)buf[1] << 16) |
@@ -51,7 +71,7 @@ get_LONG(const char *buf) // {{{
 
 
 static inline void
-set_USHORT(char *buf,
+__cfFontEmbedSetUShort(char *buf,
           unsigned short val) // {{{
 {
   buf[0] = val >> 8;
@@ -61,7 +81,7 @@ set_USHORT(char *buf,
 
 // }}}
 static inline void
-set_ULONG(char *buf,
+__cfFontEmbedSetULong(char *buf,
          unsigned int val) // {{{
 {
   buf[0] = val >> 24;
@@ -73,61 +93,63 @@ set_ULONG(char *buf,
 
 
 static inline unsigned int
-otf_checksum(const char *buf,
+__cfFontEmbedOTFCheckSum(const char *buf,
             unsigned int len) // {{{
 {
   unsigned int ret = 0;
   for (len = (len + 3) / 4; len > 0; len--, buf += 4)
-    ret += get_ULONG(buf);
+    ret += __cfFontEmbedGetULong(buf);
   return (ret);
 }
 // }}}
 
 
 static inline int
-get_width_fast(OTF_FILE *otf,
+__cfFontEmbedGetWidthFast(_cf_fontembed_otf_file_t *otf,
               int gid) // {{{
 {
   if (gid >= otf->numberOfHMetrics)
-    return (get_USHORT(otf->hmtx + (otf->numberOfHMetrics - 1) * 4));
+    return (__cfFontEmbedGetUShort(otf->hmtx +
+                                  (otf->numberOfHMetrics - 1) * 4));
   else
-    return (get_USHORT(otf->hmtx + gid * 4));
+    return (__cfFontEmbedGetUShort(otf->hmtx + gid * 4));
 }
 // }}}
 
 
-int otf_load_glyf(OTF_FILE *otf); //  - 0 on success
-int otf_load_more(OTF_FILE *otf); //  - 0 on success
-
-int otf_find_table(OTF_FILE *otf, unsigned int tag); // - table_index  or
-                                                     //   -1 on error
-
-int otf_action_copy(void *param, int csum, OUTPUT_FN output, void *context);
-int otf_action_replace(void *param, int csum, OUTPUT_FN output, void *context);
+//
+// Prototypes...
+//
 
-// Note: don't use this directly. otf_write_sfnt will internally replace
-// otf_action_copy for head with this
-int otf_action_copy_head(void *param, int csum, OUTPUT_FN output,
-                        void *context);
+int __cfFontEmbedOTFLoadGlyf(_cf_fontembed_otf_file_t *otf); //  - 0 on success
+int __cfFontEmbedOTFLoadMore(_cf_fontembed_otf_file_t *otf); //  - 0 on success
 
+int __cfFontEmbedOTFFindTable(_cf_fontembed_otf_file_t *otf,
+                             unsigned int tag); // - table_index  or
+                                                 //   -1 on error
 
-struct _OTF_WRITE
-{
-  unsigned long tag;
-  int (*action)(void *param, int length, OUTPUT_FN output, void *context);
-         // -1 on error, num_bytes_written on success; if >output == NULL
-         // return checksum in (unsigned int *)context  instead.
-  void *param;
-  int length;
-};
+int __cfFontEmbedOTFActionCopy(void *param, int csum,
+                              _cf_fontembed_output_fn_t output, void *context);
+int __cfFontEmbedOTFActionReplace(void *param, int csum,
+                                 _cf_fontembed_output_fn_t output,
+                                 void *context);
 
+// Note: Don't use this directly. __cfFontEmbedOTFWriteSFNT will internally
+//       replace
+// __cfFontEmbedOTFActionCopy for head with this
+int __cfFontEmbedOTFActionCopyHead(void *param, int csum,
+                                  _cf_fontembed_output_fn_t output,
+                                  void *context);
 
-int otf_write_sfnt(struct _OTF_WRITE *otw, unsigned int version, int numTables,
-                  OUTPUT_FN output, void *context);
+int __cfFontEmbedOTFWriteSFNT(struct __cf_fontembed_otf_write_s *otw,
+                             unsigned int version, int numTables,
+                             _cf_fontembed_output_fn_t output, void *context);
 
 /** from sfnt_subset.c: **/
 
-// otw {0, }-terminated, will be modified; returns numTables for otf_write_sfnt
-int otf_intersect_tables(OTF_FILE *otf, struct _OTF_WRITE *otw);
+// otw {0, }-terminated, will be modified; returns numTables for
+// __cfFontEmbedOTFWriteSFNT
+int __cfFontEmbedOTFIntersectTables(_cf_fontembed_otf_file_t *otf,
+                                   struct __cf_fontembed_otf_write_s *otw);
 
 #endif // !_FONTEMBED_SFNT_INT_H_
index cb8d7502a03bc51d5adc01cdca2006a8fe9c200e..fe717a58f419835bd46d63942574b40bbfc8360e 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "sfnt-private.h"
 #include <stdio.h>
@@ -8,9 +8,9 @@
 
 
 int
-otf_ttc_extract(OTF_FILE *otf,
-               OUTPUT_FN output,
-               void *context) // {{{
+_cfFontEmbedOTFTTCExtract(_cf_fontembed_otf_file_t *otf,
+                         _cf_fontembed_output_fn_t output,
+                         void *context) // {{{
 {
   DEBUG_assert(otf);
   DEBUG_assert(output);
@@ -18,8 +18,8 @@ otf_ttc_extract(OTF_FILE *otf,
 
   int iA;
 
-  struct _OTF_WRITE *otw;
-  otw = malloc(sizeof(struct _OTF_WRITE) * otf->numTables);
+  struct __cf_fontembed_otf_write_s *otw;
+  otw = malloc(sizeof(struct __cf_fontembed_otf_write_s) * otf->numTables);
   if (!otw)
   {
     fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
@@ -30,21 +30,24 @@ otf_ttc_extract(OTF_FILE *otf,
   for (iA = 0; iA < otf->numTables; iA ++)
   {
     otw[iA].tag = otf->tables[iA].tag;
-    otw[iA].action = otf_action_copy;
+    otw[iA].action = __cfFontEmbedOTFActionCopy;
     otw[iA].param = otf;
     otw[iA].length = iA;
   }
-  iA = otf_write_sfnt(otw, otf->version, otf->numTables, output, context);
+  iA = __cfFontEmbedOTFWriteSFNT(otw, otf->version, otf->numTables, output,
+                                context);
   free(otw);
 
   return (iA);
 }
 // }}}
 
-// otw {0, }-terminated, will be modified; returns numTables for otf_write_sfnt
+
+// otw {0, }-terminated, will be modified; returns numTables for
+// __cfFontEmbedOTFWriteSFNT
 int
-otf_intersect_tables(OTF_FILE *otf,
-                    struct _OTF_WRITE *otw) // {{{
+__cfFontEmbedOTFIntersectTables(_cf_fontembed_otf_file_t *otf,
+                               struct __cf_fontembed_otf_write_s *otw) // {{{
 {
   int iA, iB, numTables = 0;
 
@@ -52,10 +55,11 @@ otf_intersect_tables(OTF_FILE *otf,
   {
     if (otf->tables[iA].tag == otw[iB].tag)
     {
-      if (otw[iB].action == otf_action_copy)
+      if (otw[iB].action == __cfFontEmbedOTFActionCopy)
         otw[iB].length = iA; // original table location found.
       if (iB != numTables) // >, actually
-        memmove(otw + numTables, otw + iB, sizeof(struct _OTF_WRITE));
+        memmove(otw + numTables, otw + iB,
+               sizeof(struct __cf_fontembed_otf_write_s));
       iA ++;
       iB ++;
       numTables ++;
@@ -64,10 +68,11 @@ otf_intersect_tables(OTF_FILE *otf,
       iA ++;
     else // not in otf->tables
     {
-      if (otw[iB].action != otf_action_copy) // keep
+      if (otw[iB].action != __cfFontEmbedOTFActionCopy) // keep
       {
         if (iB != numTables) // >, actually
-          memmove(otw + numTables, otw + iB, sizeof(struct _OTF_WRITE));
+          memmove(otw + numTables, otw + iB,
+                 sizeof(struct __cf_fontembed_otf_write_s));
         numTables ++;
       }
       // else delete
@@ -84,13 +89,13 @@ otf_intersect_tables(OTF_FILE *otf,
 // returns additional space requirements (when bits below >donegid are touched)
 
 static int
-otf_subset_glyf(OTF_FILE *otf,
+otf_subset_glyf(_cf_fontembed_otf_file_t *otf,
                int curgid,
                int donegid,
-               BITSET glyphs) // {{{
+               _cf_fontembed_bit_set_t glyphs) // {{{
 {
   int ret = 0;
-  if (get_SHORT(otf->gly) >= 0) // not composite
+  if (__cfFontEmbedGetShort(otf->gly) >= 0) // not composite
     return (ret); // done
 
   char *cur = otf->gly + 10;
@@ -98,15 +103,15 @@ otf_subset_glyf(OTF_FILE *otf,
   unsigned short flags;
   do
   {
-    flags = get_USHORT(cur);
-    const unsigned short sub_gid = get_USHORT(cur + 2);
+    flags = __cfFontEmbedGetUShort(cur);
+    const unsigned short sub_gid = __cfFontEmbedGetUShort(cur + 2);
     DEBUG_assert(sub_gid < otf->numGlyphs);
-    if (!bit_check(glyphs, sub_gid))
+    if (!_cfFontEmbedBitCheck(glyphs, sub_gid))
     {
       // bad: temporarily load sub glyph
-      const int len = otf_get_glyph(otf, sub_gid);
+      const int len = _cfFontEmbedOTFGetGlyph(otf, sub_gid);
       DEBUG_assert(len > 0);
-      bit_set(glyphs, sub_gid);
+      _cfFontEmbedBitSet(glyphs, sub_gid);
       if (sub_gid < donegid)
       {
         ret += len;
@@ -116,7 +121,7 @@ otf_subset_glyf(OTF_FILE *otf,
 #ifdef DEBUG
       const int res =
 #endif
-       otf_get_glyph(otf, curgid); // reload current glyph
+       _cfFontEmbedOTFGetGlyph(otf, curgid); // reload current glyph
       DEBUG_assert(res);
     }
 
@@ -141,10 +146,10 @@ otf_subset_glyf(OTF_FILE *otf,
 // TODO: cmap only required in non-CID context
 
 int
-otf_subset(OTF_FILE *otf,
-          BITSET glyphs,
-          OUTPUT_FN output,
-          void *context) // {{{ - returns number of bytes written
+_cfFontEmbedOTFSubSet(_cf_fontembed_otf_file_t *otf,
+                     _cf_fontembed_bit_set_t glyphs,
+                     _cf_fontembed_output_fn_t output,
+                     void *context) // {{{ - returns number of bytes written
 {
   DEBUG_assert(otf);
   DEBUG_assert(glyphs);
@@ -153,7 +158,7 @@ otf_subset(OTF_FILE *otf,
   int iA, b, c;
 
   // first pass: include all required glyphs
-  bit_set(glyphs, 0); // .notdef always required
+  _cfFontEmbedBitSet(glyphs, 0); // .notdef always required
   int glyfSize = 0;
   for (iA = 0, b = 0, c = 1; iA < otf->numGlyphs; iA ++, c <<= 1)
   {
@@ -164,7 +169,7 @@ otf_subset(OTF_FILE *otf,
     }
     if (glyphs[b] & c)
     {
-      int len = otf_get_glyph(otf, iA);
+      int len = _cfFontEmbedOTFGetGlyph(otf, iA);
       if (len < 0)
       {
         DEBUG_assert(0);
@@ -210,13 +215,13 @@ otf_subset(OTF_FILE *otf,
     DEBUG_assert(offset % 2 == 0);
     // TODO? change format? if glyfSize < 0x20000
     if (otf->indexToLocFormat == 0)
-      set_USHORT(new_loca + iA * 2, offset / 2);
+      __cfFontEmbedSetUShort(new_loca + iA * 2, offset / 2);
     else // ==1
-      set_ULONG(new_loca + iA * 4, offset);
+      __cfFontEmbedSetULong(new_loca + iA * 4, offset);
 
     if (glyphs[b] & c)
     {
-      const int len = otf_get_glyph(otf, iA);
+      const int len = _cfFontEmbedOTFGetGlyph(otf, iA);
       DEBUG_assert(len >= 0);
       memcpy(new_glyf + offset, otf->gly, len);
       offset += len;
@@ -224,33 +229,45 @@ otf_subset(OTF_FILE *otf,
   }
   // last entry
   if (otf->indexToLocFormat == 0)
-    set_USHORT(new_loca + otf->numGlyphs * 2, offset / 2);
+    __cfFontEmbedSetUShort(new_loca + otf->numGlyphs * 2, offset / 2);
   else // ==1
-    set_ULONG(new_loca + otf->numGlyphs * 4, offset);
+    __cfFontEmbedSetULong(new_loca + otf->numGlyphs * 4, offset);
   DEBUG_assert(offset == glyfSize);
 
   // determine new tables.
-  struct _OTF_WRITE otw[] = // sorted
+  struct __cf_fontembed_otf_write_s otw[] = // sorted
   {
     // TODO: cmap only required in non-CID context   or always in CFF
-    {OTF_TAG('c', 'm', 'a', 'p'), otf_action_copy, otf, },
-    {OTF_TAG('c', 'v', 't', ' '), otf_action_copy, otf, },
-    {OTF_TAG('f', 'p', 'g', 'm'), otf_action_copy, otf, },
-    {OTF_TAG('g', 'l', 'y', 'f'), otf_action_replace, new_glyf, glyfSize},
-    {OTF_TAG('h', 'e', 'a', 'd'), otf_action_copy, otf, }, // _copy_head
-    {OTF_TAG('h', 'h', 'e', 'a'), otf_action_copy, otf, },
-    {OTF_TAG('h', 'm', 't', 'x'), otf_action_copy, otf, },
-    {OTF_TAG('l', 'o', 'c', 'a'), otf_action_replace, new_loca, locaSize},
-    {OTF_TAG('m', 'a', 'x', 'p'), otf_action_copy, otf, },
-    {OTF_TAG('n', 'a', 'm', 'e'), otf_action_copy, otf, },
-    {OTF_TAG('p', 'r', 'e', 'p'), otf_action_copy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('c', 'm', 'a', 'p'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('c', 'v', 't', ' '),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('f', 'p', 'g', 'm'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('g', 'l', 'y', 'f'),
+     __cfFontEmbedOTFActionReplace, new_glyf, glyfSize},
+    {_CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'),
+     __cfFontEmbedOTFActionCopy, otf, }, // _copy_head
+    {_CF_FONTEMBED_OTF_TAG('h', 'h', 'e', 'a'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('h', 'm', 't', 'x'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('l', 'o', 'c', 'a'),
+     __cfFontEmbedOTFActionReplace, new_loca, locaSize},
+    {_CF_FONTEMBED_OTF_TAG('m', 'a', 'x', 'p'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('n', 'a', 'm', 'e'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('p', 'r', 'e', 'p'),
+     __cfFontEmbedOTFActionCopy, otf, },
     // vhea vmtx (never used in PDF, but possible in PS>=3011)
     {0, 0, 0, 0}
   };
 
   // and write them
-  int numTables = otf_intersect_tables(otf, otw);
-  int ret = otf_write_sfnt(otw, otf->version, numTables, output, context);
+  int numTables = __cfFontEmbedOTFIntersectTables(otf, otw);
+  int ret = __cfFontEmbedOTFWriteSFNT(otw, otf->version, numTables, output,
+                                     context);
 
   free(new_loca);
   free(new_glyf);
@@ -265,10 +282,10 @@ otf_subset(OTF_FILE *otf,
 // TODO no subsetting actually done (for now)
 
 int
-otf_subset_cff(OTF_FILE *otf,
-              BITSET glyphs,
-              OUTPUT_FN output,
-              void *context) // {{{ - returns number of bytes written
+_cfFontEmbedOTFSubSetCFF(_cf_fontembed_otf_file_t *otf,
+                        _cf_fontembed_bit_set_t glyphs,
+                        _cf_fontembed_output_fn_t output,
+                        void *context) // {{{ - returns number of bytes written
 {
   DEBUG_assert(otf);
   DEBUG_assert(output);
@@ -276,41 +293,55 @@ otf_subset_cff(OTF_FILE *otf,
   // TODO char *new_cff = cff_subset(...);
 
   // determine new tables.
-  struct _OTF_WRITE otw[] =
+  struct __cf_fontembed_otf_write_s otw[] =
   {
-    {OTF_TAG('C', 'F', 'F', ' '), otf_action_copy, otf, },
-//  {OTF_TAG('C', 'F', 'F', ' '), otf_action_replace, new_glyf, glyfSize},
-    {OTF_TAG('c', 'm', 'a', 'p'), otf_action_copy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('C', 'F', 'F', ' '),
+     __cfFontEmbedOTFActionCopy, otf, },
+//  {_CF_FONTEMBED_OTF_TAG('C', 'F', 'F', ' '),
+//   __cfFontEmbedOTFActionReplace, new_glyf, glyfSize},
+    {_CF_FONTEMBED_OTF_TAG('c', 'm', 'a', 'p'),
+     __cfFontEmbedOTFActionCopy, otf, },
 #if 0 // not actually needed!
-    {OTF_TAG('c', 'v', 't', ' '), otf_action_copy, otf, },
-    {OTF_TAG('f', 'p', 'g', 'm'), otf_action_copy, otf, },
-    {OTF_TAG('h', 'e', 'a', 'd'), otf_action_copy, otf, }, // _copy_head
-    {OTF_TAG('h', 'h', 'e', 'a'), otf_action_copy, otf, },
-    {OTF_TAG('h', 'm', 't', 'x'), otf_action_copy, otf, },
-    {OTF_TAG('m', 'a', 'x', 'p'), otf_action_copy, otf, },
-    {OTF_TAG('n', 'a', 'm', 'e'), otf_action_copy, otf, },
-    {OTF_TAG('p', 'r', 'e', 'p'), otf_action_copy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('c', 'v', 't', ' '),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('f', 'p', 'g', 'm'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'),
+     __cfFontEmbedOTFActionCopy, otf, }, // _copy_head
+    {_CF_FONTEMBED_OTF_TAG('h', 'h', 'e', 'a'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('h', 'm', 't', 'x'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('m', 'a', 'x', 'p'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('n', 'a', 'm', 'e'),
+     __cfFontEmbedOTFActionCopy, otf, },
+    {_CF_FONTEMBED_OTF_TAG('p', 'r', 'e', 'p'),
+     __cfFontEmbedOTFActionCopy, otf, },
 #endif // 0
     {0, 0, 0, 0}
   };
 
   // and write them
-  int numTables = otf_intersect_tables(otf, otw);
-  int ret = otf_write_sfnt(otw, otf->version, numTables, output, context);
+  int numTables = __cfFontEmbedOTFIntersectTables(otf, otw);
+  int ret = __cfFontEmbedOTFWriteSFNT(otw, otf->version, numTables, output,
+                                     context);
 
 //  free(new_cff);
   return (ret);
 }
 // }}}
 
-//int copy_block(FILE *f, long pos, int length, OUTPUT_FN output,
+
+//int copy_block(FILE *f, long pos, int length,
+//               _cf_fontembed_output_fn_t output,
 //               void *context); // copied bytes or -1 (also on premature EOF)
 
 static int
 copy_block(FILE *f,
           long pos,
           int length,
-          OUTPUT_FN output,
+          _cf_fontembed_output_fn_t output,
           void *context) // {{{
 {
   DEBUG_assert(f);
@@ -345,19 +376,22 @@ copy_block(FILE *f,
 }
 // }}}
 
+
 int
-otf_cff_extract(OTF_FILE *otf,
-               OUTPUT_FN output,
-               void *context) // {{{ - returns number of bytes written
+_cfFontEmbedOTFCFFExtract(_cf_fontembed_otf_file_t *otf,
+                         _cf_fontembed_output_fn_t output,
+                         void *context) // {{{ - returns number of bytes
+                                         //       written
 {
   DEBUG_assert(otf);
   DEBUG_assert(output);
 
-  int idx = otf_find_table(otf, OTF_TAG('C', 'F', 'F', ' '));
+  int idx =
+    __cfFontEmbedOTFFindTable(otf, _CF_FONTEMBED_OTF_TAG('C', 'F', 'F', ' '));
   if (idx == -1)
     return (-1);
 
-  const OTF_DIRENT *table = otf->tables + idx;
+  const _cf_fontembed_otf_dir_ent_t *table = otf->tables + idx;
 
   return (copy_block(otf->f, table->offset, table->length, output, context));
 }
@@ -368,7 +402,7 @@ otf_cff_extract(OTF_FILE *otf,
 
 #if 0 // TODO elsewhere : char *cff_subset(...);
   // first pass: include all required glyphs
-  bit_set(glyphs, 0); // .notdef always required
+  _cfFontEmbedBitSet(glyphs, 0); // .notdef always required
   int glyfSize = 0;
   for (iA = 0, b = 0, c = 1; iA < otf->numGlyphs; iA ++, c <<= 1)
   {
index 7beee4216a280d8cd1faea78fd31417951d6817d..cad00d74bf375912c3949685e75e647c9aa85ae3 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "sfnt-private.h"
 #include <stdio.h>
@@ -8,7 +8,7 @@
 
 
 // TODO?
-// get_SHORT(head + 48) // fontDirectionHint
+// __cfFontEmbedGetShort(head + 48) // fontDirectionHint
 // reqd. Tables: cmap, head, hhea, hmtx, maxp, name, OS/2, post
 // OTF: glyf, loca [cvt, fpgm, prep]
 //
@@ -69,13 +69,13 @@ otf_bsearch(char *table, // {{{
 // }}}
 
 
-static OTF_FILE *
+static _cf_fontembed_otf_file_t *
 otf_new(FILE *f) // {{{
 {
   DEBUG_assert(f);
 
-  OTF_FILE *ret;
-  ret = calloc(1, sizeof(OTF_FILE));
+  _cf_fontembed_otf_file_t *ret;
+  ret = calloc(1, sizeof(_cf_fontembed_otf_file_t));
   if (ret)
   {
     ret->f = f;
@@ -87,11 +87,11 @@ otf_new(FILE *f) // {{{
 // }}}
 
 
-// will alloc, if >buf ==NULL, returns >buf, or NULL on error
-// NOTE: you probably want otf_get_table()
+// will alloc, if >buf == NULL, returns >buf, or NULL on error
+// NOTE: you probably want _cfFontEmbedOTFGetTable()
 
 static char *
-otf_read(OTF_FILE *otf,
+otf_read(_cf_fontembed_otf_file_t *otf,
         char *buf,
         long pos,
         int length) // {{{
@@ -143,7 +143,7 @@ otf_read(OTF_FILE *otf,
 
 
 static int
-otf_get_ttc_start(OTF_FILE *otf,
+otf_get_ttc_start(_cf_fontembed_otf_file_t *otf,
                  int use_ttc) // {{{
 {
   char buf[4];
@@ -158,13 +158,13 @@ otf_get_ttc_start(OTF_FILE *otf,
     fprintf(stderr, "Bad TTC subfont number\n");
     return (-1);
   }
-  return (get_ULONG(buf));
+  return (__cfFontEmbedGetULong(buf));
 }
 // }}}
 
 
-OTF_FILE *
-otf_do_load(OTF_FILE *otf,
+static _cf_fontembed_otf_file_t *
+otf_do_load(_cf_fontembed_otf_file_t *otf,
            int pos) // {{{
 {
   int iA;
@@ -173,29 +173,32 @@ otf_do_load(OTF_FILE *otf,
   // {{{ read offset table
   if (otf_read(otf, buf, pos, 12))
   {
-    otf->version = get_ULONG(buf);
+    otf->version = __cfFontEmbedGetULong(buf);
     if (otf->version == 0x00010000) // 1.0 truetype
     {
     }
-    else if (otf->version == OTF_TAG('O', 'T', 'T', 'O')) // OTF(CFF)
-      otf->flags |= OTF_F_FMT_CFF;
-    else if (otf->version == OTF_TAG('t', 'r', 'u', 'e')) // (old mac)
+    else if (otf->version ==
+            _CF_FONTEMBED_OTF_TAG('O', 'T', 'T', 'O')) // OTF(CFF)
+      otf->flags |= _CF_FONTEMBED_OTF_F_FMT_CFF;
+    else if (otf->version ==
+            _CF_FONTEMBED_OTF_TAG('t', 'r', 'u', 'e')) // (old mac)
     {
     }
-    else if (otf->version == OTF_TAG('t', 'y', 'p', '1')) // sfnt wrapped type1
+    else if (otf->version ==
+            _CF_FONTEMBED_OTF_TAG('t', 'y', 'p', '1')) // sfnt wrapped type1
     {
       // TODO: unsupported
     }
     else
     {
-      otf_close(otf);
+      _cfFontEmbedOTFClose(otf);
       otf = NULL;
     }
     pos += 12;
   }
   else
   {
-    otf_close(otf);
+    _cfFontEmbedOTFClose(otf);
     otf = NULL;
   }
   if (!otf)
@@ -203,67 +206,69 @@ otf_do_load(OTF_FILE *otf,
     fprintf(stderr, "Not a ttf font\n");
     return (NULL);
   }
-  otf->numTables = get_USHORT(buf + 4);
+  otf->numTables = __cfFontEmbedGetUShort(buf + 4);
   // }}}
 
   // {{{ read directory
-  otf->tables = malloc(sizeof(OTF_DIRENT) * otf->numTables);
+  otf->tables = malloc(sizeof(_cf_fontembed_otf_dir_ent_t) * otf->numTables);
   if (!otf->tables)
   {
     fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
-    otf_close(otf);
+    _cfFontEmbedOTFClose(otf);
     return (NULL);
   }
   for (iA = 0; iA < otf->numTables; iA ++)
   {
     if (!otf_read(otf, buf, pos, 16))
     {
-      otf_close(otf);
+      _cfFontEmbedOTFClose(otf);
       return (NULL);
     }
-    otf->tables[iA].tag = get_ULONG(buf);
-    otf->tables[iA].checkSum = get_ULONG(buf + 4);
-    otf->tables[iA].offset = get_ULONG(buf + 8);
-    otf->tables[iA].length = get_ULONG(buf + 12);
-    if ((otf->tables[iA].tag == OTF_TAG('C', 'F', 'F', ' ')) &&
-       ((otf->flags & OTF_F_FMT_CFF) == 0))
+    otf->tables[iA].tag = __cfFontEmbedGetULong(buf);
+    otf->tables[iA].checkSum = __cfFontEmbedGetULong(buf + 4);
+    otf->tables[iA].offset = __cfFontEmbedGetULong(buf + 8);
+    otf->tables[iA].length = __cfFontEmbedGetULong(buf + 12);
+    if ((otf->tables[iA].tag == _CF_FONTEMBED_OTF_TAG('C', 'F', 'F', ' ')) &&
+       ((otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF) == 0))
     {
       fprintf(stderr, "Wrong magic\n");
-      otf_close(otf);
+      _cfFontEmbedOTFClose(otf);
       return (NULL);
     }
-    else if ((otf->tables[iA].tag == OTF_TAG('g', 'l', 'y', 'p')) &&
-            (otf->flags & OTF_F_FMT_CFF))
+    else if ((otf->tables[iA].tag == _CF_FONTEMBED_OTF_TAG('g', 'l', 'y', 'p')) &&
+            (otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF))
     {
       fprintf(stderr, "Wrong magic\n");
-      otf_close(otf);
+      _cfFontEmbedOTFClose(otf);
       return (NULL);
     }
     pos += 16;
   }
   // }}}
 
-  //otf->flags |= OTF_F_DO_CHECKSUM;
+  //otf->flags |= _CF_FONTEMBED_OTF_F_DO_CHECKSUM;
   // {{{ check head table
   int len = 0;
-  char *head = otf_get_table(otf, OTF_TAG('h', 'e', 'a', 'd'), &len);
+  char *head =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'),
+                           &len);
   if ((!head) ||
-      (get_ULONG(head + 0) != 0x00010000) ||  // version
+      (__cfFontEmbedGetULong(head + 0) != 0x00010000) ||  // version
       (len != 54) ||
-      (get_ULONG(head + 12) != 0x5F0F3CF5) || // magic
-      (get_SHORT(head + 52) != 0x0000))   // glyphDataFormat
+      (__cfFontEmbedGetULong(head + 12) != 0x5F0F3CF5) || // magic
+      (__cfFontEmbedGetShort(head + 52) != 0x0000))   // glyphDataFormat
   {
     fprintf(stderr, "Unsupported OTF font / head table \n");
     free(head);
-    otf_close(otf);
+    _cfFontEmbedOTFClose(otf);
     return (NULL);
   }
   // }}}
-  otf->unitsPerEm = get_USHORT(head + 18);
-  otf->indexToLocFormat = get_SHORT(head + 50);
+  otf->unitsPerEm = __cfFontEmbedGetUShort(head + 18);
+  otf->indexToLocFormat = __cfFontEmbedGetShort(head + 50);
 
   // {{{ checksum whole file
-  if (otf->flags & OTF_F_DO_CHECKSUM)
+  if (otf->flags & _CF_FONTEMBED_OTF_F_DO_CHECKSUM)
   {
     unsigned int csum = 0;
     char tmp[1024];
@@ -273,13 +278,13 @@ otf_do_load(OTF_FILE *otf,
       len = fread(tmp, 1, 1024, otf->f);
       if (len & 3) // zero padding reqd.
         memset(tmp + len, 0, 4 - (len & 3));
-      csum += otf_checksum(tmp, len);
+      csum += __cfFontEmbedOTFCheckSum(tmp, len);
     }
     if (csum != 0xb1b0afba)
     {
       fprintf(stderr, "Wrong global checksum\n");
       free(head);
-      otf_close(otf);
+      _cfFontEmbedOTFClose(otf);
       return (NULL);
     }
   }
@@ -287,14 +292,16 @@ otf_do_load(OTF_FILE *otf,
   free(head);
 
   // {{{ read maxp table / numGlyphs
-  char *maxp = otf_get_table(otf, OTF_TAG('m', 'a', 'x', 'p'), &len);
+  char *maxp =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('m', 'a', 'x', 'p'),
+                           &len);
   if (maxp)
   {
-    const unsigned int maxp_version = get_ULONG(maxp);
+    const unsigned int maxp_version = __cfFontEmbedGetULong(maxp);
     if ((maxp_version == 0x00005000) && (len == 6)) // version 0.5
     {
-      otf->numGlyphs = get_USHORT(maxp + 4);
-      if ((otf->flags & OTF_F_FMT_CFF) == 0) // only CFF
+      otf->numGlyphs = __cfFontEmbedGetUShort(maxp + 4);
+      if ((otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF) == 0) // only CFF
       {
         free(maxp);
         maxp = NULL;
@@ -302,8 +309,8 @@ otf_do_load(OTF_FILE *otf,
     }
     else if ((maxp_version == 0x00010000) && (len == 32)) // version 1.0
     {
-      otf->numGlyphs = get_USHORT(maxp + 4);
-      if (otf->flags&OTF_F_FMT_CFF) // only TTF
+      otf->numGlyphs = __cfFontEmbedGetUShort(maxp + 4);
+      if (otf->flags&_CF_FONTEMBED_OTF_F_FMT_CFF) // only TTF
       {
         free(maxp);
         maxp = NULL;
@@ -319,7 +326,7 @@ otf_do_load(OTF_FILE *otf,
   {
     fprintf(stderr, "Unsupported OTF font / maxp table \n");
     free(maxp);
-    otf_close(otf);
+    _cfFontEmbedOTFClose(otf);
     return (NULL);
   }
   free(maxp);
@@ -330,11 +337,11 @@ otf_do_load(OTF_FILE *otf,
 // }}}
 
 
-OTF_FILE *
-otf_load(const char *file) // {{{
+_cf_fontembed_otf_file_t *
+_cfFontEmbedOTFLoad(const char *file) // {{{
 {
   FILE *f;
-  OTF_FILE *otf;
+  _cf_fontembed_otf_file_t *otf;
 
   int use_ttc =- 1;
   if ((f = fopen(file, "rb")) == NULL)
@@ -377,22 +384,22 @@ otf_load(const char *file) // {{{
   // {{{ check for TTC
   if (otf_read(otf, buf, pos, 12))
   {
-    const unsigned int version = get_ULONG(buf);
-    if (version == OTF_TAG('t', 't', 'c', 'f'))
+    const unsigned int version = __cfFontEmbedGetULong(buf);
+    if (version == _CF_FONTEMBED_OTF_TAG('t', 't', 'c', 'f'))
     {
-      const unsigned int ttc_version = get_ULONG(buf + 4);
+      const unsigned int ttc_version = __cfFontEmbedGetULong(buf + 4);
       if ((ttc_version != 0x00010000) && (ttc_version != 0x00020000))
       {
         fprintf(stderr, "Unsupported TTC version\n");
-        otf_close(otf);
+        _cfFontEmbedOTFClose(otf);
         return (NULL);
       }
-      otf->numTTC = get_ULONG(buf + 8);
+      otf->numTTC = __cfFontEmbedGetULong(buf + 8);
       otf->useTTC = use_ttc;
       pos = otf_get_ttc_start(otf, use_ttc);
       if (pos == -1)
       {
-        otf_close(otf);
+        _cfFontEmbedOTFClose(otf);
         return (NULL);
       }
     }
@@ -400,7 +407,7 @@ otf_load(const char *file) // {{{
   else
   {
     fprintf(stderr, "Not a ttf font\n");
-    otf_close(otf);
+    _cfFontEmbedOTFClose(otf);
     return (NULL);
   }
   // }}}
@@ -411,7 +418,7 @@ otf_load(const char *file) // {{{
 
 
 void
-otf_close(OTF_FILE *otf) // {{{
+_cfFontEmbedOTFClose(_cf_fontembed_otf_file_t *otf) // {{{
 {
   DEBUG_assert(otf);
   if (otf)
@@ -432,8 +439,8 @@ otf_close(OTF_FILE *otf) // {{{
 static int
 otf_dirent_compare(const void *a, const void *b) // {{{
 {
-  const unsigned int aa = ((const OTF_DIRENT *)a)->tag;
-  const unsigned int bb = ((const OTF_DIRENT *)b)->tag;
+  const unsigned int aa = ((const _cf_fontembed_otf_dir_ent_t *)a)->tag;
+  const unsigned int bb = ((const _cf_fontembed_otf_dir_ent_t *)b)->tag;
   if (aa < bb)
     return (-1);
   else if (aa > bb)
@@ -444,8 +451,8 @@ otf_dirent_compare(const void *a, const void *b) // {{{
 
 
 int
-otf_find_table(OTF_FILE *otf,
-              unsigned int tag) // {{{  - table_index  or -1 on error
+__cfFontEmbedOTFFindTable(_cf_fontembed_otf_file_t *otf,
+                         unsigned int tag) // {{{ - table_index  or -1 on error
 {
 #if 0
   // binary search would require raw table
@@ -454,7 +461,7 @@ otf_find_table(OTF_FILE *otf,
   if (!otf_read(otf, buf, pos, 12))
     return (-1);
   pos = 12;
-  const unsigned int numTables = get_USHORT(buf + 4);
+  const unsigned int numTables = __cfFontEmbedGetUShort(buf + 4);
   char *tables = malloc(16 * numTables);
   if (!tables)
     return (-1);
@@ -464,16 +471,17 @@ otf_find_table(OTF_FILE *otf,
     return (-1);
   }
   char target[] = {(tag >> 24), (tag >> 16), (tag >> 8), tag};
-  //  DEBUG_assert(get_USHORT(buf+6)+get_USHORT(buf+10)==16*numTables);
+  //  DEBUG_assert(__cfFontEmbedGetUShort(buf + 6) +
+  //               __cfFontEmbedGetUShort(buf + 10) == 16 * numTables);
   char *result = otf_bsearch(tables, target, 4,
-                            get_USHORT(buf + 6),
-                            get_USHORT(buf + 8),
-                            get_USHORT(buf + 10), 0);
+                            __cfFontEmbedGetUShort(buf + 6),
+                            __cfFontEmbedGetUShort(buf + 8),
+                            __cfFontEmbedGetUShort(buf + 10), 0);
   free(tables);
   if (result)
     return (result - tables) / 16;
 #elif 1
-  OTF_DIRENT key = {.tag = tag}, *res;
+  _cf_fontembed_otf_dir_ent_t key = {.tag = tag}, *res;
   res = bsearch(&key, otf->tables, otf->numTables, sizeof(otf->tables[0]),
                otf_dirent_compare);
   if (res)
@@ -492,32 +500,33 @@ otf_find_table(OTF_FILE *otf,
 
 
 char *
-otf_get_table(OTF_FILE *otf,
-             unsigned int tag,
-             int *ret_len) // {{{
+_cfFontEmbedOTFGetTable(_cf_fontembed_otf_file_t *otf,
+                       unsigned int tag,
+                       int *ret_len) // {{{
 {
   DEBUG_assert(otf);
   DEBUG_assert(ret_len);
 
-  const int idx = otf_find_table(otf, tag);
+  const int idx = __cfFontEmbedOTFFindTable(otf, tag);
   if (idx == -1)
   {
     *ret_len =- 1;
     return (NULL);
   }
-  const OTF_DIRENT *table = otf->tables + idx;
+  const _cf_fontembed_otf_dir_ent_t *table = otf->tables + idx;
 
   char *ret = otf_read(otf, NULL, table->offset, table->length);
   if (!ret)
     return (NULL);
-  if (otf->flags & OTF_F_DO_CHECKSUM)
+  if (otf->flags & _CF_FONTEMBED_OTF_F_DO_CHECKSUM)
   {
-    unsigned int csum = otf_checksum(ret, table->length);
-    if (tag==OTF_TAG('h', 'e', 'a', 'd')) // special case
-      csum -= get_ULONG(ret + 8);
+    unsigned int csum = __cfFontEmbedOTFCheckSum(ret, table->length);
+    if (tag==_CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd')) // special case
+      csum -= __cfFontEmbedGetULong(ret + 8);
     if (csum != table->checkSum)
     {
-      fprintf(stderr, "Wrong checksum for %c%c%c%c\n", OTF_UNTAG(tag));
+      fprintf(stderr, "Wrong checksum for %c%c%c%c\n",
+             _CF_FONTEMBED_OTF_UNTAG(tag));
       free(ret);
       return (NULL);
     }
@@ -529,12 +538,13 @@ otf_get_table(OTF_FILE *otf,
 
 
 int
-otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
+__cfFontEmbedOTFLoadGlyf(_cf_fontembed_otf_file_t *otf) // {{{  - 0 on success
 {
-  DEBUG_assert((otf->flags & OTF_F_FMT_CFF) == 0); // not for CFF
+  DEBUG_assert((otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF) == 0); // not for CFF
   int iA, len;
   // {{{ find glyf table
-  iA = otf_find_table(otf, OTF_TAG('g', 'l', 'y', 'f'));
+  iA =
+    __cfFontEmbedOTFFindTable(otf, _CF_FONTEMBED_OTF_TAG('g', 'l', 'y', 'f'));
   if (iA == -1)
   {
     fprintf(stderr, "Unsupported OTF font / glyf table \n");
@@ -544,7 +554,9 @@ otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
   // }}}
 
   // {{{ read loca table
-  char *loca = otf_get_table(otf, OTF_TAG('l', 'o', 'c', 'a'), &len);
+  char *loca =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('l', 'o', 'c', 'a'),
+                           &len);
   if ((!loca) ||
       (otf->indexToLocFormat >= 2) ||
       (((len + 3) & ~3) != ((((otf->numGlyphs + 1) *
@@ -567,12 +579,12 @@ otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
   if (otf->indexToLocFormat == 0)
   {
     for (iA = 0; iA <= otf->numGlyphs; iA ++)
-      otf->glyphOffsets[iA] = get_USHORT(loca + iA * 2) * 2;
+      otf->glyphOffsets[iA] = __cfFontEmbedGetUShort(loca + iA * 2) * 2;
   }
   else // indexToLocFormat == 1
   {
     for (iA = 0; iA <= otf->numGlyphs; iA ++)
-      otf->glyphOffsets[iA] = get_ULONG(loca + iA * 4);
+      otf->glyphOffsets[iA] = __cfFontEmbedGetULong(loca + iA * 4);
   }
   free(loca);
   if (otf->glyphOffsets[otf->numGlyphs] > otf->glyfTable->length)
@@ -613,33 +625,38 @@ otf_load_glyf(OTF_FILE *otf) // {{{  - 0 on success
 // }}}
 
 int
-otf_load_more(OTF_FILE *otf) // {{{  - 0 on success => hhea, hmtx, name, [glyf]
+__cfFontEmbedOTFLoadMore(_cf_fontembed_otf_file_t *otf)
+                           // {{{  - 0 on success => hhea, hmtx, name, [glyf]
 {
   int iA;
   int len;
 
-  if ((otf->flags & OTF_F_FMT_CFF) == 0) // not for CFF
+  if ((otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF) == 0) // not for CFF
   {
-    if (otf_load_glyf(otf) == -1)
+    if (__cfFontEmbedOTFLoadGlyf(otf) == -1)
       return (-1);
   }
 
   // {{{ read hhea table
-  char *hhea = otf_get_table(otf, OTF_TAG('h', 'h', 'e', 'a'), &len);
+  char *hhea =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'h', 'e', 'a'),
+                           &len);
   if ((!hhea) ||
-      (get_ULONG(hhea) != 0x00010000) || // version
+      (__cfFontEmbedGetULong(hhea) != 0x00010000) || // version
       (len != 36) ||
-      (get_SHORT(hhea + 32) != 0)) // metric format
+      (__cfFontEmbedGetShort(hhea + 32) != 0)) // metric format
   {
     fprintf(stderr, "Unsupported OTF font / hhea table \n");
     return (-1);
   }
-  otf->numberOfHMetrics = get_USHORT(hhea + 34);
+  otf->numberOfHMetrics = __cfFontEmbedGetUShort(hhea + 34);
   free(hhea);
   // }}}
 
   // {{{ read hmtx table
-  char *hmtx = otf_get_table(otf, OTF_TAG('h', 'm', 't', 'x'), &len);
+  char *hmtx =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'm', 't', 'x'),
+                           &len);
   if ((!hmtx) ||
       (len != otf->numberOfHMetrics * 2 + otf->numGlyphs * 2))
   {
@@ -655,23 +672,26 @@ otf_load_more(OTF_FILE *otf) // {{{  - 0 on success => hhea, hmtx, name, [glyf]
   // }}}
 
   // {{{ read name table
-  char *name = otf_get_table(otf, OTF_TAG('n', 'a', 'm', 'e'), &len);
+  char *name =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('n', 'a', 'm', 'e'),
+                           &len);
   if ((!name) ||
-      (get_USHORT(name) != 0x0000) || // version
-      (len < get_USHORT(name + 2) * 12 + 6) ||
-      (len <= get_USHORT(name + 4)))
+      (__cfFontEmbedGetUShort(name) != 0x0000) || // version
+      (len < __cfFontEmbedGetUShort(name + 2) * 12 + 6) ||
+      (len <= __cfFontEmbedGetUShort(name + 4)))
   {
     fprintf(stderr, "Unsupported OTF font / name table\n");
     return (-1);
   }
 
   // check bounds
-  int name_count = get_USHORT(name + 2);
-  const char *nstore = name + get_USHORT(name + 4);
+  int name_count = __cfFontEmbedGetUShort(name + 2);
+  const char *nstore = name + __cfFontEmbedGetUShort(name + 4);
   for (iA = 0; iA < name_count; iA ++)
   {
     const char *nrec = name + 6 + 12 * iA;
-    if (nstore-name + get_USHORT(nrec + 10) + get_USHORT(nrec + 8) > len)
+    if (nstore-name + __cfFontEmbedGetUShort(nrec + 10) +
+       __cfFontEmbedGetUShort(nrec + 8) > len)
     {
       fprintf(stderr, "Bad name table\n");
       free(name);
@@ -691,41 +711,43 @@ otf_load_more(OTF_FILE *otf) // {{{  - 0 on success => hhea, hmtx, name, [glyf]
 // }}}
 
 
-int
-otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
+static int
+otf_load_cmap(_cf_fontembed_otf_file_t *otf) // {{{  - 0 on success
 {
   int iA;
   int len;
 
-  char *cmap = otf_get_table(otf, OTF_TAG('c', 'm', 'a', 'p'), &len);
+  char *cmap =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('c', 'm', 'a', 'p'),
+                           &len);
   if ((!cmap) ||
-      (get_USHORT(cmap) != 0x0000) || // version
-      (len < get_USHORT(cmap + 2) * 8 + 4))
+      (__cfFontEmbedGetUShort(cmap) != 0x0000) || // version
+      (len < __cfFontEmbedGetUShort(cmap + 2) * 8 + 4))
   {
     fprintf(stderr, "Unsupported OTF font / cmap table\n");
     DEBUG_assert(0);
     return (-1);
   }
   // check bounds, find (3, 0) or (3, 1) [TODO?]
-  const int numTables = get_USHORT(cmap + 2);
+  const int numTables = __cfFontEmbedGetUShort(cmap + 2);
   for (iA = 0; iA < numTables; iA ++)
   {
     const char *nrec = cmap + 4 + 8 * iA;
-    const unsigned int offset = get_ULONG(nrec + 4);
+    const unsigned int offset = __cfFontEmbedGetULong(nrec + 4);
     const char *ndata = cmap + offset;
     if ((ndata < cmap + 4 + 8 * numTables) ||
        (offset >= len) ||
-       (offset + get_USHORT(ndata + 2) > len))
+       (offset + __cfFontEmbedGetUShort(ndata + 2) > len))
     {
       fprintf(stderr, "Bad cmap table\n");
       free(cmap);
       DEBUG_assert(0);
       return (-1);
     }
-    if ((get_USHORT(nrec) == 3) &&
-       (get_USHORT(nrec + 2) <= 1) &&
-       (get_USHORT(ndata) == 4) &&
-       (get_USHORT(ndata + 4) == 0))
+    if ((__cfFontEmbedGetUShort(nrec) == 3) &&
+       (__cfFontEmbedGetUShort(nrec + 2) <= 1) &&
+       (__cfFontEmbedGetUShort(ndata) == 4) &&
+       (__cfFontEmbedGetUShort(ndata + 4) == 0))
       otf->unimap = ndata;
   }
   if (otf->cmap)
@@ -741,8 +763,8 @@ otf_load_cmap(OTF_FILE *otf) // {{{  - 0 on success
 
 
 int
-otf_get_width(OTF_FILE *otf,
-             unsigned short gid) // {{{  -1 on error
+_cfFontEmbedOTFGetWidth(_cf_fontembed_otf_file_t *otf,
+                       unsigned short gid) // {{{  -1 on error
 {
   DEBUG_assert(otf);
 
@@ -752,23 +774,25 @@ otf_get_width(OTF_FILE *otf,
   // ensure hmtx is there
   if (!otf->hmtx)
   {
-    if (otf_load_more(otf) != 0)
+    if (__cfFontEmbedOTFLoadMore(otf) != 0)
     {
       fprintf(stderr, "Unsupported OTF font / cmap table\n");
       return (-1);
     }
   }
 
-  return (get_width_fast(otf, gid));
+  return (__cfFontEmbedGetWidthFast(otf, gid));
 #if 0
   if (gid >= otf->numberOfHMetrics)
   {
-    return (get_USHORT(otf->hmtx + (otf->numberOfHMetrics - 1) * 2));
-    // TODO? lsb = get_SHORT(otf->hmtx + otf->numberOfHMetrics * 2 + gid * 2);
+    return (__cfFontEmbedGetUShort(otf->hmtx +
+                                  (otf->numberOfHMetrics - 1) * 2));
+    // TODO? lsb = __cfFontEmbedGetShort(otf->hmtx +
+    //                                   otf->numberOfHMetrics * 2 + gid * 2);
     //                lsb: left_side_bearing (also in table)
   }
-  return (get_USHORT(otf->hmtx + gid * 4));
-  // TODO? lsb = get_SHORT(otf->hmtx + gid * 4 + 2);
+  return (__cfFontEmbedGetUShort(otf->hmtx + gid * 4));
+  // TODO? lsb = __cfFontEmbedGetShort(otf->hmtx + gid * 4 + 2);
 #endif
 }
 // }}}
@@ -784,12 +808,12 @@ otf_name_compare(const void *a,
 
 
 const char *
-otf_get_name(OTF_FILE *otf,
-            int platformID,
-            int encodingID,
-            int languageID,
-            int nameID,
-            int *ret_len) // {{{
+_cfFontEmbedOTFGetName(_cf_fontembed_otf_file_t *otf,
+                      int platformID,
+                      int encodingID,
+                      int languageID,
+                      int nameID,
+                      int *ret_len) // {{{
 {
   DEBUG_assert(otf);
   DEBUG_assert(ret_len);
@@ -797,7 +821,7 @@ otf_get_name(OTF_FILE *otf,
   // ensure name is there
   if (!otf->name)
   {
-    if (otf_load_more(otf) != 0)
+    if (__cfFontEmbedOTFLoadMore(otf) != 0)
     {
       *ret_len = -1;
       DEBUG_assert(0);
@@ -806,18 +830,19 @@ otf_get_name(OTF_FILE *otf,
   }
 
   char key[8];
-  set_USHORT(key, platformID);
-  set_USHORT(key + 2, encodingID);
-  set_USHORT(key + 4, languageID);
-  set_USHORT(key + 6, nameID);
+  __cfFontEmbedSetUShort(key, platformID);
+  __cfFontEmbedSetUShort(key + 2, encodingID);
+  __cfFontEmbedSetUShort(key + 4, languageID);
+  __cfFontEmbedSetUShort(key + 6, nameID);
 
-  char *res = bsearch(key, otf->name + 6, get_USHORT(otf->name + 2), 12,
+  char *res = bsearch(key, otf->name + 6,
+                     __cfFontEmbedGetUShort(otf->name + 2), 12,
                      otf_name_compare);
   if (res)
   {
-    *ret_len = get_USHORT(res + 8);
-    int npos = get_USHORT(res + 10);
-    const char *nstore = otf->name + get_USHORT(otf->name + 4);
+    *ret_len = __cfFontEmbedGetUShort(res + 8);
+    int npos = __cfFontEmbedGetUShort(res + 10);
+    const char *nstore = otf->name + __cfFontEmbedGetUShort(otf->name + 4);
     return (nstore + npos);
   }
   *ret_len = 0;
@@ -827,12 +852,12 @@ otf_get_name(OTF_FILE *otf,
 
 
 int
-otf_get_glyph(OTF_FILE *otf,
-             unsigned short gid) // {{{ result in >otf->gly, returns length,
-                                  //     -1 on error
+_cfFontEmbedOTFGetGlyph(_cf_fontembed_otf_file_t *otf,
+                       unsigned short gid) // {{{ result in >otf->gly,
+                                            //     returns length, -1 on error
 {
   DEBUG_assert(otf);
-  DEBUG_assert((otf->flags & OTF_F_FMT_CFF) == 0); // not for CFF
+  DEBUG_assert((otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF) == 0); // not for CFF
 
   if (gid >= otf->numGlyphs)
     return (-1);
@@ -840,7 +865,7 @@ otf_get_glyph(OTF_FILE *otf,
   // ensure >glyphOffsets and >gly is there
   if ((!otf->gly) || (!otf->glyphOffsets))
   {
-    if (otf_load_more(otf) != 0)
+    if (__cfFontEmbedOTFLoadMore(otf) != 0)
     {
       DEBUG_assert(0);
       return (-1);
@@ -862,12 +887,13 @@ otf_get_glyph(OTF_FILE *otf,
 
 
 unsigned short
-otf_from_unicode(OTF_FILE *otf,
-                int unicode) // {{{ 0 = missing
+_cfFontEmbedOTFFromUnicode(_cf_fontembed_otf_file_t *otf,
+                          int unicode) // {{{ 0 = missing
 {
   DEBUG_assert(otf);
   DEBUG_assert((unicode >= 0) && (unicode < 65536));
-//DEBUG_assert((otf->flags & OTF_F_FMT_CFF) == 0); // not for CFF, other method!
+  //DEBUG_assert((otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF) == 0);
+                                           // not for CFF, other method!
 
   // ensure >cmap and >unimap is there
   if (!otf->cmap)
@@ -887,12 +913,13 @@ otf_from_unicode(OTF_FILE *otf,
 #if 0
   // linear search is cache friendly and should be quite fast
 #else
-  const unsigned short segCountX2 = get_USHORT(otf->unimap + 6);
-  char target[] = {unicode >> 8, unicode}; // set_USHORT(target, unicode);
+  const unsigned short segCountX2 = __cfFontEmbedGetUShort(otf->unimap + 6);
+  char target[] = {unicode >> 8, unicode};
+                                   // __cfFontEmbedSetUShort(target, unicode);
   char *result = otf_bsearch((char *)otf->unimap + 14, target, 2,
-                            get_USHORT(otf->unimap + 8),
-                            get_USHORT(otf->unimap + 10),
-                            get_USHORT(otf->unimap + 12), 1);
+                            __cfFontEmbedGetUShort(otf->unimap + 8),
+                            __cfFontEmbedGetUShort(otf->unimap + 10),
+                            __cfFontEmbedGetUShort(otf->unimap + 12), 1);
   if (result >= otf->unimap + 14 + segCountX2) // outside of endCode[segCount]
   {
     DEBUG_assert(0); // bad font, no 0xffff sentinel
@@ -900,21 +927,22 @@ otf_from_unicode(OTF_FILE *otf,
   }
 
   result += 2 + segCountX2; // jump over padding into startCode[segCount]
-  const unsigned short startCode = get_USHORT(result);
+  const unsigned short startCode = __cfFontEmbedGetUShort(result);
   if (startCode > unicode)
     return (0);
   result += 2 * segCountX2;
-  const unsigned short rangeOffset = get_USHORT(result);
+  const unsigned short rangeOffset = __cfFontEmbedGetUShort(result);
   if (rangeOffset)
   {
-    return (get_USHORT(result + rangeOffset + 2 * (unicode-startCode)));
+    return (__cfFontEmbedGetUShort(result + rangeOffset +
+                                  2 * (unicode-startCode)));
                  // the so called "obscure indexing trick" into glyphIdArray[]
     // NOTE: this is according to apple spec; microsoft says we must add
     // delta (probably incorrect; fonts probably have delta == 0)
   }
   else
   {
-    const short delta = get_SHORT(result - segCountX2);
+    const short delta = __cfFontEmbedGetShort(result - segCountX2);
     return (delta + unicode) & 0xffff;
   }
 #endif // 0
@@ -924,13 +952,13 @@ otf_from_unicode(OTF_FILE *otf,
 
 /** output stuff **/
 int
-otf_action_copy(void *param,
-               int table_no,
-               OUTPUT_FN output,
-               void *context) // {{{
+__cfFontEmbedOTFActionCopy(void *param,
+                          int table_no,
+                          _cf_fontembed_output_fn_t output,
+                          void *context) // {{{
 {
-  OTF_FILE *otf = param;
-  const OTF_DIRENT *table = otf->tables + table_no;
+  _cf_fontembed_otf_file_t *otf = param;
+  const _cf_fontembed_otf_dir_ent_t *table = otf->tables + table_no;
 
   if (!output) // get checksum and unpadded length
   {
@@ -953,20 +981,22 @@ otf_action_copy(void *param,
 
 
 // TODO? >modified time-stamp?
-// Note: don't use this directly. otf_write_sfnt will internally replace
-// otf_action_copy for head with this
+// Note: don't use this directly. __cfFontEmbedOTFWriteSFNT will internally
+//       replace
+// __cfFontEmbedOTFActionCopy for head with this
 
 int
-otf_action_copy_head(void *param,
-                    int csum,
-                    OUTPUT_FN output,
-                    void *context) // {{{
+__cfFontEmbedOTFActionCopyHead(void *param,
+                              int csum,
+                              _cf_fontembed_output_fn_t output,
+                              void *context) // {{{
 {
-  OTF_FILE *otf = param;
-  const int table_no = otf_find_table(otf, OTF_TAG('h', 'e', 'a', 'd'));
+  _cf_fontembed_otf_file_t *otf = param;
+  const int table_no =
+    __cfFontEmbedOTFFindTable(otf, _CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'));
                           // we can't have csum AND table_no ... never mind!
   DEBUG_assert(table_no != -1);
-  const OTF_DIRENT *table = otf->tables + table_no;
+  const _cf_fontembed_otf_dir_ent_t *table = otf->tables + table_no;
 
   if (!output) // get checksum and unpadded length
   {
@@ -977,7 +1007,8 @@ otf_action_copy_head(void *param,
   char *data = otf_read(otf, NULL, table->offset, table->length);
   if (!data)
     return (-1);
-  set_ULONG(data + 8, 0xb1b0afba - csum); // head. fix global checksum
+  __cfFontEmbedSetULong(data + 8, 0xb1b0afba - csum);
+                                                // head. fix global checksum
   int ret = (table->length + 3) & ~3;
   (*output)(data, ret, context);
   free(data);
@@ -987,10 +1018,10 @@ otf_action_copy_head(void *param,
 
 
 int
-otf_action_replace(void *param,
-                  int length,
-                  OUTPUT_FN output,
-                  void *context) // {{{
+__cfFontEmbedOTFActionReplace(void *param,
+                             int length,
+                             _cf_fontembed_output_fn_t output,
+                             void *context) // {{{
 {
   char *data = param;
   char pad[4] = {0, 0, 0, 0};
@@ -1000,13 +1031,13 @@ otf_action_replace(void *param,
   {
     if (ret != length)
     {
-      unsigned int csum = otf_checksum(data, ret - 4);
+      unsigned int csum = __cfFontEmbedOTFCheckSum(data, ret - 4);
       memcpy(pad, data + ret - 4, ret - length);
-      csum += get_ULONG(pad);
+      csum += __cfFontEmbedGetULong(pad);
       *(unsigned int *)context = csum;
     }
     else
-      *(unsigned int *)context = otf_checksum(data, length);
+      *(unsigned int *)context = __cfFontEmbedOTFCheckSum(data, length);
     return (length);
   }
 
@@ -1034,36 +1065,36 @@ static const struct
   unsigned int tag;
 } otf_tagorder_win[] =
 { // {{{
-  {19, OTF_TAG('D', 'S', 'I', 'G')},
-  { 5, OTF_TAG('L', 'T', 'S', 'H')},
-  { 3, OTF_TAG('O', 'S', '/', '2')},
-  {18, OTF_TAG('P', 'C', 'L', 'T')},
-  { 6, OTF_TAG('V', 'D', 'M', 'X')},
-  { 8, OTF_TAG('c', 'm', 'a', 'p')},
-  {11, OTF_TAG('c', 'v', 't', ' ')},
-  { 9, OTF_TAG('f', 'p', 'g', 'm')},
-  {17, OTF_TAG('g', 'a', 's', 'p')},
-  {13, OTF_TAG('g', 'l', 'y', 'f')},
-  { 7, OTF_TAG('h', 'd', 'm', 'x')},
-  { 0, OTF_TAG('h', 'e', 'a', 'd')},
-  { 1, OTF_TAG('h', 'h', 'e', 'a')},
-  { 4, OTF_TAG('h', 'm', 't', 'x')},
-  {14, OTF_TAG('k', 'e', 'r', 'n')},
-  {12, OTF_TAG('l', 'o', 'c', 'a')},
-  { 2, OTF_TAG('m', 'a', 'x', 'p')},
-  {15, OTF_TAG('n', 'a', 'm', 'e')},
-  {16, OTF_TAG('p', 'o', 's', 't')},
-  {10, OTF_TAG('p', 'r', 'e', 'p')}
+  {19, _CF_FONTEMBED_OTF_TAG('D', 'S', 'I', 'G')},
+  { 5, _CF_FONTEMBED_OTF_TAG('L', 'T', 'S', 'H')},
+  { 3, _CF_FONTEMBED_OTF_TAG('O', 'S', '/', '2')},
+  {18, _CF_FONTEMBED_OTF_TAG('P', 'C', 'L', 'T')},
+  { 6, _CF_FONTEMBED_OTF_TAG('V', 'D', 'M', 'X')},
+  { 8, _CF_FONTEMBED_OTF_TAG('c', 'm', 'a', 'p')},
+  {11, _CF_FONTEMBED_OTF_TAG('c', 'v', 't', ' ')},
+  { 9, _CF_FONTEMBED_OTF_TAG('f', 'p', 'g', 'm')},
+  {17, _CF_FONTEMBED_OTF_TAG('g', 'a', 's', 'p')},
+  {13, _CF_FONTEMBED_OTF_TAG('g', 'l', 'y', 'f')},
+  { 7, _CF_FONTEMBED_OTF_TAG('h', 'd', 'm', 'x')},
+  { 0, _CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd')},
+  { 1, _CF_FONTEMBED_OTF_TAG('h', 'h', 'e', 'a')},
+  { 4, _CF_FONTEMBED_OTF_TAG('h', 'm', 't', 'x')},
+  {14, _CF_FONTEMBED_OTF_TAG('k', 'e', 'r', 'n')},
+  {12, _CF_FONTEMBED_OTF_TAG('l', 'o', 'c', 'a')},
+  { 2, _CF_FONTEMBED_OTF_TAG('m', 'a', 'x', 'p')},
+  {15, _CF_FONTEMBED_OTF_TAG('n', 'a', 'm', 'e')},
+  {16, _CF_FONTEMBED_OTF_TAG('p', 'o', 's', 't')},
+  {10, _CF_FONTEMBED_OTF_TAG('p', 'r', 'e', 'p')}
 };
 // }}}
 
 
 int
-otf_write_sfnt(struct _OTF_WRITE *otw,
-              unsigned int version,
-              int numTables,
-              OUTPUT_FN output,
-              void *context) // {{{
+__cfFontEmbedOTFWriteSFNT(struct __cf_fontembed_otf_write_s *otw,
+                         unsigned int version,
+                         int numTables,
+                         _cf_fontembed_output_fn_t output,
+                         void *context) // {{{
 {
   int iA;
   int ret;
@@ -1096,7 +1127,7 @@ otf_write_sfnt(struct _OTF_WRITE *otw,
       else // <
         iB --;
     }
-    for (iA=NUM_PRIO - 1; iA >= 0; iA --)
+    for (iA = NUM_PRIO - 1; iA >= 0; iA --)
     {
       // pick the matched tables up in sorted order (bucketsort principle)
       if (priolist[iA])
@@ -1110,13 +1141,13 @@ otf_write_sfnt(struct _OTF_WRITE *otw,
   }
 
   // the header
-  set_ULONG(start, version);
-  set_USHORT(start + 4, numTables);
+  __cfFontEmbedSetULong(start, version);
+  __cfFontEmbedSetUShort(start + 4, numTables);
   int a, b, c;
   otf_bsearch_params(numTables, 16, &a, &b, &c);
-  set_USHORT(start + 6, a);
-  set_USHORT(start + 8, b);
-  set_USHORT(start + 10, c);
+  __cfFontEmbedSetUShort(start + 6, a);
+  __cfFontEmbedSetUShort(start + 8, b);
+  __cfFontEmbedSetUShort(start + 10, c);
 
   // first pass: calculate table directory / offsets and checksums
   unsigned int globalSum = 0, csum;
@@ -1129,12 +1160,12 @@ otf_write_sfnt(struct _OTF_WRITE *otw,
                                             otw[order[iA]].length, NULL,
                                             &csum);
     DEBUG_assert(res >= 0);
-    if (otw[order[iA]].tag == OTF_TAG('h', 'e', 'a', 'd'))
+    if (otw[order[iA]].tag == _CF_FONTEMBED_OTF_TAG('h', 'e', 'a', 'd'))
       headAt = order[iA];
-    set_ULONG(entry, otw[order[iA]].tag);
-    set_ULONG(entry + 4, csum);
-    set_ULONG(entry + 8, offset);
-    set_ULONG(entry + 12, res);
+    __cfFontEmbedSetULong(entry, otw[order[iA]].tag);
+    __cfFontEmbedSetULong(entry + 4, csum);
+    __cfFontEmbedSetULong(entry + 8, offset);
+    __cfFontEmbedSetULong(entry + 12, res);
     offset += (res + 3) & ~3; // padding
     globalSum += csum;
   }
@@ -1143,12 +1174,13 @@ otf_write_sfnt(struct _OTF_WRITE *otw,
   // write header + directory
   ret= 12 + 16 * numTables;
   (*output)(start, ret, context);
-  globalSum += otf_checksum(start, ret);
+  globalSum += __cfFontEmbedOTFCheckSum(start, ret);
 
   // change head
-  if ((headAt != -1) && (otw[headAt].action == otf_action_copy)) // more needed?
+  if ((headAt != -1) && (otw[headAt].action ==
+                        __cfFontEmbedOTFActionCopy)) // more needed?
   {
-    otw[headAt].action = otf_action_copy_head;
+    otw[headAt].action = __cfFontEmbedOTFActionCopyHead;
     otw[headAt].length = globalSum;
   }
 
index 36155cda08cfa1d821750246fffa8b8121d894eb..a88571510095603cddfc3e7c6f8b016fe70ac839 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "embed-sfnt-private.h"
 #include "sfnt-private.h"
@@ -25,13 +25,15 @@ enum {
 
 
 void
-show_post(OTF_FILE *otf) // {{{
+show_post(_cf_fontembed_otf_file_t *otf) // {{{
 {
   DEBUG_assert(otf);
   int len = 0;
   char *buf;
 
-  buf = otf_get_table(otf, OTF_TAG('p', 'o', 's', 't'), &len);
+  buf =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('p', 'o', 's', 't'),
+                           &len);
   if (!buf)
   {
     DEBUG_assert(len == -1);
@@ -48,29 +50,31 @@ show_post(OTF_FILE *otf) // {{{
          "  vmType42: %d %d\n"
          "  vmType1: %d %d\n",
         len,
-         get_ULONG(buf),
-         get_LONG(buf + 4) >> 16,
-        get_ULONG(buf + 4) & 0xffff,
-         get_SHORT(buf + 8),
-         get_SHORT(buf + 10),
-         get_ULONG(buf + 12),
-         get_ULONG(buf + 16),
-        get_ULONG(buf + 20),
-         get_ULONG(buf + 24),
-        get_ULONG(buf + 38));
+         __cfFontEmbedGetULong(buf),
+         __cfFontEmbedGetLong(buf + 4) >> 16,
+        __cfFontEmbedGetULong(buf + 4) & 0xffff,
+         __cfFontEmbedGetShort(buf + 8),
+         __cfFontEmbedGetShort(buf + 10),
+         __cfFontEmbedGetULong(buf + 12),
+         __cfFontEmbedGetULong(buf + 16),
+        __cfFontEmbedGetULong(buf + 20),
+         __cfFontEmbedGetULong(buf + 24),
+        __cfFontEmbedGetULong(buf + 38));
   free(buf);
 }
 // }}}
 
 
 void
-show_name(OTF_FILE *otf) // {{{
+show_name(_cf_fontembed_otf_file_t *otf) // {{{
 {
   DEBUG_assert(otf);
   int iA, len = 0;
   char *buf;
 
-  buf = otf_get_table(otf, OTF_TAG('n', 'a', 'm', 'e'), &len);
+  buf =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('n', 'a', 'm', 'e'),
+                           &len);
   if (!buf)
   {
     DEBUG_assert(len == -1);
@@ -78,24 +82,24 @@ show_name(OTF_FILE *otf) // {{{
     return;
   }
   printf("NAME:\n");
-  int name_count = get_USHORT(buf + 2);
-  const char *nstore = buf + get_USHORT(buf + 4);
+  int name_count = __cfFontEmbedGetUShort(buf + 2);
+  const char *nstore = buf + __cfFontEmbedGetUShort(buf + 4);
   for (iA = 0; iA < name_count; iA ++)
   {
     const char *nrec = buf + 6 + 12 * iA;
     printf("  { platformID/encodingID/languageID/nameID: %d/%d/%d/%d\n"
            "    length: %d, offset: %d, data                       :",
-           get_USHORT(nrec),
-           get_USHORT(nrec + 2),
-           get_USHORT(nrec + 4),
-           get_USHORT(nrec + 6),
-           get_USHORT(nrec + 8),
-           get_USHORT(nrec + 10));
-    if ((get_USHORT(nrec) == 0) ||
-       (get_USHORT(nrec) == 3)) // WCHAR
+           __cfFontEmbedGetUShort(nrec),
+           __cfFontEmbedGetUShort(nrec + 2),
+           __cfFontEmbedGetUShort(nrec + 4),
+           __cfFontEmbedGetUShort(nrec + 6),
+           __cfFontEmbedGetUShort(nrec + 8),
+           __cfFontEmbedGetUShort(nrec + 10));
+    if ((__cfFontEmbedGetUShort(nrec) == 0) ||
+       (__cfFontEmbedGetUShort(nrec) == 3)) // WCHAR
     {
-      int nlen = get_USHORT(nrec + 8);
-      int npos = get_USHORT(nrec + 10);
+      int nlen = __cfFontEmbedGetUShort(nrec + 8);
+      int npos = __cfFontEmbedGetUShort(nrec + 10);
       for (; nlen > 0; nlen -= 2, npos += 2)
       {
         if (nstore[npos] != 0x00)
@@ -107,7 +111,8 @@ show_name(OTF_FILE *otf) // {{{
     }
     else
       printf("%.*s }\n",
-             get_USHORT(nrec + 8), nstore + get_USHORT(nrec + 10));
+             __cfFontEmbedGetUShort(nrec + 8),
+            nstore + __cfFontEmbedGetUShort(nrec + 10));
   }
   free(buf);
 }
@@ -115,12 +120,14 @@ show_name(OTF_FILE *otf) // {{{
 
 
 void
-show_cmap(OTF_FILE *otf) // {{{
+show_cmap(_cf_fontembed_otf_file_t *otf) // {{{
 {
   DEBUG_assert(otf);
   int iA, len = 0;
 
-  char *cmap = otf_get_table(otf, OTF_TAG('c', 'm', 'a', 'p'), &len);
+  char *cmap =
+    _cfFontEmbedOTFGetTable(otf, _CF_FONTEMBED_OTF_TAG('c', 'm', 'a', 'p'),
+                           &len);
   if (!cmap)
   {
     DEBUG_assert(len == -1);
@@ -128,19 +135,20 @@ show_cmap(OTF_FILE *otf) // {{{
     return;
   }
   printf("cmap:\n");
-  DEBUG_assert(get_USHORT(cmap) == 0x0000); // version
-  const int numTables = get_USHORT(cmap + 2);
+  DEBUG_assert(__cfFontEmbedGetUShort(cmap) == 0x0000); // version
+  const int numTables = __cfFontEmbedGetUShort(cmap + 2);
   printf("  numTables: %d\n", numTables);
   for (iA = 0; iA < numTables; iA ++)
   {
     const char *nrec = cmap + 4 + 8 * iA;
-    const char *ndata = cmap + get_ULONG(nrec + 4);
+    const char *ndata = cmap + __cfFontEmbedGetULong(nrec + 4);
     DEBUG_assert(ndata >= cmap + 4 + 8 * numTables);
     printf("  platformID/encodingID: %d/%d\n"
            "  offset: %d  data (format: %d, length: %d, language: %d);\n",
-           get_USHORT(nrec), get_USHORT(nrec + 2),
-           get_ULONG(nrec + 4),
-           get_USHORT(ndata), get_USHORT(ndata + 2), get_USHORT(ndata + 4));
+           __cfFontEmbedGetUShort(nrec), __cfFontEmbedGetUShort(nrec + 2),
+           __cfFontEmbedGetULong(nrec + 4),
+           __cfFontEmbedGetUShort(ndata), __cfFontEmbedGetUShort(ndata + 2),
+          __cfFontEmbedGetUShort(ndata + 4));
   }
   free(cmap);
 }
@@ -148,7 +156,7 @@ show_cmap(OTF_FILE *otf) // {{{
 
 
 void
-show_glyf(OTF_FILE *otf,
+show_glyf(_cf_fontembed_otf_file_t *otf,
          int full) // {{{
 {
   DEBUG_assert(otf);
@@ -156,7 +164,7 @@ show_glyf(OTF_FILE *otf,
   // ensure >glyphOffsets and >gly is there
   if ((!otf->gly) || (!otf->glyphOffsets))
   {
-    if (otf_load_glyf(otf) != 0)
+    if (__cfFontEmbedOTFLoadGlyf(otf) != 0)
     {
       DEBUG_assert(0);
       return;
@@ -170,13 +178,13 @@ show_glyf(OTF_FILE *otf,
   DEBUG_assert(otf->gly);
   for (iA = 0; iA < otf->numGlyphs; iA ++)
   {
-    int len = otf_get_glyph(otf, iA);
+    int len = _cfFontEmbedOTFGetGlyph(otf, iA);
     if (len == 0)
       zeroGlyf ++;
-    else if (get_SHORT(otf->gly) == -1)
+    else if (__cfFontEmbedGetShort(otf->gly) == -1)
       compGlyf ++;
     if (full)
-      printf("%d(%d) ", get_SHORT(otf->gly), len);
+      printf("%d(%d) ", __cfFontEmbedGetShort(otf->gly), len);
   }
   if (full)
     printf("\n");
@@ -188,12 +196,12 @@ show_glyf(OTF_FILE *otf,
 
 
 void
-show_hmtx(OTF_FILE *otf) // {{{
+show_hmtx(_cf_fontembed_otf_file_t *otf) // {{{
 {
   DEBUG_assert(otf);
   int iA;
 
-  otf_get_width(otf, 0); // load table.
+  _cfFontEmbedOTFGetWidth(otf, 0); // load table.
   if (!otf->hmtx)
   {
     printf("NOTE: no hmtx table!\n");
@@ -203,8 +211,8 @@ show_hmtx(OTF_FILE *otf) // {{{
   for (iA = 0; iA < otf->numberOfHMetrics; iA ++)
   {
     printf("(%d,%d) ",
-           get_USHORT(otf->hmtx + iA * 4),
-           get_SHORT(otf->hmtx + iA * 4 + 2));
+           __cfFontEmbedGetUShort(otf->hmtx + iA * 4),
+           __cfFontEmbedGetShort(otf->hmtx + iA * 4 + 2));
   }
   printf(" (last is repeated for the remaining %d glyphs)\n",
         otf->numGlyphs - otf->numberOfHMetrics);
@@ -216,10 +224,10 @@ main(int argc,
      char **argv)
 {
   const char *fn = TESTFONT;
-  OTF_FILE *otf = NULL;
+  _cf_fontembed_otf_file_t *otf = NULL;
   if (argc == 2)
     fn = argv[1];
-  otf = otf_load(fn);
+  otf = _cfFontEmbedOTFLoad(fn);
   if (!otf)
   {
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
@@ -231,11 +239,11 @@ main(int argc,
     printf("TTC has %d fonts, using %d\n", otf->numTTC, otf->useTTC);
   if (otf->version == 0x00010000)
     printf("Got TTF 1.0\n");
-  else if (otf->version == OTF_TAG('O','T','T','O'))
+  else if (otf->version == _CF_FONTEMBED_OTF_TAG('O','T','T','O'))
     printf("Got OTF(CFF)\n");
-  else if (otf->version == OTF_TAG('t','r','u','e'))
+  else if (otf->version == _CF_FONTEMBED_OTF_TAG('t','r','u','e'))
     printf("Got TTF (true)\n");
-  else if (otf->version == OTF_TAG('t','y','p','1'))
+  else if (otf->version == _CF_FONTEMBED_OTF_TAG('t','y','p','1'))
     printf("Got SFNT(Type1)\n");
 
   printf("Has %d tables\n", otf->numTables);
@@ -243,30 +251,30 @@ main(int argc,
   int iA;
   for (iA=0; iA < otf->numTables; iA ++)
   {
-    printf("%c%c%c%c %d @%d\n", OTF_UNTAG(otf->tables[iA].tag),
+    printf("%c%c%c%c %d @%d\n", _CF_FONTEMBED_OTF_UNTAG(otf->tables[iA].tag),
           otf->tables[iA].length, otf->tables[iA].offset);
   }
   printf("unitsPerEm: %d, indexToLocFormat: %d\n",
          otf->unitsPerEm, otf->indexToLocFormat);
   printf("num glyphs: %d\n", otf->numGlyphs);
-  otf_get_width(otf, 0); // load table.
+  _cfFontEmbedOTFGetWidth(otf, 0); // load table.
   printf("numberOfHMetrics: %d\n", otf->numberOfHMetrics);
 
-  printf("Embedding rights: %x\n", emb_otf_get_rights(otf));
+  printf("Embedding rights: %x\n", __cfFontEmbedEmbOTFGetRights(otf));
 
   show_post(otf);
 
   show_name(otf);
 
   show_cmap(otf);
-  // printf("%d %d\n", otf_from_unicode(otf, 'A'), 0);
+  // printf("%d %d\n", _cfFontEmbedOTFFromUnicode(otf, 'A'), 0);
 
-  if (!(otf->flags & OTF_F_FMT_CFF))
+  if (!(otf->flags & _CF_FONTEMBED_OTF_F_FMT_CFF))
     show_glyf(otf, 1);
 
   show_hmtx(otf);
 
-  otf_close(otf);
+  _cfFontEmbedOTFClose(otf);
 
   return (0);
 }
index 6e6c224f6636e163903be2fc9e2f5e459734c4ac..1484a0c1db0290e84c1bf69faa3751f06a3c6b2d 100644 (file)
@@ -1,4 +1,4 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "config.h"
 #include <stdio.h>
@@ -53,19 +53,20 @@ example_outfn(const char *buf,
 
 static inline void
 write_string(FILE *f,
-            EMB_PARAMS *emb,
+            _cf_fontembed_emb_params_t *emb,
             const char *str) // {{{
 {
   DEBUG_assert(f);
   DEBUG_assert(emb);
   int iA;
 
-  if (emb->plan & EMB_A_MULTIBYTE)
+  if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE)
   {
     putc('<', f);
     for (iA = 0; str[iA]; iA ++)
     {
-      const unsigned short gid = emb_get(emb, (unsigned char)str[iA]);
+      const unsigned short gid =
+       _cfFontEmbedEmbGet(emb, (unsigned char)str[iA]);
       fprintf(f, "%04x", gid);
     }
     putc('>', f);
@@ -74,7 +75,7 @@ write_string(FILE *f,
   {
     putc('(', f);
     for (iA = 0; str[iA]; iA ++)
-      emb_get(emb, (unsigned char)str[iA]);
+      _cfFontEmbedEmbGet(emb, (unsigned char)str[iA]);
     fprintf(f, "%s", str); // TODO
     putc(')', f);
   }
@@ -87,21 +88,22 @@ main(int argc,
      char **argv)
 {
   const char *fn = TESTFONT;
-  OTF_FILE *otf = NULL;
+  _cf_fontembed_otf_file_t *otf = NULL;
   if (argc == 2)
     fn = argv[1];
-  otf = otf_load(fn);
+  otf = _cfFontEmbedOTFLoad(fn);
   if (!otf)
   {
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
     return (1);
   }
   DEBUG_assert(otf);
-  FONTFILE *ff = fontfile_open_sfnt(otf);
-  EMB_PARAMS *emb = emb_new(ff,
-                           EMB_DEST_PDF16,
-                           EMB_C_FORCE_MULTIBYTE|
-                           EMB_C_TAKE_FONTFILE);
+  _cf_fontembed_fontfile_t *ff = _cfFontEmbedFontFileOpenSFNT(otf);
+  _cf_fontembed_emb_params_t *emb =
+    _cfFontEmbedEmbNew(ff,
+                      _CF_FONTEMBED_EMB_DEST_PDF16,
+                      _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE|
+                      _CF_FONTEMBED_EMB_C_TAKE_FONTFILE);
 
   FILE *f = fopen("test.pdf", "w");
   DEBUG_assert(f);
@@ -119,31 +121,31 @@ main(int argc,
              "ET\n");
   ENDSTREAM;
 
-  emb_get(emb, 'a');
+  _cfFontEmbedEmbGet(emb, 'a');
 
   // {{{ do font
-  EMB_PDF_FONTDESCR *fdes = emb_pdf_fontdescr(emb);
+  _cf_fontembed_emb_pdf_font_descr_t *fdes = _cfFontEmbedEmbPDFFontDescr(emb);
   DEBUG_assert(fdes);
-  EMB_PDF_FONTWIDTHS *fwid = emb_pdf_fontwidths(emb);
+  _cf_fontembed_emb_pdf_font_widths_t *fwid = _cfFontEmbedEmbPDFFontWidths(emb);
   DEBUG_assert(fwid);
 
   STREAMDICT;
   int ff_ref = xrefpos;
-  if (emb_pdf_get_fontfile_subtype(emb))
+  if (_cfFontEmbedEmbPDFGetFontFileSubType(emb))
   {
     fprintf(f,"  /Subtype /%s\n",
-           emb_pdf_get_fontfile_subtype(emb));
+           _cfFontEmbedEmbPDFGetFontFileSubType(emb));
   }
-  if (emb->outtype == EMB_FMT_T1)
+  if (emb->outtype == _CF_FONTEMBED_EMB_FMT_T1)
     fprintf(f, "  /Length1 ?\n"
                "  /Length2 ?\n"
                "  /Length3 ?\n");
-  else if (emb->outtype == EMB_FMT_TTF)
+  else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
     fprintf(f, "  /Length1 %d 0 R\n", xrefpos + 2);
   STREAMDATA;
-  const int outlen = emb_embed(emb, example_outfn, f);
+  const int outlen = _cfFontEmbedEmbEmbed(emb, example_outfn, f);
   ENDSTREAM;
-  if (emb->outtype == EMB_FMT_TTF)
+  if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
   {
     OBJ;
     fprintf(f, "%d\n", outlen);
@@ -152,7 +154,7 @@ main(int argc,
 
   OBJ;
   const int fd_ref = xrefpos;
-  char *res = emb_pdf_simple_fontdescr(emb, fdes, ff_ref);
+  char *res = _cfFontEmbedEmbPDFSimpleFontDescr(emb, fdes, ff_ref);
   DEBUG_assert(res);
   fputs(res, f);
   free(res);
@@ -160,16 +162,16 @@ main(int argc,
 
   OBJ;
   int f_ref = xrefpos;
-  res = emb_pdf_simple_font(emb, fdes, fwid, fd_ref);
+  res = _cfFontEmbedEmbPDFSimpleFont(emb, fdes, fwid, fd_ref);
   DEBUG_assert(res);
   fputs(res, f);
   free(res);
   ENDOBJ;
 
-  if (emb->plan&EMB_A_MULTIBYTE)
+  if (emb->plan&_CF_FONTEMBED_EMB_A_MULTIBYTE)
   {
     OBJ;
-    res = emb_pdf_simple_cidfont(emb, fdes->fontname, f_ref);
+    res = _cfFontEmbedEmbPDFSimpleCIDFont(emb, fdes->fontname, f_ref);
     f_ref = xrefpos;
     DEBUG_assert(res);
     fputs(res, f);
@@ -230,7 +232,7 @@ main(int argc,
   // }}}
   fclose(f);
 
-  emb_close(emb);
+  _cfFontEmbedEmbClose(emb);
 
   return (0);
 }
index 770fb6d8facc977df4c0993e314e944b2d54dae3..eedf2884c87f458b9fe5ed0276de26e0f85fd3d6 100644 (file)
@@ -1,10 +1,11 @@
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 #include <cupsfilters/debug-internal.h>
 #include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 
-const char *emb_otf_get_fontname(OTF_FILE *otf); // TODO
+const char *__cfFontEmbedEmbOTFGetFontName(_cf_fontembed_otf_file_t *otf);
+                                                                    // TODO
 
 
 static void
@@ -25,19 +26,20 @@ example_outfn(const char *buf,
 
 static inline void
 write_string(FILE *f,
-            EMB_PARAMS *emb,
+            _cf_fontembed_emb_params_t *emb,
             const char *str) // {{{
 {
   DEBUG_assert(f);
   DEBUG_assert(emb);
   int iA;
 
-  if (emb->plan & EMB_A_MULTIBYTE)
+  if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE)
   {
     putc('<', f);
     for (iA=0; str[iA] ;iA ++)
     {
-      const unsigned short gid = emb_get(emb, (unsigned char)str[iA]);
+      const unsigned short gid =
+       _cfFontEmbedEmbGet(emb, (unsigned char)str[iA]);
       fprintf(f, "%04x", gid);
     }
     putc('>', f);
@@ -46,7 +48,7 @@ write_string(FILE *f,
   {
     putc('(', f);
     for (iA = 0; str[iA]; iA ++)
-      emb_get(emb, (unsigned char)str[iA]);
+      _cfFontEmbedEmbGet(emb, (unsigned char)str[iA]);
     fprintf(f, "%s", str); // TODO
     putc(')', f);
   }
@@ -59,21 +61,22 @@ main(int argc,
      char **argv)
 {
   const char *fn = TESTFONT;
-  OTF_FILE *otf = NULL;
+  _cf_fontembed_otf_file_t *otf = NULL;
   if (argc == 2)
     fn = argv[1];
-  otf = otf_load(fn);
+  otf = _cfFontEmbedOTFLoad(fn);
   if (!otf)
   {
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
     return (1);
   }
   DEBUG_assert(otf);
-  FONTFILE *ff = fontfile_open_sfnt(otf);
-  EMB_PARAMS *emb = emb_new(ff,
-                           EMB_DEST_PS,
-//                          EMB_C_FORCE_MULTIBYTE| // not yet...
-                           EMB_C_TAKE_FONTFILE);
+  _cf_fontembed_fontfile_t *ff = _cfFontEmbedFontFileOpenSFNT(otf);
+  _cf_fontembed_emb_params_t *emb =
+    _cfFontEmbedEmbNew(ff,
+                      _CF_FONTEMBED_EMB_DEST_PS,
+  //                   _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE| // not yet...
+                      _CF_FONTEMBED_EMB_C_TAKE_FONTFILE);
 
   FILE *f = fopen("test.ps", "w");
   DEBUG_assert(f);
@@ -82,18 +85,18 @@ main(int argc,
 
   char *str = "Hallo";
 
-  emb_get(emb, 'a');
+  _cfFontEmbedEmbGet(emb, 'a');
 
   int iA;
   for (iA = 0; str[iA]; iA ++)
-    emb_get(emb, (unsigned char)str[iA]);
+    _cfFontEmbedEmbGet(emb, (unsigned char)str[iA]);
 
-  emb_embed(emb, example_outfn, f);
+  _cfFontEmbedEmbEmbed(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));
+         __cfFontEmbedEmbOTFGetFontName(emb->font->sfnt));
   write_string(f, emb, "Hallo");
   // Note that write_string sets subset bits, but it's too late
   fprintf(f, " show\n"
@@ -102,7 +105,7 @@ main(int argc,
   fprintf(f, "%%%%EOF\n");
   fclose(f);
 
-  emb_close(emb);
+  _cfFontEmbedEmbClose(emb);
 
   return (0);
 }
index 7e18766e7c9046dcc709b176e93d4296dca8f5ac..8154bf3d02f9f3d7f680d706826968a52bac7470 100644 (file)
@@ -13,7 +13,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "pdfutils.h"
-#include "fontembed.h"
+#include "fontembed-private.h"
 #include "debug-internal.h"
 
 
@@ -417,18 +417,18 @@ pdf_out_outfn(const char *buf,
 
 int
 cfPDFOutWriteFont(cf_pdf_out_t *pdf,
-                 EMB_PARAMS *emb) // {{{ 
+                 _cf_fontembed_emb_params_t *emb) // {{{ 
 {
   DEBUG_assert(pdf);
   DEBUG_assert(emb);
 
-  EMB_PDF_FONTDESCR *fdes = emb_pdf_fontdescr(emb);
+  _cf_fontembed_emb_pdf_font_descr_t *fdes = _cfFontEmbedEmbPDFFontDescr(emb);
   if (!fdes)
   {
-    if (emb->outtype == EMB_FMT_STDFONT)
+    if (emb->outtype == _CF_FONTEMBED_EMB_FMT_STDFONT)
     { // std-14 font
       const int f_obj = cfPDFOutAddXRef(pdf);
-      char *res = emb_pdf_simple_stdfont(emb);
+      char *res = _cfFontEmbedEmbPDFSimpleStdFont(emb);
       if (!res)
         return (0);
 
@@ -450,13 +450,13 @@ cfPDFOutWriteFont(cf_pdf_out_t *pdf,
                 "<</Length %d 0 R\n",
                 ff_obj,
                 ff_obj + 1);
-  if (emb_pdf_get_fontfile_subtype(emb))
+  if (_cfFontEmbedEmbPDFGetFontFileSubType(emb))
     cfPDFOutPrintF(pdf, "  /Subtype /%s\n",
-                  emb_pdf_get_fontfile_subtype(emb));
-  if (emb->outtype == EMB_FMT_TTF)
+                  _cfFontEmbedEmbPDFGetFontFileSubType(emb));
+  if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
     cfPDFOutPrintF(pdf, "  /Length1 %d 0 R\n",
                   ff_obj + 2);
-  else if (emb->outtype == EMB_FMT_T1) // TODO
+  else if (emb->outtype == _CF_FONTEMBED_EMB_FMT_T1) // TODO
     cfPDFOutPrintF(pdf,
                   "  /Length1 ?\n"
                   "  /Length2 ?\n"
@@ -465,7 +465,7 @@ cfPDFOutWriteFont(cf_pdf_out_t *pdf,
                 ">>\n"
                 "stream\n");
   long streamsize = -pdf->filepos;
-  const int outlen = emb_embed(emb, pdf_out_outfn, pdf);
+  const int outlen = _cfFontEmbedEmbEmbed(emb, pdf_out_outfn, pdf);
   streamsize += pdf->filepos;
   cfPDFOutPrintF(pdf,"\nendstream\n"
                     "endobj\n");
@@ -478,7 +478,7 @@ cfPDFOutWriteFont(cf_pdf_out_t *pdf,
                 "endobj\n",
                 l0_obj, streamsize);
 
-  if (emb->outtype == EMB_FMT_TTF)
+  if (emb->outtype == _CF_FONTEMBED_EMB_FMT_TTF)
   {
     const int l1_obj = cfPDFOutAddXRef(pdf);
     DEBUG_assert(l1_obj == ff_obj + 2);
@@ -490,7 +490,7 @@ cfPDFOutWriteFont(cf_pdf_out_t *pdf,
   }
 
   const int fd_obj = cfPDFOutAddXRef(pdf);
-  char *res = emb_pdf_simple_fontdescr(emb, fdes, ff_obj);
+  char *res = _cfFontEmbedEmbPDFSimpleFontDescr(emb, fdes, ff_obj);
   if (!res)
   {
     free(fdes);
@@ -503,14 +503,14 @@ cfPDFOutWriteFont(cf_pdf_out_t *pdf,
                 fd_obj, res);
   free(res);
 
-  EMB_PDF_FONTWIDTHS *fwid = emb_pdf_fontwidths(emb);
+  _cf_fontembed_emb_pdf_font_widths_t *fwid = _cfFontEmbedEmbPDFFontWidths(emb);
   if (!fwid)
   {
     free(fdes);
     return (0);
   }
   const int f_obj = cfPDFOutAddXRef(pdf);
-  res = emb_pdf_simple_font(emb, fdes, fwid, fd_obj);
+  res = _cfFontEmbedEmbPDFSimpleFont(emb, fdes, fwid, fd_obj);
   if (!res)
   {
     free(fwid);
@@ -525,9 +525,9 @@ cfPDFOutWriteFont(cf_pdf_out_t *pdf,
   free(res);
   free(fwid);
 
-  if (emb->plan & EMB_A_MULTIBYTE)
+  if (emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE)
   {
-    res = emb_pdf_simple_cidfont(emb, fdes->fontname, f_obj);
+    res = _cfFontEmbedEmbPDFSimpleCIDFont(emb, fdes->fontname, f_obj);
     if (!res)
     {
       free(fdes);
index 792cf1e8c715ae75bf69a60a5ee585aeac6b0400..40eca4ed1d3c76f3cb39ec14980882794e3a8f9d 100644 (file)
@@ -20,7 +20,7 @@ extern "C" {
 //
 
 #include <time.h>
-#include <cupsfilters/fontembed.h>
+#include <cupsfilters/fontembed-private.h>
 
 
 //
@@ -101,7 +101,8 @@ int cfPDFOutAddKeyValue(cf_pdf_out_t *pdf, const char *key, const char *val);
 // and returns the object number.
 // On error 0 is returned.
 
-int cfPDFOutWriteFont(cf_pdf_out_t *pdf, struct _EMB_PARAMS *emb);
+int cfPDFOutWriteFont(cf_pdf_out_t *pdf,
+                     struct _cf_fontembed_emb_params_s *emb);
 
 #  ifdef __cplusplus
 }
index f943fc9296eee77751b212e86d634e97c259fc59..859ebd75c105744d9301eb840e760b8e47466163 100644 (file)
@@ -20,7 +20,7 @@
 #include "debug-internal.h"
 #include "filter.h"
 #include "raster.h"
-#include "fontembed.h"
+#include "fontembed-private.h"
 #include <ctype.h>
 #include <errno.h>
 #include "fontconfig/fontconfig.h"
@@ -481,7 +481,7 @@ typedef struct                      // **** Character/attribute structure... ****
 typedef struct texttopdf_doc_s
 {
   int          NumFonts;       // Number of fonts to use
-  EMB_PARAMS   *Fonts[256][4]; // Fonts to use
+  _cf_fontembed_emb_params_t *Fonts[256][4]; // Fonts to use
   unsigned short Chars[256];   // Input char to unicode
   unsigned char        Codes[65536];   // Unicode glyph mapping to font
   int          Widths[256];    // Widths of each font
@@ -528,9 +528,9 @@ typedef struct texttopdf_doc_s
 // Local functions...
 //
 
-static EMB_PARAMS *font_load(const char *font, int fontwidth, cf_logfunc_t log,
-                            void *ld);
-static EMB_PARAMS *font_std(const char *name);
+static _cf_fontembed_emb_params_t *font_load(const char *font, int fontwidth,
+                                            cf_logfunc_t log, void *ld);
+static _cf_fontembed_emb_params_t *font_std(const char *name);
 static int     compare_keywords(const void *k1, const void *k2);
 static int     get_utf8(FILE *fp);
 static void    write_line(int row, lchar_t *line, texttopdf_doc_t *doc);
@@ -1429,13 +1429,13 @@ cfFilterTextToPDF(int inputfd,          // I - File descriptor input stream
 }
 
 
-static EMB_PARAMS *
+static _cf_fontembed_emb_params_t *
 font_load(const char *font,
          int fontwidth,
          cf_logfunc_t log,
          void *ld)
 {
-  OTF_FILE *otf;
+  _cf_fontembed_otf_file_t *otf;
 
   FcPattern *pattern;
   FcFontSet *candidates;
@@ -1504,31 +1504,33 @@ font_load(const char *font,
     return (NULL);
   }
 
-  otf = otf_load((const char *)fontname);
+  otf = _cfFontEmbedOTFLoad((const char *)fontname);
   free(fontname);
   if (!otf)
     return (NULL);
 
-  FONTFILE *ff = fontfile_open_sfnt(otf);
+  _cf_fontembed_fontfile_t *ff = _cfFontEmbedFontFileOpenSFNT(otf);
   DEBUG_assert(ff);
-  EMB_PARAMS *emb = emb_new(ff,
-                           EMB_DEST_PDF16,
-                           EMB_C_FORCE_MULTIBYTE|
-                           EMB_C_TAKE_FONTFILE);
+  _cf_fontembed_emb_params_t *emb =
+    _cfFontEmbedEmbNew(ff,
+                      _CF_FONTEMBED_EMB_DEST_PDF16,
+                      _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE |
+                      _CF_FONTEMBED_EMB_C_TAKE_FONTFILE);
   DEBUG_assert(emb);
-  DEBUG_assert(emb->plan&EMB_A_MULTIBYTE);
+  DEBUG_assert(emb->plan & _CF_FONTEMBED_EMB_A_MULTIBYTE);
 
   return (emb);
 }
 
-static EMB_PARAMS *
+static _cf_fontembed_emb_params_t *
 font_std(const char *name)
 {
-  FONTFILE *ff = fontfile_open_std(name);
+  _cf_fontembed_fontfile_t *ff = _cfFontEmbedFontFileOpenStd(name);
   DEBUG_assert(ff);
-  EMB_PARAMS *emb = emb_new(ff,
-                           EMB_DEST_PDF16,
-                           EMB_C_TAKE_FONTFILE);
+  _cf_fontembed_emb_params_t *emb =
+    _cfFontEmbedEmbNew(ff,
+                      _CF_FONTEMBED_EMB_DEST_PDF16,
+                      _CF_FONTEMBED_EMB_C_TAKE_FONTFILE);
   DEBUG_assert(emb);
 
   return (emb);
@@ -1638,11 +1640,11 @@ write_epilogue(texttopdf_doc_t *doc)
   {
     for (j = 0; j < doc->NumFonts; j ++) 
     {
-      EMB_PARAMS *emb = doc->Fonts[j][i];
+      _cf_fontembed_emb_params_t *emb = doc->Fonts[j][i];
       if (emb->font->fobj) // already embedded
         continue;
       if ((!emb->subset) ||
-         (bits_used(emb->subset, emb->font->sfnt->numGlyphs)))
+         (_cfFontEmbedBitsUsed(emb->subset, emb->font->sfnt->numGlyphs)))
       {
         emb->font->fobj = cfPDFOutWriteFont(doc->pdf,emb);
         DEBUG_assert(emb->font->fobj);
@@ -1664,7 +1666,7 @@ write_epilogue(texttopdf_doc_t *doc)
   {
     for (j = 0; j < doc->NumFonts; j ++)
     {
-      EMB_PARAMS *emb = doc->Fonts[j][i];
+      _cf_fontembed_emb_params_t *emb = doc->Fonts[j][i];
       if (emb->font->fobj) // used
         cfPDFOutPrintF(doc->pdf, "  /%s%02x %d 0 R\n", names[i], j,
                       emb->font->fobj);
@@ -1762,7 +1764,7 @@ write_prolog(const char *title,           // I - Title of job
   struct tm    *curtm;         // Current date
   char         curdate[255];   // Current date (text format)
   int          num_fonts = 0;  // Number of unique fonts
-  EMB_PARAMS   *fonts[1024];   // Unique fonts
+  _cf_fontembed_emb_params_t *fonts[1024]; // Unique fonts
   char         *fontnames[1024]; // Unique fonts
 #if 0
   static char  *names[] =      // Font names
@@ -2424,14 +2426,14 @@ write_font_str(float x,
     else
       lastfont = doc->Codes[doc->Chars[str->ch]];
 
-    EMB_PARAMS *emb = doc->Fonts[lastfont][fontid];
-    OTF_FILE *otf = emb->font->sfnt;
+    _cf_fontembed_emb_params_t *emb = doc->Fonts[lastfont][fontid];
+    _cf_fontembed_otf_file_t *otf = emb->font->sfnt;
 
     if (otf) // TODO?
     {
       cfPDFOutPrintF(doc->pdf,"  %.3f Tz\n",
                     doc->FontScaleX * 600.0 /
-                    (otf_get_width(otf, 4) * 1000.0 /
+                    (_cfFontEmbedOTFGetWidth(otf, 4) * 1000.0 /
                      otf->unitsPerEm) * 100.0 / (doc->FontScaleY)); // TODO? 
       // gid == 4 is usually '!', the char after space. We just need "the"
       // width for the monospaced font. gid == 0 is bad, and space might also
@@ -2460,7 +2462,7 @@ write_font_str(float x,
         break;
       if (otf) // TODO
       {
-        const unsigned short gid = emb_get(emb,ch);
+        const unsigned short gid = _cfFontEmbedEmbGet(emb, ch);
         cfPDFOutPrintF(doc->pdf, "%04x", gid);
       }
       else // std 14 font with 7-bit us-ascii uses single byte encoding, TODO
index 46414c31d48bbc990e2d4d836a318023a967fef7..b3ee72d410a1779c7275472f5765c8788b615202 100644 (file)
@@ -1,27 +1,27 @@
 #include "pdfutils.h"
 #include "config.h"
 #include "debug-internal.h"
-#include "cupsfilters/fontembed.h"
+#include "cupsfilters/fontembed-private.h"
 
 #include <stdio.h>
 
-static inline void write_string(cf_pdf_out_t *pdf,EMB_PARAMS *emb,const char *str) // {{{
+static inline void write_string(cf_pdf_out_t *pdf,_cf_fontembed_emb_params_t *emb,const char *str) // {{{
 {
   DEBUG_assert(pdf);
   DEBUG_assert(emb);
   int iA;
 
-  if (emb->plan&EMB_A_MULTIBYTE) {
+  if (emb->plan&_CF_FONTEMBED_EMB_A_MULTIBYTE) {
     putc('<',stdout); 
     for (iA=0;str[iA];iA++) {
-      const unsigned short gid=emb_get(emb,(unsigned char)str[iA]);
+      const unsigned short gid=_cfFontEmbedEmbGet(emb,(unsigned char)str[iA]);
       fprintf(stdout,"%04x",gid);
     }
     putc('>',stdout); 
     pdf->filepos+=4*iA+2;
   } else { 
     for (iA=0;str[iA];iA++) {
-      emb_get(emb,(unsigned char)str[iA]);
+      _cfFontEmbedEmbGet(emb,(unsigned char)str[iA]);
       // TODO: pdf: otf_from_pdf_default_encoding
     }
     cfPDFOutputString(pdf,str,-1);
@@ -40,24 +40,24 @@ int main()
 
   // font, pt.1 
   const char *fn=TESTFONT;
-  OTF_FILE *otf=NULL;
+  _cf_fontembed_otf_file_t *otf=NULL;
 /*
   if (argc==2) {
     fn=argv[1];
   }
 */
-  otf=otf_load(fn);
+  otf=_cfFontEmbedOTFLoad(fn);
   if (!otf)
   {
     printf("Font %s was not loaded, exiting.\n", TESTFONT);
     return 1;
   }
   DEBUG_assert(otf);
-  FONTFILE *ff=fontfile_open_sfnt(otf);
-  EMB_PARAMS *emb=emb_new(ff,
-                          EMB_DEST_PDF16,
-                          EMB_C_FORCE_MULTIBYTE|
-                          EMB_C_TAKE_FONTFILE);
+  _cf_fontembed_fontfile_t *ff=_cfFontEmbedFontFileOpenSFNT(otf);
+  _cf_fontembed_emb_params_t *emb=_cfFontEmbedEmbNew(ff,
+                          _CF_FONTEMBED_EMB_DEST_PDF16,
+                          _CF_FONTEMBED_EMB_C_FORCE_MULTIBYTE|
+                          _CF_FONTEMBED_EMB_C_TAKE_FONTFILE);
 
   // test
   const int PageWidth=595,PageLength=842;
@@ -101,7 +101,7 @@ int main()
 
   cfPDFOutFree(pdf);
 
-  emb_close(emb);
+  _cfFontEmbedEmbClose(emb);
 
   return 0;
 }