| 1 |
// -*- related-file-name: "../include/efont/t1unparser.hh" -*- |
| 2 |
|
| 3 |
/* t1unparser.{cc,hh} -- debug printing of Type 1 fonts |
| 4 |
* |
| 5 |
* Copyright (c) 1998-2019 Eddie Kohler |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify it |
| 8 |
* under the terms of the GNU General Public License as published by the Free |
| 9 |
* Software Foundation; either version 2 of the License, or (at your option) |
| 10 |
* any later version. This program is distributed in the hope that it will be |
| 11 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 13 |
* Public License for more details. |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifdef HAVE_CONFIG_H |
| 17 |
# include <config.h> |
| 18 |
#endif |
| 19 |
#include <efont/t1unparser.hh> |
| 20 |
namespace Efont { |
| 21 |
|
| 22 |
CharstringUnparser::CharstringUnparser() |
| 23 |
: CharstringInterp(), |
| 24 |
_one_command_per_line(false), _start_of_line(true) |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
CharstringUnparser::CharstringUnparser(const CharstringUnparser &o) |
| 29 |
: CharstringInterp(o), |
| 30 |
_one_command_per_line(o._one_command_per_line), |
| 31 |
_start_of_line(o._start_of_line) |
| 32 |
{ |
| 33 |
} |
| 34 |
|
| 35 |
void |
| 36 |
CharstringUnparser::clear() |
| 37 |
{ |
| 38 |
_sa.clear(); |
| 39 |
_start_of_line = true; |
| 40 |
} |
| 41 |
|
| 42 |
bool |
| 43 |
CharstringUnparser::number(double n) |
| 44 |
{ |
| 45 |
if (_start_of_line) { |
| 46 |
_sa << _indent; |
| 47 |
_start_of_line = false; |
| 48 |
} else |
| 49 |
_sa << ' '; |
| 50 |
_sa << n; |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
bool |
| 55 |
CharstringUnparser::type1_command(int cmd) |
| 56 |
{ |
| 57 |
if (_start_of_line) { |
| 58 |
_sa << _indent; |
| 59 |
_start_of_line = false; |
| 60 |
} else |
| 61 |
_sa << ' '; |
| 62 |
if (cmd >= 0 && cmd <= Cs::cLastCommand) |
| 63 |
_sa << Cs::command_names[cmd]; |
| 64 |
else |
| 65 |
_sa << "UNKNOWN_12_" << (cmd - 32); |
| 66 |
if (_one_command_per_line) { |
| 67 |
_sa << '\n'; |
| 68 |
_start_of_line = true; |
| 69 |
} |
| 70 |
return true; |
| 71 |
} |
| 72 |
|
| 73 |
bool |
| 74 |
CharstringUnparser::type2_command(int cmd, const unsigned char *data, int *left) |
| 75 |
{ |
| 76 |
if (_start_of_line) { |
| 77 |
_sa << _indent; |
| 78 |
_start_of_line = false; |
| 79 |
} else |
| 80 |
_sa << ' '; |
| 81 |
|
| 82 |
if (cmd >= 0 && cmd <= Cs::cLastCommand) |
| 83 |
_sa << Cs::command_names[cmd]; |
| 84 |
else |
| 85 |
_sa << "UNKNOWN_12_" << (cmd - 32); |
| 86 |
|
| 87 |
switch (cmd) { |
| 88 |
case Cs::cHstem: case Cs::cHstemhm: case Cs::cVstem: case Cs::cVstemhm: |
| 89 |
case Cs::cHintmask: case Cs::cCntrmask: |
| 90 |
CharstringInterp::type2_command(cmd, data, left); |
| 91 |
break; |
| 92 |
} |
| 93 |
|
| 94 |
if (_one_command_per_line) { |
| 95 |
_sa << '\n'; |
| 96 |
_start_of_line = true; |
| 97 |
} |
| 98 |
|
| 99 |
return true; |
| 100 |
} |
| 101 |
|
| 102 |
void |
| 103 |
CharstringUnparser::act_hintmask(int, const unsigned char *data, int nhints) |
| 104 |
{ |
| 105 |
static const char hexdig[] = "0123456789ABCDEF"; |
| 106 |
_sa << '['; |
| 107 |
for (int i = 0; i < nhints; i++, data++) { |
| 108 |
_sa << hexdig[(unsigned) ((*data >> 4) & 15)] << hexdig[(unsigned) (*data & 15)]; |
| 109 |
} |
| 110 |
_sa << ']'; |
| 111 |
} |
| 112 |
|
| 113 |
String |
| 114 |
CharstringUnparser::value() |
| 115 |
{ |
| 116 |
_start_of_line = true; |
| 117 |
return _sa.take_string(); |
| 118 |
} |
| 119 |
|
| 120 |
String |
| 121 |
CharstringUnparser::unparse(const Charstring *cs) |
| 122 |
{ |
| 123 |
if (cs) { |
| 124 |
CharstringUnparser u; |
| 125 |
u.interpret(0, cs); |
| 126 |
return u.value(); |
| 127 |
} else |
| 128 |
return "(null)"; |
| 129 |
} |
| 130 |
|
| 131 |
String |
| 132 |
CharstringUnparser::unparse(const Charstring &cs) |
| 133 |
{ |
| 134 |
CharstringUnparser u; |
| 135 |
u.interpret(0, &cs); |
| 136 |
return u.value(); |
| 137 |
} |
| 138 |
|
| 139 |
} |