diff options
author | Karl Berry <karl@freefriends.org> | 2008-02-17 19:29:39 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-02-17 19:29:39 +0000 |
commit | fc3b5d4d4f684baa6216685a0696efb853141529 (patch) | |
tree | 0694ed01c09b3c97fcd64453e2c1f647a3fb31ad /Build/source/texk/lcdf-typetools/include | |
parent | 5fc0a693ca037d37d815b00c49660c138b332224 (diff) |
move lcdf-typetools to texk and update to 2.66
git-svn-id: svn://tug.org/texlive/trunk@6662 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/lcdf-typetools/include')
48 files changed, 7227 insertions, 0 deletions
diff --git a/Build/source/texk/lcdf-typetools/include/efont/afm.hh b/Build/source/texk/lcdf-typetools/include/efont/afm.hh new file mode 100644 index 00000000000..465ff87dd54 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/afm.hh @@ -0,0 +1,59 @@ +// -*- related-file-name: "../../libefont/afm.cc" -*- +#ifndef EFONT_AFM_HH +#define EFONT_AFM_HH +#include <efont/metrics.hh> +class Slurper; +class Filename; +class ErrorHandler; +namespace Efont { +class AfmParser; + +struct AfmMetricsXt: public MetricsXt { + + Vector<PermString> opening_comments; + PermString notice; + PermString encoding_scheme; + + PermString kind() const { return "AFM"; } + +}; + +class AfmReader { public: + + static Metrics *read(const Filename &, ErrorHandler *); + static Metrics *read(Slurper &, ErrorHandler *); + + private: + + Metrics *_afm; + AfmMetricsXt *_afm_xt; + AfmParser &_l; + ErrorHandler *_errh; + + mutable bool _composite_warned; + mutable bool _metrics_sets_warned; + mutable int _y_width_warned; + + void lwarning(const char *, ...) const; + void lerror(const char *, ...) const; + void composite_warning() const; + void metrics_sets_warning() const; + void y_width_warning() const; + void no_match_warning(const char *context = 0) const; + + double &fd(int i) { return _afm->fd(i); } + GlyphIndex find_err(PermString, const char *) const; + + void read_char_metric_data() const; + void read_char_metrics() const; + void read_kerns() const; + void read_composites() const; + + bool read(); + + AfmReader(AfmParser &, Metrics *, AfmMetricsXt *, ErrorHandler *); + +}; + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/afmparse.hh b/Build/source/texk/lcdf-typetools/include/efont/afmparse.hh new file mode 100644 index 00000000000..5a5350a55c7 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/afmparse.hh @@ -0,0 +1,64 @@ +// -*- related-file-name: "../../libefont/afmparse.cc" -*- +#ifndef EFONT_AFMPARSE_HH +#define EFONT_AFMPARSE_HH +#include <lcdf/slurper.hh> +#include <lcdf/permstr.hh> +#include <stdarg.h> +namespace Efont { + +class AfmParser { public: + + AfmParser(Slurper &); + + bool ok() const { return _slurper.ok(); } + operator Landmark() const { return _slurper.landmark(); } + Landmark landmark() const { return _slurper.landmark(); } + unsigned lineno() const { return _slurper.lineno(); } + const Filename &filename() const { return _slurper.filename(); } + + bool key_matched() const { return _fail_field >= 0; } + int fail_field() const { return _fail_field; } + PermString message() const { return _message; } + void clear_message() { _message = PermString(); } + + PermString keyword() const; + bool is(const char *, ...); + bool isall(const char *, ...); + + inline bool next_line(); + void save_line() { _slurper.save_line(); } + void skip_until(unsigned char); + + unsigned char *cur_line() const { return _pos; } + unsigned char first() const { return _pos[0]; } + unsigned char operator[](int i) const { return _pos[i]; } + bool left() const { return *_pos != 0; } + + private: + + Slurper &_slurper; + bool _save_line; + + unsigned char *_line; + unsigned char *_pos; + int _length; + + PermString _message; + int _fail_field; + + void static_initialize(); + void trim_end(); + unsigned char *vis(const char *, va_list); + +}; + + +inline bool AfmParser::next_line() +{ + _pos = _line = (unsigned char *)_slurper.next_line(); + _length = _slurper.cur_line_length(); + return _line != 0; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/afmw.hh b/Build/source/texk/lcdf-typetools/include/efont/afmw.hh new file mode 100644 index 00000000000..fa883517999 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/afmw.hh @@ -0,0 +1,29 @@ +#ifndef EFONT_AFMW_HH +#define EFONT_AFMW_HH +#include <efont/afm.hh> +#include <stdio.h> +namespace Efont { + +class AfmWriter { public: + + static void write(Metrics *, FILE *); + + private: + + Metrics *_m; + AfmMetricsXt *_afm_xt; + FILE *_f; + + void write_prologue() const; + void write_char_metric_data(GlyphIndex, int) const; + void write_kerns() const; + void write(); + + double fd(int i) const { return _m->fd(i); } + + AfmWriter(Metrics *, FILE *); + +}; + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/amfm.hh b/Build/source/texk/lcdf-typetools/include/efont/amfm.hh new file mode 100644 index 00000000000..27e87c093ca --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/amfm.hh @@ -0,0 +1,153 @@ +// -*- related-file-name: "../../libefont/amfm.cc" -*- +#ifndef EFONT_AMFM_HH +#define EFONT_AMFM_HH +#include <efont/metrics.hh> +#include <efont/t1mm.hh> +#include <lcdf/hashmap.hh> +class Slurper; +class Filename; +class ErrorHandler; +namespace Efont { +class AfmParser; +class MetricsFinder; +class Type1Charstring; + + +struct AmfmMaster { + + PermString font_name; + PermString family; + PermString full_name; + PermString version; + Vector<double> weight_vector; + + bool loaded; + Metrics *afm; + + AmfmMaster() : loaded(0), afm(0) { } + +}; + + +struct AmfmPrimaryFont { + + Vector<int> design_vector; + Vector<PermString> labels; + PermString name; + AmfmPrimaryFont *next; + +}; + + +class AmfmMetrics { public: + + AmfmMetrics(MetricsFinder *); + ~AmfmMetrics(); + + void use() { _uses++; } + void unuse() { if (--_uses == 0) delete this; } + + bool sanity(ErrorHandler *) const; + + double fd(int i) const { return _fdv[i]; } + double &fd(int i) { return _fdv[i]; } + + PermString font_name() const { return _font_name; } + PermString directory() const { return _directory; } + + int naxes() const { return _naxes; } + int nmasters() const { return _nmasters; } + MultipleMasterSpace *mmspace() const { return _mmspace; } + + int primary_label_value(int, PermString) const; + + Metrics *interpolate(const Vector<double> &design, + const Vector<double> &weight, ErrorHandler *); + + private: + + MetricsFinder *_finder; + PermString _directory; + + Vector<double> _fdv; + + PermString _font_name; + PermString _family; + PermString _full_name; + PermString _weight; + + PermString _version; + PermString _notice; + Vector<PermString> _opening_comments; + + PermString _encoding_scheme; + Vector<double> _weight_vector; + + int _nmasters; + int _naxes; + AmfmMaster *_masters; + MultipleMasterSpace *_mmspace; + + AmfmPrimaryFont *_primary_fonts; + + Metrics *_sanity_afm; + + unsigned _uses; + + friend class AmfmReader; + + AmfmMetrics(const AmfmMetrics &) { assert(0); } + AmfmMetrics &operator=(const AmfmMetrics &) { assert(0); return *this; } + + AmfmPrimaryFont *find_primary_font(const Vector<double> &design) const; + + Metrics *master(int, ErrorHandler *); + +}; + + +class AmfmReader { public: + + static AmfmMetrics *read(const Filename &, MetricsFinder *, ErrorHandler*); + static AmfmMetrics *read(Slurper &, MetricsFinder *, ErrorHandler *); + static void add_amcp_file(Slurper &, AmfmMetrics *, ErrorHandler *); + + private: + + typedef Vector<double> NumVector; + + AmfmMetrics *_amfm; + MetricsFinder *_finder; + AfmParser &_l; + MultipleMasterSpace *_mmspace; + ErrorHandler *_errh; + + double &fd(int i) const { return _amfm->fd(i); } + int naxes() const { return _amfm->_naxes; } + int nmasters() const { return _amfm->_nmasters; } + + void check_mmspace(); + + void lwarning(const char *, ...) const; + void lerror(const char *, ...) const; + void no_match_warning(const char *context = 0) const; + + bool read_simple_array(Vector<double> &) const; + void read_positions() const; + void read_normalize() const; + void read_axis_types() const; + void read_axis(int axis) const; + void read_master(int master) const; + void read_primary_fonts() const; + void read_one_primary_font() const; + void read_conversion_programs() const; + bool read(); + + void read_amcp_file(); + + AmfmReader(AfmParser &, AmfmMetrics *, ErrorHandler *); + +}; + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/cff.hh b/Build/source/texk/lcdf-typetools/include/efont/cff.hh new file mode 100644 index 00000000000..775f56498f6 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/cff.hh @@ -0,0 +1,452 @@ +// -*- related-file-name: "../../libefont/cff.cc" -*- +#ifndef EFONT_CFF_HH +#define EFONT_CFF_HH +#include <lcdf/hashmap.hh> +#include <efont/t1cs.hh> +class ErrorHandler; +namespace Efont { +class Type1Encoding; + +class Cff { public: + + class Dict; + class IndexIterator; + class Charset; + class FDSelect; + class FontParent; + class Font; + class CIDFont; + class ChildFont; + + Cff(const String &, ErrorHandler * = 0); + ~Cff(); + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + const String &data_string() const { return _data_string; } + const uint8_t *data() const { return _data; } + int length() const { return _len; } + + int nfonts() const { return _name_index.size(); } + PermString font_name(int i) const { return _name_index[i]; } + FontParent *font(PermString = PermString(), ErrorHandler * = 0); + + enum { NSTANDARD_STRINGS = 391, MAX_SID = 64999 }; + int max_sid() const { return NSTANDARD_STRINGS - 1 + _strings.size(); } + int sid(PermString); + String sid_string(int sid) const; + PermString sid_permstring(int sid) const; + + int ngsubrs() const { return _gsubrs_index.nitems(); } + Charstring *gsubr(int i); + + enum DictOperator { + oVersion = 0, oNotice = 1, oFullName = 2, oFamilyName = 3, + oWeight = 4, oFontBBox = 5, oBlueValues = 6, oOtherBlues = 7, + oFamilyBlues = 8, oFamilyOtherBlues = 9, oStdHW = 10, oStdVW = 11, + oUniqueID = 13, oXUID = 14, oCharset = 15, oEncoding = 16, + oCharStrings = 17, oPrivate = 18, oSubrs = 19, oDefaultWidthX = 20, + oNominalWidthX = 21, + oCopyright = 32 + 0, oIsFixedPitch = 32 + 1, oItalicAngle = 32 + 2, + oUnderlinePosition = 32 + 3, oUnderlineThickness = 32 + 4, + oPaintType = 32 + 5, oCharstringType = 32 + 6, oFontMatrix = 32 + 7, + oStrokeWidth = 32 + 8, oBlueScale = 32 + 9, oBlueShift = 32 + 10, + oBlueFuzz = 32 + 11, oStemSnapH = 32 + 12, oStemSnapV = 32 + 13, + oForceBold = 32 + 14, oLanguageGroup = 32 + 17, + oExpansionFactor = 32 + 18, oInitialRandomSeed = 32 + 19, + oSyntheticBase = 32 + 20, oPostScript = 32 + 21, + oBaseFontName = 32 + 22, oBaseFontBlend = 32 + 23, + oROS = 32 + 30, oCIDFontVersion = 32 + 31, oCIDFontRevision = 32 + 32, + oCIDFontType = 32 + 33, oCIDCount = 32 + 34, oUIDBase = 32 + 35, + oFDArray = 32 + 36, oFDSelect = 32 + 37, oFontName = 32 + 38, + oLastOperator = oFontName + }; + + enum DictType { + tNone = 0, tSID, tFontNumber, tBoolean, tNumber, tOffset, tLocalOffset, + tArray, tArray2, tArray3, tArray4, tArray5, tArray6, tPrivateType, + tTypeMask = 0x7F, tPrivate = 0x80, tP = tPrivate + }; + + static const char * const operator_names[]; + static const int operator_types[]; + + + class IndexIterator { public: + + IndexIterator() : _offset(0), _last_offset(0), _offsize(-1) { } + IndexIterator(const uint8_t *, int, int, ErrorHandler * = 0, const char *index_name = "INDEX"); + + int error() const { return (_offsize < 0 ? _offsize : 0); } + + bool live() const { return _offset < _last_offset; } + operator bool() const { return live(); } + int nitems() const; + + inline const uint8_t *operator*() const; + inline const uint8_t *operator[](int) const; + const uint8_t *index_end() const; + + void operator++() { _offset += _offsize; } + void operator++(int) { ++(*this); } + + private: + + const uint8_t *_contents; + const uint8_t *_offset; + const uint8_t *_last_offset; + int _offsize; + + inline uint32_t offset_at(const uint8_t *) const; + + }; + + private: + + String _data_string; + const uint8_t *_data; + int _len; + + int _error; + + Vector<PermString> _name_index; + + IndexIterator _top_dict_index; + + IndexIterator _strings_index; + mutable Vector<PermString> _strings; + mutable HashMap<PermString, int> _strings_map; + + IndexIterator _gsubrs_index; + Vector<Charstring *> _gsubrs_cs; + + int parse_header(ErrorHandler *); + int font_offset(int, int &, int &) const; + int font_offset(PermString, int &, int &) const; + + enum { HEADER_SIZE = 4 }; + +}; + + +class Cff::Dict { public: + + Dict(); + Dict(Cff *, int pos, int dict_len, ErrorHandler * = 0, const char *dict_name = "DICT"); + int assign(Cff *, int pos, int dict_len, ErrorHandler * = 0, const char *dict_name = "DICT"); + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + int check(bool is_private, ErrorHandler * = 0, const char *dict_name = "DICT") const; + + bool has(DictOperator) const; + inline bool has_first(DictOperator) const; + bool xvalue(DictOperator, Vector<double> &) const; + bool xvalue(DictOperator, int *) const; + bool xvalue(DictOperator, double *) const; + bool value(DictOperator, Vector<double> &) const; + bool value(DictOperator, int *) const; + bool value(DictOperator, double *) const; + + void unparse(ErrorHandler *, const char *) const; + + private: + + Cff *_cff; + int _pos; + Vector<int> _operators; + Vector<int> _pointers; + Vector<double> _operands; + int _error; + +}; + +class Cff::Charset { public: + + Charset() : _error(-1) { } + Charset(const Cff *, int pos, int nglyphs, int max_sid, ErrorHandler * = 0); + void assign(const Cff *, int pos, int nglyphs, int max_sid, ErrorHandler * = 0); + + int error() const { return _error; } + + int nglyphs() const { return _sids.size(); } + int nsids() const { return _gids.size(); } + + inline int gid_to_sid(int gid) const; + inline int sid_to_gid(int sid) const; + + private: + + Vector<int> _sids; + Vector<int> _gids; + int _error; + + void assign(const int *, int, int); + int parse(const Cff *, int pos, int nglyphs, int max_sid, ErrorHandler *); + +}; + +class Cff::FDSelect { public: + + FDSelect() : _fds(0), _my_fds(false), _nglyphs(0), _error(-1) { } + ~FDSelect(); + void assign(const Cff *, int pos, int nglyphs, ErrorHandler * = 0); + + int error() const { return _error; } + + int nglyphs() const { return _nglyphs; } + inline int gid_to_fd(int gid) const; + + private: + + const uint8_t *_fds; + bool _my_fds; + int _nglyphs; + int _error; + + FDSelect(const FDSelect &); + FDSelect &operator=(const FDSelect &); + int parse(const Cff *, int pos, int nglyphs, ErrorHandler *); + +}; + + +class Cff::FontParent : public CharstringProgram { public: + + FontParent(Cff *); + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + int ngsubrs_x() const { return _cff->ngsubrs(); } + int ngsubrs() const { return ngsubrs_x(); } + Charstring *gsubr(int) const; + int gsubr_bias() const; + + private: + + Cff *_cff; + int _charstring_type; + int _error; + + FontParent(const FontParent &); + FontParent &operator=(const FontParent &); + + Charstring *charstring(const IndexIterator &, int) const; + + friend class Cff::Font; + friend class Cff::CIDFont; + friend class Cff::ChildFont; + +}; + +class Cff::CIDFont : public Cff::FontParent { public: + + CIDFont(Cff *, PermString, const Dict &, ErrorHandler *); + ~CIDFont(); + + PermString font_name() const { return _font_name; } + void font_matrix(double[6]) const; + + int nglyphs() const { return _charstrings_index.nitems(); } + PermString glyph_name(int) const; + void glyph_names(Vector<PermString> &) const; + Charstring *glyph(int) const; + Charstring *glyph(PermString) const; + int glyphid(PermString) const; + const CharstringProgram *child_program(int) const; + + bool dict_has(DictOperator) const; + String dict_string(DictOperator) const; + bool dict_value(DictOperator, double *) const; + bool dict_xvalue(DictOperator, double, double *) const; + bool dict_value(DictOperator, Vector<double> &) const; + + private: + + PermString _font_name; + + Dict _top_dict; + Dict _private_dict; + + Cff::Charset _charset; + + IndexIterator _charstrings_index; + mutable Vector<Charstring *> _charstrings_cs; + + Vector<ChildFont *> _child_fonts; + Cff::FDSelect _fdselect; + + const Dict &dict_of(DictOperator) const; + +}; + +class Cff::ChildFont : public Cff::FontParent { public: + + ChildFont(Cff *, Cff::CIDFont *, int charstring_type, const Dict &, ErrorHandler * = 0); + ~ChildFont(); + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + PermString font_name() const { return _parent->font_name(); } + void font_matrix(double m[6]) const { _parent->font_matrix(m); } + + inline bool cid() const; + + int nsubrs_x() const { return _subrs_index.nitems(); } + int nsubrs() const { return nsubrs_x(); } + Charstring *subr(int) const; + int subr_bias() const; + + int nglyphs() const { return _parent->nglyphs(); } + PermString glyph_name(int gi) const { return _parent->glyph_name(gi); } + void glyph_names(Vector<PermString> &v) const { _parent->glyph_names(v); } + Charstring *glyph(int gi) const { return _parent->glyph(gi); } + Charstring *glyph(PermString n) const { return _parent->glyph(n); } + + double global_width_x(bool) const; + + private: + + Cff::CIDFont *_parent; + + Dict _top_dict; + Dict _private_dict; + + IndexIterator _subrs_index; + mutable Vector<Charstring *> _subrs_cs; + + double _default_width_x; + double _nominal_width_x; + + ChildFont(const ChildFont &); // does not exist + ChildFont &operator=(const ChildFont &); // does not exist + + Charstring *charstring(const IndexIterator &, int) const; + + friend class Cff::Font; + +}; + +class Cff::Font : public Cff::ChildFont { public: + + Font(Cff *, PermString, const Dict &, ErrorHandler *); + ~Font(); + + PermString font_name() const { return _font_name; } + void font_matrix(double[6]) const; + + int nglyphs() const { return _charstrings_index.nitems(); } + PermString glyph_name(int) const; + void glyph_names(Vector<PermString> &) const; + Charstring *glyph(int) const; + Charstring *glyph(PermString) const; + int glyphid(PermString) const; + + Type1Encoding *type1_encoding() const; + Type1Encoding *type1_encoding_copy() const; + + bool dict_has(DictOperator) const; + String dict_string(DictOperator) const; + inline bool dict_value(DictOperator, double *) const; + inline bool dict_value(DictOperator, Vector<double> &) const; + const Dict &top_dict() const { return _top_dict; } + + private: + + PermString _font_name; + + Cff::Charset _charset; + + IndexIterator _charstrings_index; + mutable Vector<Charstring *> _charstrings_cs; + + int _encoding_pos; + int _encoding[256]; + mutable Type1Encoding *_t1encoding; + + int parse_encoding(int pos, ErrorHandler *); + int assign_standard_encoding(const int *standard_encoding); + + inline const Dict &dict_of(DictOperator) const; + +}; + + +inline uint32_t Cff::IndexIterator::offset_at(const uint8_t *x) const +{ + switch (_offsize) { + case 0: + return 0; + case 1: + return x[0]; + case 2: + return (x[0] << 8) | x[1]; + case 3: + return (x[0] << 16) | (x[1] << 8) | x[2]; + default: + return (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3]; + } +} + +inline const uint8_t *Cff::IndexIterator::operator*() const +{ + assert(live()); + return _contents + offset_at(_offset); +} + +inline const uint8_t *Cff::IndexIterator::operator[](int which) const +{ + assert(live() && _offset + which * _offsize <= _last_offset); + return _contents + offset_at(_offset + which * _offsize); +} + +inline int Cff::Charset::gid_to_sid(int gid) const +{ + if (gid >= 0 && gid < _sids.size()) + return _sids[gid]; + else + return -1; +} + +inline int Cff::Charset::sid_to_gid(int sid) const +{ + if (sid >= 0 && sid < _gids.size()) + return _gids[sid]; + else + return -1; +} + +inline int Cff::FDSelect::gid_to_fd(int gid) const +{ + if (gid >= 0 && gid < _nglyphs) + return _fds[gid]; + else + return -1; +} + +inline bool Cff::Dict::has_first(DictOperator op) const +{ + return _operators.size() && _operators[0] == op; +} + +inline const Cff::Dict &Cff::Font::dict_of(DictOperator op) const +{ + return (op >= 0 && op <= oLastOperator && (operator_types[op] & tP) ? _private_dict : _top_dict); +} + +inline bool Cff::Font::dict_value(DictOperator op, double *val) const +{ + return dict_of(op).value(op, val); +} + +inline bool Cff::Font::dict_value(DictOperator op, Vector<double> &val) const +{ + return dict_of(op).value(op, val); +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/encoding.hh b/Build/source/texk/lcdf-typetools/include/efont/encoding.hh new file mode 100644 index 00000000000..59758b06607 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/encoding.hh @@ -0,0 +1,27 @@ +// -*- related-file-name: "../../libefont/encoding.cc" -*- +#ifndef EFONT_ENCODING_HH +#define EFONT_ENCODING_HH +#include <lcdf/vector.hh> +namespace Efont { +typedef int GlyphIndex; + +class Encoding8 { + + Vector<GlyphIndex> _codes; + Vector<int> _code_map; + + public: + + Encoding8() : _code_map(256, -1) { } + + void reserve_glyphs(int); + + int code(GlyphIndex gi) const { return _codes[gi]; } + GlyphIndex find_code(int c) const { return _code_map[c]; } + + void set_code(GlyphIndex gi, int c) { _codes[gi] = c; _code_map[c] = gi; } + +}; + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/findmet.hh b/Build/source/texk/lcdf-typetools/include/efont/findmet.hh new file mode 100644 index 00000000000..dcfa8fb438a --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/findmet.hh @@ -0,0 +1,114 @@ +// -*- related-file-name: "../../libefont/findmet.cc" -*- +#ifndef EFONT_FINDMET_HH +#define EFONT_FINDMET_HH +#include <lcdf/hashmap.hh> +#include <lcdf/vector.hh> +#include <lcdf/permstr.hh> +class Filename; +class ErrorHandler; +namespace Efont { +class Metrics; +class AmfmMetrics; +class PsresDatabase; + +class MetricsFinder { public: + + MetricsFinder() : _next(0), _prev(0) { } + virtual ~MetricsFinder(); + + MetricsFinder *next() const { return _next; } + + void add_finder(MetricsFinder *); + + Metrics *find_metrics(PermString, ErrorHandler * = 0); + AmfmMetrics *find_amfm(PermString, ErrorHandler * = 0); + + virtual Metrics *find_metrics_x(PermString, MetricsFinder *, ErrorHandler *); + virtual AmfmMetrics *find_amfm_x(PermString, MetricsFinder *, ErrorHandler *); + + void record(Metrics *m); + virtual void record(Metrics *, PermString); + virtual void record(AmfmMetrics *); + + private: + + MetricsFinder *_next; + MetricsFinder *_prev; + + MetricsFinder(const MetricsFinder &) { } + MetricsFinder &operator=(const MetricsFinder &) { return *this; } + + protected: + + Metrics *try_metrics_file(const Filename &, MetricsFinder *, ErrorHandler *); + AmfmMetrics *try_amfm_file(const Filename &, MetricsFinder *, ErrorHandler *); + +}; + + +class CacheMetricsFinder: public MetricsFinder { public: + + CacheMetricsFinder(); + ~CacheMetricsFinder(); + + Metrics *find_metrics_x(PermString, MetricsFinder *, ErrorHandler *); + AmfmMetrics *find_amfm_x(PermString, MetricsFinder *, ErrorHandler *); + void record(Metrics *, PermString); + void record(AmfmMetrics *); + + void clear(); + + private: + + HashMap<PermString, int> _metrics_map; + Vector<Metrics *> _metrics; + HashMap<PermString, int> _amfm_map; + Vector<AmfmMetrics *> _amfm; + +}; + + +class InstanceMetricsFinder: public MetricsFinder { public: + + InstanceMetricsFinder(bool call_mmpfb = true); + + Metrics *find_metrics_x(PermString, MetricsFinder *, ErrorHandler *); + + private: + + bool _call_mmpfb; + + Metrics *find_metrics_instance(PermString, MetricsFinder *, ErrorHandler *); + +}; + + +class PsresMetricsFinder: public MetricsFinder { public: + + PsresMetricsFinder(PsresDatabase *); + + Metrics *find_metrics_x(PermString, MetricsFinder *, ErrorHandler *); + AmfmMetrics *find_amfm_x(PermString, MetricsFinder *, ErrorHandler *); + + private: + + PsresDatabase *_psres; + +}; + + +class DirectoryMetricsFinder: public MetricsFinder { public: + + DirectoryMetricsFinder(PermString); + + Metrics *find_metrics_x(PermString, MetricsFinder *, ErrorHandler *); + AmfmMetrics *find_amfm_x(PermString, MetricsFinder *, ErrorHandler *); + + private: + + PermString _directory; + +}; + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/metrics.hh b/Build/source/texk/lcdf-typetools/include/efont/metrics.hh new file mode 100644 index 00000000000..ae0a61126ed --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/metrics.hh @@ -0,0 +1,177 @@ +// -*- related-file-name: "../../libefont/metrics.cc" -*- +#ifndef EFONT_METRICS_HH +#define EFONT_METRICS_HH +#include <lcdf/permstr.hh> +#include <lcdf/vector.hh> +#include <lcdf/hashmap.hh> +#include <efont/encoding.hh> +#include <efont/pairop.hh> +namespace Efont { +class MetricsXt; + +class Metrics { public: + + Metrics(); + Metrics(PermString font_name, PermString full_name, const Metrics &); + ~Metrics(); + + void use() { _uses++; } + void unuse() { if (--_uses == 0) delete this; } + + // GLOBALS + + PermString font_name() const { return _font_name; } + PermString family() const { return _family; } + PermString full_name() const { return _full_name; } + PermString weight() const { return _weight; } + PermString version() const { return _version; } + + void set_font_name(PermString); + void set_family(PermString s) { _family = s; } + void set_full_name(PermString s) { _full_name = s; } + void set_weight(PermString s) { _weight = s; } + void set_version(PermString s) { _version = s; } + + // GLYPHS + + int nglyphs() const { return _names.size(); } + PermString name(GlyphIndex gi) const { return _names[gi]; } + GlyphIndex find(PermString n) const { return _name_map[n]; } + + int code(GlyphIndex gi) const { return _encoding.code(gi); } + GlyphIndex find_code(int c) const { return _encoding.find_code(c); } + void set_code(GlyphIndex gi, int c) { _encoding.set_code(gi, c); } + + GlyphIndex add_glyph(PermString); + void reserve_glyphs(int); + + // DIMENSIONS + + double scale() const { return _scale; } + void set_scale(double d) { _scale = d; } + + int nfd() const { return _fdv.size(); } + int nkv() const { return _kernv.size(); } + + double fd(int i) const { return _fdv[i]; } + double wd(int i) const { return _wdv[i]; } + double lf(int i) const { return _lfv[i]; } + double rt(int i) const { return _rtv[i]; } + double tp(int i) const { return _tpv[i]; } + double bt(int i) const { return _btv[i]; } + double kv(int i) const { return _kernv[i]; } + + double &fd(int i) { return _fdv[i]; } + double &wd(int i) { return _wdv[i]; } + double &lf(int i) { return _lfv[i]; } + double &rt(int i) { return _rtv[i]; } + double &tp(int i) { return _tpv[i]; } + double &bt(int i) { return _btv[i]; } + double &kv(int i) { return _kernv[i]; } + + inline int add_kv(double d); + + void interpolate_dimens(const Metrics &, double, bool increment); + + // PAIR PROGRAM + + PairProgram *pair_program() { return &_pairp; } + const PairProgram *pair_program() const { return &_pairp; } + inline bool add_kern(GlyphIndex, GlyphIndex, int); + inline bool add_lig(GlyphIndex, GlyphIndex, GlyphIndex, int = opLigSimple); + + // EXTENSIONS + + MetricsXt *find_xt(PermString name) const { return _xt[_xt_map[name]]; } + void add_xt(MetricsXt *); + + private: + + PermString _font_name; + + PermString _family; + PermString _full_name; + PermString _weight; + PermString _version; + + HashMap<PermString, GlyphIndex> _name_map; + Vector<PermString> _names; + Encoding8 _encoding; + + double _scale; + + Vector<double> _fdv; + Vector<double> _wdv; + Vector<double> _lfv; + Vector<double> _rtv; + Vector<double> _tpv; + Vector<double> _btv; + + PairProgram _pairp; + Vector<double> _kernv; + + HashMap<PermString, int> _xt_map; + Vector<MetricsXt *> _xt; + + unsigned _uses; + +}; + + +class MetricsXt { + + public: + + MetricsXt() { } + virtual ~MetricsXt() { } + + virtual PermString kind() const = 0; + + virtual void reserve_glyphs(int) { } + +}; + + +enum FontDimensionDefs { + + fdCapHeight = 0, + fdXHeight, + fdAscender, + fdDescender, + + fdItalicAngle, + fdUnderlinePosition, + fdUnderlineThickness, + + fdFontBBllx, + fdFontBBlly, + fdFontBBurx, + fdFontBBury, + + fdStdHW, + fdStdVW, + + fdLast + +}; + + +inline bool Metrics::add_kern(GlyphIndex g1, GlyphIndex g2, int ki) +{ + return _pairp.add_kern(g1, g2, ki); +} + +inline bool Metrics::add_lig(GlyphIndex g1, GlyphIndex g2, GlyphIndex gr, int kind) +{ + return _pairp.add_lig(g1, g2, gr, kind); +} + +inline int Metrics::add_kv(double d) +{ + int k = _kernv.size(); + _kernv.push_back(d); + return k; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otf.hh b/Build/source/texk/lcdf-typetools/include/efont/otf.hh new file mode 100644 index 00000000000..0333e70e3f5 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otf.hh @@ -0,0 +1,385 @@ +// -*- related-file-name: "../../libefont/otf.cc" -*- +#ifndef EFONT_OTF_HH +#define EFONT_OTF_HH +#include <efont/otfdata.hh> +class ErrorHandler; +namespace Efont { namespace OpenType { +class Post; +class Name; + +typedef int Glyph; // 16-bit integer + +class Tag { public: + + Tag() : _tag(0U) { } + explicit Tag(uint32_t tag) : _tag(tag) { } + Tag(const char*); + Tag(const String&); + // default destructor + + bool null() const { return _tag == 0; } + operator bool() const { return _tag != 0; } + bool valid() const; + + uint32_t value() const { return _tag; } + + String text() const; + static String langsys_text(Tag script, Tag langsys = Tag()); + + const uint8_t* table_entry(const uint8_t* table, int n, int entry_size) const; + + const char* script_description() const; + const char* language_description() const; + const char* feature_description() const; + + private: + + uint32_t _tag; + +}; + +class Font { public: + + Font(const String&, ErrorHandler* = 0); + // default destructor + + bool ok() const { return _error >= 0; } + bool check_checksums(ErrorHandler * = 0) const; + int error() const { return _error; } + + const String& data_string() const { return _str; } + const uint8_t* data() const { return _str.udata(); } + int length() const { return _str.length(); } + + int ntables() const; + String table(Tag) const; + uint32_t table_checksum(Tag) const; + Tag table_tag(int) const; + + static uint32_t checksum(const uint8_t *, const uint8_t *); + static uint32_t checksum(const String &); + static Font make(bool truetype, const Vector<Tag>& tags, const Vector<String>& data); + + enum { HEADER_SIZE = 12, TABLE_DIR_ENTRY_SIZE = 16 }; + + private: + + String _str; + int _error; + + int parse_header(ErrorHandler*); + +}; + +class ScriptList { public: + + ScriptList() { } + inline ScriptList(const String&, ErrorHandler* = 0); + int assign(const String&, ErrorHandler* = 0); + // default destructor + + bool ok() const { return _str.length() > 0; } + + int language_systems(Vector<Tag>& scripts, Vector<Tag>& langsys, ErrorHandler* = 0) const; + int features(Tag script, Tag langsys, int& required_fid, Vector<int>& fids, ErrorHandler* = 0, bool clear_fids = true) const; + + private: + + enum { SCRIPTLIST_HEADERSIZE = 2, SCRIPT_RECSIZE = 6, + SCRIPT_HEADERSIZE = 4, LANGSYS_RECSIZE = 6, + LANGSYS_HEADERSIZE = 6, FEATURE_RECSIZE = 2 }; + + String _str; + + int check_header(ErrorHandler*); + int script_offset(Tag) const; + int check_script(Tag, int, ErrorHandler*) const; + int langsys_offset(Tag, Tag, ErrorHandler* = 0) const; + +}; + +class FeatureList { public: + + FeatureList() { } + inline FeatureList(const String&, ErrorHandler* = 0); + int assign(const String&, ErrorHandler* = 0); + // default destructor + + bool ok() const { return _str.length() > 0; } + + Tag tag(int fid) const; + String params(int fid, int length, ErrorHandler* = 0, bool old_style_offset = false) const; + String size_params(int fid, const Name& name, ErrorHandler* = 0) const; + int lookups(int fid, Vector<int>& results, ErrorHandler* = 0, bool clear_results = true) const; + + int find(Tag, const Vector<int>& fids) const; + void filter(Vector<int>& fids, const Vector<Tag>& sorted_ftags) const; + inline void filter(Vector<int>& fids, Tag ftag) const; + + int lookups(const Vector<int>& fids, Vector<int>& results, ErrorHandler* = 0) const; + int lookups(const Vector<int>& required_fids, const Vector<int>& fids, const Vector<Tag>& sorted_ftags, Vector<int>& results, ErrorHandler* = 0) const; + int lookups(int required_fid, const Vector<int>& fids, const Vector<Tag>& sorted_ftags, Vector<int>& results, ErrorHandler* = 0) const; + int lookups(const ScriptList&, Tag script, Tag langsys, const Vector<Tag>& sorted_ftags, Vector<int>& results, ErrorHandler* = 0) const; + + private: + + enum { FEATURELIST_HEADERSIZE = 2, FEATURE_RECSIZE = 6, + FEATURE_HEADERSIZE = 4, LOOKUPLIST_RECSIZE = 2 }; + + String _str; + + int check_header(ErrorHandler*); + int script_offset(Tag) const; + int langsys_offset(Tag, Tag, ErrorHandler* = 0) const; + +}; + +class Coverage { public: + + Coverage() throw (); // empty coverage + Coverage(Glyph first, Glyph last) throw (); // range coverage + Coverage(const String&, ErrorHandler* = 0, bool check = true) throw (); + // default destructor + + bool ok() const throw () { return _str.length() > 0; } + int size() const throw (); + + int coverage_index(Glyph) const throw (); + bool covers(Glyph g) const throw () { return coverage_index(g) >= 0; } + + void unparse(StringAccum&) const throw (); + String unparse() const throw (); + + class iterator { public: + iterator() : _pos(0), _value(0) { } + // private constructor + // default destructor + + bool ok() const { return _pos < _str.length(); } + operator bool() const { return ok(); } + + Glyph operator*() const { return _value; } + Glyph value() const { return _value; } + int coverage_index() const; + + void operator++(int); + void operator++() { (*this)++; } + bool forward_to(Glyph); + + // XXX should check iterators are of same type + bool operator<(const iterator& o) { return _value < o._value; } + bool operator<=(const iterator& o) { return _value <= o._value; } + bool operator>=(const iterator& o) { return _value >= o._value; } + bool operator>(const iterator& o) { return _value > o._value; } + bool operator==(const iterator& o) { return _value == o._value; } + bool operator!=(const iterator& o) { return _value != o._value; } + + private: + String _str; + int _pos; + Glyph _value; + friend class Coverage; + iterator(const String&, int); + }; + + iterator begin() const { return iterator(_str, 0); } + iterator end() const { return iterator(_str, _str.length()); } + Glyph operator[](int) const throw (); + + enum { T_LIST = 1, T_RANGES = 2, + HEADERSIZE = 4, LIST_RECSIZE = 2, RANGES_RECSIZE = 6 }; + + private: + + String _str; + + int check(ErrorHandler*); + +}; + +Coverage operator&(const Coverage&, const Coverage&); +bool operator<=(const Coverage&, const Coverage&); + +inline bool operator>=(const Coverage& a, const Coverage& b) +{ + return b <= a; +} + +class GlyphSet { public: + + GlyphSet(); + GlyphSet(const GlyphSet&); + ~GlyphSet(); + + inline bool covers(Glyph g) const; + inline bool operator[](Glyph g) const; + int change(Glyph, bool); + void insert(Glyph g) { change(g, true); } + void remove(Glyph g) { change(g, false); } + + GlyphSet& operator=(const GlyphSet&); + + private: + + enum { GLYPHBITS = 16, SHIFT = 8, + MAXGLYPH = (1 << GLYPHBITS) - 1, UNSHIFT = GLYPHBITS - SHIFT, + MASK = (1 << UNSHIFT) - 1, VLEN = (1 << SHIFT), + VULEN = (1 << UNSHIFT) >> 5 + }; + + uint32_t* _v[VLEN]; + +}; + +class ClassDef { public: + + ClassDef(const String&, ErrorHandler* = 0) throw (); + // default destructor + + bool ok() const { return _str.length() > 0; } + int nclass() const throw (); + + int lookup(Glyph) const throw (); + int operator[](Glyph g) const throw () { return lookup(g); } + + void unparse(StringAccum&) const throw (); + String unparse() const throw (); + + class class_iterator { public: + // private constructor + // default destructor + + bool ok() const { return _pos < _str.length(); } + operator bool() const { return ok(); } + + Glyph operator*() const { return *_coviter; } + Glyph value() const { return *_coviter; } + int class_value() const { return _class; } + + void operator++(int); + void operator++() { (*this)++; } + + // XXX should check iterators are of same type + bool operator<(const class_iterator& o) { return _coviter < o._coviter; } + bool operator<=(const class_iterator& o) { return _coviter <= o._coviter; } + bool operator>=(const class_iterator& o) { return _coviter >= o._coviter; } + bool operator>(const class_iterator& o) { return _coviter > o._coviter; } + bool operator==(const class_iterator& o) { return _coviter == o._coviter; } + bool operator!=(const class_iterator& o) { return _coviter != o._coviter; } + + private: + String _str; + int _pos; + int _class; + Coverage::iterator _coviter; + friend class ClassDef; + class_iterator(const String&, int, int, const Coverage::iterator&); + void increment_class0(); + enum { FIRST_POS = -1, LAST_POS = -2 }; + }; + + // XXX does not work correctly for class 0 + class_iterator begin(int c) const { return class_iterator(_str, 0, c, Coverage::iterator()); } + class_iterator begin(int c, const Coverage& coverage) const { return class_iterator(_str, 0, c, coverage.begin()); } + class_iterator end(int c) const { return class_iterator(_str, _str.length(), c, Coverage::iterator()); } + + enum { T_LIST = 1, T_RANGES = 2, + LIST_HEADERSIZE = 6, LIST_RECSIZE = 2, + RANGES_HEADERSIZE = 4, RANGES_RECSIZE = 6 }; + + private: + + String _str; + + int check(ErrorHandler*); + +}; + +extern Vector<PermString> debug_glyph_names; + + +inline bool operator==(Tag t1, uint32_t t2) +{ + return t1.value() == t2; +} + +inline bool operator!=(Tag t1, uint32_t t2) +{ + return t1.value() != t2; +} + +inline bool operator<(Tag t1, uint32_t t2) +{ + return t1.value() < t2; +} + +inline bool operator>(Tag t1, uint32_t t2) +{ + return t1.value() > t2; +} + +inline bool operator<=(Tag t1, uint32_t t2) +{ + return t1.value() <= t2; +} + +inline bool operator>=(Tag t1, uint32_t t2) +{ + return t1.value() >= t2; +} + +inline bool operator==(Tag t1, Tag t2) +{ + return t1.value() == t2.value(); +} + +inline bool operator!=(Tag t1, Tag t2) +{ + return t1.value() != t2.value(); +} + +inline bool operator<(Tag t1, Tag t2) +{ + return t1.value() < t2.value(); +} + +inline ScriptList::ScriptList(const String& str, ErrorHandler* errh) +{ + assign(str, errh); +} + +inline FeatureList::FeatureList(const String& str, ErrorHandler* errh) +{ + assign(str, errh); +} + +inline void FeatureList::filter(Vector<int>& fids, Tag ftag) const +{ + Vector<Tag> tags; + tags.push_back(ftag); + filter(fids, tags); +} + +inline bool GlyphSet::covers(Glyph g) const +{ + if ((unsigned)g > MAXGLYPH) + return false; + else if (const uint32_t* u = _v[g >> SHIFT]) + return (u[(g & MASK) >> 5] & (1 << (g & 0x1F))) != 0; + else + return false; +} + +inline bool GlyphSet::operator[](Glyph g) const +{ + return covers(g); +} + +}} + +inline unsigned hashcode(Efont::OpenType::Tag t) +{ + return t.value(); +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfcmap.hh b/Build/source/texk/lcdf-typetools/include/efont/otfcmap.hh new file mode 100644 index 00000000000..7f732364bff --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfcmap.hh @@ -0,0 +1,54 @@ +// -*- related-file-name: "../../libefont/otfcmap.cc" -*- +#ifndef EFONT_OTFCMAP_HH +#define EFONT_OTFCMAP_HH +#include <efont/otf.hh> +#include <lcdf/error.hh> +namespace Efont { namespace OpenType { + +class Cmap { public: + + Cmap(const String &, ErrorHandler * = 0); + // default destructor + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + inline Glyph map_uni(uint32_t c) const; + int map_uni(const Vector<uint32_t> &in, Vector<Glyph> &out) const; + inline void unmap_all(Vector<uint32_t> &g2c) const; + + private: + + String _str; + int _error; + int _ntables; + int _first_unicode_table; + mutable Vector<int> _table_error; + + enum { HEADER_SIZE = 4, ENCODING_SIZE = 8, + HIBYTE_SUBHEADERS = 524 }; + enum Format { F_BYTE = 0, F_HIBYTE = 2, F_SEGMENTED = 4, F_TRIMMED = 6, + F_HIBYTE32 = 8, F_TRIMMED32 = 10, F_SEGMENTED32 = 12 }; + + int parse_header(ErrorHandler *); + int first_unicode_table() const { return _first_unicode_table; } + int first_table(int platform, int encoding) const; + int check_table(int t, ErrorHandler * = 0) const; + Glyph map_table(int t, uint32_t, ErrorHandler * = 0) const; + void dump_table(int t, Vector<uint32_t> &g2c, ErrorHandler * = 0) const; + +}; + + +inline Glyph Cmap::map_uni(uint32_t c) const +{ + return map_table(first_unicode_table(), c, ErrorHandler::default_handler()); +} + +inline void Cmap::unmap_all(Vector<uint32_t> &g2c) const +{ + dump_table(first_unicode_table(), g2c, ErrorHandler::default_handler()); +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfdata.hh b/Build/source/texk/lcdf-typetools/include/efont/otfdata.hh new file mode 100644 index 00000000000..b8df8b6dcbf --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfdata.hh @@ -0,0 +1,130 @@ +// -*- related-file-name: "../../libefont/otfdata.cc" -*- +#ifndef EFONT_OTFDATA_HH +#define EFONT_OTFDATA_HH +#include <lcdf/string.hh> +#include <lcdf/vector.hh> +#include <lcdf/inttypes.h> +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#if NEED_ARPA_INET_H +# include <arpa/inet.h> +#endif +#if HAVE_BYTEORDER_H +# include <byteorder.h> +#elif HAVE_NETINET_IN_H +# include <netinet/in.h> +#elif HAVE_SYS_PARAM_H +# include <sys/param.h> +#elif defined(WIN32) +# ifdef __MSC_VER +# pragma warning (disable: 4290) +# endif +# include <winsock2.h> +#else +# error "configury disaster! Report this error to kohler@icir.org" +#endif +class ErrorHandler; +namespace Efont { namespace OpenType { + +class Error { public: + String description; + Error() : description(String::stable_string("unspecified error")) { } + Error(const String &d) : description(d) { } +}; + +class Bounds : public Error { public: + Bounds() : Error(String::stable_string("bounds error")) { } +}; + +class Format : public Error { public: + Format(const String& name) : Error(name + " format error") { } + Format(const String& name, const String& type) + : Error(name + " " + type + " format error") { } +}; + +class BlankTable : public Format { public: + BlankTable(const String& name) : Format(name, "blank table") { } +}; + +class Data { public: + + Data() { } + Data(const String& str) : _str(str) { _str.align(2); } + // default copy constructor + // default destructor + + operator const String&() const { return _str; } + + operator bool() const { return _str; } + const uint8_t *udata() const { return _str.udata(); } + int length() const { return _str.length(); } + + inline uint8_t operator[](unsigned offset) const throw (Bounds); + inline uint16_t u16(unsigned offset) const throw (Bounds); + inline int16_t s16(unsigned offset) const throw (Bounds); + inline uint32_t u32(unsigned offset) const throw (Bounds); + inline int32_t s32(unsigned offset) const throw (Bounds); + + Data subtable(unsigned offset) const throw (Bounds); + Data offset_subtable(unsigned offset_offset) const throw (Bounds); + inline Data substring(int left, int len = -1) const throw (); + + void align_long() { _str.align(4); } + + private: + + String _str; + +}; + +inline uint8_t Data::operator[](unsigned offset) const throw (Bounds) +{ + if (offset >= static_cast<unsigned>(_str.length())) + throw Bounds(); + else + return _str[offset]; +} + +inline uint16_t Data::u16(unsigned offset) const throw (Bounds) +{ + if (offset + 1 >= static_cast<unsigned>(_str.length()) || offset + 1 == 0) + throw Bounds(); + else + return ntohs(*reinterpret_cast<const uint16_t *>(_str.data() + offset)); +} + +inline int16_t Data::s16(unsigned offset) const throw (Bounds) +{ + if (offset + 1 >= static_cast<unsigned>(_str.length()) || offset + 1 == 0) + throw Bounds(); + else + return ntohs(*reinterpret_cast<const int16_t *>(_str.data() + offset)); +} + +inline uint32_t Data::u32(unsigned offset) const throw (Bounds) +{ + if (offset + 3 >= static_cast<unsigned>(_str.length()) || offset + 3 < 3) + throw Bounds(); + else + return (ntohs(*reinterpret_cast<const uint16_t *>(_str.data() + offset)) << 16) + | ntohs(*reinterpret_cast<const uint16_t *>(_str.data() + offset + 2)); +} + +inline int32_t Data::s32(unsigned offset) const throw (Bounds) +{ + if (offset + 3 >= static_cast<unsigned>(_str.length()) || offset + 3 < 3) + throw Bounds(); + else + return (ntohs(*reinterpret_cast<const uint16_t *>(_str.data() + offset)) << 16) + | ntohs(*reinterpret_cast<const uint16_t *>(_str.data() + offset + 2)); +} + +inline Data +Data::substring(int left, int len) const throw () +{ + return Data(_str.substring(left, len)); +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfgpos.hh b/Build/source/texk/lcdf-typetools/include/efont/otfgpos.hh new file mode 100644 index 00000000000..bc274285485 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfgpos.hh @@ -0,0 +1,233 @@ +// -*- related-file-name: "../../libefont/otfgpos.cc" -*- +#ifndef EFONT_OTFGPOS_HH +#define EFONT_OTFGPOS_HH +#include <efont/otf.hh> +#include <efont/otfdata.hh> +namespace Efont { namespace OpenType { +class GposLookup; +class Positioning; + +class Gpos { public: + + Gpos(const Data &, ErrorHandler * = 0) throw (Error); + // default destructor + + const ScriptList &script_list() const { return _script_list; } + const FeatureList &feature_list() const { return _feature_list; } + + int nlookups() const; + GposLookup lookup(unsigned) const; + + enum { HEADERSIZE = 10 }; + + private: + + ScriptList _script_list; + FeatureList _feature_list; + Data _lookup_list; + +}; + +class GposLookup { public: + GposLookup(const Data &) throw (Error); + int type() const { return _type; } + uint16_t flags() const { return _d.u16(2); } + bool unparse_automatics(Vector<Positioning> &, ErrorHandler * = 0) const; + enum { + HEADERSIZE = 6, RECSIZE = 2, + L_SINGLE = 1, L_PAIR = 2, L_CURSIVE = 3, L_MARKTOBASE = 4, + L_MARKTOLIGATURE = 5, L_MARKTOMARK = 6, L_CONTEXT = 7, + L_CHAIN = 8, L_EXTENSION = 9 + }; + private: + Data _d; + int _type; + Data subtable(int i) const; +}; + +class GposValue { public: + static inline int size(uint16_t format); + static inline int16_t xplacement(uint16_t format, const Data &); + static inline int16_t yplacement(uint16_t format, const Data &); + static inline int16_t xadvance(uint16_t format, const Data &); + static inline int16_t yadvance(uint16_t format, const Data &); + enum { + F_XPLACEMENT = 0x0001, + F_YPLACEMENT = 0x0002, + F_XADVANCE = 0x0004, + F_YADVANCE = 0x0008, + F_XPLACEMENT_DEVICE = 0x0010, + F_YPLACEMENT_DEVICE = 0x0020, + F_XADVANCE_DEVICE = 0x0040, + F_YADVANCE_DEVICE = 0x0080 + }; + private: + static const int nibble_bitcount_x2[]; +}; + +class GposSingle { public: + GposSingle(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + void unparse(Vector<Positioning> &) const; + enum { F2_HEADERSIZE = 8 }; + private: + Data _d; +}; + +class GposPair { public: + GposPair(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + void unparse(Vector<Positioning> &) const; + enum { F1_HEADERSIZE = 10, F1_RECSIZE = 2, + PAIRSET_HEADERSIZE = 2, PAIRVALUE_HEADERSIZE = 2, + F2_HEADERSIZE = 16 }; + private: + Data _d; +}; + +struct Position { + Glyph g; + int pdx, pdy; // placement + int adx, ady; // advance + inline Position(); + inline Position(Glyph, uint16_t format, const Data &); + inline Position(uint16_t format, const Data &); + inline Position(Glyph, const Position &); + bool empty() const { return pdx == 0 && pdy == 0 && adx == 0 && ady == 0; } + operator bool() const { return !empty(); } + bool h_empty() const { return pdx == 0 && pdy == 0 && adx == 0; } + bool placed() const { return pdx != 0 || pdy != 0; } + void unparse(StringAccum &, const Vector<PermString> * = 0) const; + String unparse(const Vector<PermString> * = 0) const; +}; + +class Positioning { public: + + Positioning(); + + // single positioning + inline Positioning(const Position &); + + // pair positioning + inline Positioning(const Position &, const Position &); + + bool context_in(const Coverage &) const; + bool context_in(const GlyphSet &) const; + + // types + inline operator bool() const; + inline bool is_single() const; + inline bool is_pair() const; + inline bool is_pairkern() const; + + // extract data + const Position &left() const { return _left; } + Glyph left_glyph() const { return _left.g; } + const Position &right() const { return _right; } + Glyph right_glyph() const { return _right.g; } + + void unparse(StringAccum &, const Vector<PermString> * = 0) const; + String unparse(const Vector<PermString> * = 0) const; + + private: + + Position _left; + Position _right; + +}; + +inline int GposValue::size(uint16_t format) +{ + return (nibble_bitcount_x2[format & 15] + nibble_bitcount_x2[(format>>4) & 15]); +} + +inline int16_t GposValue::xplacement(uint16_t format, const Data &d) +{ + if (format & F_XPLACEMENT) + return d.s16(0); + else + return 0; +} + +inline int16_t GposValue::yplacement(uint16_t format, const Data &d) +{ + if (format & F_YPLACEMENT) + return d.s16((format & F_XPLACEMENT ? 2 : 0)); + else + return 0; +} + +inline int16_t GposValue::xadvance(uint16_t format, const Data &d) +{ + if (format & F_XADVANCE) + return d.s16(nibble_bitcount_x2[format & (F_XADVANCE - 1)]); + else + return 0; +} + +inline int16_t GposValue::yadvance(uint16_t format, const Data &d) +{ + if (format & F_YADVANCE) + return d.s16(nibble_bitcount_x2[format & (F_YADVANCE - 1)]); + else + return 0; +} + +inline Position::Position() + : g(0) +{ +} + +inline Position::Position(Glyph g_, uint16_t format, const Data &value) + : g(g_), + pdx(GposValue::xplacement(format, value)), pdy(GposValue::yplacement(format, value)), + adx(GposValue::xadvance(format, value)), ady(GposValue::yadvance(format, value)) +{ +} + +inline Position::Position(uint16_t format, const Data &value) + : g(0), + pdx(GposValue::xplacement(format, value)), pdy(GposValue::yplacement(format, value)), + adx(GposValue::xadvance(format, value)), ady(GposValue::yadvance(format, value)) +{ +} + +inline Position::Position(Glyph g_, const Position &p) + : g(g_), pdx(p.pdx), pdy(p.pdy), adx(p.adx), ady(p.ady) +{ +} + +inline Positioning::Positioning(const Position &left) + : _left(left) +{ +} + +inline Positioning::Positioning(const Position &left, const Position &right) + : _left(left), _right(right) +{ +} + +inline Positioning::operator bool() const +{ + return _left.g != 0; +} + +inline bool Positioning::is_single() const +{ + return _left.g != 0 && _right.g == 0; +} + +inline bool Positioning::is_pair() const +{ + return _left.g != 0 && _right.g != 0; +} + +inline bool Positioning::is_pairkern() const +{ + return _left.g != 0 && !_left.placed() && _right.g != 0 && _right.h_empty(); +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfgsub.hh b/Build/source/texk/lcdf-typetools/include/efont/otfgsub.hh new file mode 100644 index 00000000000..a930b12f7ab --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfgsub.hh @@ -0,0 +1,398 @@ +// -*- related-file-name: "../../libefont/otfgsub.cc" -*- +#ifndef EFONT_OTFGSUB_HH +#define EFONT_OTFGSUB_HH +#include <efont/otf.hh> +#include <efont/otfdata.hh> +namespace Efont { namespace OpenType { +class GsubLookup; +class Substitution; + +class Gsub { public: + + Gsub(const Data &, const Font *, ErrorHandler * = 0) throw (Error); + // default destructor + + const ScriptList &script_list() const { return _script_list; } + const FeatureList &feature_list() const { return _feature_list; } + bool chaincontext_reverse_backtrack() const { return _chaincontext_reverse_backtrack; } + + int nlookups() const; + GsubLookup lookup(unsigned) const; + + enum { HEADERSIZE = 10 }; + + private: + + ScriptList _script_list; + FeatureList _feature_list; + Data _lookup_list; + bool _chaincontext_reverse_backtrack; + +}; + +class GsubLookup { public: + GsubLookup(const Data &) throw (Error); + int type() const { return _type; } + uint16_t flags() const { return _d.u16(2); } + bool unparse_automatics(const Gsub &, Vector<Substitution> &) const; + bool apply(const Glyph *, int pos, int n, Substitution &) const; + enum { + HEADERSIZE = 6, RECSIZE = 2, + L_SINGLE = 1, L_MULTIPLE = 2, L_ALTERNATE = 3, L_LIGATURE = 4, + L_CONTEXT = 5, L_CHAIN = 6, L_EXTENSION = 7, L_REVCHAIN = 8 + }; + private: + Data _d; + int _type; + Data subtable(int i) const; +}; + +class GsubSingle { public: + GsubSingle(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + Glyph map(Glyph) const; + void unparse(Vector<Substitution> &) const; + bool apply(const Glyph *, int pos, int n, Substitution &) const; + enum { HEADERSIZE = 6, FORMAT2_RECSIZE = 2 }; + private: + Data _d; +}; + +class GsubMultiple { public: + GsubMultiple(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + bool map(Glyph, Vector<Glyph> &) const; + void unparse(Vector<Substitution> &, bool alternate = false) const; + bool apply(const Glyph *, int pos, int n, Substitution &, bool alternate = false) const; + enum { HEADERSIZE = 6, RECSIZE = 2, + SEQ_HEADERSIZE = 2, SEQ_RECSIZE = 2 }; + private: + Data _d; +}; + +class GsubLigature { public: + GsubLigature(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + bool map(const Vector<Glyph> &, Glyph &, int &) const; + void unparse(Vector<Substitution> &) const; + bool apply(const Glyph *, int pos, int n, Substitution &) const; + enum { HEADERSIZE = 6, RECSIZE = 2, + SET_HEADERSIZE = 2, SET_RECSIZE = 2, + LIG_HEADERSIZE = 4, LIG_RECSIZE = 2 }; + private: + Data _d; +}; + +class GsubContext { public: + GsubContext(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + bool unparse(const Gsub &, Vector<Substitution> &) const; + enum { F3_HSIZE = 6, SUBRECSIZE = 4 }; + private: + Data _d; + static bool f3_unparse(const Data &, int nglyph, int glyphtab_offset, int nsub, int subtab_offset, const Gsub &, Vector<Substitution> &, const Substitution &prototype_sub); + friend class GsubChainContext; +}; + +class GsubChainContext { public: + GsubChainContext(const Data &) throw (Error); + // default destructor + Coverage coverage() const throw (); + bool unparse(const Gsub &, Vector<Substitution> &) const; + enum { F1_HEADERSIZE = 6, F1_RECSIZE = 2, + F1_SRS_HSIZE = 2, F1_SRS_RSIZE = 2, + F3_HSIZE = 4, F3_INPUT_HSIZE = 2, F3_LOOKAHEAD_HSIZE = 2, F3_SUBST_HSIZE = 2 }; + private: + Data _d; +}; + +class Substitution { public: + + Substitution(); + Substitution(const Substitution &); + + // single substitution + Substitution(Glyph in, Glyph out); + + // multiple substitution + Substitution(Glyph in, const Vector<Glyph> &out, bool is_alternate = false); + + // ligature substitution + Substitution(Glyph in1, Glyph in2, Glyph out); + Substitution(const Vector<Glyph> &in, Glyph out); + Substitution(int nin, const Glyph *in, Glyph out); + + // space + Substitution(int nleft, int nin, int nout, int nright); + + ~Substitution(); + + Substitution &operator=(const Substitution &); + + bool context_in(const Coverage &) const; + bool context_in(const GlyphSet &) const; + + // types + inline operator bool() const; + bool is_noop() const; + inline bool is_single() const; + inline bool is_multiple() const; + inline bool is_alternate() const; + inline bool is_ligature() const; + inline bool is_simple_context() const; + inline bool is_single_lcontext() const; + inline bool is_single_rcontext() const; + inline bool is_lcontext() const; + inline bool is_rcontext() const; + + // extract data + inline Glyph left_glyph() const; + inline int left_nglyphs() const; + inline Glyph *left_glyphptr(); + inline const Glyph *left_glyphptr() const; + + inline Glyph in_glyph() const; + inline Glyph in_glyph(int pos) const; + inline bool in_glyphs(Vector<Glyph> &) const; + inline int in_nglyphs() const; + inline Glyph *in_glyphptr(); + inline const Glyph *in_glyphptr() const; + + inline bool in_matches(int pos, Glyph) const; + + inline Glyph out_glyph() const; + inline Glyph out_glyph(int pos) const; + inline bool out_glyphs(Vector<Glyph> &) const; + inline Glyph *out_glyphptr(); + inline const Glyph *out_glyphptr() const; + + inline int out_nglyphs() const; + inline Glyph right_glyph() const; + inline Glyph *right_glyphptr(); + inline const Glyph *right_glyphptr() const; + + bool all_in_glyphs(Vector<Glyph> &) const; + bool all_out_glyphs(Vector<Glyph> &) const; + + // alter + void add_outer_left(Glyph); + void remove_outer_left(); + Substitution in_out_append_glyph(Glyph) const; + bool out_alter(const Substitution &, int) throw (); + void add_outer_right(Glyph); + void remove_outer_right(); + + void unparse(StringAccum &, const Vector<PermString> * = &debug_glyph_names) const; + String unparse(const Vector<PermString> * = &debug_glyph_names) const; + + private: + + enum { T_NONE = 0, T_GLYPH, T_GLYPHS, T_COVERAGE }; + typedef union { + Glyph gid; + Glyph *gids; // first entry is a count + Coverage *coverage; + } Substitute; + + Substitute _left; + Substitute _in; + Substitute _out; + Substitute _right; + + uint8_t _left_is; + uint8_t _in_is; + uint8_t _out_is; + uint8_t _right_is; + + bool _alternate : 1; + + static void clear(Substitute &, uint8_t &); + static void assign_space(Substitute &, uint8_t &, int); + static void assign(Substitute &, uint8_t &, Glyph); + static void assign(Substitute &, uint8_t &, int, const Glyph *); + static void assign(Substitute &, uint8_t &, const Coverage &); + static void assign(Substitute &, uint8_t &, const Substitute &, uint8_t); + static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, const Substitute &, uint8_t); + static void assign_append(Substitute &, uint8_t &, const Substitute &, uint8_t, Glyph); + static bool substitute_in(const Substitute &, uint8_t, const Coverage &); + static bool substitute_in(const Substitute &, uint8_t, const GlyphSet &); + + static Glyph extract_glyph(const Substitute &, uint8_t) throw (); + static Glyph extract_glyph(const Substitute &, int which, uint8_t) throw (); + static bool extract_glyphs(const Substitute &, uint8_t, Vector<Glyph> &, bool coverage_ok) throw (); + static Glyph *extract_glyphptr(const Substitute &, uint8_t) throw (); + static int extract_nglyphs(const Substitute &, uint8_t, bool coverage_ok) throw (); + static bool matches(const Substitute &, uint8_t, int pos, Glyph) throw (); + + static void unparse_glyphids(StringAccum &, const Substitute &, uint8_t, const Vector<PermString> *) throw (); + +}; + +inline Substitution::Substitution() + : _left_is(T_NONE), _in_is(T_NONE), _out_is(T_NONE), _right_is(T_NONE) +{ +} + +/* Single 1: u16 format, offset coverage, u16 glyphdelta + Single 2: u16 format, offset coverage, u16 count, glyph subst[] + Multiple 1: u16 format, offset coverage, u16 count, offset sequence[]; + sequence is: u16 count, glyph subst[] + Alternate 1: u16 format, offset coverage, u16 count, offset alternates[]; + alternate is: u16 count, glyph alts[] + Ligature 1: u16 format, offset coverage, u16 count, offset sets[]; + set is: u16 count, offset ligatures[]; + ligature is: glyph result, u16 count, glyph components[] +*/ + +inline Substitution::operator bool() const +{ + return !(_left_is == T_NONE && _in_is == T_NONE && _out_is == T_NONE && _right_is == T_NONE); +} + +inline bool Substitution::is_single() const +{ + return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_NONE; +} + +inline bool Substitution::is_multiple() const +{ + return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPHS && _right_is == T_NONE && !_alternate; +} + +inline bool Substitution::is_alternate() const +{ + return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPHS && _right_is == T_NONE && _alternate; +} + +inline bool Substitution::is_ligature() const +{ + return _left_is == T_NONE && _in_is == T_GLYPHS && _out_is == T_GLYPH && _right_is == T_NONE; +} + +inline bool Substitution::is_simple_context() const +{ + return _left_is != T_COVERAGE && (_in_is == T_GLYPH || _in_is == T_GLYPHS) && (_out_is == T_GLYPH || _out_is == T_GLYPHS) && _right_is != T_COVERAGE; +} + +inline bool Substitution::is_single_lcontext() const +{ + return _left_is == T_GLYPH && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_NONE; +} + +inline bool Substitution::is_single_rcontext() const +{ + return _left_is == T_NONE && _in_is == T_GLYPH && _out_is == T_GLYPH && _right_is == T_GLYPH; +} + +inline Glyph Substitution::left_glyph() const +{ + return extract_glyph(_left, _left_is); +} + +inline int Substitution::left_nglyphs() const +{ + return extract_nglyphs(_left, _left_is, false); +} + +inline Glyph Substitution::in_glyph() const +{ + return extract_glyph(_in, _in_is); +} + +inline Glyph Substitution::in_glyph(int which) const +{ + return extract_glyph(_in, which, _in_is); +} + +inline bool Substitution::in_glyphs(Vector<Glyph> &v) const +{ + return extract_glyphs(_in, _in_is, v, true); +} + +inline int Substitution::in_nglyphs() const +{ + return extract_nglyphs(_in, _in_is, true); +} + +inline bool Substitution::in_matches(int pos, Glyph g) const +{ + return matches(_in, _in_is, pos, g); +} + +inline Glyph Substitution::out_glyph() const +{ + return extract_glyph(_out, _out_is); +} + +inline Glyph Substitution::out_glyph(int which) const +{ + return extract_glyph(_out, which, _out_is); +} + +inline bool Substitution::out_glyphs(Vector<Glyph> &v) const +{ + return extract_glyphs(_out, _out_is, v, false); +} + +inline int Substitution::out_nglyphs() const +{ + return extract_nglyphs(_out, _out_is, false); +} + +inline Glyph Substitution::right_glyph() const +{ + return extract_glyph(_right, _right_is); +} + +inline const Glyph *Substitution::left_glyphptr() const +{ + return extract_glyphptr(_left, _left_is); +} + +inline Glyph *Substitution::left_glyphptr() +{ + return extract_glyphptr(_left, _left_is); +} + +inline const Glyph *Substitution::in_glyphptr() const +{ + return extract_glyphptr(_in, _in_is); +} + +inline Glyph *Substitution::in_glyphptr() +{ + return extract_glyphptr(_in, _in_is); +} + +inline const Glyph *Substitution::out_glyphptr() const +{ + return extract_glyphptr(_out, _out_is); +} + +inline Glyph *Substitution::out_glyphptr() +{ + return extract_glyphptr(_out, _out_is); +} + +inline const Glyph *Substitution::right_glyphptr() const +{ + return extract_glyphptr(_right, _right_is); +} + +inline Glyph *Substitution::right_glyphptr() +{ + return extract_glyphptr(_right, _right_is); +} + +inline StringAccum &operator<<(StringAccum &sa, const Substitution &sub) +{ + sub.unparse(sa); + return sa; +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfname.hh b/Build/source/texk/lcdf-typetools/include/efont/otfname.hh new file mode 100644 index 00000000000..7643b66923d --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfname.hh @@ -0,0 +1,134 @@ +// -*- related-file-name: "../../libefont/otfname.cc" -*- +#ifndef EFONT_OTFNAME_HH +#define EFONT_OTFNAME_HH +#include <efont/otf.hh> +#include <efont/otfdata.hh> // for ntohl() +#include <lcdf/error.hh> +namespace Efont { namespace OpenType { + +class Name { public: + + Name(const String &, ErrorHandler * = 0); + // default destructor + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + enum NameID { N_COPYRIGHT = 0, N_FAMILY = 1, N_SUBFAMILY = 2, + N_UNIQUEID = 3, N_FULLNAME = 4, N_VERSION = 5, + N_POSTSCRIPT = 6, N_TRADEMARK = 7, N_MANUFACTURER = 8, + N_DESIGNER = 9, N_DESCRIPTION = 10, N_VENDOR_URL = 11, + N_DESIGNER_URL = 12, N_LICENSE_DESCRIPTION = 13, + N_LICENSE_URL = 14, N_PREF_FAMILY = 16, + N_PREF_SUBFAMILY = 17, N_MAC_COMPAT_FULLNAME = 18, + N_SAMPLE_TEXT = 19, N_POSTSCRIPT_CID = 20 }; + enum Platform { P_UNICODE = 0, P_MACINTOSH = 1, P_MICROSOFT = 3, + E_MS_UNICODE_BMP = 1, E_MAC_ROMAN = 0, + L_MS_ENGLISH_AMERICAN = 0x409 }; + enum { HEADER_SIZE = 6, NAMEREC_SIZE = 12 }; + + typedef uint8_t namerecord_t[NAMEREC_SIZE]; + typedef const namerecord_t *const_iterator; + + inline static int nameid(const namerecord_t &); + inline static int platform(const namerecord_t &); + inline static int encoding(const namerecord_t &); + inline static int language(const namerecord_t &); + + inline const_iterator begin() const; + inline const_iterator end() const; + String name(const_iterator) const; + String utf8_name(const_iterator) const; + String english_name(int nameid) const; + + // check version string for backwards compatibility + bool version_chaincontext_reverse_backtrack() const; + + struct PlatformPred { + inline PlatformPred(int nameid, int platform = -1, int encoding = -1, int language = -1); + inline bool operator()(const namerecord_t &) const; + private: + int _nameid, _platform, _encoding, _language; + }; + + struct EnglishPlatformPred { + EnglishPlatformPred(int nameid) : _nameid(nameid) { } + inline bool operator()(const namerecord_t &) const; + private: + int _nameid; + }; + + private: + + String _str; + int _error; + + int parse_header(ErrorHandler *); + +}; + + +#define USHORT_AT(d) (ntohs(*reinterpret_cast<const uint16_t *>(d))) + +inline int Name::nameid(const namerecord_t &nr) +{ + return USHORT_AT(reinterpret_cast<const uint8_t *>(&nr) + 6); +} + +inline int Name::platform(const namerecord_t &nr) +{ + return USHORT_AT(reinterpret_cast<const uint8_t *>(&nr)); +} + +inline int Name::encoding(const namerecord_t &nr) +{ + return USHORT_AT(reinterpret_cast<const uint8_t *>(&nr) + 2); +} + +inline int Name::language(const namerecord_t &nr) +{ + return USHORT_AT(reinterpret_cast<const uint8_t *>(&nr) + 4); +} + +inline Name::const_iterator Name::begin() const +{ + return reinterpret_cast<const_iterator>(_str.udata() + HEADER_SIZE); +} + +inline Name::const_iterator Name::end() const +{ + if (_error >= 0) { + int count = USHORT_AT(_str.data() + 2); + return reinterpret_cast<const_iterator>(_str.udata() + HEADER_SIZE + NAMEREC_SIZE * count); + } else + return reinterpret_cast<const_iterator>(_str.udata() + HEADER_SIZE); +} + +#undef USHORT_AT + + +inline Name::PlatformPred::PlatformPred(int nid, int p, int e, int l) + : _nameid(nid), _platform(p), _encoding(e), _language(l) +{ +} + +inline bool Name::PlatformPred::operator()(const namerecord_t &i) const +{ + return (_nameid == nameid(i)) + && (_platform < 0 || _platform == platform(i)) + && (_encoding < 0 || _encoding == encoding(i)) + && (_language < 0 || _language == language(i)); +} + +inline bool Name::EnglishPlatformPred::operator()(const namerecord_t &i) const +{ + if (_nameid == nameid(i)) { + int p = platform(i), e = encoding(i), l = language(i); + return (p == P_MACINTOSH && e == E_MAC_ROMAN && l == 0) + || (p == P_MICROSOFT && e == E_MS_UNICODE_BMP && l == L_MS_ENGLISH_AMERICAN); + } else + return false; +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfos2.hh b/Build/source/texk/lcdf-typetools/include/efont/otfos2.hh new file mode 100644 index 00000000000..23cc513715a --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfos2.hh @@ -0,0 +1,69 @@ +// -*- related-file-name: "../../libefont/otfos2.cc" -*- +#ifndef EFONT_OTFOS2_HH +#define EFONT_OTFOS2_HH +#include <efont/otf.hh> +#include <efont/otfdata.hh> +#include <lcdf/error.hh> +namespace Efont { namespace OpenType { + +class Os2 { public: + + Os2(const Data &, ErrorHandler * = 0); + // default destructor + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + enum Offsets { O_AVGCHARWIDTH = 2, O_SUBSCRIPTXSIZE = 10, + O_SUBSCRIPTYSIZE = 12, O_SUBSCRIPTXOFFSET = 14, + O_SUBSCRIPTYOFFSET = 16, O_SUPERSCRIPTXSIZE = 18, + O_SUPERSCRIPTYSIZE = 20, O_SUPERSCRIPTXOFFSET = 22, + O_SUPERSCRIPTYOFFSET = 24, O_STRIKEOUTSIZE = 26, + O_STRIKEOUTPOSITION = 28, O_TYPOASCENDER = 68, + O_TYPODESCENDER = 70, O_TYPOLINEGAP = 72, + O_XHEIGHT = 86, O_CAPHEIGHT = 88 }; + enum { HEADER_SIZE = 2 }; + + inline int16_t typo_ascender() const throw (Bounds); + inline int16_t typo_descender() const throw (Bounds); + inline int16_t typo_line_gap() const throw (Bounds); + inline int16_t x_height() const throw (Bounds); + inline int16_t cap_height() const throw (Bounds); + + private: + + Data _data; + int _error; + + int parse_header(ErrorHandler *); + +}; + + +inline int16_t Os2::typo_ascender() const throw (Bounds) +{ + return _data.s16(O_TYPOASCENDER); +} + +inline int16_t Os2::typo_descender() const throw (Bounds) +{ + return _data.s16(O_TYPODESCENDER); +} + +inline int16_t Os2::typo_line_gap() const throw (Bounds) +{ + return _data.s16(O_TYPOLINEGAP); +} + +inline int16_t Os2::x_height() const throw (Bounds) +{ + return _data.s16(O_XHEIGHT); +} + +inline int16_t Os2::cap_height() const throw (Bounds) +{ + return _data.s16(O_CAPHEIGHT); +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/otfpost.hh b/Build/source/texk/lcdf-typetools/include/efont/otfpost.hh new file mode 100644 index 00000000000..4d7ff64146c --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/otfpost.hh @@ -0,0 +1,62 @@ +// -*- related-file-name: "../../libefont/otfpost.cc" -*- +#ifndef EFONT_OTFPOST_HH +#define EFONT_OTFPOST_HH +#include <efont/otfdata.hh> +#include <lcdf/error.hh> +namespace Efont { namespace OpenType { + +class Post { public: + + Post(const String &, ErrorHandler * = 0); + // default destructor + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + double italic_angle() const; + bool is_fixed_pitch() const; + inline int underline_position() const; + inline int underline_thickness() const; + inline uint32_t mem_type42(bool ismax) const; + int nglyphs() const { return _nglyphs; } + bool glyph_names(Vector<PermString> &gnames) const; + + private: + + Data _str; + int _error; + uint32_t _version; + int _nglyphs; + Vector<int> _extend_glyph_names; + + enum { HEADER_SIZE = 32, N_MAC_GLYPHS = 258 }; + int parse_header(ErrorHandler *); + +}; + +inline int +Post::underline_position() const +{ + // NB: "This is the suggested distance of the top of the underline from + // the baseline (negative values indicate below baseline). The PostScript + // definition of this FontInfo dictionary key (the y coordinate of the + // center of the stroke) is not used for historical reasons. The value of + // the PostScript key may be calculated by subtracting half the + // underlineThickness from the value of this field." -- OpenType spec + return ok() ? _str.s16(8) : 0; +} + +inline int +Post::underline_thickness() const +{ + return ok() ? _str.s16(10) : 0; +} + +inline uint32_t +Post::mem_type42(bool ismax) const +{ + return ok() ? _str.u32(ismax ? 20 : 16) : 0; +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/pairop.hh b/Build/source/texk/lcdf-typetools/include/efont/pairop.hh new file mode 100644 index 00000000000..c445f16624a --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/pairop.hh @@ -0,0 +1,113 @@ +// -*- related-file-name: "../../libefont/pairop.cc" -*- +#ifndef PAIROP_HH +#define PAIROP_HH +#include <efont/encoding.hh> /* get GlyphIndex */ +namespace Efont { + +enum PairOpDefs { + + opNoop = -1, + opLigature = -2, + + opLigSimple = 0, + opLigSaveLeft = 1, + opLigSaveRight = 2, + opLigPast1 = 4, + opLigPast2 = 8, + + opAllblock = 0 + +}; + + +typedef int PairOpIndex; + + +class PairOp { public: + + PairOp() { } + inline PairOp(GlyphIndex l, GlyphIndex r, int v, PairOpIndex nl); + inline PairOp(GlyphIndex l, GlyphIndex r, GlyphIndex x, int kind, PairOpIndex nl); + + void noopify() { _val = opNoop; } + void set_value(int val) { _val = val; } + + inline void set_next(PairOpIndex); + + bool is_lig() const { return _val <= opLigature; } + bool is_kern() const { return _val >= 0; } + bool is_noop() const { return _val == opNoop; } + int lig_kind() const { assert(is_lig()); return -_val+opLigature; } + + GlyphIndex left() const { return _left; } + GlyphIndex right() const { return _right; } + GlyphIndex result() const { assert(is_lig()); return _result; } + int value() const { return _val; } + PairOpIndex next_left() const { return _next_left; } + + private: + + GlyphIndex _left; + GlyphIndex _right; + GlyphIndex _result; + int _val; + + PairOpIndex _next_left; + +}; + + +class PairProgram { public: + + PairProgram() : _reversed(false) { } + PairProgram(const PairProgram &); + + void reserve_glyphs(int); + + PairOpIndex find_left(GlyphIndex gi) const { return _left_map[gi]; } + PairOpIndex find(GlyphIndex leftgi, GlyphIndex rightgi) const; + + int op_count() const { return _op.size(); } + const PairOp &op(PairOpIndex i) const { return _op[i]; } + + // Return true if it's a duplicate. + bool add_kern(GlyphIndex, GlyphIndex, int); + bool add_lig(GlyphIndex, GlyphIndex, GlyphIndex, int kind = opLigSimple); + + void set_reversed(bool r) { _reversed = r; } + void unreverse(); + void optimize(); + + void print() const; + + private: + + bool _reversed; + Vector<PairOpIndex> _left_map; + Vector<PairOp> _op; + + inline const char *print_name(GlyphIndex) const; + + PairProgram &operator=(const PairProgram &) { assert(0); return *this; } + +}; + + +inline PairOp::PairOp(GlyphIndex l, GlyphIndex r, int v, PairOpIndex nl) + : _left(l), _right(r), _result(), _val(v), _next_left(nl) +{ +} + +inline PairOp::PairOp(GlyphIndex l, GlyphIndex r, GlyphIndex x, int kind, + PairOpIndex nl) + : _left(l), _right(r), _result(x), _val(opLigature - kind), _next_left(nl) +{ +} + +inline void PairOp::set_next(PairOpIndex nl) +{ + _next_left = nl; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/psres.hh b/Build/source/texk/lcdf-typetools/include/efont/psres.hh new file mode 100644 index 00000000000..b08e2fe35a5 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/psres.hh @@ -0,0 +1,74 @@ +// -*- related-file-name: "../../libefont/psres.cc" -*- +#ifndef EFONT_PSRES_HH +#define EFONT_PSRES_HH +#include <lcdf/vector.hh> +#include <lcdf/hashmap.hh> +#include <lcdf/string.hh> +#include <lcdf/filename.hh> +class Slurper; +namespace Efont { +class PsresDatabaseSection; + +class PsresDatabase { public: + + PsresDatabase(); + ~PsresDatabase(); + + void add_psres_path(const char* path, const char* defaults, bool override); + bool add_psres_file(Filename&, bool override); + void add_database(PsresDatabase*, bool override); + + inline PsresDatabaseSection* section(PermString section) const; + const String& value(PermString section, PermString key) const; + const String& unescaped_value(PermString section, PermString key) const; + Filename filename_value(PermString section, PermString key) const; + + private: + + HashMap<PermString, int> _section_map; + Vector<PsresDatabaseSection*> _sections; + + PsresDatabaseSection* force_section(PermString); + bool add_one_psres_file(Slurper&, bool override); + void add_psres_directory(PermString); + +}; + +class PsresDatabaseSection { public: + + PsresDatabaseSection(PermString); + + PermString section_name() const { return _section_name; } + + void add_psres_file_section(Slurper&, PermString, bool); + void add_section(PsresDatabaseSection*, bool override); + + const String& value(PermString key) { return value(_map[key]); } + inline const String& unescaped_value(PermString key) const; + Filename filename_value(PermString key); + + private: + + PermString _section_name; + HashMap<PermString, int> _map; + Vector<PermString> _directories; + Vector<String> _values; + Vector<int> _value_escaped; + + const String& value(int index); + +}; + +inline PsresDatabaseSection* PsresDatabase::section(PermString n) const +{ + return _sections[_section_map[n]]; +} + +inline const String& PsresDatabaseSection::unescaped_value(PermString key) const +{ + assert(!_value_escaped[_map[key]]); + return _values[_map[key]]; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1bounds.hh b/Build/source/texk/lcdf-typetools/include/efont/t1bounds.hh new file mode 100644 index 00000000000..116705f9a10 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1bounds.hh @@ -0,0 +1,93 @@ +// -*- related-file-name: "../../libefont/t1bounds.cc" -*- +#ifndef EFONT_T1BOUNDS_HH +#define EFONT_T1BOUNDS_HH +#include <efont/t1interp.hh> +#include <lcdf/transform.hh> +namespace Efont { + +class CharstringBounds : public CharstringInterp { public: + + CharstringBounds(); + CharstringBounds(const Transform&); + CharstringBounds(const Transform&, const Vector<double>& weight_vec); + ~CharstringBounds() { } + + const Point& width() const { return _width; } + double x_width() const { return _width.x; } + bool bb_known() const { return KNOWN(_lb.x); } + double bb_left() const { return _lb.x; } + double bb_top() const { return _rt.y; } + double bb_right() const { return _rt.x; } + double bb_bottom() const { return _lb.y; } + const Point& bb_bottom_left() const { return _lb; } + const Point& bb_top_right() const { return _rt; } + + void act_width(int, const Point&); + void act_line(int, const Point&, const Point&); + void act_curve(int, const Point&, const Point&, const Point&, const Point&); + inline void mark(const Point&); + + void clear(); + bool char_bounds(const CharstringContext&, bool shift = true); + void translate(double dx, double dy); + inline Point transform(const Point &) const; + bool output(int bb[4], int& width, bool use_cur_width = false) const; + + static bool bounds(const CharstringContext&, int bounds[4], int& width); + static bool bounds(const Transform&, const CharstringContext&, int bounds[4], int& width); + + private: + + Point _lb; + Point _rt; + Point _width; + Transform _xf; + Transform _nonfont_xf; + const CharstringProgram* _last_xf_program; + + void set_xf(const CharstringProgram*); + + inline void xf_mark(const Point&); + void xf_mark(const Bezier&); + + inline bool xf_inside(const Point&) const; + inline bool xf_controls_inside(const Bezier&) const; + +}; + +inline void CharstringBounds::xf_mark(const Point& p) +{ + if (!KNOWN(_lb.x)) + _lb = _rt = p; + if (p.x < _lb.x) + _lb.x = p.x; + else if (p.x > _rt.x) + _rt.x = p.x; + if (p.y < _lb.y) + _lb.y = p.y; + else if (p.y > _rt.y) + _rt.y = p.y; +} + +inline void CharstringBounds::mark(const Point& p) +{ + xf_mark(p * _xf); +} + +inline bool CharstringBounds::xf_inside(const Point& p) const +{ + return p.x >= _lb.x && p.x <= _rt.x && p.y >= _lb.y && p.y <= _rt.y; +} + +inline bool CharstringBounds::xf_controls_inside(const Bezier& b) const +{ + return xf_inside(b.point(1)) && xf_inside(b.point(2)); +} + +inline Point CharstringBounds::transform(const Point& p) const +{ + return p * _xf; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1cs.hh b/Build/source/texk/lcdf-typetools/include/efont/t1cs.hh new file mode 100644 index 00000000000..35816f6f64e --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1cs.hh @@ -0,0 +1,340 @@ +// -*- related-file-name: "../../libefont/t1cs.cc" -*- +#ifndef EFONT_T1CS_HH +#define EFONT_T1CS_HH +#include <lcdf/permstr.hh> +#include <lcdf/string.hh> +#include <lcdf/vector.hh> +#include <lcdf/inttypes.h> +namespace Efont { + +// Allow unknown doubles to have some `fuzz' -- so if an unknown double +// is a bit off from the canonical UNKDOUBLE value, we'll still recognize +// it as unknown. (Useful for interpolation.) +#define UNKDOUBLE -9.79797e97 +#define MIN_KNOWN_DOUBLE -9.69696e97 +#define KNOWN(d) ((d) >= MIN_KNOWN_DOUBLE) + +class CharstringProgram; +class CharstringInterp; +struct CharstringContext; +class MultipleMasterSpace; +class Type1Encoding; + +class Charstring { public: + + Charstring() { } + virtual ~Charstring(); + + virtual bool process(CharstringInterp &) const = 0; + + enum Commands { + cError = 0, + cHstem = 1, + cVstem = 3, + cVmoveto = 4, + cRlineto = 5, + cHlineto = 6, + cVlineto = 7, + cRrcurveto = 8, + cClosepath = 9, + cCallsubr = 10, + cReturn = 11, + cEscape = 12, + cHsbw = 13, + cEndchar = 14, + cBlend = 16, + cHstemhm = 18, + cHintmask = 19, + cCntrmask = 20, + cRmoveto = 21, + cHmoveto = 22, + cVstemhm = 23, + cRcurveline = 24, + cRlinecurve = 25, + cVvcurveto = 26, + cHhcurveto = 27, + cShortint = 28, + cCallgsubr = 29, + cVhcurveto = 30, + cHvcurveto = 31, + + cEscapeDelta = 32, + cDotsection = 32 + 0, + cVstem3 = 32 + 1, + cHstem3 = 32 + 2, + cAnd = 32 + 3, + cOr = 32 + 4, + cNot = 32 + 5, + cSeac = 32 + 6, + cSbw = 32 + 7, + cStore = 32 + 8, + cAbs = 32 + 9, + cAdd = 32 + 10, + cSub = 32 + 11, + cDiv = 32 + 12, + cLoad = 32 + 13, + cNeg = 32 + 14, + cEq = 32 + 15, + cCallothersubr = 32 + 16, + cPop = 32 + 17, + cDrop = 32 + 18, + cPut = 32 + 20, + cGet = 32 + 21, + cIfelse = 32 + 22, + cRandom = 32 + 23, + cMul = 32 + 24, + cSqrt = 32 + 26, + cDup = 32 + 27, + cExch = 32 + 28, + cIndex = 32 + 29, + cRoll = 32 + 30, + cSetcurrentpoint = 32 + 33, + cHflex = 32 + 34, + cFlex = 32 + 35, + cHflex1 = 32 + 36, + cFlex1 = 32 + 37, + + cLastCommand = cFlex1 + }; + + enum OthersubrCommands { + othcFlexend = 0, + othcFlexbegin = 1, + othcFlexmiddle = 2, + othcReplacehints = 3, + othcMM1 = 14, + othcMM2 = 15, + othcMM3 = 16, + othcMM4 = 17, + othcMM6 = 18, + othcITC_load = 19, + othcITC_add = 20, + othcITC_sub = 21, + othcITC_mul = 22, + othcITC_div = 23, + othcITC_put = 24, + othcITC_get = 25, + othcITC_unknown = 26, + othcITC_ifelse = 27, + othcITC_random = 28 + }; + + static String command_name(int); + static const char * const command_names[]; + + static const char * const standard_encoding[256]; + +}; + + +class Type1Charstring : public Charstring { public: + + Type1Charstring() { } + inline Type1Charstring(const String &); // unencrypted + Type1Charstring(int lenIV, const String &); // encrypted + // default copy constructor + // default destructor + // default assignment operator + + inline const uint8_t *data() const; + int length() const { return _s.length(); } + operator bool() const { return _s.length() != 0; } + + inline const String &data_string() const; + inline String substring(int pos, int len) const; + int first_caret_after(int pos) const; + + inline void assign(const String &); + void prepend(const Type1Charstring &); + void assign_substring(int pos, int len, const String &); + + bool process(CharstringInterp &) const; + + private: + + mutable String _s; + mutable int _key; + + void decrypt() const; + +}; + + +class Type2Charstring : public Charstring { public: + + Type2Charstring() { } + inline Type2Charstring(const String &); + // default copy constructor + // default destructor + // default assignment operator + + inline const uint8_t *data() const; + int length() const { return _s.length(); } + + bool process(CharstringInterp &) const; + + private: + + String _s; + +}; + + +struct CharstringContext { + + CharstringContext(const CharstringProgram *program_, const Charstring *cs_) : program(program_), cs(cs_) { } + + operator bool() const { return cs != 0; } + + const CharstringProgram *program; + const Charstring *cs; + +}; + + +class CharstringProgram { public: + + CharstringProgram() : _parent_program(false) { } + virtual ~CharstringProgram() { } + + virtual PermString font_name() const { return PermString(); } + virtual void font_matrix(double[6]) const; + virtual int units_per_em() const; + + inline const CharstringProgram *program(int) const; + virtual const CharstringProgram *child_program(int) const; + bool parent_program() const { return _parent_program; } + void set_parent_program(bool pp) { _parent_program = pp; } + + virtual int nsubrs() const { return 0; } + virtual Charstring *subr(int) const { return 0; } + virtual int subr_bias() const { return 0; } + + virtual int ngsubrs() const { return 0; } + virtual Charstring *gsubr(int) const { return 0; } + virtual int gsubr_bias() const { return 0; } + + inline int nxsubrs(bool g) const; + inline Charstring *xsubr(bool g, int) const; + inline int xsubr_bias(bool g) const; + + virtual int nglyphs() const { return 0; } + virtual PermString glyph_name(int) const { return PermString();} + virtual void glyph_names(Vector<PermString> &) const; + virtual Charstring *glyph(int) const { return 0; } + virtual Charstring *glyph(PermString) const { return 0; } + + inline CharstringContext glyph_context(int) const; + inline CharstringContext glyph_context(PermString) const; + + virtual bool is_mm() const { return mmspace() != 0; } + virtual MultipleMasterSpace *mmspace() const { return 0; } + enum VectorType { VEC_WEIGHT = 0, VEC_NORM_DESIGN = 1, VEC_DESIGN = 2 }; + virtual Vector<double> *mm_vector(VectorType, bool writable) const; + + virtual Type1Encoding *type1_encoding() const { return 0; } + + virtual double global_width_x(bool is_nominal) const; + + private: + + bool _parent_program; + +}; + + +enum Type1Defs { + t1Warmup_ee = 4, + t1R_ee = 55665, + t1R_cs = 4330, + t1C1 = 52845, + t1C2 = 22719 +}; + + +inline Type1Charstring::Type1Charstring(const String &s) + : Charstring(), _s(s), _key(-1) +{ +} + +inline void Type1Charstring::assign(const String &s) +{ + _s = s; + _key = -1; +} + +inline const uint8_t *Type1Charstring::data() const +{ + if (_key >= 0) + decrypt(); + return reinterpret_cast<const uint8_t *>(_s.data()); +} + +inline const String &Type1Charstring::data_string() const +{ + if (_key >= 0) + decrypt(); + return _s; +} + +inline String Type1Charstring::substring(int pos, int len) const +{ + if (_key >= 0) + decrypt(); + return _s.substring(pos, len); +} + +inline bool operator==(const Type1Charstring &a, const Type1Charstring &b) +{ + return a.data_string() == b.data_string(); +} + + +inline Type2Charstring::Type2Charstring(const String &s) + : _s(s) +{ +} + +inline const uint8_t *Type2Charstring::data() const +{ + return reinterpret_cast<const uint8_t *>(_s.data()); +} + + +inline int CharstringProgram::nxsubrs(bool g) const +{ + return (g ? ngsubrs() : nsubrs()); +} + +inline Charstring *CharstringProgram::xsubr(bool g, int i) const +{ + return (g ? gsubr(i) : subr(i)); +} + +inline int CharstringProgram::xsubr_bias(bool g) const +{ + return (g ? gsubr_bias() : subr_bias()); +} + +inline const CharstringProgram *CharstringProgram::program(int gi) const +{ + return (_parent_program ? child_program(gi) : this); +} + +inline CharstringContext CharstringProgram::glyph_context(int gi) const +{ + if (!_parent_program) + return CharstringContext(this, glyph(gi)); + else if (const CharstringProgram *p = child_program(gi)) + return CharstringContext(p, p->glyph(gi)); + else + return CharstringContext(0, 0); +} + +inline CharstringContext CharstringProgram::glyph_context(PermString gn) const +{ + return CharstringContext(this, glyph(gn)); +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1csgen.hh b/Build/source/texk/lcdf-typetools/include/efont/t1csgen.hh new file mode 100644 index 00000000000..8c054643f86 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1csgen.hh @@ -0,0 +1,119 @@ +// -*- related-file-name: "../../libefont/t1csgen.cc" -*- +#ifndef EFONT_T1CSGEN_HH +#define EFONT_T1CSGEN_HH +#include <efont/t1interp.hh> +#include <lcdf/straccum.hh> +namespace Efont { +class Type1Font; + +class Type1CharstringGen { public: + + Type1CharstringGen(int precision = 5); + + int precision() const { return _precision; } + + void clear(); + char *data() const { return _ncs.data(); } + int length() const { return _ncs.length(); } + + void gen_number(double, int kind = 0); + void gen_command(int); + void gen_stack(CharstringInterp &, int for_cmd); + + void append_charstring(const String &); + + const Point ¤t_point(bool real) const { return (real ? _true : _false); } + void gen_moveto(const Point &, bool closepath, bool always); + + inline String take_string(); + Type1Charstring *output(); + void output(Type1Charstring &); + + static String callsubr_string(int subr); + + private: + + StringAccum _ncs; + int _precision; + double _f_precision; + + Point _true; + Point _false; + + enum State { S_INITIAL, S_GEN }; + State _state; + +}; + +class Type1CharstringGenInterp : public CharstringInterp { public: + + Type1CharstringGenInterp(int precision); + + int precision() const { return _csgen.precision(); } + void set_direct_hint_replacement(bool dhr) { _direct_hr = dhr; } + void set_hint_replacement_storage(Type1Font *); + + int nhints() const { return _stem_hstem.size(); } + double max_flex_height() const { return _max_flex_height; } + bool bad_flex() const { return _bad_flex; } + + const Type1CharstringGen &csgen() const { return _csgen; } + + void act_width(int, const Point &); + void act_seac(int, double, double, double, int, int); + + void act_hstem(int, double, double); + void act_vstem(int, double, double); + void act_hintmask(int, const unsigned char *, int); + + void act_line(int, const Point &, const Point &); + void act_curve(int, const Point &, const Point &, const Point &, const Point &); + void act_closepath(int); + void act_flex(int, const Point &, const Point &, const Point &, const Point &, const Point &, const Point &, const Point &, double); + + void intermediate_output(Type1Charstring &out); + void run(const CharstringContext &g, Type1Charstring &out); + + private: + + // output + Type1CharstringGen _csgen; + mutable Type1CharstringGen _hint_csgen; + + // current glyph + Point _width; + enum State { S_INITIAL, S_OPEN, S_CLOSED, S_SEAC }; + State _state; + + // hints and hint replacement + Vector<double> _stem_pos; + Vector<double> _stem_width; + Vector<int> _stem_hstem; + String _last_hints; + + bool _in_hr; + bool _direct_hr; + int _hr_firstsubr; + Type1Font *_hr_storage; + + // Flex + double _max_flex_height; + bool _bad_flex; + + inline void gen_number(double, int = 0); + inline void gen_command(int); + void gen_sbw(bool hints_follow); + String gen_hints(const unsigned char *, int) const; + void swap_stem_hints(); + +}; + +inline String Type1CharstringGen::take_string() +{ + String s = _ncs.take_string(); + clear(); + return s; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1font.hh b/Build/source/texk/lcdf-typetools/include/efont/t1font.hh new file mode 100644 index 00000000000..e63e2197d42 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1font.hh @@ -0,0 +1,167 @@ +// -*- related-file-name: "../../libefont/t1font.cc" -*- +#ifndef EFONT_T1FONT_HH +#define EFONT_T1FONT_HH +#include <efont/t1cs.hh> +#include <lcdf/hashmap.hh> +class StringAccum; +class ErrorHandler; +namespace Efont { +class Type1Item; +class Type1Definition; +class Type1Encoding; +class Type1IncludedFont; +class Type1Subr; +class Type1Reader; +class Type1Writer; +class MultipleMasterSpace; + +class Type1Font : public CharstringProgram { public: + + Type1Font(Type1Reader &); + ~Type1Font(); + + int read(Type1Reader &); + + bool ok() const; + + inline PermString font_name() const; + void font_matrix(double[6]) const; + + int nitems() const { return _items.size(); } + Type1Item *item(int i) const { return _items[i]; } + void add_item(Type1Item *it) { _items.push_back(it); } + void add_definition(int dict, Type1Definition *); + void add_type1_encoding(Type1Encoding *); + + int nsubrs() const { return _subrs.size(); } + Type1Charstring *subr(int) const; + + int nglyphs() const { return _glyphs.size(); } + PermString glyph_name(int) const; + Type1Charstring *glyph(int) const; + Type1Charstring *glyph(PermString) const; + void add_glyph(Type1Subr *); + + Type1Subr *subr_x(int i) const { return _subrs[i]; } + bool set_subr(int, const Type1Charstring &, PermString definer = PermString()); + bool remove_subr(int); + void fill_in_subrs(); + void renumber_subrs(const Vector<int> &); // dangerous! + + Type1Subr *glyph_x(int i) const { return _glyphs[i]; } + + Type1Encoding *type1_encoding() const { return _encoding; } + + // note: the order is relevant + enum Dict { + dFont = 0, dF = dFont, + dFontInfo = 1, dFI = dFontInfo, + dPrivate = 2, dP = dPrivate, + dBlend = 3, dB = dBlend, + dBlendFontInfo = dB+dFI, dBFI = dBlendFontInfo, + dBlendPrivate = dB+dP, dBP = dBlendPrivate, + dLast + }; + + Type1Definition *dict(int d, PermString s) const { return _dict[d][s]; } + Type1Definition *dict(PermString s) const { return _dict[dF][s]; } + Type1Definition *p_dict(PermString s) const { return _dict[dP][s]; } + Type1Definition *b_dict(PermString s) const { return _dict[dB][s]; } + Type1Definition *bp_dict(PermString s) const { return _dict[dBP][s];} + Type1Definition *fi_dict(PermString s) const { return _dict[dFI][s];} + + typedef HashMap<PermString, Type1Definition *> DictHashMap; + inline DictHashMap::const_iterator dict_begin(int dict) const; + inline DictHashMap::iterator dict_begin(int dict); + int first_dict_item(int d) const { return _index[d]; } + + Type1Definition *ensure(Dict, PermString); + void add_header_comment(const String &); + + MultipleMasterSpace *create_mmspace(ErrorHandler * = 0) const; + MultipleMasterSpace *mmspace() const; + + void undo_synthetic(); + + void set_charstring_definer(PermString d) { _charstring_definer = d; } + + void write(Type1Writer &); + + // font skeletons + static Type1Font *skeleton_make(PermString, const String &version = String()); + static Type1Font *skeleton_make_copy(const Type1Font *, PermString, const Vector<double> *xuid_extension); + void skeleton_comments_end(); + void skeleton_fontinfo_end(); + void skeleton_fontdict_end(); + void skeleton_private_end(); + void skeleton_common_subrs(); + + // for experts only + void set_item(int, Type1Item *); + inline void set_dict(int dict, PermString, Type1Definition *); + void uncache_defs(); + + private: + + mutable bool _cached_defs; + bool _built; + mutable PermString _font_name; + + Vector<Type1Item *> _items; + + HashMap<PermString, Type1Definition *> *_dict; + int _index[dLast]; + int _dict_deltas[dLast]; + + Vector<Type1Subr *> _subrs; + Vector<Type1Subr *> _glyphs; + HashMap<PermString, int> _glyph_map; + + PermString _charstring_definer; + Type1Encoding *_encoding; + + mutable bool _cached_mmspace; + mutable MultipleMasterSpace *_mmspace; + + Type1IncludedFont *_synthetic_item; + + Type1Font(PermString); + Type1Font(const Type1Font &); + Type1Font &operator=(const Type1Font &); + + void read_encoding(Type1Reader &, const char *); + bool read_synthetic_font(Type1Reader &, const char *, StringAccum &); + void cache_defs() const; + void shift_indices(int, int); + + Type1Item *dict_size_item(int) const; + int get_dict_size(int) const; + void set_dict_size(int, int); + +}; + + +inline Type1Font::DictHashMap::const_iterator Type1Font::dict_begin(int dict) const +{ + return _dict[dict].begin(); +} + +inline Type1Font::DictHashMap::iterator Type1Font::dict_begin(int dict) +{ + return _dict[dict].begin(); +} + +inline void Type1Font::set_dict(int dict, PermString name, Type1Definition *t1d) +{ + _dict[dict].insert(name, t1d); +} + +inline PermString Type1Font::font_name() const +{ + if (!_cached_defs) + cache_defs(); + return _font_name; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1interp.hh b/Build/source/texk/lcdf-typetools/include/efont/t1interp.hh new file mode 100644 index 00000000000..934c0a5885f --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1interp.hh @@ -0,0 +1,239 @@ +// -*- related-file-name: "../../libefont/t1interp.cc" -*- +#ifndef EFONT_T1INTERP_HH +#define EFONT_T1INTERP_HH +#include <efont/t1cs.hh> +#include <lcdf/point.hh> +#include <stdio.h> +namespace Efont { + +class CharstringInterp { public: + + CharstringInterp(); + CharstringInterp(const Vector<double> &weight_vec); + virtual ~CharstringInterp() { } + + int error() const { return _error; } + int error_data() const { return _error_data; } + static String error_string(int error, int error_data); + inline String error_string() const; + + bool careful() const { return _careful; } + void set_careful(bool c) { _careful = c; } + + bool done() const { return _done; } + void set_done() { _done = true; } + + int size() const { return _sp; } + double &at(unsigned i) { return _s[i]; } + double &top(unsigned i = 0) { return _s[_sp - i - 1]; } + double pop(unsigned n = 1) { _sp -= n; return _s[_sp]; } + inline void push(double); + void clear() { _sp = 0; } + + int ps_size() const { return _ps_sp; } + double ps_at(unsigned i) const { return _ps_s[i]; } + double ps_pop() { return _ps_s[--_ps_sp]; } + inline void ps_push(double); + void ps_clear() { _ps_sp = 0; } + + int subr_depth() const { return _subr_depth; } + + inline double &vec(Vector<double> *, int); + const Vector<double> &weight_vector() const { return _weight_vector; } + Vector<double> *scratch_vector() { return &_scratch_vector; } + + const CharstringProgram *program() const { return _program; } + inline Charstring *get_subr(int) const; + inline Charstring *get_gsubr(int) const; + inline Charstring *get_xsubr(bool g, int) const; + inline Charstring *get_glyph(PermString) const; + + bool interpret(const CharstringProgram *, const Charstring *); + inline bool interpret(const CharstringContext &); + + //virtual void init(const CharstringProgram *); + bool error(int c) { return error(c, 0); } + virtual bool error(int, int); + virtual bool number(double); + + bool arith_command(int); + bool vector_command(int); + bool blend_command(); + bool callsubr_command(); + bool callgsubr_command(); + inline bool callxsubr_command(bool g); + bool mm_command(int, int); + bool itc_command(int, int); + + const Point &left_sidebearing() const { return _lsb; } + const Point ¤tpoint() const { return _cp; } + void set_state_path() { _state = S_PATH; } + + virtual bool callothersubr_command(int, int); + virtual bool type1_command(int); + virtual bool type2_command(int, const uint8_t *, int *); + + virtual void act_sidebearing(int cmd, const Point &lsb); + virtual void act_width(int cmd, const Point &width); + virtual void act_default_width(int cmd); + virtual void act_nominal_width_delta(int cmd, double delta); + virtual void act_seac(int cmd, double asb, double adx, double ady, int bchar, int achar); + + virtual void act_line(int cmd, const Point &p0, const Point &p1); + virtual void act_curve(int cmd, const Point &p0, const Point &p1, const Point &p2, const Point &p3); + virtual void act_closepath(int cmd); + + virtual void act_flex(int cmd, const Point &p0, const Point &p1, const Point &p2, const Point &p3_4, const Point &p5, const Point &p6, const Point &p7, double flex_depth); + + virtual void act_hstem(int cmd, double y, double dy); + virtual void act_vstem(int cmd, double x, double dx); + virtual void act_hstem3(int cmd, double y0, double dy0, double y1, double dy1, double y2, double dy2); + virtual void act_vstem3(int cmd, double x0, double dx0, double x1, double dx1, double x2, double dx2); + virtual void act_hintmask(int cmd, const uint8_t *data, int nhints); + + typedef Charstring Cs; + + enum Errors { + errOK = 0, + errInternal = -1, + errRunoff = -2, + errUnimplemented = -3, + errOverflow = -4, + errUnderflow = -5, + errVector = -6, + errValue = -7, + errSubr = -8, + errGlyph = -9, + errCurrentPoint = -10, + errFlex = -11, + errMultipleMaster = -12, + errOpenStroke = -13, + errLateSidebearing = -14, + errOthersubr = -15, + errOrdering = -16, + errHintmask = -17, + errSubrDepth = -18, + errLastError = -18 + }; + + enum { STACK_SIZE = 48, PS_STACK_SIZE = 24, MAX_SUBR_DEPTH = 10, + SCRATCH_SIZE = 32 }; + + private: + + int _error; + int _error_data; + bool _done; + bool _careful; + + double _s[STACK_SIZE]; + int _sp; + double _ps_s[PS_STACK_SIZE]; + int _ps_sp; + + int _subr_depth; + + Vector<double> _weight_vector; + Vector<double> _scratch_vector; + + Point _lsb; + Point _cp; + Point _seac_origin; + + const CharstringProgram *_program; + + enum State { + S_INITIAL, S_SEAC, S_SBW, S_HSTEM, S_VSTEM, S_HINTMASK, S_IPATH, S_PATH + }; + State _state; + bool _flex; + + // for processing Type 2 charstrings + int _t2nhints; + + static double double_for_error; + + void initialize(); + + inline void ensure_weight_vector(); + void fetch_weight_vector(); + + bool roll_command(); + int type2_handle_width(int, bool); + + inline void actp_rmoveto(int, double, double); + inline void actp_rlineto(int, double, double); + void actp_rrcurveto(int, double, double, double, double, double, double); + void actp_rrflex(int, double, double, double, double, double, double, double, double, double, double, double, double, double); + +}; + + +inline String CharstringInterp::error_string() const +{ + return error_string(_error, _error_data); +} + +inline void CharstringInterp::push(double d) +{ + if (_sp < STACK_SIZE) + _s[_sp++] = d; + else + error(errOverflow); +} + +inline void CharstringInterp::ps_push(double d) +{ + if (_ps_sp < PS_STACK_SIZE) + _ps_s[_ps_sp++] = d; + else + error(errOverflow); +} + +inline double &CharstringInterp::vec(Vector<double> *v, int i) +{ + if (i < 0 || i >= v->size()) { + error(errVector); + return double_for_error; + } else + return v->at_u(i); +} + +inline Charstring *CharstringInterp::get_subr(int n) const +{ + return _program ? _program->subr(n) : 0; +} + +inline Charstring *CharstringInterp::get_gsubr(int n) const +{ + return _program ? _program->gsubr(n) : 0; +} + +inline Charstring *CharstringInterp::get_xsubr(bool g, int n) const +{ + return _program ? _program->xsubr(g, n) : 0; +} + +inline Charstring *CharstringInterp::get_glyph(PermString n) const +{ + return _program ? _program->glyph(n) : 0; +} + +inline void CharstringInterp::ensure_weight_vector() +{ + if (!_weight_vector.size()) + fetch_weight_vector(); +} + +inline bool CharstringInterp::callxsubr_command(bool g) +{ + return (g ? callgsubr_command() : callsubr_command()); +} + +inline bool CharstringInterp::interpret(const CharstringContext &g) +{ + return interpret(g.program, g.cs); +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1item.hh b/Build/source/texk/lcdf-typetools/include/efont/t1item.hh new file mode 100644 index 00000000000..7358410e38e --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1item.hh @@ -0,0 +1,268 @@ +// -*- related-file-name: "../../libefont/t1item.cc" -*- +#ifndef EFONT_T1ITEM_HH +#define EFONT_T1ITEM_HH +#include <efont/t1cs.hh> +#include <lcdf/straccum.hh> +namespace Efont { +class Type1Reader; +class Type1Writer; +class CharstringInterp; +class Type1Font; +class Type1CopyItem; +class Type1Subr; +class Type1SubrGroupItem; +class Type1Definition; + +class Type1Item { public: + + Type1Item() { } + virtual ~Type1Item() { } + + virtual void gen(Type1Writer &) = 0; + + virtual Type1CopyItem *cast_copy() { return 0; } + virtual Type1Subr *cast_subr() { return 0; } + virtual Type1Definition *cast_definition() { return 0; } + virtual Type1SubrGroupItem *cast_subr_group() { return 0; } + + private: + + Type1Item(const Type1Item &); + Type1Item &operator=(const Type1Item &); + +}; + +class Type1NullItem : public Type1Item { public: + + Type1NullItem() { } + + void gen(Type1Writer &); + +}; + +class Type1CopyItem : public Type1Item { public: + + Type1CopyItem(const String &s) : _value(s) { } + ~Type1CopyItem() { } + + const String &value() const { return _value; } + int length() const { return _value.length(); } + + void set_value(const String &s) { _value = s; } + + void gen(Type1Writer &); + + Type1CopyItem *cast_copy() { return this; } + + private: + + String _value; + +}; + +class Type1EexecItem : public Type1Item { public: + + Type1EexecItem(bool on) : _eexec_on(on) { } + + void gen(Type1Writer &w); + + private: + + bool _eexec_on; + +}; + +class Type1Definition : public Type1Item { public: + + typedef Vector<double> NumVector; + + Type1Definition(PermString, const String &, PermString); + ~Type1Definition() { } + static Type1Definition *make(StringAccum &, Type1Reader * = 0, bool force = false); + static Type1Definition *make_string(PermString, const String &, PermString); + static inline Type1Definition *make_literal(PermString, const String &, PermString); + static inline Type1Definition *make(PermString, double, PermString); + + PermString name() const { return _name; } + const String &value() const { return _val; } + PermString definer() const { return _definer; } + + bool value_bool(bool &) const; + bool value_int(int &) const; + bool value_num(double &) const; + bool value_string(String &) const; + bool value_name(PermString &) const; + bool value_numvec(NumVector &) const; + bool value_numvec_vec(Vector<NumVector> &) const; + bool value_normalize(Vector<NumVector> &in, Vector<NumVector> &out) const; + bool value_namevec(Vector<PermString> &) const; + + void set_bool(bool); + void set_int(int); + void set_num(double); + void set_string(const String &); + void set_name(PermString, bool name = true); + void set_code(const char *s) { set_val(s); } + void set_numvec(const NumVector &, bool executable = false); + void set_numvec_vec(const Vector<NumVector> &); + void set_normalize(const Vector<NumVector> &, const Vector<NumVector> &); + void set_namevec(const Vector<PermString> &, bool executable = true); + + void gen(Type1Writer &); + void gen(StringAccum &); + + Type1Definition *cast_definition() { return this; } + + private: + + PermString _name; + String _val; + PermString _definer; + + static int slurp_string(StringAccum &, int, Type1Reader *); + static int slurp_proc(StringAccum &, int, Type1Reader *); + + inline void set_val(const String &); + inline void set_val(StringAccum &); + +}; + +class Type1Encoding : public Type1Item { public: + + Type1Encoding(); + Type1Encoding(const Type1Encoding &); + ~Type1Encoding(); + + void clear(); + void unshare(); + + PermString operator[](int e) const { assert(e>=0&&e<256); return _v[e]; } + PermString elt(int e) const { return (*this)[e]; } + PermString operator[](unsigned char e) const { return _v[e]; } + PermString elt(unsigned char e) const { return operator[](e); } + inline void put(int e, PermString p); + + void set_definer(PermString s) { _definer = s; } + + static Type1Encoding *standard_encoding(); + + void gen(Type1Writer &); + + private: + + PermString *_v; + Type1Encoding *_copy_of; + PermString _definer; + + Type1Encoding(Type1Encoding *); + Type1Encoding &operator=(const Type1Encoding &); + +}; + +class Type1Subr : public Type1Item { public: + + static Type1Subr *make(const char *, int, int cs_start, int cs_len, int lenIV); + static Type1Subr *make_subr(int, const Type1Charstring &, PermString); + static Type1Subr *make_glyph(PermString, const Type1Charstring &, PermString); + + bool is_subr() const { return !_name; } + PermString name() const { return _name; } + int subrno() const { return _subrno; } + PermString definer() const { return _definer; } + + Type1Charstring &t1cs() { return _cs; } + const Type1Charstring &t1cs() const { return _cs; } + operator Type1Charstring &() { return _cs; } + operator const Type1Charstring &() const { return _cs; } + + void gen(Type1Writer &); + + virtual Type1Subr *cast_subr() { return this; } + + private: + + PermString _name; + int _subrno; + PermString _definer; + + Type1Charstring _cs; + + static PermString cached_definer; + + Type1Subr(PermString, int, PermString, int, const String &); + Type1Subr(PermString, int, PermString, const Type1Charstring &); + +}; + +class Type1SubrGroupItem : public Type1Item { public: + + Type1SubrGroupItem(Type1Font *, bool, const String &); + Type1SubrGroupItem(const Type1SubrGroupItem &, Type1Font *); + ~Type1SubrGroupItem() { } + + void set_end_text(const String &s) { _end_text = s; } + void add_end_text(const String &); + + bool is_subrs() const { return _is_subrs; } + const String &end_text() const { return _end_text; } + + void gen(Type1Writer &); + + Type1SubrGroupItem *cast_subr_group() { return this; } + + private: + + Type1Font *_font; + bool _is_subrs; + String _value; + String _end_text; + +}; + +class Type1IncludedFont : public Type1Item { public: + + Type1IncludedFont(Type1Font *, int); + ~Type1IncludedFont(); + + Type1Font *included_font() const { return _included_font; } + + void gen(Type1Writer &); + + private: + + Type1Font *_included_font; + int _unique_id; + +}; + + +inline Type1Definition *Type1Definition::make_literal(PermString n, const String &v, PermString d) +{ + return new Type1Definition(n, v, d); +} + +inline Type1Definition *Type1Definition::make(PermString n, double v, PermString d) +{ + return new Type1Definition(n, String(v), d); +} + +inline void Type1Definition::set_val(const String &v) +{ + _val = v; +} + +inline void Type1Definition::set_val(StringAccum &sa) +{ + _val = sa.take_string(); +} + +inline void Type1Encoding::put(int e, PermString glyph) +{ + if (_copy_of) + unshare(); + assert(e >= 0 && e < 256); + _v[e] = glyph; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1mm.hh b/Build/source/texk/lcdf-typetools/include/efont/t1mm.hh new file mode 100644 index 00000000000..94e32e3ed14 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1mm.hh @@ -0,0 +1,108 @@ +// -*- related-file-name: "../../libefont/t1mm.cc" -*- +#ifndef EFONT_T1MM_HH +#define EFONT_T1MM_HH +#include <efont/t1cs.hh> +class ErrorHandler; +namespace Efont { +class Type1Font; + +class MultipleMasterSpace : public CharstringProgram { public: + + MultipleMasterSpace(PermString, int naxes, int nmasters); + // default destructor + + typedef Vector<double> NumVector; + + PermString font_name() const { return _font_name; } + int naxes() const { return _naxes; } + int nmasters() const { return _nmasters; } + + int axis(PermString) const; + double axis_low(int) const; + double axis_high(int) const; + + PermString axis_type(int a) const { return _axis_types[a]; } + PermString axis_label(int a) const { return _axis_labels[a]; } + inline PermString axis_abbreviation(int a) const; + static PermString axis_abbreviation(PermString); + + const Type1Charstring &ndv() const { return _ndv; } + const Type1Charstring &cdv() const { return _cdv; } + + void set_master_positions(const Vector<NumVector> &); + void set_normalize(const Vector<NumVector> &, const Vector<NumVector> &); + void set_axis_type(int, PermString); + void set_axis_label(int, PermString); + void set_ndv(const Type1Charstring &cs) { _ndv = cs; } + void set_cdv(const Type1Charstring &cs) { _cdv = cs; } + void set_design_vector(const NumVector &); + void set_weight_vector(const NumVector &); + + bool check(ErrorHandler * = 0); + bool check_intermediate(ErrorHandler * = 0); + + NumVector empty_design_vector() const; + inline const NumVector &default_design_vector() const; + bool set_design(NumVector &, int, double, ErrorHandler * = 0) const; + bool set_design(NumVector &, PermString, double, ErrorHandler * = 0) const; + + inline const NumVector &default_weight_vector() const; + + bool design_to_norm_design(const NumVector &, NumVector &, ErrorHandler * = 0) const; + bool design_to_weight(const NumVector &, NumVector &, ErrorHandler * = 0) const; + + NumVector *mm_vector(VectorType, bool writable) const; + + private: + + mutable bool _ok; + + PermString _font_name; + int _naxes; + int _nmasters; + + Vector<NumVector> _master_positions; + Vector<NumVector> _normalize_in; + Vector<NumVector> _normalize_out; + + Vector<PermString> _axis_types; + Vector<PermString> _axis_labels; + + Type1Charstring _ndv; + Type1Charstring _cdv; + + NumVector _default_design_vector; + NumVector _default_weight_vector; + + mutable NumVector *_design_vector; + mutable NumVector *_norm_design_vector; + mutable NumVector *_weight_vector; + + bool error(ErrorHandler *, const char *, ...) const; + + MultipleMasterSpace(const MultipleMasterSpace &); + MultipleMasterSpace &operator=(const MultipleMasterSpace &); + + bool normalize_vector(ErrorHandler *) const; + bool convert_vector(ErrorHandler *) const; + +}; + + +inline const Vector<double> &MultipleMasterSpace::default_design_vector() const +{ + return _default_design_vector; +} + +inline const Vector<double> &MultipleMasterSpace::default_weight_vector() const +{ + return _default_weight_vector; +} + +inline PermString MultipleMasterSpace::axis_abbreviation(int a) const +{ + return axis_abbreviation(_axis_types[a]); +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1rw.hh b/Build/source/texk/lcdf-typetools/include/efont/t1rw.hh new file mode 100644 index 00000000000..ae37856342a --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1rw.hh @@ -0,0 +1,232 @@ +// -*- related-file-name: "../../libefont/t1rw.cc" -*- +#ifndef EFONT_T1RW_HH +#define EFONT_T1RW_HH +#include <stdio.h> +#include <lcdf/string.hh> +#include <lcdf/straccum.hh> +namespace Efont { + +class Type1Reader { public: + + Type1Reader(); + virtual ~Type1Reader(); + + int get_data(unsigned char *, int); + virtual int more_data(unsigned char *, int) = 0; + virtual bool preserve_whitespace() const { return false; } + + void switch_eexec(bool, unsigned char *, int); + virtual void set_charstring_definer(PermString); + + bool next_line(StringAccum &); + bool was_charstring() const { return _charstring_len > 0; } + int charstring_start() const { return _charstring_start; } + int charstring_length() const { return _charstring_len; } + + private: + + enum { DATA_SIZE = 1024 }; + + unsigned char *_data; + int _len; + int _pos; + + PermString _charstring_definer; + int _charstring_start; + int _charstring_len; + + int _ungot; + int _crlf; + + bool _eexec; + bool _binary_eexec; + int _r; + + Type1Reader(const Type1Reader &); + Type1Reader &operator=(const Type1Reader &); + + int more_data(); + + inline int eexec(int); + int ascii_eexec_get(); + inline int get_base(); + inline int get(); + + void start_eexec(int ascii_chars); + + bool test_charstring(StringAccum &); + + static unsigned char xvalue_store[]; + static unsigned char *xvalue; + static void static_initialize(); + +}; + + +class Type1PFAReader : public Type1Reader { + + FILE *_f; + + public: + + Type1PFAReader(FILE *); + + int more_data(unsigned char *, int); + +}; + +class Type1PFBReader : public Type1Reader { + + FILE *_f; + bool _binary; + int _left; + + public: + + Type1PFBReader(FILE *); + + int more_data(unsigned char *, int); + bool preserve_whitespace() const; + +}; + +class Type1SubsetReader : public Type1Reader { + + Type1Reader *_reader; + int _left; + + public: + + Type1SubsetReader(Type1Reader *, int); + + int more_data(unsigned char *, int); + bool preserve_whitespace() const; + +}; + + +/***** + * Writers + **/ + +class Type1Writer { public: + + Type1Writer(); + virtual ~Type1Writer(); + + bool eexecing() const { return _eexec; } + + inline void print(int); + void print(const char *, int); + + inline Type1Writer &operator<<(char); + inline Type1Writer &operator<<(unsigned char); + Type1Writer &operator<<(int); + Type1Writer &operator<<(double); + + virtual void flush(); + virtual void switch_eexec(bool); + virtual void print0(const unsigned char *, int) = 0; + + PermString charstring_start() const { return _charstring_start; } + int lenIV() const { return _lenIV; } + void set_charstring_start(PermString p) { _charstring_start = p; } + void set_lenIV(int l) { _lenIV = l; } + + private: + + enum { BufSize = 1024 }; + + unsigned char *_buf; + int _pos; + + bool _eexec; + int _eexec_start; + int _eexec_end; + int _r; + + PermString _charstring_start; + int _lenIV; + + void local_flush(); + inline unsigned char eexec(int); + + Type1Writer(const Type1Writer &); + Type1Writer &operator=(const Type1Writer &); + +}; + + +class Type1PFAWriter: public Type1Writer { + + FILE *_f; + int _hex_line; + + public: + + Type1PFAWriter(FILE *); + ~Type1PFAWriter(); + + void switch_eexec(bool); + void print0(const unsigned char *, int); + +}; + + +class Type1PFBWriter: public Type1Writer { + + StringAccum _save; + FILE *_f; + bool _binary; + + public: + + Type1PFBWriter(FILE *); + ~Type1PFBWriter(); + + void flush(); + void switch_eexec(bool); + void print0(const unsigned char *, int); + +}; + + +inline void Type1Writer::print(int c) +{ + if (_pos >= BufSize) + local_flush(); + _buf[_pos++] = c; +} + +inline Type1Writer &operator<<(Type1Writer &w, const char *cc) +{ + w.print(cc, strlen(cc)); + return w; +} + +inline Type1Writer &operator<<(Type1Writer &w, PermString p) +{ + w.print(p.c_str(), p.length()); + return w; +} + +inline Type1Writer &operator<<(Type1Writer &w, const String &s) +{ + w.print(s.data(), s.length()); + return w; +} + +inline Type1Writer &Type1Writer::operator<<(char c) +{ + print((unsigned char)c); + return *this; +} + +inline Type1Writer &Type1Writer::operator<<(unsigned char c) +{ + print(c); + return *this; +} + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/t1unparser.hh b/Build/source/texk/lcdf-typetools/include/efont/t1unparser.hh new file mode 100644 index 00000000000..06d46ee96ee --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/t1unparser.hh @@ -0,0 +1,39 @@ +// -*- related-file-name: "../../libefont/t1unparser.cc" -*- +#ifndef EFONT_T1UNPARSER_HH +#define EFONT_T1UNPARSER_HH +#include <efont/t1interp.hh> +#include <lcdf/straccum.hh> +namespace Efont { + +class CharstringUnparser : public CharstringInterp { public: + + CharstringUnparser(); + CharstringUnparser(const CharstringUnparser &); + + const String &indent() const { return _indent; } + void set_indent(const String &s) { _indent = s; } + void set_one_command_per_line(bool b) { _one_command_per_line = b; } + + void clear(); + + bool number(double); + bool type1_command(int); + bool type2_command(int, const unsigned char *, int *); + void act_hintmask(int, const unsigned char *, int); + + String value(); + + static String unparse(const Charstring *); + static String unparse(const Charstring &); + + private: + + String _indent; + bool _one_command_per_line; + bool _start_of_line; + StringAccum _sa; + +}; + +} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/efont/ttfcs.hh b/Build/source/texk/lcdf-typetools/include/efont/ttfcs.hh new file mode 100644 index 00000000000..6253fac0c3d --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/ttfcs.hh @@ -0,0 +1,41 @@ +// -*- related-file-name: "../../libefont/ttfcs.cc" -*- +#ifndef EFONT_TTFCS_HH +#define EFONT_TTFCS_HH +#include <efont/t1cs.hh> +#include <efont/otf.hh> +#include <efont/otfdata.hh> +namespace Efont { + +class TrueTypeBoundsCharstringProgram : public CharstringProgram { public: + + TrueTypeBoundsCharstringProgram(const OpenType::Font *); + ~TrueTypeBoundsCharstringProgram(); + + int units_per_em() const; + + int nglyphs() const; + Charstring *glyph(int gi) const; + PermString glyph_name(int gi) const; + void glyph_names(Vector<PermString> &) const; + + private: + + const OpenType::Font *_otf; + int _nglyphs; + int _nhmtx; + bool _loca_long; + int _units_per_em; + OpenType::Data _loca; + OpenType::Data _glyf; + OpenType::Data _hmtx; + mutable Vector<Charstring *> _charstrings; + mutable Vector<PermString> _glyph_names; + mutable bool _got_glyph_names; + mutable Vector<uint32_t> _unicodes; + mutable bool _got_unicodes; + +}; + +} +#endif + diff --git a/Build/source/texk/lcdf-typetools/include/efont/ttfhead.hh b/Build/source/texk/lcdf-typetools/include/efont/ttfhead.hh new file mode 100644 index 00000000000..59ad0d95aec --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/efont/ttfhead.hh @@ -0,0 +1,41 @@ +// -*- related-file-name: "../../libefont/ttfhead.cc" -*- +#ifndef EFONT_TTFHEAD_HH +#define EFONT_TTFHEAD_HH +#include <efont/otf.hh> +#include <efont/otfdata.hh> // for ntohl() +#include <lcdf/error.hh> +namespace Efont { namespace OpenType { + +class Head { public: + + Head(const String &, ErrorHandler * = 0); + // default destructor + + bool ok() const { return _error >= 0; } + int error() const { return _error; } + + unsigned units_per_em() const; + unsigned index_to_loc_format() const; + + private: + + Data _d; + int _error; + + int parse_header(ErrorHandler *); + +}; + + +inline unsigned Head::units_per_em() const +{ + return (_error >= 0 ? _d.u16(18) : 0); +} + +inline unsigned Head::index_to_loc_format() const +{ + return (_error >= 0 ? _d.u16(50) : 0); +} + +}} +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/bezier.hh b/Build/source/texk/lcdf-typetools/include/lcdf/bezier.hh new file mode 100644 index 00000000000..2635069521b --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/bezier.hh @@ -0,0 +1,136 @@ +// -*- related-file-name: "../../liblcdf/bezier.cc" -*- +#ifndef LCDF_BEZIER_HH +#define LCDF_BEZIER_HH +#include <lcdf/point.hh> +#include <lcdf/vector.hh> +#include <string.h> + +class Bezier { public: + + Bezier() : _bb(-1) { } + inline Bezier(Point p[4]) throw (); + inline Bezier(const Point &, const Point &, const Point &, const Point &) throw (); + + const Point *points() const { return _p; } + const Point &point(int i) const { assert(i>=0&&i<4); return _p[i]; } + Point &mpoint(int i) { assert(i>=0&&i<4); _bb = -1; return _p[i]; } + void set_point(int i, const Point &p) { mpoint(i) = p; } + + Point eval(double) const throw (); + bool is_flat(double) const throw (); + bool in_bb(const Point &, double) const throw (); + bool hit(const Point &, double) const throw (); + + inline double bb_left() const throw (); + inline double bb_right() const throw (); + inline double bb_top() const throw (); + inline double bb_bottom() const throw (); + + inline double bb_left_x() const throw (); + inline double bb_right_x() const throw (); + inline double bb_top_x() const throw (); + inline double bb_bottom_x() const throw (); + + void halve(Bezier &, Bezier &) const throw (); + + inline void segmentize(Vector<Point> &) const; + void segmentize(Vector<Point> &, bool) const; + + static void fit(const Vector<Point> &, double, Vector<Bezier> &); + + private: + + Point _p[4]; + mutable int _bb; + + void make_bb() const throw (); + inline void ensure_bb() const throw (); + + double hit_recurse(const Point &, double, double, double, double, double) const throw (); + +}; + + +inline +Bezier::Bezier(Point p[4]) throw () + : _bb(-1) +{ + memcpy(_p, p, sizeof(Point) * 4); +} + +inline +Bezier::Bezier(const Point &p0, const Point &p1, const Point &p2, const Point &p3) throw () +{ + _p[0] = p0; + _p[1] = p1; + _p[2] = p2; + _p[3] = p3; + _bb = -1; +} + +inline void +Bezier::ensure_bb() const throw () +{ + if (_bb < 0) + make_bb(); +} + +inline double +Bezier::bb_top_x() const throw () +{ + return _p[(_bb >> 4) & 3].y; +} + +inline double +Bezier::bb_left_x() const throw () +{ + return _p[(_bb >> 2) & 3].x; +} + +inline double +Bezier::bb_bottom_x() const throw () +{ + return _p[(_bb >> 6) & 3].y; +} + +inline double +Bezier::bb_right_x() const throw () +{ + return _p[(_bb >> 0) & 3].x; +} + +inline double +Bezier::bb_top() const throw () +{ + ensure_bb(); + return bb_top_x(); +} + +inline double +Bezier::bb_left() const throw () +{ + ensure_bb(); + return bb_left_x(); +} + +inline double +Bezier::bb_bottom() const throw () +{ + ensure_bb(); + return bb_bottom_x(); +} + +inline double +Bezier::bb_right() const throw () +{ + ensure_bb(); + return bb_right_x(); +} + +inline void +Bezier::segmentize(Vector<Point> &v) const +{ + segmentize(v, v.size() == 0 || v.back() != _p[0]); +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/clp.h b/Build/source/texk/lcdf-typetools/include/lcdf/clp.h new file mode 100644 index 00000000000..2126aacbf9c --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/clp.h @@ -0,0 +1,167 @@ +/* -*- related-file-name: "../../liblcdf/clp.c" -*- */ +#ifndef LCDF_CLP_H +#define LCDF_CLP_H +#ifdef __cplusplus +extern "C" { +#endif + +/* clp.h - Public interface to CLP. + * This file is part of CLP, the command line parser package. + * + * Copyright (c) 1997-2005 Eddie Kohler, kohler@icir.org + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file, which is available in full at + * http://www.pdos.lcs.mit.edu/click/license.html. The conditions include: you + * must preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. */ + + +/* Argument types */ +#define Clp_NoArg 0 +#define Clp_ArgString 1 +#define Clp_ArgStringNotOption 2 +#define Clp_ArgBool 3 +#define Clp_ArgInt 4 +#define Clp_ArgUnsigned 5 +#define Clp_ArgDouble 6 + +#define Clp_FirstUserType 10 + +/* Flags for individual Clp_Options */ +#define Clp_Mandatory (1<<0) /* Has mandatory argument */ +#define Clp_Optional (1<<1) /* Has optional argument */ +#define Clp_Negate (1<<2) /* Allow --no-OPT */ +#define Clp_OnlyNegated (1<<3) /* Allow --no-OPT, but not --OPT */ +#define Clp_PreferredMatch (1<<4) /* Prefer --OPT to --OPTwhatever */ + /* when matching option prefixes */ + +struct Clp_Option { + const char *long_name; /* e.g. "version" */ + int short_name; /* e.g. 'v' */ + int option_id; /* number returned by Clp_Next */ + int arg_type; /* e.g. Clp_ArgBool */ + int flags; /* e.g. Clp_Optional | Clp_Negate */ +}; + + +/* Sizes of clp->val */ +#define Clp_ValSize 40 +#define Clp_ValIntSize 10 + +typedef struct Clp_Option Clp_Option; +typedef struct Clp_Parser Clp_Parser; +typedef struct Clp_Internal Clp_Internal; +typedef struct Clp_ParserState Clp_ParserState; +typedef struct Clp_Argv Clp_Argv; + +typedef int (*Clp_ArgParseFunc)(Clp_Parser *, const char *, int, void *); +typedef void (*Clp_ErrorHandler)(const char *); + +struct Clp_Parser { + + int negated; + + int have_arg; + const char *arg; + + union { + int i; + unsigned u; + double d; + const char *s; + void *pv; +#ifdef HAVE_INT64_TYPES + int64_t i64; + uint64_t u64; +#endif + char cs[Clp_ValSize]; + unsigned char ucs[Clp_ValSize]; + int is[Clp_ValIntSize]; + unsigned us[Clp_ValIntSize]; + } val; + + Clp_Internal *internal; + +}; + + +Clp_Parser * Clp_NewParser(int argc, const char * const *argv, + int nopt, Clp_Option *opt); +void Clp_DeleteParser(Clp_Parser *); + +Clp_ErrorHandler Clp_SetErrorHandler(Clp_Parser *, Clp_ErrorHandler); + +const char * Clp_ProgramName(Clp_Parser *); +void Clp_SetProgramName(Clp_Parser *, const char *); + + +struct Clp_Argv { + int argc; + char **argv; + char *argv_buf; +}; + +Clp_Argv * Clp_NewArgv(const char *args, int len); +void Clp_DeleteArgv(Clp_Argv *); + + +/* Option types for Clp_SetOptionChar */ +/* Clp_NotOption 0 */ +#define Clp_Short (1<<0) +#define Clp_Long (1<<1) +#define Clp_ShortNegated (1<<2) +#define Clp_LongNegated (1<<3) +#define Clp_LongImplicit (1<<4) + +int Clp_SetOptionChar(Clp_Parser *, int c, int option_type); + + +/* Argument type flags for Clp_AddType */ +#define Clp_DisallowOptions (1<<0) /* No option-looking args */ + +int Clp_AddType + (Clp_Parser *, int type_id, int flags, + Clp_ArgParseFunc func, void *user_data); + + +/* Flags for Clp_AddStringListType */ +#define Clp_AllowNumbers (1<<0) /* Number args OK */ + +int Clp_AddStringListType + (Clp_Parser *, int type_id, int flags, ...); +int Clp_AddStringListTypeVec + (Clp_Parser *, int type_id, int flags, + int n, char **str, int *val); + + +/* Return values from Clp_Next */ +#define Clp_NotOption 0 +#define Clp_Done -1 +#define Clp_BadOption -2 +#define Clp_Error -3 + +int Clp_Next(Clp_Parser *); + + +const char * Clp_Shift(Clp_Parser *, int allow_dashes); +int Clp_SetOptionProcessing(Clp_Parser *, int option_processing); + +Clp_ParserState *Clp_NewParserState(void); +void Clp_DeleteParserState(Clp_ParserState *); +void Clp_SaveParser(Clp_Parser *, Clp_ParserState *); +void Clp_RestoreParser(Clp_Parser *, Clp_ParserState *); + +int Clp_OptionError(Clp_Parser *, const char *, ...); +int Clp_CurOptionNameBuf(Clp_Parser *, char *buf, int buflen); +const char * Clp_CurOptionName(Clp_Parser *); /* uses static memory */ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/error.hh b/Build/source/texk/lcdf-typetools/include/lcdf/error.hh new file mode 100644 index 00000000000..8d38cbfb87a --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/error.hh @@ -0,0 +1,192 @@ +// -*- related-file-name: "../../liblcdf/error.cc" -*- +#ifndef LCDF_ERROR_HH +#define LCDF_ERROR_HH +#include <lcdf/string.hh> +#ifndef __KERNEL__ +# include <stdio.h> +#endif +#include <stdarg.h> +#if HAVE_ADDRESSABLE_VA_LIST +# define VA_LIST_REF_T va_list * +# define VA_LIST_DEREF(val) (*(val)) +# define VA_LIST_REF(val) (&(val)) +#else +# define VA_LIST_REF_T va_list +# define VA_LIST_DEREF(val) (val) +# define VA_LIST_REF(val) (val) +#endif + +class ErrorHandler { public: + + enum Seriousness { + ERRVERBOSITY_CONTEXT= 0x8000, + ERRVERBOSITY_MAX = 0xFFFF, + ERRVERBOSITY_DEFAULT= ERRVERBOSITY_MAX, + ERRVERBOSITY_MASK = 0x0000FFFF, + ERRVERBOSITY_SHIFT = 16, + + ERR_MIN_DEBUG = 0x00000000, + ERR_MIN_MESSAGE = 0x00010000, + ERR_MIN_WARNING = 0x00020000, + ERR_MIN_ERROR = 0x00030000, + ERR_MIN_FATAL = 0x00040000, + + // fatal() with no explicit exit status exits with this status + FATAL_EXITSTATUS = 1, + + ERR_DEBUG = ERR_MIN_DEBUG + ERRVERBOSITY_DEFAULT, + ERR_CONTEXT_MESSAGE = ERR_MIN_MESSAGE + ERRVERBOSITY_CONTEXT, + ERR_MESSAGE = ERR_MIN_MESSAGE + ERRVERBOSITY_DEFAULT, + ERR_WARNING = ERR_MIN_WARNING + ERRVERBOSITY_DEFAULT, + ERR_CONTEXT_ERROR = ERR_MIN_ERROR + ERRVERBOSITY_CONTEXT, + ERR_ERROR = ERR_MIN_ERROR + ERRVERBOSITY_DEFAULT, + ERR_FATAL = ERR_MIN_FATAL + ERRVERBOSITY_DEFAULT + (FATAL_EXITSTATUS << ERRVERBOSITY_SHIFT) + }; + + ErrorHandler() { } + virtual ~ErrorHandler() { } + + static ErrorHandler *static_initialize(ErrorHandler *errh); // returns errh + static void static_cleanup(); + + static ErrorHandler *default_handler(); + static ErrorHandler *ignore_handler(); + + static bool has_default_handler(); + static void set_default_handler(ErrorHandler *); + + virtual int nwarnings() const = 0; + virtual int nerrors() const = 0; + virtual void reset_counts() = 0; + virtual int min_verbosity() const; + + // seriousness < ERR_MIN_WARNING returns OK_RESULT, which is 0 + // seriousness >= ERR_MIN_WARNING returns ERROR_RESULT, which is -EINVAL + static const int OK_RESULT; + static const int ERROR_RESULT; + + void debug(const char *format, ...); + void message(const char *format, ...); + int warning(const char *format, ...); + int error(const char *format, ...); + int fatal(const char *format, ...); + int fatal(int exit_status, const char *format, ...); + + void ldebug(const String &landmark, const char *format, ...); + void lmessage(const String &landmark, const char *format, ...); + int lwarning(const String &landmark, const char *format, ...); + int lerror(const String &landmark, const char *format, ...); + int lfatal(const String &landmark, const char *format, ...); + int lfatal(int exit_status, const String &landmark, const char *format, ...); + + int verror(Seriousness, const String &landmark, const char *format, va_list); + int verror_text(Seriousness, const String &landmark, const String &text); + + String make_text(Seriousness, const char *, ...); + virtual String make_text(Seriousness, const char *, va_list); + virtual String decorate_text(Seriousness, const String &, const String &); + virtual void handle_text(Seriousness, const String &) = 0; + virtual int count_error(Seriousness, const String &) = 0; + + virtual void set_error_code(int); + + static String prepend_lines(const String &prefix, const String &text); + + // error conversions + struct Conversion; + typedef String (*ConversionHook)(int flags, VA_LIST_REF_T); + enum ConversionFlags { + ZERO_PAD = 1, PLUS_POSITIVE = 2, SPACE_POSITIVE = 4, LEFT_JUST = 8, + ALTERNATE_FORM = 16, UPPERCASE = 32, SIGNED = 64, NEGATIVE = 128 + }; + static Conversion *add_conversion(const String &, ConversionHook); + static int remove_conversion(Conversion *); + +}; + +class BaseErrorHandler : public ErrorHandler { public: + BaseErrorHandler() : _nwarnings(0), _nerrors(0) { } + int nwarnings() const { return _nwarnings; } + int nerrors() const { return _nerrors; } + void reset_counts() { _nwarnings = _nerrors = 0; } + int count_error(Seriousness, const String &); + private: + int _nwarnings, _nerrors; +}; + +#ifndef __KERNEL__ +class FileErrorHandler : public BaseErrorHandler { public: + FileErrorHandler(FILE *, const String & = String()); + void handle_text(Seriousness, const String &); + private: + FILE *_f; + String _context; +}; +#endif + +class SilentErrorHandler : public BaseErrorHandler { public: + SilentErrorHandler() { } + void handle_text(Seriousness, const String &); +}; + +class ErrorVeneer : public ErrorHandler { public: + + ErrorVeneer(ErrorHandler *errh) : _errh(errh) { } + + int nwarnings() const; + int nerrors() const; + void reset_counts(); + + String make_text(Seriousness, const char *, va_list); + String decorate_text(Seriousness, const String &, const String &); + void handle_text(Seriousness, const String &); + int count_error(Seriousness, const String &); + + protected: + + ErrorHandler *_errh; + +}; + +class ContextErrorHandler : public ErrorVeneer { public: + ContextErrorHandler(ErrorHandler *, const String &context, const String &indent = " ", const String &context_landmark = ""); + String decorate_text(Seriousness, const String &, const String &); + private: + String _context; + String _indent; + String _context_landmark; +}; + +class PrefixErrorHandler : public ErrorVeneer { public: + PrefixErrorHandler(ErrorHandler *, const String &prefix); + String decorate_text(Seriousness, const String &, const String &); + private: + String _prefix; +}; + +class LandmarkErrorHandler : public ErrorVeneer { public: + LandmarkErrorHandler(ErrorHandler *, const String &); + void set_landmark(const String &s) { _landmark = s; } + String decorate_text(Seriousness, const String &, const String &); + private: + String _landmark; +}; + +class VerboseFilterErrorHandler : public ErrorVeneer { public: + VerboseFilterErrorHandler(ErrorHandler *, int min_verbosity); + int min_verbosity() const; + void handle_text(Seriousness, const String &); + private: + int _min_verbosity; +}; + +#ifndef __KERNEL__ +class BailErrorHandler : public ErrorVeneer { public: + BailErrorHandler(ErrorHandler *, Seriousness = ERR_MIN_ERROR); + void handle_text(Seriousness, const String &); + private: + int _exit_seriousness; +}; +#endif + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/filename.hh b/Build/source/texk/lcdf-typetools/include/lcdf/filename.hh new file mode 100644 index 00000000000..9f1589d4779 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/filename.hh @@ -0,0 +1,41 @@ +// -*- related-file-name: "../../liblcdf/filename.cc" -*- +#ifndef LCDF_FILENAME_HH +#define LCDF_FILENAME_HH +#include <lcdf/string.hh> +#include <stdio.h> + +class Filename { public: + + Filename() : _dir("."), _actual(0) { } + Filename(const String &); + Filename(const String &dir, const String &name); + Filename(FILE *, const String &fake_name); + + bool fake() const { return _actual != 0; } + + const String &directory() const { return _dir; } + const String &name() const { return _name; } + const String &path() const { return _path; } + String base() const; + String extension() const; + + operator bool() const { return _name; } + bool operator!() const { return !_name; } + + FILE *open_read(bool binary = false) const; + bool readable() const; + + FILE *open_write(bool binary = false) const; + + Filename from_directory(const String &n) const { return Filename(_dir, n);} + + private: + + mutable String _dir; // mutable for c_str() + mutable String _name; + mutable String _path; + FILE *_actual; + +}; + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/globmatch.hh b/Build/source/texk/lcdf-typetools/include/lcdf/globmatch.hh new file mode 100644 index 00000000000..963035e0ead --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/globmatch.hh @@ -0,0 +1,8 @@ +// -*- related-file-name: "../../liblcdf/globmatch.cc" -*- +#ifndef LCDF_GLOBMATCH_HH +#define LCDF_GLOBMATCH_HH +class String; + +bool glob_match(const String& str, const String& pattern); + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/hashmap.cc b/Build/source/texk/lcdf-typetools/include/lcdf/hashmap.cc new file mode 100644 index 00000000000..17cec16e0d5 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/hashmap.cc @@ -0,0 +1,187 @@ +#ifndef LCDF_HASHMAP_CC +#define LCDF_HASHMAP_CC + +/* + * hashmap.{cc,hh} -- simple open-coded hash table class + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2001-2003 International Computer Science Institute + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +/* #include <lcdf/hashmap.hh> */ + +template <class K, class V> +HashMap<K, V>::HashMap() + : _capacity(0), _grow_limit(0), _n(0), _e(0), _default_value() +{ + increase(-1); +} + +template <class K, class V> +HashMap<K, V>::HashMap(const V &def) + : _capacity(0), _grow_limit(0), _n(0), _e(0), _default_value(def) +{ + increase(-1); +} + + +template <class K, class V> +HashMap<K, V>::HashMap(const HashMap<K, V> &m) + : _capacity(m._capacity), _grow_limit(m._grow_limit), _n(m._n), + _e(new Pair[m._capacity]), _default_value(m._default_value) +{ + for (int i = 0; i < _capacity; i++) + _e[i] = m._e[i]; +} + + +template <class K, class V> +HashMap<K, V> & +HashMap<K, V>::operator=(const HashMap<K, V> &o) +{ + // This works with self-assignment. + + _capacity = o._capacity; + _grow_limit = o._grow_limit; + _n = o._n; + _default_value = o._default_value; + + Pair *new_e = new Pair[_capacity]; + for (int i = 0; i < _capacity; i++) + new_e[i] = o._e[i]; + + delete[] _e; + _e = new_e; + + return *this; +} + + +template <class K, class V> +void +HashMap<K, V>::increase(int min_size) +{ + int ncap = (_capacity < 8 ? 8 : _capacity * 2); + while (ncap < min_size && ncap > 0) + ncap *= 2; + if (ncap <= 0) // want too many elements + return; + + Pair *ne = new Pair[ncap]; + if (!ne) // out of memory + return; + + Pair *oe = _e; + int ocap = _capacity; + _e = ne; + _capacity = ncap; + _grow_limit = ((3 * _capacity) >> 2) - 1; + + Pair *otrav = oe; + for (int i = 0; i < ocap; i++, otrav++) + if (otrav->key) { + int j = bucket(otrav->key); + _e[j] = *otrav; + } + + delete[] oe; +} + +template <class K, class V> +inline void +HashMap<K, V>::check_capacity() +{ + if (_n >= _grow_limit) + increase(-1); +} + +template <class K, class V> +bool +HashMap<K, V>::insert(const K &key, const V &val) +{ + check_capacity(); + int i = bucket(key); + bool is_new = !(bool)_e[i].key; + _e[i].key = key; + _e[i].value = val; + _n += is_new; + return is_new; +} + +template <class K, class V> +V & +HashMap<K, V>::find_force(const K &key, const V &value) +{ + check_capacity(); + int i = bucket(key); + if (!(bool)_e[i].key) { + _e[i].key = key; + _e[i].value = value; + _n++; + } + return _e[i].value; +} + +template <class K, class V> +void +HashMap<K, V>::clear() +{ + delete[] _e; + _e = 0; + _capacity = _grow_limit = _n = 0; + increase(-1); +} + +template <class K, class V> +void +HashMap<K, V>::swap(HashMap<K, V> &o) +{ + int capacity = _capacity; + int grow_limit = _grow_limit; + int n = _n; + Pair *e = _e; + V default_value = _default_value; + _capacity = o._capacity; + _grow_limit = o._grow_limit; + _n = o._n; + _e = o._e; + _default_value = o._default_value; + o._capacity = capacity; + o._grow_limit = grow_limit; + o._n = n; + o._e = e; + o._default_value = default_value; +} + +template <class K, class V> +_HashMap_const_iterator<K, V>::_HashMap_const_iterator(const HashMap<K, V> *hm, int pos) + : _hm(hm), _pos(pos) +{ + typename HashMap<K, V>::Pair *e = _hm->_e; + int capacity = _hm->_capacity; + while (_pos < capacity && !(bool)e[_pos].key) + _pos++; +} + +template <class K, class V> +void +_HashMap_const_iterator<K, V>::operator++(int) +{ + typename HashMap<K, V>::Pair *e = _hm->_e; + int capacity = _hm->_capacity; + for (_pos++; _pos < capacity && !(bool)e[_pos].key; _pos++) + ; +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/hashmap.hh b/Build/source/texk/lcdf-typetools/include/lcdf/hashmap.hh new file mode 100644 index 00000000000..10b5c321177 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/hashmap.hh @@ -0,0 +1,231 @@ +#ifndef LCDF_HASHMAP_HH +#define LCDF_HASHMAP_HH +#include <assert.h> + +// K AND V REQUIREMENTS: +// +// K::K() +// K::operator bool() const +// Must have (bool)(K()) == false +// and no k with (bool)k == false is stored. +// K & K::operator=(const K &) +// k1 == k2 +// unsigned hashcode(const K &) +// If hashcode(k1) != hashcode(k2), then k1 != k2. +// +// V::V() +// V & V::operator=(const V &) + +template <class K, class V> class _HashMap_const_iterator; +template <class K, class V> class _HashMap_iterator; + +inline unsigned +hashcode(int i) +{ + return static_cast<unsigned>(i); +} + +inline unsigned +hashcode(unsigned u) +{ + return u; +} + +inline unsigned +hashcode(long l) +{ + return static_cast<unsigned>(l); +} + +inline unsigned +hashcode(unsigned long ul) +{ + return static_cast<unsigned long>(ul); +} + +template <class K, class V> +class HashMap { public: + + HashMap(); + explicit HashMap(const V &); + HashMap(const HashMap<K, V> &); + ~HashMap() { delete[] _e; } + + int size() const { return _n; } + bool empty() const { return _n == 0; } + int capacity() const { return _capacity; } + void set_default_value(const V &v) { _default_value = v; } + + typedef _HashMap_const_iterator<K, V> const_iterator; + typedef _HashMap_iterator<K, V> iterator; + + inline const_iterator begin() const; + inline iterator begin(); + inline const_iterator end() const; + inline iterator end(); + + inline const V &find(const K &) const; + inline V *findp(const K &) const; + inline const V &operator[](const K &k) const; + V &find_force(const K &, const V &); + inline V &find_force(const K &); + + bool insert(const K &, const V &); + void clear(); + + HashMap<K, V> &operator=(const HashMap<K, V> &); + void swap(HashMap<K, V> &); + + void resize(int size) { increase(size); } + + struct Pair { + K key; + V value; + Pair() : key(), value() { } + }; + + private: + + int _capacity; + int _grow_limit; + int _n; + Pair *_e; + V _default_value; + + void increase(int); + inline void check_capacity(); + inline int bucket(const K &) const; + + friend class _HashMap_const_iterator<K, V>; + friend class _HashMap_iterator<K, V>; + +}; + +template <class K, class V> +class _HashMap_const_iterator { public: + typedef _HashMap_const_iterator const_iterator; + typedef typename HashMap<K, V>::Pair Pair; + + operator bool() const { return _pos < _hm->_capacity; } + bool operator!() const { return _pos >= _hm->_capacity; } + + void operator++(int); + void operator++() { (*this)++; } + + const K &key() const { return _hm->_e[_pos].key; } + const V &value() const { return _hm->_e[_pos].value; } + const Pair &pair() const { return _hm->_e[_pos]; } + + inline bool operator==(const const_iterator &) const; + inline bool operator!=(const const_iterator &) const; + + private: + const HashMap<K, V> *_hm; + int _pos; + _HashMap_const_iterator(const HashMap<K, V> *, int); + friend class HashMap<K, V>; + friend class _HashMap_iterator<K, V>; +}; + +template <class K, class V> +class _HashMap_iterator : public _HashMap_const_iterator<K, V> { public: + typedef _HashMap_iterator iterator; + + V &value() const { return this->_hm->_e[this->_pos].value; } + + private: + _HashMap_iterator(const HashMap<K, V> *hm, int pos) : _HashMap_const_iterator<K, V>(hm, pos) { } + friend class HashMap<K, V>; +}; + + +template <class K, class V> +inline int +HashMap<K, V>::bucket(const K &key) const +{ + assert(key); + unsigned hc = hashcode(key); + int i = hc & (_capacity - 1); + int j = ((hc >> 6) & (_capacity - 1)) | 1; + + while (_e[i].key && !(_e[i].key == key)) + i = (i + j) & (_capacity - 1); + + return i; +} + +template <class K, class V> +inline const V & +HashMap<K, V>::find(const K &key) const +{ + int i = bucket(key); + const V *v = (_e[i].key ? &_e[i].value : &_default_value); + return *v; +} + +template <class K, class V> +inline const V & +HashMap<K, V>::operator[](const K &key) const +{ + return find(key); +} + +template <class K, class V> +inline V * +HashMap<K, V>::findp(const K &key) const +{ + int i = bucket(key); + return _e[i].key ? &_e[i].value : 0; +} + +template <class K, class V> +inline V & +HashMap<K, V>::find_force(const K &key) +{ + return find_force(key, _default_value); +} + +template <class K, class V> +inline _HashMap_const_iterator<K, V> +HashMap<K, V>::begin() const +{ + return const_iterator(this, 0); +} + +template <class K, class V> +inline _HashMap_const_iterator<K, V> +HashMap<K, V>::end() const +{ + return const_iterator(this, _capacity); +} + +template <class K, class V> +inline _HashMap_iterator<K, V> +HashMap<K, V>::begin() +{ + return iterator(this, 0); +} + +template <class K, class V> +inline _HashMap_iterator<K, V> +HashMap<K, V>::end() +{ + return iterator(this, _capacity); +} + +template <class K, class V> +inline bool +_HashMap_const_iterator<K, V>::operator==(const const_iterator &i) const +{ + return _hm == i._hm && _pos == i._pos; +} + +template <class K, class V> +inline bool +_HashMap_const_iterator<K, V>::operator!=(const const_iterator &i) const +{ + return _hm != i._hm || _pos != i._pos; +} + +#include <lcdf/hashmap.cc> // necessary to support GCC 3.3 +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/inttypes.h b/Build/source/texk/lcdf-typetools/include/lcdf/inttypes.h new file mode 100644 index 00000000000..b88e9e9faf0 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/inttypes.h @@ -0,0 +1,34 @@ +#ifndef LCDF_INTTYPES_H +#define LCDF_INTTYPES_H +/* Define known-width integer types. */ + +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#elif defined(HAVE_SYS_TYPES_H) +# include <sys/types.h> +# ifdef HAVE_U_INT_TYPES +typedef u_int8_t uint8_t; +typedef u_int16_t uint16_t; +typedef u_int32_t uint32_t; +# endif +#endif + +#ifdef HAVE_FAKE_INT_TYPES +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +#endif + +#ifndef HAVE_UINTPTR_T +# if SIZEOF_VOID_P == SIZEOF_UNSIGNED_INT +typedef unsigned int uintptr_t; +# elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG +typedef unsigned long uintptr_t; +# endif +#endif + +/* Note: Windows compilers call these types '[un]signed __int8', etc. */ +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/landmark.hh b/Build/source/texk/lcdf-typetools/include/lcdf/landmark.hh new file mode 100644 index 00000000000..836f14ec088 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/landmark.hh @@ -0,0 +1,39 @@ +// -*- related-file-name: "../../liblcdf/landmark.cc" -*- +#ifndef LCDF_LANDMARK_HH +#define LCDF_LANDMARK_HH +#include <lcdf/string.hh> + +class Landmark { public: + + Landmark() : _file(), _line(~0U) { } + explicit Landmark(const String &f) : _file(f), _line(~0U) { } + Landmark(const String &f, unsigned l) : _file(f), _line(l) { } + + operator bool() const { return _file; } + bool operator!() const { return !_file; } + bool has_line() const { return _line != ~0U; } + + const String &file() const { return _file; } + unsigned line() const { return _line; } + + Landmark next_line() const; + Landmark whole_file() const { return Landmark(_file); } + + operator String() const; + + private: + + String _file; + unsigned _line; + +}; + +Landmark operator+(const Landmark &, int); + +inline Landmark +Landmark::next_line() const +{ + return *this + 1; +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/md5.h b/Build/source/texk/lcdf-typetools/include/lcdf/md5.h new file mode 100644 index 00000000000..7d7f8641d23 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/md5.h @@ -0,0 +1,48 @@ +/* -*- related-file-name: "../../liblcdf/md5.c" -*- + * md5.h - MD5 Message-Digest Algorithm + * Copyright (C) 1995, 1996, 1998, 1999 Free Software Foundation, Inc. + * + * according to the definition of MD5 in RFC 1321 from April 1992. + * NOTE: This is *not* the same file as the one from glibc + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef LCDF_MD5_H +#define LCDF_MD5_H +#ifdef __cplusplus +extern "C" { +#endif + +#define MD5_DIGEST_SIZE 16 +#define MD5_TEXT_DIGEST_SIZE 26 /* + 1 for the terminating NUL */ + +typedef struct { /* Hmm, should be private */ + uint32_t A,B,C,D; + uint32_t nblocks; + unsigned char buf[64]; + int count; + int finalized; +} MD5_CONTEXT; + +void md5_init(MD5_CONTEXT *ctx); +void md5_update(MD5_CONTEXT *hd, const unsigned char *inbuf, size_t inlen); +void md5_final(unsigned char digest[MD5_DIGEST_SIZE], MD5_CONTEXT *ctx); +void md5_final_text(char *text_digest, MD5_CONTEXT *ctx); + +#ifdef __cplusplus +} +#endif +#endif /* LCDF_MD5_H */ diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/permstr.hh b/Build/source/texk/lcdf-typetools/include/lcdf/permstr.hh new file mode 100644 index 00000000000..2db15772ded --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/permstr.hh @@ -0,0 +1,167 @@ +// -*- related-file-name: "../../liblcdf/permstr.cc" -*- +#ifndef LCDF_PERMSTR_HH +#define LCDF_PERMSTR_HH +#include <assert.h> +#include <stddef.h> +#include <stdarg.h> +#include <lcdf/inttypes.h> +class PermString; +inline bool operator==(PermString, PermString); +inline bool operator!=(PermString, PermString); + +class PermString { struct Doodad; public: + + typedef Doodad *Capsule; + // Declare a PermString::Initializer in any file in which you declare + // static global PermStrings. + struct Initializer { Initializer(); }; + + PermString() : _rep(zero_char_doodad.data) { } + explicit PermString(char c); + inline PermString(const char*); + inline PermString(const char*, int); + inline PermString(const char*, const char*); + + inline operator bool() const; + inline bool operator!() const; + + inline int length() const; + char operator[](int) const; + const char* begin() const { return _rep; } + inline const char* end() const; + + friend inline bool operator==(PermString, PermString); + friend inline bool operator!=(PermString, PermString); + + const char* c_str() const { return _rep; } + + inline Capsule capsule() const; + inline static PermString decapsule(Capsule c); + + friend PermString permprintf(const char*, ...); + friend PermString vpermprintf(const char*, va_list); + friend PermString permcat(PermString, PermString); + friend PermString permcat(PermString, PermString, PermString); + + private: + + struct Doodad { + Doodad* next; + int length; + char data[2]; + }; + + const char* _rep; + + PermString(Doodad* d) : _rep(d->data) { } + void initialize(const char*, int); + Doodad* doodad() const { return (Doodad*)(_rep - offsetof(Doodad, data)); } + + friend struct PermString::Initializer; + static void static_initialize(); + + enum { NHASH = 1024 }; // must be power of 2 + static Doodad zero_char_doodad, one_char_doodad[256], *buckets[NHASH]; + +}; + + +inline +PermString::PermString(const char* s) +{ + initialize(s, -1); +} + +inline +PermString::PermString(const char* s, int len) +{ + initialize(s, len); +} + +inline +PermString::PermString(const char* begin, const char* end) +{ + assert(end); + initialize(begin, end > begin ? end - begin : 0); +} + +inline +PermString::operator bool() const +{ + return _rep != zero_char_doodad.data; +} + +inline bool +PermString::operator!() const +{ + return _rep == zero_char_doodad.data; +} + +inline int +PermString::length() const +{ + return doodad()->length; +} + +inline const char* +PermString::end() const +{ + return _rep + doodad()->length; +} + +inline bool +operator==(PermString a, PermString b) +{ + return a._rep == b._rep; +} + +bool operator==(PermString, const char*); + +inline bool +operator==(const char* a, PermString b) +{ + return b == a; +} + +inline bool +operator!=(PermString a, PermString b) +{ + return a._rep != b._rep; +} + +inline bool +operator!=(PermString a, const char* b) +{ + return !(a == b); +} + +inline bool +operator!=(const char* a, PermString b) +{ + return !(b == a); +} + +inline PermString::Capsule +PermString::capsule() const +{ + return doodad(); +} + +inline PermString +PermString::decapsule(Capsule c) +{ + return PermString(c); +} + +inline unsigned +hashcode(PermString s) +{ + return (uintptr_t)(s.c_str()); +} + +PermString permprintf(const char*, ...); +PermString vpermprintf(const char*, va_list); +PermString permcat(PermString, PermString); +PermString permcat(PermString, PermString, PermString); + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/point.hh b/Build/source/texk/lcdf-typetools/include/lcdf/point.hh new file mode 100644 index 00000000000..a4d2495cac2 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/point.hh @@ -0,0 +1,185 @@ +// -*- related-file-name: "../../liblcdf/point.cc" -*- +#ifndef LCDF_POINT_HH +#define LCDF_POINT_HH +#include <math.h> + +struct Point { + + double x; + double y; + + Point() { } + Point(double xx, double yy) : x(xx), y(yy) { } + // Point(const Point &) use compiler default + Point(const Point &p, double dx, double dy) : x(p.x + dx), y(p.y + dy) { } + // ~Point() use compiler default + + inline double squared_length() const throw (); + inline double length() const throw (); + inline double magnitude() const throw (); + static inline double distance(const Point &, const Point &) throw (); + static inline double dot(const Point &, const Point &) throw (); + static Point midpoint(const Point &, const Point &) throw (); + + inline double angle() const throw (); + + void shift(double dx, double dy) { x += dx; y += dy; } + + inline Point shifted(double dx, double dy) const throw (); + Point rotated(double) const throw (); + inline Point normal() const throw (); + + bool on_line(const Point &, const Point &, double) const throw (); + bool on_segment(const Point &, const Point &, double) const throw (); + + inline Point &operator+=(const Point &) throw (); + inline Point &operator-=(const Point &) throw (); + inline Point &operator*=(double) throw (); + inline Point &operator/=(double) throw (); + + // Point operator+(Point, const Point &); + // Point operator-(Point, const Point &); + // Point operator*(Point, double); + // Point operator/(Point, double); + // Point operator-(const Point &); + + // bool operator==(const Point &, const Point &); + // bool operator!=(const Point &, const Point &); + +}; + +inline double +Point::squared_length() const throw () +{ + return x*x + y*y; +} + +inline double +Point::length() const throw () +{ + return sqrt(x*x + y*y); +} + +inline double +Point::magnitude() const throw () +{ + return length(); +} + +inline double +Point::angle() const throw () +{ + return atan2(y, x); +} + +inline Point +Point::shifted(double dx, double dy) const throw () +{ + return Point(x + dx, y + dy); +} + +inline Point +Point::normal() const throw () +{ + double l = length(); + return (l ? Point(x/l, y/l) : *this); +} + +inline Point & +Point::operator+=(const Point &p) throw () +{ + x += p.x; + y += p.y; + return *this; +} + +inline Point & +Point::operator-=(const Point &p) throw () +{ + x -= p.x; + y -= p.y; + return *this; +} + +inline Point & +Point::operator*=(double d) throw () +{ + x *= d; + y *= d; + return *this; +} + +inline Point & +Point::operator/=(double d) throw () +{ + x /= d; + y /= d; + return *this; +} + +inline bool +operator==(const Point &a, const Point &b) throw () +{ + return a.x == b.x && a.y == b.y; +} + +inline bool +operator!=(const Point &a, const Point &b) throw () +{ + return a.x != b.x || a.y != b.y; +} + +inline Point +operator+(Point a, const Point &b) throw () +{ + a += b; + return a; +} + +inline Point +operator-(Point a, const Point &b) throw () +{ + a -= b; + return a; +} + +inline Point +operator-(const Point &a) throw () +{ + return Point(-a.x, -a.y); +} + +inline Point +operator*(Point a, double scale) throw () +{ + a *= scale; + return a; +} + +inline Point +operator*(double scale, Point a) throw () +{ + a *= scale; + return a; +} + +inline Point +operator/(Point a, double scale) throw () +{ + a /= scale; + return a; +} + +inline double +Point::distance(const Point &a, const Point &b) throw () +{ + return (a - b).length(); +} + +inline double +Point::dot(const Point &a, const Point &b) throw () +{ + return a.x*b.x + a.y*b.y; +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/slurper.hh b/Build/source/texk/lcdf-typetools/include/lcdf/slurper.hh new file mode 100644 index 00000000000..2e400d3c3f2 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/slurper.hh @@ -0,0 +1,63 @@ +// -*- related-file-name: "../../liblcdf/slurper.cc" -*- +#ifndef LCDF_SLURPER_HH +#define LCDF_SLURPER_HH +#include <lcdf/landmark.hh> +#include <lcdf/filename.hh> +#include <stdio.h> + +class Slurper { public: + + Slurper(const Filename &, FILE * = 0); + ~Slurper(); + + bool ok() const { return _f != 0; } + + Landmark landmark() const { return Landmark(_filename.name(), _lineno); } + operator Landmark() const { return landmark(); } + unsigned lineno() const { return _lineno; } + + const Filename &filename() const { return _filename; } + char *peek_line(); + char *next_line(); + char *append_next_line(); + void save_line() { _saved_line = true; } + + char *cur_line() const { return (char *)_line; } + unsigned cur_line_length() const { return _line_len; } + void shorten_line(unsigned); + + private: + + FILE *_f; + Filename _filename; + unsigned _lineno; + bool _own_f; + + unsigned char *_data; + unsigned _cap; + unsigned _pos; + unsigned _len; + + unsigned char *_line; + unsigned _line_len; + + bool _saved_line; + bool _at_eof; + + void grow_buffer(); + inline int more_data(); + char *get_line_at(unsigned); + +}; + + +inline void +Slurper::shorten_line(unsigned pos) +{ + if (pos < _line_len) { + _line_len = pos; + _line[_line_len] = 0; + } +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/straccum.hh b/Build/source/texk/lcdf-typetools/include/lcdf/straccum.hh new file mode 100644 index 00000000000..e6c6422d2af --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/straccum.hh @@ -0,0 +1,298 @@ +// -*- related-file-name: "../../liblcdf/straccum.cc" -*- +#ifndef LCDF_STRACCUM_HH +#define LCDF_STRACCUM_HH +#include <string.h> +#include <assert.h> +#include <lcdf/string.hh> +#ifdef HAVE_PERMSTRING +# include <lcdf/permstr.hh> +#endif +template<class T> class Vector; + +class StringAccum { public: + + StringAccum() : _s(0), _len(0), _cap(0) { } + explicit inline StringAccum(int); + explicit StringAccum(const char *); + explicit StringAccum(const String &); +#ifdef HAVE_PERMSTRING + explicit StringAccum(PermString); +#endif + ~StringAccum() { if (_cap >= 0) delete[] _s; } + + char *data() const { return (char *)_s; } + int length() const { return _len; } + + operator bool() const { return _len != 0; } + bool operator!() const { return _len == 0; } + + bool out_of_memory() const { return _cap < 0; } + + const char *c_str(); + + char operator[](int i) const{ assert(i>=0&&i<_len); return (char)_s[i]; } + char &operator[](int i) { assert(i>=0&&i<_len); return (char &)_s[i]; } + char back() const { assert(_len>0); return (char)_s[_len-1]; } + char &back() { assert(_len>0); return (char &)_s[_len-1]; } + + inline void clear(); + + inline char *extend(int, int = 0); + + inline void append(char); + inline void append(unsigned char); + inline void append_utf8(uint32_t); + inline void append(const char *, int); + inline void append(const char *begin, const char *end); + inline void append(const unsigned char *, int); + + // word joining + void append_break_lines(const String& text, int linelen, const String& leftmargin = String()); + + inline char *reserve(int); + void set_length(int l) { assert(l>=0 && _len<=_cap); _len = l; } + void forward(int n) { assert(n>=0 && _len+n<=_cap); _len += n; } + void pop_back(int n = 1) { assert(n>=0 && _len>=n); _len -= n; } + + StringAccum &snprintf(int, const char *, ...); + + inline unsigned char *take_bytes(); // returns array allocated by new[] + String take_string(); + + // see also operator<< declarations below + + private: + + unsigned char *_s; + int _len; + int _cap; + + void make_out_of_memory(); + inline void safe_append(const char *, int); + bool grow(int); + inline void erase(); + void append_utf8_hard(uint32_t); + + StringAccum(const StringAccum &); + StringAccum &operator=(const StringAccum &); + + friend StringAccum &operator<<(StringAccum &, const char *); +#ifdef HAVE_PERMSTRING + friend StringAccum &operator<<(StringAccum &, PermString); +#endif + +}; + +inline StringAccum &operator<<(StringAccum &, char); +inline StringAccum &operator<<(StringAccum &, unsigned char); +inline StringAccum &operator<<(StringAccum &, const char *); +inline StringAccum &operator<<(StringAccum &, const String &); +inline StringAccum &operator<<(StringAccum &, const StringAccum &); +#ifdef HAVE_PERMSTRING +inline StringAccum &operator<<(StringAccum &, PermString); +#endif + +inline StringAccum &operator<<(StringAccum &, bool); +inline StringAccum &operator<<(StringAccum &, short); +inline StringAccum &operator<<(StringAccum &, unsigned short); +inline StringAccum &operator<<(StringAccum &, int); +inline StringAccum &operator<<(StringAccum &, unsigned); +StringAccum &operator<<(StringAccum &, long); +StringAccum &operator<<(StringAccum &, unsigned long); +StringAccum &operator<<(StringAccum &, double); + + +inline +StringAccum::StringAccum(int cap) + : _s(new unsigned char[cap]), _len(0), _cap(cap) +{ + assert(cap > 0); + if (!_s) + _cap = -1; +} + +inline void +StringAccum::append(unsigned char c) +{ + if (_len < _cap || grow(_len)) + _s[_len++] = c; +} + +inline void +StringAccum::append(char c) +{ + append(static_cast<unsigned char>(c)); +} + +inline void +StringAccum::append_utf8(uint32_t ch) +{ + if (ch < 0x80) + append((unsigned char) ch); + else + append_utf8_hard(ch); +} + +inline char * +StringAccum::reserve(int hm) +{ + assert(hm >= 0); + if (_len + hm <= _cap || grow(_len + hm)) + return (char *)(_s + _len); + else + return 0; +} + +inline char * +StringAccum::extend(int amt, int extra) +{ + assert(extra >= 0); + char *c = reserve(amt + extra); + if (c) + _len += amt; + return c; +} + +inline void +StringAccum::safe_append(const char *s, int len) +{ + if (char *x = extend(len)) + memcpy(x, s, len); +} + +inline void +StringAccum::append(const char *s, int len) +{ + if (len < 0) + len = strlen(s); + else if (len == 0 && s == String::out_of_memory_data()) + make_out_of_memory(); + safe_append(s, len); +} + +inline void +StringAccum::append(const unsigned char *s, int len) +{ + append(reinterpret_cast<const char *>(s), len); +} + +inline void +StringAccum::append(const char *begin, const char *end) +{ + if (begin < end) + safe_append(begin, end - begin); + else if (begin == String::out_of_memory_data()) + make_out_of_memory(); +} + +inline void +StringAccum::erase() +{ + _s = 0; + _len = 0; + _cap = 0; +} + +inline unsigned char * +StringAccum::take_bytes() +{ + unsigned char *str = _s; + erase(); + return str; +} + +inline void +StringAccum::clear() +{ + if (_cap < 0) + _cap = 0, _s = 0; + _len = 0; +} + +inline StringAccum & +operator<<(StringAccum &sa, char c) +{ + sa.append(c); + return sa; +} + +inline StringAccum & +operator<<(StringAccum &sa, unsigned char c) +{ + sa.append(c); + return sa; +} + +inline StringAccum & +operator<<(StringAccum &sa, const char *s) +{ + sa.safe_append(s, strlen(s)); + return sa; +} + +inline StringAccum & +operator<<(StringAccum &sa, bool b) +{ + return sa << (b ? "true" : "false"); +} + +inline StringAccum & +operator<<(StringAccum &sa, short i) +{ + return sa << static_cast<long>(i); +} + +inline StringAccum & +operator<<(StringAccum &sa, unsigned short u) +{ + return sa << static_cast<unsigned long>(u); +} + +inline StringAccum & +operator<<(StringAccum &sa, int i) +{ + return sa << static_cast<long>(i); +} + +inline StringAccum & +operator<<(StringAccum &sa, unsigned u) +{ + return sa << static_cast<unsigned long>(u); +} + +inline StringAccum & +operator<<(StringAccum &sa, const String &s) +{ + sa.append(s.data(), s.length()); + return sa; +} + +#ifdef HAVE_PERMSTRING +inline StringAccum & +operator<<(StringAccum &sa, PermString s) +{ + sa.safe_append(s.c_str(), s.length()); + return sa; +} +#endif + +inline StringAccum & +operator<<(StringAccum &sa, const StringAccum &sb) +{ + sa.append(sb.data(), sb.length()); + return sa; +} + +inline bool +operator==(StringAccum &sa, const char *s) +{ + return strcmp(sa.c_str(), s) == 0; +} + +inline bool +operator!=(StringAccum &sa, const char *s) +{ + return strcmp(sa.c_str(), s) != 0; +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/string.hh b/Build/source/texk/lcdf-typetools/include/lcdf/string.hh new file mode 100644 index 00000000000..34eb1af3ed9 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/string.hh @@ -0,0 +1,460 @@ +// -*- related-file-name: "../../liblcdf/string.cc" -*- +#ifndef LCDF_STRING_HH +#define LCDF_STRING_HH +#ifdef HAVE_PERMSTRING +# include <lcdf/permstr.hh> +#endif +#include <assert.h> +class StringAccum; + +class String { public: + + // Call static_initialize() before any function which might deal with + // Strings, and declare a String::Initializer in any file in which you + // declare static global Strings. + struct Initializer { Initializer(); }; + friend struct String::Initializer; + static void static_initialize(); + static void static_cleanup(); + + inline String(); + inline String(const String &s); + String(const char *cc) { assign(cc, -1); } + String(const char *cc, int l) { assign(cc, l); } +#ifdef HAVE_PERMSTRING + inline String(PermString p); +#endif + explicit inline String(char); + explicit inline String(unsigned char); + explicit String(int); + explicit String(unsigned); + explicit String(long); + explicit String(unsigned long); + explicit String(double); + inline ~String(); + + static const String &null_string() { return *null_string_p; } + static const String &out_of_memory_string() { return *oom_string_p; } + static const char *out_of_memory_data() { return &oom_string_data; } + static String garbage_string(int n); // n garbage characters + static String fill_string(int c, int n); // n copies of c + static String stable_string(const char *, int = -1); // stable read-only memory + + bool out_of_memory() const { return _data == &oom_string_data; } + + int length() const { return _length; } + const char *data() const { return _data; } + const unsigned char *udata() const { return reinterpret_cast<const unsigned char *>(_data); } + + typedef const char *const_iterator; + typedef const_iterator iterator; + const_iterator begin() const { return _data; } + const_iterator end() const { return _data + _length; } + + char *mutable_data(); + char *mutable_c_str(); + unsigned char *mutable_udata() { return reinterpret_cast<unsigned char *>(mutable_data()); } + + operator bool() const { return _length != 0; } + bool operator!() const { return _length == 0; } + +#ifdef HAVE_PERMSTRING + operator PermString() const { return PermString(_data, _length); } +#endif + + const char *c_str() const; // pointer returned is semi-transient + + char operator[](int i) const { return _data[i]; } + char back() const { return _data[_length - 1]; } + int find_left(int c, int start = 0) const; + int find_left(const String &s, int start = 0) const; + int find_right(int c, int start = 0x7FFFFFFF) const; + + bool equals(const char *, int) const; + // bool operator==(const String &, const String &); + // bool operator==(const String &, const char *); + // bool operator==(const char *, const String &); + // bool operator!=(const String &, const String &); + // bool operator!=(const String &, const char *); + // bool operator!=(const char *, const String &); + + int compare(const char *, int) const; + int compare(const String &x) const { return compare(x._data, x._length); } + static inline int compare(const String &a, const String &b); + // bool operator<(const String &, const String &); + // bool operator<=(const String &, const String &); + // bool operator>(const String &, const String &); + // bool operator>=(const String &, const String &); + + String substring(const char *begin, const char *end) const; + String substring(int pos, int len) const; + String substring(int pos) const { return substring(pos, _length); } + + String lower() const; + String upper() const; + String printable() const; + + inline String &operator=(const String &); + inline String &operator=(const char *); +#ifdef HAVE_PERMSTRING + inline String &operator=(PermString); +#endif + + void append(const char *, int len); + void append_fill(int c, int len); + char *append_garbage(int len); + inline String &operator+=(const String &); + inline String &operator+=(const char *); + inline String &operator+=(char); +#ifdef HAVE_PERMSTRING + inline String &operator+=(PermString p); +#endif + + // String operator+(String, const String &); + // String operator+(String, const char *); + // String operator+(const char *, const String &); + // String operator+(String, PermString); + // String operator+(PermString, String); + // String operator+(PermString, const char *); + // String operator+(const char *, PermString); + // String operator+(PermString, PermString); + // String operator+(String, char); + + void align(int); + + private: + + struct Memo { + int _refcount; + int _capacity; + int _dirty; + char *_real_data; + + inline Memo(); + inline Memo(char *, int, int); + Memo(int, int); + ~Memo(); + }; + + mutable const char *_data; // mutable for c_str() + mutable int _length; + mutable Memo *_memo; + + inline String(const char *, int, Memo *); + + inline void assign(const String &) const; + void assign(const char *, int); +#ifdef HAVE_PERMSTRING + inline void assign(PermString) const; +#endif + inline void deref() const; + void make_out_of_memory(); + + static Memo *null_memo; + static Memo *permanent_memo; + static Memo *oom_memo; + static String *null_string_p; + static String *oom_string_p; + static const char oom_string_data; + + static String claim_string(char *, int, int); // claim memory + + friend class StringAccum; + +}; + + +inline +String::String(const char *data, int length, Memo *memo) + : _data(data), _length(length), _memo(memo) +{ + _memo->_refcount++; +} + +inline void +String::assign(const String &s) const +{ + _data = s._data; + _length = s._length; + _memo = s._memo; + _memo->_refcount++; +} + +inline void +String::deref() const +{ + if (--_memo->_refcount == 0) + delete _memo; +} + +inline +String::String() + : _data(null_memo->_real_data), _length(0), _memo(null_memo) +{ + _memo->_refcount++; +} + +inline +String::String(char c) +{ + assign(&c, 1); +} + +inline +String::String(unsigned char c) +{ + assign(reinterpret_cast<char *>(&c), 1); +} + +inline +String::String(const String &s) +{ + assign(s); +} + +inline +String::~String() +{ + deref(); +} + +inline String +String::substring(const char *begin, const char *end) const +{ + if (begin < end && begin >= _data && end <= _data + _length) + return String(begin, end - begin, _memo); + else + return String(); +} + +inline int +String::compare(const String &a, const String &b) +{ + return a.compare(b); +} + +inline bool +operator==(const String &s1, const String &s2) +{ + return s1.equals(s2.data(), s2.length()); +} + +inline bool +operator==(const char *cc1, const String &s2) +{ + return s2.equals(cc1, -1); +} + +inline bool +operator==(const String &s1, const char *cc2) +{ + return s1.equals(cc2, -1); +} + +inline bool +operator!=(const String &s1, const String &s2) +{ + return !s1.equals(s2.data(), s2.length()); +} + +inline bool +operator!=(const char *cc1, const String &s2) +{ + return !s2.equals(cc1, -1); +} + +inline bool +operator!=(const String &s1, const char *cc2) +{ + return !s1.equals(cc2, -1); +} + +inline bool +operator<(const String &s1, const String &s2) +{ + return s1.compare(s2.data(), s2.length()) < 0; +} + +inline bool +operator<=(const String &s1, const String &s2) +{ + return s1.compare(s2.data(), s2.length()) <= 0; +} + +inline bool +operator>(const String &s1, const String &s2) +{ + return s1.compare(s2.data(), s2.length()) > 0; +} + +inline bool +operator>=(const String &s1, const String &s2) +{ + return s1.compare(s2.data(), s2.length()) >= 0; +} + + +inline String & +String::operator=(const String &s) +{ + if (&s != this) { + deref(); + assign(s); + } + return *this; +} + +inline String & +String::operator=(const char *cc) +{ + deref(); + assign(cc, -1); + return *this; +} + +inline String & +String::operator+=(const String &s) +{ + append(s._data, s._length); + return *this; +} + +inline String & +String::operator+=(const char *cc) +{ + append(cc, -1); + return *this; +} + +inline String & +String::operator+=(char c) +{ + append_fill(c, 1); + return *this; +} + +inline String +operator+(String s1, const String &s2) +{ + s1 += s2; + return s1; +} + +inline String +operator+(String s1, const char *cc2) +{ + s1.append(cc2, -1); + return s1; +} + +inline String +operator+(const char *cc1, const String &s2) +{ + String s1(cc1); + s1 += s2; + return s1; +} + +inline String +operator+(String s1, char c2) +{ + s1.append(&c2, 1); + return s1; +} + +#ifdef HAVE_PERMSTRING + +inline void +String::assign(PermString p) const +{ + _data = p.c_str(); + _length = p.length(); + _memo = permanent_memo; + _memo->_refcount++; +} + +inline +String::String(PermString p) +{ + assign(p); +} + +inline bool +operator==(PermString p1, const String &s2) +{ + return s2.equals(p1.c_str(), p1.length()); +} + +inline bool +operator==(const String &s1, PermString p2) +{ + return s1.equals(p2.c_str(), p2.length()); +} + +inline bool +operator!=(PermString p1, const String &s2) +{ + return !s2.equals(p1.c_str(), p1.length()); +} + +inline bool +operator!=(const String &s1, PermString p2) +{ + return !s1.equals(p2.c_str(), p2.length()); +} + +inline String & +String::operator=(PermString p) +{ + deref(); + assign(p); + return *this; +} + +inline String & +String::operator+=(PermString p) +{ + append(p.c_str(), p.length()); + return *this; +} + +inline String +operator+(String s1, PermString p2) +{ + s1.append(p2.c_str(), p2.length()); + return s1; +} + +inline String +operator+(PermString p1, String s2) +{ + String s1(p1); + return s1 + s2; +} + +inline String +operator+(PermString p1, const char *cc2) +{ + String s1(p1); + return s1 + cc2; +} + +inline String +operator+(const char *cc1, PermString p2) +{ + String s1(cc1); + return s1 + p2; +} + +inline String +operator+(PermString p1, PermString p2) +{ + String s1(p1); + return s1 + p2; +} + +#endif + +unsigned hashcode(const String &); + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/strtonum.h b/Build/source/texk/lcdf-typetools/include/lcdf/strtonum.h new file mode 100644 index 00000000000..ee8745a4a42 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/strtonum.h @@ -0,0 +1,10 @@ +#ifdef __cplusplus +extern "C" { +#endif + +double strtonumber(const char *, char **); + +#ifdef __cplusplus +} +#endif + diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/transform.hh b/Build/source/texk/lcdf-typetools/include/lcdf/transform.hh new file mode 100644 index 00000000000..64c8dc384b7 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/transform.hh @@ -0,0 +1,162 @@ +// -*- related-file-name: "../../liblcdf/transform.cc" -*- +#ifndef LCDF_TRANSFORM_HH +#define LCDF_TRANSFORM_HH +#include <lcdf/bezier.hh> +#include <lcdf/string.hh> +#include <assert.h> + +class Transform { public: + + Transform(); + Transform(const double[6]); + Transform(double scalex, double sheary, double shearx, double scaley, double shiftx, double shifty); + // Transform(const Transform &) generated by compiler + // ~Transform() generated by compiler + + double operator[](int i) const { assert(i>=0&&i<6); return _m[i]; } + bool null() const { return _null; } + void check_null(double tolerance); + + void scale(double, double); + void scale(const Point &p) { scale(p.x, p.y); } + void scale(double d) { scale(d, d); } + void rotate(double); + void translate(double, double); + void translate(const Point &p) { translate(p.x, p.y); } + void shear(double); + inline void transform(const Transform &); + + inline Transform scaled(double, double) const; + Transform scaled(const Point &p) const { return scaled(p.x, p.y); } + Transform scaled(double d) const { return scaled(d, d); } + inline Transform rotated(double) const; + inline Transform translated(double, double) const; + inline Transform translated(const Point &p) const; + inline Transform sheared(double) const; + Transform transformed(const Transform &) const; + + // Transform operator+(Transform, const Point &); + // Transform &operator+=(Transform &, const Point &); + // Transform operator*(Transform, double); + // Transform &operator*=(Transform &, double); + // Transform operator*(Transform, const Transform &); + // Transform &operator*=(Transform &, const Transform &); + friend Point operator*(const Point &, const Transform &); + friend Point &operator*=(Point &, const Transform &); + friend Bezier operator*(const Bezier &, const Transform &); + friend Bezier &operator*=(Bezier &, const Transform &); + + String unparse() const; + + private: + + // stored in PostScript order (along columns) + double _m[6]; + bool _null; + + void real_apply_to(Point &) const; + Point real_apply(const Point &) const; + +}; + + +inline Transform +Transform::scaled(double x, double y) const +{ + Transform t(*this); + t.scale(x, y); + return t; +} + +inline Transform +Transform::rotated(double r) const +{ + Transform t(*this); + t.rotate(r); + return t; +} + +inline Transform +Transform::translated(double x, double y) const +{ + Transform t(*this); + t.translate(x, y); + return t; +} + +inline Transform +Transform::translated(const Point &p) const +{ + return translated(p.x, p.y); +} + +inline Transform +Transform::sheared(double s) const +{ + Transform t(*this); + t.shear(s); + return t; +} + + +inline Transform & +operator+=(Transform &t, const Point &p) +{ + t.translate(p); + return t; +} + +inline Transform +operator+(Transform t, const Point &p) +{ + return t += p; +} + +inline Transform & +operator*=(Transform &t, double scale) +{ + t.scale(scale); + return t; +} + +inline Transform +operator*(Transform t, double scale) +{ + return t *= scale; +} + +inline Transform +operator*(const Transform &t, const Transform &tt) +{ + return t.transformed(tt); +} + +inline Transform & +operator*=(Transform &t, const Transform &tt) +{ + t = t.transformed(tt); + return t; +} + +inline void +Transform::transform(const Transform &t) +{ + *this *= t; +} + + +inline Point & +operator*=(Point &p, const Transform &t) +{ + if (!t.null()) + t.real_apply_to(p); + return p; +} + +inline Point +operator*(const Point &p, const Transform &t) +{ + return (t.null() ? p : t.real_apply(p)); +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/vector.cc b/Build/source/texk/lcdf-typetools/include/lcdf/vector.cc new file mode 100644 index 00000000000..0097edb2e47 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/vector.cc @@ -0,0 +1,130 @@ +#ifndef LCDF_VECTOR_CC +#define LCDF_VECTOR_CC + +/* + * vector.{cc,hh} -- simple array template class + * Eddie Kohler + * + * Copyright (c) 1999-2000 Massachusetts Institute of Technology + * Copyright (c) 2001-2003 International Computer Science Institute + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, subject to the conditions + * listed in the Click LICENSE file. These conditions include: you must + * preserve this copyright notice, and you cannot mention the copyright + * holders in advertising related to the Software without their permission. + * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This + * notice is a summary of the Click LICENSE file; the license in that file is + * legally binding. + */ + +/* #include <lcdf/vector.hh> */ + +template <class T> +Vector<T>::Vector(const Vector<T> &o) + : _l(0), _n(0), _capacity(0) +{ + *this = o; +} + +template <class T> +Vector<T>::~Vector() +{ + for (int i = 0; i < _n; i++) + _l[i].~T(); + delete[] (unsigned char *)_l; +} + +template <class T> Vector<T> & +Vector<T>::operator=(const Vector<T> &o) +{ + if (&o != this) { + for (int i = 0; i < _n; i++) + _l[i].~T(); + _n = 0; + if (reserve(o._n)) { + _n = o._n; + for (int i = 0; i < _n; i++) + new(velt(i)) T(o._l[i]); + } + } + return *this; +} + +template <class T> Vector<T> & +Vector<T>::assign(int n, const T &e) +{ + resize(0, e); + resize(n, e); + return *this; +} + +template <class T> typename Vector<T>::iterator +Vector<T>::erase(iterator a, iterator b) +{ + if (b > a) { + assert(a >= begin() && b <= end()); + iterator i = a, j = b; + for (; j < end(); i++, j++) { + i->~T(); + new((void*) i) T(*j); + } + for (; i < end(); i++) + i->~T(); + _n -= b - a; + return a; + } else + return b; +} + +template <class T> bool +Vector<T>::reserve(int want) +{ + if (want < 0) + want = _capacity > 0 ? _capacity * 2 : 4; + if (want <= _capacity) + return true; + + T *new_l = (T *)new unsigned char[sizeof(T) * want]; + if (!new_l) + return false; + + for (int i = 0; i < _n; i++) { + new(velt(new_l, i)) T(_l[i]); + _l[i].~T(); + } + delete[] (unsigned char *)_l; + + _l = new_l; + _capacity = want; + return true; +} + +template <class T> void +Vector<T>::resize(int nn, const T &e) +{ + if (nn <= _capacity || reserve(nn)) { + for (int i = nn; i < _n; i++) + _l[i].~T(); + for (int i = _n; i < nn; i++) + new(velt(i)) T(e); + _n = nn; + } +} + +template <class T> void +Vector<T>::swap(Vector<T> &o) +{ + T *l = _l; + int n = _n; + int cap = _capacity; + _l = o._l; + _n = o._n; + _capacity = o._capacity; + o._l = l; + o._n = n; + o._capacity = cap; +} + +#endif diff --git a/Build/source/texk/lcdf-typetools/include/lcdf/vector.hh b/Build/source/texk/lcdf-typetools/include/lcdf/vector.hh new file mode 100644 index 00000000000..672abb88036 --- /dev/null +++ b/Build/source/texk/lcdf-typetools/include/lcdf/vector.hh @@ -0,0 +1,255 @@ +#ifndef LCDF_VECTOR_HH +#define LCDF_VECTOR_HH +#include <assert.h> +#include <stdlib.h> +#ifdef HAVE_NEW_HDR +# include <new> +#elif defined(HAVE_NEW_H) +# include <new.h> +#else +static inline void *operator new(size_t, void *v) { return v; } +#endif + +template <class T> +class Vector { public: + + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* pointer; + typedef const T* const_pointer; + + typedef int size_type; + + typedef T* iterator; + typedef const T* const_iterator; + + explicit Vector() : _l(0), _n(0), _capacity(0) { } + explicit Vector(size_type n, const T &e) : _l(0), _n(0), _capacity(0) { resize(n, e); } + // template <class In> ... + Vector(const Vector<T> &); + ~Vector(); + + Vector<T>& operator=(const Vector<T>&); + Vector<T>& assign(size_type n, const T& e = T()); + // template <class In> ... + + // iterators + iterator begin() { return _l; } + const_iterator begin() const { return _l; } + iterator end() { return _l + _n; } + const_iterator end() const { return _l + _n; } + + // capacity + size_type size() const { return _n; } + void resize(size_type nn, const T& e = T()); + size_type capacity() const { return _capacity; } + bool empty() const { return _n == 0; } + bool reserve(size_type); + + // element access + T& operator[](size_type i) { assert(i>=0 && i<_n); return _l[i]; } + const T& operator[](size_type i) const{ assert(i>=0 && i<_n); return _l[i]; } + T& at(size_type i) { return operator[](i); } + const T& at(size_type i) const { return operator[](i); } + T& front() { return operator[](0); } + const T& front() const { return operator[](0); } + T& back() { return operator[](_n - 1); } + const T& back() const { return operator[](_n - 1); } + T& at_u(size_type i) { return _l[i]; } + const T& at_u(size_type i) const { return _l[i]; } + + // modifiers + inline void push_back(const T&); + inline void pop_back(); + inline iterator erase(iterator); + iterator erase(iterator, iterator); + void swap(Vector<T> &); + void clear() { erase(begin(), end()); } + + private: + + T *_l; + size_type _n; + size_type _capacity; + + void *velt(size_type i) const { return (void *)&_l[i]; } + static void *velt(T *l, size_type i) { return (void *)&l[i]; } + +}; + +template <class T> inline void +Vector<T>::push_back(const T &e) +{ + if (_n < _capacity || reserve(-1)) { + new(velt(_n)) T(e); + _n++; + } +} + +template <class T> inline void +Vector<T>::pop_back() +{ + assert(_n > 0); + --_n; + _l[_n].~T(); +} + +template <class T> inline typename Vector<T>::iterator +Vector<T>::erase(iterator e) +{ + return (e < end() ? erase(e, e + 1) : e); +} + + +template <> +class Vector<void*> { public: + + typedef void* value_type; + typedef void*& reference; + typedef void* const& const_reference; + typedef void** pointer; + typedef void* const* const_pointer; + + typedef int size_type; + + typedef void** iterator; + typedef void* const* const_iterator; + + explicit Vector() : _l(0), _n(0), _capacity(0) { } + explicit Vector(size_type n, void* e) : _l(0), _n(0), _capacity(0) { resize(n, e); } + Vector(const Vector<void*> &); + ~Vector(); + + Vector<void*> &operator=(const Vector<void*> &); + Vector<void*> &assign(size_type n, void* e = 0); + + // iterators + iterator begin() { return _l; } + const_iterator begin() const { return _l; } + iterator end() { return _l + _n; } + const_iterator end() const { return _l + _n; } + + // capacity + size_type size() const { return _n; } + void resize(size_type nn, void* e = 0); + size_type capacity() const { return _capacity; } + bool empty() const { return _n == 0; } + bool reserve(size_type); + + // element access + void*& operator[](size_type i) { assert(i>=0 && i<_n); return _l[i]; } + void* operator[](size_type i) const { assert(i>=0 && i<_n); return _l[i]; } + void*& at(size_type i) { return operator[](i); } + void* at(size_type i) const { return operator[](i); } + void*& front() { return operator[](0); } + void* front() const { return operator[](0); } + void*& back() { return operator[](_n - 1); } + void* back() const { return operator[](_n - 1); } + void*& at_u(size_type i) { return _l[i]; } + void* at_u(size_type i) const { return _l[i]; } + + // modifiers + inline void push_back(void*); + inline void pop_back(); + inline iterator erase(iterator); + iterator erase(iterator, iterator); + void swap(Vector<void*> &); + void clear() { _n = 0; } + + private: + + void **_l; + size_type _n; + size_type _capacity; + +}; + +inline void +Vector<void*>::push_back(void *e) +{ + if (_n < _capacity || reserve(-1)) { + _l[_n] = e; + _n++; + } +} + +inline void +Vector<void*>::pop_back() +{ + assert(_n > 0); + --_n; +} + +inline Vector<void*>::iterator +Vector<void*>::erase(Vector<void*>::iterator e) +{ + return (e < end() ? erase(e, e + 1) : e); +} + + +template <class T> +class Vector<T*>: private Vector<void*> { + + typedef Vector<void*> Base; + + public: + + typedef T* value_type; + typedef T*& reference; + typedef T* const& const_reference; + typedef T** pointer; + typedef T* const* const_pointer; + + typedef int size_type; + + typedef T** iterator; + typedef T* const* const_iterator; + + explicit Vector() : Base() { } + explicit Vector(size_type n, T* e) : Base(n, (void *)e) { } + Vector(const Vector<T *> &o) : Base(o) { } + ~Vector() { } + + Vector<T *> &operator=(const Vector<T *> &o) + { Base::operator=(o); return *this; } + Vector<T *> &assign(size_type n, T *e = 0) + { Base::assign(n, (void *)e); return *this; } + + // iterators + const_iterator begin() const { return (const_iterator)(Base::begin()); } + iterator begin() { return (iterator)(Base::begin()); } + const_iterator end() const { return (const_iterator)(Base::end()); } + iterator end() { return (iterator)(Base::end()); } + + // capacity + size_type size() const { return Base::size(); } + void resize(size_type n, T *e = 0) { Base::resize(n, (void *)e); } + size_type capacity() const { return Base::capacity(); } + bool empty() const { return Base::empty(); } + bool reserve(size_type n) { return Base::reserve(n); } + + // element access + T*& operator[](size_type i) { return (T*&)(Base::at(i)); } + T* operator[](size_type i) const { return (T*)(Base::operator[](i)); } + T*& at(size_type i) { return (T*&)(Base::operator[](i)); } + T* at(size_type i) const { return (T*)(Base::at(i)); } + T*& front() { return (T*&)(Base::front()); } + T* front() const { return (T*)(Base::front()); } + T*& back() { return (T*&)(Base::back()); } + T* back() const { return (T*)(Base::back()); } + T*& at_u(size_type i) { return (T*&)(Base::at_u(i)); } + T* at_u(size_type i) const { return (T*)(Base::at_u(i)); } + + // modifiers + void push_back(T* e) { Base::push_back((void*)e); } + void pop_back() { Base::pop_back(); } + iterator erase(iterator i) { return Base::erase((void**)i); } + iterator erase(iterator i, iterator j) { return Base::erase((void**)i, (void**)j); } + void swap(Vector<T *> &o) { Base::swap(o); } + void clear() { Base::clear(); } + +}; + +#include <lcdf/vector.cc> // necessary to support GCC 3.3 +#endif |