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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
// -*- related-file-name: "../include/efont/pairop.hh" -*-
/* pairop.{cc,hh} -- ligature/kern font metrics
*
* Copyright (c) 1998-2011 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/pairop.hh>
#include <stdio.h>
namespace Efont {
PairProgram::PairProgram(const PairProgram &o)
: _reversed(o._reversed),
_left_map(o._left_map),
_op(o._op)
{
}
void
PairProgram::reserve_glyphs(int e)
{
if (e <= _left_map.size()) return;
_left_map.resize(e, -1);
}
PairOpIndex
PairProgram::find(GlyphIndex leftgi, GlyphIndex rightgi) const
{
PairOpIndex opi = find_left(leftgi);
while (opi >= 0) {
if (op(opi).right() == rightgi)
return opi;
opi = op(opi).next_left();
}
return -1;
}
bool
PairProgram::add_kern(GlyphIndex left, GlyphIndex right, int ki)
{
PairOp newop(left, right, ki, _left_map[left]);
int newopi = _op.size();
_op.push_back(newop);
_left_map[left] = newopi;
//PairOpIndex duplicate = map[newop];
//map.add(newop, newopi);
return false;
}
bool
PairProgram::add_lig(GlyphIndex left, GlyphIndex right, GlyphIndex result,
int kind)
{
PairOp newop(left, right, result, kind, _left_map[left]);
int newopi = _op.size();
_op.push_back(newop);
_left_map[left] = newopi;
//PairOpIndex duplicate = map[newop];
//map.add(newop, newopi);
return false;
}
void
PairProgram::unreverse()
{
if (!_reversed) return;
_left_map.assign(_left_map.size(), -1);
for (PairOpIndex opi = _op.size() - 1; opi >= 0; opi--) {
PairOp &o = _op[opi];
PairOpIndex l = o.left();
o.set_next(_left_map[l]);
_left_map[l] = opi;
}
_reversed = false;
}
void
PairProgram::optimize()
{
/* PairOpIndex opi;
// Get rid of 0-valued kerns.
for (opi = 0; opi < opcount(); opi++) {
PairOp &o = op(opi);
if (o.is_kern() && o.value() == 0)
o.noopify();
}*/
}
inline const char *
PairProgram::print_name(GlyphIndex) const
{
#if 0
if (gi == opAnychar) return "*";
else return glyph(gi).name();
#endif
return 0;
}
void
PairProgram::print() const
{
#if 0
for (GlyphIndex gi = 0; gi < glyphblock.size(); gi++)
if (glyphblock[gi] != -1)
printf("%s->B%d ", glyph(gi).name().c_str(), glyphblock[gi]);
printf("\n");
for (int i = 0; i < blocks.size(); i++) {
printf("B%-2d: ", i);
PairOpBlock &opb = *blocks[i];
for (int j = 0; j < opb.size(); j++)
if (opb[j].is_lig())
printf("%s->%s ", printname(opb[j].right()),
printname(opb[j].result()));
else if (opb[j].is_kern())
printf("%s[%g] ", printname(opb[j].right()), kern(opb[j].value()));
else if (opb[j].is_noop())
printf(". ");
if (blocks[i]->nextblock != -1)
printf(" :B%d", blocks[i]->nextblock);
printf("\n");
}
#endif
}
}
|