Debian Codegraph @

texk/lcdf-typetools/lcdf-typetools-src/include/efont/t1font.hh

raw
1 // -*- related-file-name: "../../libefont/t1font.cc" -*-
2 #ifndef EFONT_T1FONT_HH
3 #define EFONT_T1FONT_HH
4 #include <efont/t1cs.hh>
5 #include <lcdf/hashmap.hh>
6 class StringAccum;
7 class ErrorHandler;
8 namespace Efont {
9 class Type1Item;
10 class Type1Definition;
11 class Type1Encoding;
12 class Type1IncludedFont;
13 class Type1Subr;
14 class Type1Reader;
15 class Type1Writer;
16 class MultipleMasterSpace;
17
18 class Type1Font : public CharstringProgram { public:
19
20 Type1Font(Type1Reader&);
21 ~Type1Font();
22
23 int read(Type1Reader&);
24
25 bool ok() const;
26
27 inline PermString font_name() const;
28 void font_matrix(double[6]) const;
29
30 int nitems() const { return _items.size(); }
31 Type1Item* item(int i) const { return _items[i]; }
32 void add_item(Type1Item* it) { _items.push_back(it); }
33 void add_definition(int dict, Type1Definition*);
34 void add_type1_encoding(Type1Encoding*);
35
36 int nsubrs() const { return _subrs.size(); }
37 Type1Charstring* subr(int) const;
38
39 int nglyphs() const { return _glyphs.size(); }
40 PermString glyph_name(int) const;
41 Type1Charstring* glyph(int) const;
42 Type1Charstring* glyph(PermString) const;
43 void add_glyph(Type1Subr*);
44
45 Type1Subr* subr_x(int i) const { return _subrs[i]; }
46 bool set_subr(int, const Type1Charstring&, PermString definer = PermString());
47 bool remove_subr(int);
48 void fill_in_subrs();
49 void renumber_subrs(const Vector<int>&); // dangerous!
50
51 Type1Subr* glyph_x(int i) const { return _glyphs[i]; }
52
53 Type1Encoding* type1_encoding() const { return _encoding; }
54
55 // note: the order is relevant
56 enum Dict {
57 dFont = 0, dF = dFont,
58 dFontInfo = 1, dFI = dFontInfo,
59 dPrivate = 2, dP = dPrivate,
60 dBlend = 3, dB = dBlend,
61 dBlendFontInfo = dB+dFI, dBFI = dBlendFontInfo,
62 dBlendPrivate = dB+dP, dBP = dBlendPrivate,
63 dLast
64 };
65
66 Type1Definition* dict(int d, PermString s) const { return _dict[d][s]; }
67 Type1Definition* dict(PermString s) const { return _dict[dF][s]; }
68 Type1Definition* p_dict(PermString s) const { return _dict[dP][s]; }
69 Type1Definition* b_dict(PermString s) const { return _dict[dB][s]; }
70 Type1Definition* bp_dict(PermString s) const { return _dict[dBP][s];}
71 Type1Definition* fi_dict(PermString s) const { return _dict[dFI][s];}
72
73 typedef HashMap<PermString, Type1Definition*> DictHashMap;
74 inline DictHashMap::const_iterator dict_begin(int dict) const;
75 inline DictHashMap::iterator dict_begin(int dict);
76 int first_dict_item(int d) const { return _index[d]; }
77
78 Type1Definition* ensure(Dict, PermString);
79 void add_header_comment(const String&);
80
81 MultipleMasterSpace* create_mmspace(ErrorHandler* = 0) const;
82 MultipleMasterSpace* mmspace() const;
83
84 void undo_synthetic();
85
86 void set_charstring_definer(PermString d) { _charstring_definer = d; }
87
88 void write(Type1Writer&);
89
90 // font skeletons
91 static Type1Font* skeleton_make(PermString, const String& version = String());
92 static Type1Font* skeleton_make_copy(const Type1Font*, PermString, const Vector<double>*xuid_extension);
93 void skeleton_fontinfo_end();
94 void skeleton_fontdict_end();
95 void skeleton_private_end();
96 void skeleton_common_subrs();
97
98 // for experts only
99 void set_item(int, Type1Item*);
100 inline void set_dict(int dict, PermString, Type1Definition*);
101 void uncache_defs();
102
103 private:
104
105 mutable bool _cached_defs;
106 bool _built;
107 mutable PermString _font_name;
108
109 Vector<Type1Item*> _items;
110
111 HashMap<PermString, Type1Definition*>* _dict;
112 int _index[dLast];
113 int _dict_deltas[dLast];
114
115 Vector<Type1Subr*> _subrs;
116 Vector<Type1Subr*> _glyphs;
117 HashMap<PermString, int> _glyph_map;
118
119 PermString _charstring_definer;
120 Type1Encoding* _encoding;
121
122 mutable bool _cached_mmspace;
123 mutable MultipleMasterSpace* _mmspace;
124
125 Type1IncludedFont* _synthetic_item;
126
127 Type1Font(PermString);
128 Type1Font(const Type1Font&);
129 Type1Font& operator=(const Type1Font&);
130
131 void read_encoding(Type1Reader&, const char*);
132 bool read_synthetic_font(Type1Reader&, const char*, StringAccum&);
133 void cache_defs() const;
134 void shift_indices(int, int);
135
136 Type1Item* dict_size_item(int) const;
137 int get_dict_size(int) const;
138 void set_dict_size(int, int);
139
140 };
141
142
143 inline Type1Font::DictHashMap::const_iterator Type1Font::dict_begin(int dict) const
144 {
145 return _dict[dict].begin();
146 }
147
148 inline Type1Font::DictHashMap::iterator Type1Font::dict_begin(int dict)
149 {
150 return _dict[dict].begin();
151 }
152
153 inline void Type1Font::set_dict(int dict, PermString name, Type1Definition* t1d)
154 {
155 _dict[dict].insert(name, t1d);
156 }
157
158 inline PermString Type1Font::font_name() const
159 {
160 if (!_cached_defs)
161 cache_defs();
162 return _font_name;
163 }
164
165 }
166 #endif