| 1 |
// -*- related-file-name: "../include/efont/pairop.hh" -*- |
| 2 |
|
| 3 |
/* pairop.{cc,hh} -- ligature/kern font metrics |
| 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/pairop.hh> |
| 20 |
#include <stdio.h> |
| 21 |
namespace Efont { |
| 22 |
|
| 23 |
PairProgram::PairProgram(const PairProgram &o) |
| 24 |
: _reversed(o._reversed), |
| 25 |
_left_map(o._left_map), |
| 26 |
_op(o._op) |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
void |
| 32 |
PairProgram::reserve_glyphs(int e) |
| 33 |
{ |
| 34 |
if (e <= _left_map.size()) return; |
| 35 |
_left_map.resize(e, -1); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
PairOpIndex |
| 40 |
PairProgram::find(GlyphIndex leftgi, GlyphIndex rightgi) const |
| 41 |
{ |
| 42 |
PairOpIndex opi = find_left(leftgi); |
| 43 |
while (opi >= 0) { |
| 44 |
if (op(opi).right() == rightgi) |
| 45 |
return opi; |
| 46 |
opi = op(opi).next_left(); |
| 47 |
} |
| 48 |
return -1; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
bool |
| 53 |
PairProgram::add_kern(GlyphIndex left, GlyphIndex right, int ki) |
| 54 |
{ |
| 55 |
PairOp newop(left, right, ki, _left_map[left]); |
| 56 |
int newopi = _op.size(); |
| 57 |
_op.push_back(newop); |
| 58 |
_left_map[left] = newopi; |
| 59 |
|
| 60 |
//PairOpIndex duplicate = map[newop]; |
| 61 |
//map.add(newop, newopi); |
| 62 |
|
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
bool |
| 68 |
PairProgram::add_lig(GlyphIndex left, GlyphIndex right, GlyphIndex result, |
| 69 |
int kind) |
| 70 |
{ |
| 71 |
PairOp newop(left, right, result, kind, _left_map[left]); |
| 72 |
int newopi = _op.size(); |
| 73 |
_op.push_back(newop); |
| 74 |
_left_map[left] = newopi; |
| 75 |
|
| 76 |
//PairOpIndex duplicate = map[newop]; |
| 77 |
//map.add(newop, newopi); |
| 78 |
|
| 79 |
return false; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
void |
| 84 |
PairProgram::unreverse() |
| 85 |
{ |
| 86 |
if (!_reversed) return; |
| 87 |
|
| 88 |
_left_map.assign(_left_map.size(), -1); |
| 89 |
|
| 90 |
for (PairOpIndex opi = _op.size() - 1; opi >= 0; opi--) { |
| 91 |
PairOp &o = _op[opi]; |
| 92 |
PairOpIndex l = o.left(); |
| 93 |
o.set_next(_left_map[l]); |
| 94 |
_left_map[l] = opi; |
| 95 |
} |
| 96 |
|
| 97 |
_reversed = false; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
void |
| 102 |
PairProgram::optimize() |
| 103 |
{ |
| 104 |
/* PairOpIndex opi; |
| 105 |
|
| 106 |
// Get rid of 0-valued kerns. |
| 107 |
for (opi = 0; opi < opcount(); opi++) { |
| 108 |
PairOp &o = op(opi); |
| 109 |
if (o.is_kern() && o.value() == 0) |
| 110 |
o.noopify(); |
| 111 |
}*/ |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
inline const char * |
| 116 |
PairProgram::print_name(GlyphIndex) const |
| 117 |
{ |
| 118 |
#if 0 |
| 119 |
if (gi == opAnychar) return "*"; |
| 120 |
else return glyph(gi).name(); |
| 121 |
#endif |
| 122 |
return 0; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
void |
| 127 |
PairProgram::print() const |
| 128 |
{ |
| 129 |
#if 0 |
| 130 |
for (GlyphIndex gi = 0; gi < glyphblock.size(); gi++) |
| 131 |
if (glyphblock[gi] != -1) |
| 132 |
printf("%s->B%d ", glyph(gi).name().c_str(), glyphblock[gi]); |
| 133 |
printf("\n"); |
| 134 |
|
| 135 |
for (int i = 0; i < blocks.size(); i++) { |
| 136 |
printf("B%-2d: ", i); |
| 137 |
PairOpBlock &opb = *blocks[i]; |
| 138 |
for (int j = 0; j < opb.size(); j++) |
| 139 |
if (opb[j].is_lig()) |
| 140 |
printf("%s->%s ", printname(opb[j].right()), |
| 141 |
printname(opb[j].result())); |
| 142 |
else if (opb[j].is_kern()) |
| 143 |
printf("%s[%g] ", printname(opb[j].right()), kern(opb[j].value())); |
| 144 |
else if (opb[j].is_noop()) |
| 145 |
printf(". "); |
| 146 |
if (blocks[i]->nextblock != -1) |
| 147 |
printf(" :B%d", blocks[i]->nextblock); |
| 148 |
printf("\n"); |
| 149 |
} |
| 150 |
#endif |
| 151 |
} |
| 152 |
|
| 153 |
} |