Tizen 2.0 Release
[platform/upstream/cups-filters.git] / fontembed / embed.h
1 #ifndef EMBED_H
2 #define EMBED_H
3
4 #include "bitset.h"
5 #include "fontfile.h"
6 #include "iofn.h"
7
8 typedef enum { EMB_FMT_T1,       // type1, with AFM/PFM,PFA/PFB
9                EMB_FMT_TTF,      // sfnt, for TTF(glyf)
10                EMB_FMT_OTF,      // sfnt+cff, for OTF(cff)
11                EMB_FMT_CFF,      // cff, for raw CFF
12                EMB_FMT_STDFONT   // don't embed (already present)
13                } EMB_FORMAT;
14 typedef enum { EMB_DEST_NATIVE,  // just subsetting/conversion
15                EMB_DEST_PS, 
16 //               EMB_DEST_PS2,
17 //               EMB_DEST_PDF13,
18                EMB_DEST_PDF16
19                } EMB_DESTINATION;
20
21 typedef enum { EMB_RIGHT_FULL=0, EMB_RIGHT_NONE=0x02,
22                EMB_RIGHT_READONLY=0x04, 
23                EMB_RIGHT_NO_SUBSET=0x0100,
24                EMB_RIGHT_BITMAPONLY=0x0200 } EMB_RIGHT_TYPE;
25
26 typedef enum { EMB_A_MULTIBYTE=0x01,    // embedd as multibyte font?
27                EMB_A_SUBSET=0x02,       // do subsetting?
28                EMB_A_T1_TO_CFF=0x04,    // convert Type1 to CFF?
29                EMB_A_CFF_TO_OTF=0x08,   // wrap CFF(from input or T1+CONVERT_CFF) in sfnt? (OTF)
30                EMB_A_OTF_TO_CFF=0x10,   // unwrap CFF
31
32                EMB_A_CLOSE_FONTFILE=0x8000
33                } EMB_ACTIONS;
34
35 typedef enum { EMB_C_MUST_SUBSET=0x01,     // (fail, when not possible)
36                EMB_C_EDITABLE_SUBSET=0x02, // (...)
37                EMB_C_NEVER_SUBSET=0x04,    // (...)
38
39                EMB_C_FORCE_MULTIBYTE=0x08, // always use multibyte fonts
40
41                EMB_C_PDF_OT=0x10, // output TTF/OTF (esp. CFF to OTF)
42                EMB_C_KEEP_T1=0x20, // don't convert T1 to CFF
43
44                EMB_C_TAKE_FONTFILE=0x8000 // take ownership of fontfile
45                } EMB_CONSTRAINTS;
46
47 typedef struct _EMB_PARAMS {
48   EMB_FORMAT intype;
49   EMB_FORMAT outtype;
50   EMB_DESTINATION dest;
51
52   EMB_ACTIONS plan;
53
54   // font infos
55   FONTFILE *font;
56   EMB_RIGHT_TYPE rights;
57 // public:
58   BITSET subset;
59
60 } EMB_PARAMS;
61
62 EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode);
63 // emb_embedd does only the "binary" part 
64 int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context); // returns number of bytes written
65 void emb_close(EMB_PARAMS *emb);
66
67 // TODO: encoding, TODO: ToUnicode
68 static inline void emb_set(EMB_PARAMS *emb,int unicode,unsigned short gid) // {{{
69 {
70   if (emb->subset) {
71     if (emb->plan&EMB_A_MULTIBYTE) {
72       bit_set(emb->subset,gid);
73       // ToUnicode.add(gid,unicode);
74     } else {
75       // TODO ... encoding
76     }
77   }
78 }
79 // }}}
80
81 // TODO: encoding?, TODO: non-sfnt
82 static inline unsigned short emb_get(EMB_PARAMS *emb,int unicode) // {{{ gid
83 {
84   const unsigned short gid=otf_from_unicode(emb->font->sfnt,unicode);
85   emb_set(emb,unicode,gid);
86   return gid;
87 }
88 // }}}
89
90 #include "embed_pdf.h"
91
92 #endif