| 1 |
// -*- related-file-name: "../include/efont/metrics.hh" -*- |
| 2 |
|
| 3 |
/* metrics.{cc,hh} -- generic 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/metrics.hh> |
| 20 |
#include <efont/t1cs.hh> /* for UNKDOUBLE */ |
| 21 |
namespace Efont { |
| 22 |
|
| 23 |
Metrics::Metrics() |
| 24 |
: _name_map(-1), |
| 25 |
_scale(1), _fdv(fdLast, UNKDOUBLE), |
| 26 |
_xt_map(0), |
| 27 |
_uses(0) |
| 28 |
{ |
| 29 |
_xt.push_back((MetricsXt *)0); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
Metrics::Metrics(PermString font_name, PermString full_name, const Metrics &m) |
| 34 |
: _font_name(font_name), |
| 35 |
_family(m._family), _full_name(full_name), _version(m._version), |
| 36 |
_name_map(m._name_map), _names(m._names), _encoding(m._encoding), |
| 37 |
_scale(1), _fdv(fdLast, UNKDOUBLE), |
| 38 |
_pairp(m._pairp), |
| 39 |
_xt_map(0), |
| 40 |
_uses(0) |
| 41 |
{ |
| 42 |
reserve_glyphs(m._wdv.size()); |
| 43 |
_kernv.resize(m._kernv.size(), UNKDOUBLE); |
| 44 |
_xt.push_back((MetricsXt *)0); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
Metrics::~Metrics() |
| 49 |
{ |
| 50 |
assert(_uses == 0); |
| 51 |
for (int i = 1; i < _xt.size(); i++) |
| 52 |
delete _xt[i]; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
void |
| 57 |
Metrics::set_font_name(PermString n) |
| 58 |
{ |
| 59 |
assert(!_font_name); |
| 60 |
_font_name = n; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
void |
| 65 |
Metrics::reserve_glyphs(int amt) |
| 66 |
{ |
| 67 |
if (amt <= _wdv.size()) return; |
| 68 |
_wdv.resize(amt, UNKDOUBLE); |
| 69 |
_lfv.resize(amt, UNKDOUBLE); |
| 70 |
_rtv.resize(amt, UNKDOUBLE); |
| 71 |
_tpv.resize(amt, UNKDOUBLE); |
| 72 |
_btv.resize(amt, UNKDOUBLE); |
| 73 |
_encoding.reserve_glyphs(amt); |
| 74 |
_pairp.reserve_glyphs(amt); |
| 75 |
for (int i = 1; i < _xt.size(); i++) |
| 76 |
_xt[i]->reserve_glyphs(amt); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
GlyphIndex |
| 81 |
Metrics::add_glyph(PermString n) |
| 82 |
{ |
| 83 |
if (nglyphs() >= _wdv.size()) |
| 84 |
reserve_glyphs(nglyphs() ? nglyphs() * 2 : 64); |
| 85 |
GlyphIndex gi = _names.size(); |
| 86 |
_names.push_back(n); |
| 87 |
_name_map.insert(n, gi); |
| 88 |
return gi; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
static void |
| 93 |
set_dimen(Vector<double> &dest, const Vector<double> &src, double scale, |
| 94 |
bool increment) |
| 95 |
{ |
| 96 |
int c = src.size(); |
| 97 |
if (increment) |
| 98 |
for (int i = 0; i < c; i++) |
| 99 |
dest.at_u(i) += src.at_u(i) * scale; |
| 100 |
else if (scale < 0.9999 || scale > 1.0001) |
| 101 |
for (int i = 0; i < c; i++) |
| 102 |
dest.at_u(i) = src.at_u(i) * scale; |
| 103 |
else |
| 104 |
dest = src; |
| 105 |
} |
| 106 |
|
| 107 |
void |
| 108 |
Metrics::interpolate_dimens(const Metrics &m, double scale, bool increment) |
| 109 |
{ |
| 110 |
set_dimen(_fdv, m._fdv, scale, increment); |
| 111 |
set_dimen(_wdv, m._wdv, scale, increment); |
| 112 |
set_dimen(_lfv, m._lfv, scale, increment); |
| 113 |
set_dimen(_rtv, m._rtv, scale, increment); |
| 114 |
set_dimen(_tpv, m._tpv, scale, increment); |
| 115 |
set_dimen(_btv, m._btv, scale, increment); |
| 116 |
set_dimen(_kernv, m._kernv, scale, increment); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
void |
| 121 |
Metrics::add_xt(MetricsXt *mxt) |
| 122 |
{ |
| 123 |
int n = _xt.size(); |
| 124 |
_xt.push_back(mxt); |
| 125 |
_xt_map.insert(mxt->kind(), n); |
| 126 |
if (_wdv.size() > 0) |
| 127 |
mxt->reserve_glyphs(_wdv.size()); |
| 128 |
} |
| 129 |
|
| 130 |
} |