summaryrefslogtreecommitdiff
path: root/Build/source/texk/lcdf-typetools/lcdf-typetools-2.98/libefont/t1unparser.cc
blob: 993253deec9aa823b7ea9d334b111fb64d3a4440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// -*- related-file-name: "../include/efont/t1unparser.hh" -*-

/* t1unparser.{cc,hh} -- debug printing of Type 1 fonts
 *
 * Copyright (c) 1998-2012 Eddie Kohler
 *
 * 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 of the License, 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.
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <efont/t1unparser.hh>
namespace Efont {

CharstringUnparser::CharstringUnparser()
    : CharstringInterp(),
      _one_command_per_line(false), _start_of_line(true)
{
}

CharstringUnparser::CharstringUnparser(const CharstringUnparser &o)
    : CharstringInterp(o),
      _one_command_per_line(o._one_command_per_line),
      _start_of_line(o._start_of_line)
{
}

void
CharstringUnparser::clear()
{
    _sa.clear();
    _start_of_line = true;
}

bool
CharstringUnparser::number(double n)
{
    if (_start_of_line) {
	_sa << _indent;
	_start_of_line = false;
    } else
	_sa << ' ';
    _sa << n;
    return true;
}

bool
CharstringUnparser::type1_command(int cmd)
{
    if (_start_of_line) {
	_sa << _indent;
	_start_of_line = false;
    } else
	_sa << ' ';
    if (cmd >= 0 && cmd <= Cs::cLastCommand)
	_sa << Cs::command_names[cmd];
    else
	_sa << "UNKNOWN_12_" << (cmd - 32);
    if (_one_command_per_line) {
	_sa << '\n';
	_start_of_line = true;
    }
    return true;
}

bool
CharstringUnparser::type2_command(int cmd, const unsigned char *data, int *left)
{
    if (_start_of_line) {
	_sa << _indent;
	_start_of_line = false;
    } else
	_sa << ' ';

    if (cmd >= 0 && cmd <= Cs::cLastCommand)
	_sa << Cs::command_names[cmd];
    else
	_sa << "UNKNOWN_12_" << (cmd - 32);

    switch (cmd) {
      case Cs::cHstem: case Cs::cHstemhm: case Cs::cVstem: case Cs::cVstemhm:
      case Cs::cHintmask: case Cs::cCntrmask:
	CharstringInterp::type2_command(cmd, data, left);
	break;
    }

    if (_one_command_per_line) {
	_sa << '\n';
	_start_of_line = true;
    }

    return true;
}

void
CharstringUnparser::act_hintmask(int, const unsigned char *data, int nhints)
{
    _sa << '[';
    for (int i = 0; i < nhints; i++, data++)
	sprintf(_sa.extend(2), "%02X", *data);
    _sa << ']';
}

String
CharstringUnparser::value()
{
    _start_of_line = true;
    return _sa.take_string();
}

String
CharstringUnparser::unparse(const Charstring *cs)
{
    if (cs) {
	CharstringUnparser u;
	u.interpret(0, cs);
	return u.value();
    } else
	return "(null)";
}

String
CharstringUnparser::unparse(const Charstring &cs)
{
    CharstringUnparser u;
    u.interpret(0, &cs);
    return u.value();
}

}