1 /*************************************************************************
2 ** Font.cpp **
3 ** **
4 ** This file is part of dvisvgm -- the DVI to SVG converter **
5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de> **
6 ** **
7 ** This program is free software; you can redistribute it and/or **
8 ** modify it under the terms of the GNU General Public License as **
9 ** published by the Free Software Foundation; either version 3 of **
10 ** the License, or (at your option) any later version. **
11 ** **
12 ** This program is distributed in the hope that it will be useful, but **
13 ** WITHOUT ANY WARRANTY; without even the implied warranty of **
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
15 ** GNU General Public License for more details. **
16 ** **
17 ** You should have received a copy of the GNU General Public License **
18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. **
19 *************************************************************************/
20
21 #include <config.h>
22 #include <sys/time.h>
23 #include <cstdlib>
24 #include <iostream>
25 #include <fstream>
26 #include <sstream>
27 #include "CMap.h"
28 #include "FileFinder.h"
29 #include "FileSystem.h"
30 #include "Font.h"
31 #include "FontEncoding.h"
32 #include "FontEngine.h"
33 #include "GFGlyphTracer.h"
34 #include "Glyph.h"
35 #include "Message.h"
36 #include "MetafontWrapper.h"
37 #include "TFM.h"
38 #include "VFReader.h"
39 #include "SignalHandler.h"
40 #include "Subfont.h"
41 #include "SVGTree.h"
42 #include "Unicode.h"
43 #include "macros.h"
44
45
46 using namespace std;
47
48
unicode(UInt32 c) const49 UInt32 Font::unicode (UInt32 c) const {
50 // @@ this should be optimized :-)
51 return Unicode::isValidCodepoint(c) ? c : 0x3400+c;
52 }
53
54
55 /** Returns the encoding object of this font which is asigned in a map file.
56 * If there's no encoding assigned, the function returns 0. */
encoding() const57 const FontEncoding* Font::encoding () const {
58 if (const FontMap::Entry *entry = fontMapEntry())
59 return FontEncoding::encoding(entry->encname);
60 return 0;
61 }
62
63
fontMapEntry() const64 const FontMap::Entry* Font::fontMapEntry () const {
65 string fontname = name();
66 size_t pos = fontname.rfind('.');
67 if (pos != string::npos)
68 fontname = fontname.substr(0, pos); // strip extension
69 return FontMap::instance().lookup(fontname);
70 }
71
72
73 /** Compute the extents of a given glyph.
74 * @param[in] c character code of glyph
75 * @param[in] vertical true if is glyph is part of vertical aligned text
76 * @param[out] metrics the resulting extents */
getGlyphMetrics(int c,bool vertical,GlyphMetrics & metrics) const77 void Font::getGlyphMetrics (int c, bool vertical, GlyphMetrics &metrics) const {
78 double s = scaleFactor();
79 if (vertical) { // get metrics for vertical text flow?
80 if (verticalLayout()) { // is the font designed for vertical texts?
81 metrics.wl = s*charDepth(c);
82 metrics.wr = s*charHeight(c);
83 metrics.h = 0;
84 metrics.d = s*charWidth(c);
85 }
86 else { // rotate box by 90 degrees for alphabetic text
87 metrics.wl = s*charDepth(c);
88 metrics.wr = s*charHeight(c);
89 metrics.h = 0;
90 metrics.d = s*(charWidth(c)+italicCorr(c));
91 }
92 }
93 else {
94 metrics.wl = 0;
95 metrics.wr = s*(charWidth(c)+italicCorr(c));
96 metrics.h = s*charHeight(c);
97 metrics.d = s*charDepth(c);
98 }
99 }
100
101
filename() const102 const char* Font::filename () const {
103 const char *fname = strrchr(path(), '/');
104 if (fname)
105 return fname+1;
106 return path();
107 }
108
109 ///////////////////////////////////////////////////////////////////////////////////////
110
TFMFont(string name,UInt32 cs,double ds,double ss)111 TFMFont::TFMFont (string name, UInt32 cs, double ds, double ss)
112 : _metrics(0), _fontname(name), _checksum(cs), _dsize(ds), _ssize(ss)
113 {
114 }
115
116
~TFMFont()117 TFMFont::~TFMFont () {
118 delete _metrics;
119 }
120
121
122 /** Returns a font metrics object for the current font.
123 * @throw FontException if TFM file can't be found */
getMetrics() const124 const FontMetrics* TFMFont::getMetrics () const {
125 if (!_metrics) {
126 try {
127 _metrics = FontMetrics::read(_fontname.c_str());
128 if (!_metrics) {
129 _metrics = new NullFontMetric;
130 Message::wstream(true) << "can't find "+_fontname+".tfm\n";
131 }
132 }
133 catch (FontMetricException &e) {
134 _metrics = new NullFontMetric;
135 Message::wstream(true) << e.what() << " in " << _fontname << ".tfm\n";
136 }
137 }
138 return _metrics;
139 }
140
141
charWidth(int c) const142 double TFMFont::charWidth (int c) const {
143 double w = getMetrics() ? getMetrics()->getCharWidth(c) : 0;
144 if (style()) {
145 w *= style()->extend;
146 w += fabs(style()->slant*charHeight(c)); // slant := tan(phi) = dx/height
147 }
148 return w;
149 }
150
151
italicCorr(int c) const152 double TFMFont::italicCorr (int c) const {
153 double w = getMetrics() ? getMetrics()->getItalicCorr(c) : 0;
154 if (style())
155 w *= style()->extend;
156 return w;
157 }
158
159
charDepth(int c) const160 double TFMFont::charDepth (int c) const {return getMetrics() ? getMetrics()->getCharDepth(c) : 0;}
charHeight(int c) const161 double TFMFont::charHeight (int c) const {return getMetrics() ? getMetrics()->getCharHeight(c) : 0;}
162
163
164 /** Tests if the checksum of the font matches that of the corresponding TFM file. */
verifyChecksums() const165 bool TFMFont::verifyChecksums () const {
166 if (_checksum != 0 && getMetrics() && getMetrics()->getChecksum() != 0)
167 return _checksum == getMetrics()->getChecksum();
168 return true;
169 }
170
171 //////////////////////////////////////////////////////////////////////////////
172
173 // static class variables
174 bool PhysicalFont::EXACT_BBOX = false;
175 bool PhysicalFont::KEEP_TEMP_FILES = false;
176 const char *PhysicalFont::CACHE_PATH = 0;
177 double PhysicalFont::METAFONT_MAG = 4;
178 FontCache PhysicalFont::_cache;
179
180
create(string name,UInt32 checksum,double dsize,double ssize,PhysicalFont::Type type)181 Font* PhysicalFont::create (string name, UInt32 checksum, double dsize, double ssize, PhysicalFont::Type type) {
182 return new PhysicalFontImpl(name, 0, checksum, dsize, ssize, type);
183 }
184
185
create(string name,int fontindex,UInt32 checksum,double dsize,double ssize)186 Font* PhysicalFont::create (string name, int fontindex, UInt32 checksum, double dsize, double ssize) {
187 return new PhysicalFontImpl(name, fontindex, checksum, dsize, ssize, PhysicalFont::TTC);
188 }
189
190
path() const191 const char* PhysicalFont::path () const {
192 const char *ext=0;
193 switch (type()) {
194 case OTF: ext = "otf"; break;
195 case PFB: ext = "pfb"; break;
196 case TTC: ext = "ttc"; break;
197 case TTF: ext = "ttf"; break;
198 case MF : ext = "mf"; break;
199 default : ext = 0;
200 }
201 if (ext)
202 return FileFinder::lookup(name()+"."+ext);
203 return FileFinder::lookup(name());
204 }
205
206
207 /** Returns true if this font is CID-based. */
isCIDFont() const208 bool PhysicalFont::isCIDFont () const {
209 if (type() == MF)
210 return false;
211 FontEngine::instance().setFont(*this);
212 return FontEngine::instance().isCIDFont();
213 }
214
215
216 /** Retrieve the IDs of all charachter maps available in the font file.
217 * @param[out] charMapIDs IDs of the found character maps
218 * @return number of found character maps */
collectCharMapIDs(std::vector<CharMapID> & charMapIDs) const219 int PhysicalFont::collectCharMapIDs (std::vector<CharMapID> &charMapIDs) const {
220 if (type() == MF)
221 return 0;
222 FontEngine::instance().setFont(*this);
223 return FontEngine::instance().getCharMapIDs(charMapIDs);
224 }
225
226
227 /** Decodes a character code used in the DVI file to the code required to
228 * address the correct character in the font.
229 * @param[in] c DVI character to decode
230 * @return target character code or name */
decodeChar(UInt32 c) const231 Character PhysicalFont::decodeChar (UInt32 c) const {
232 if (const FontEncoding *enc = encoding())
233 return enc->decode(c);
234 return Character(Character::CHRCODE, c);
235 }
236
237
238 /** Returns the number of units per EM. The EM square is the virtual area a glyph is designed on.
239 * All coordinates used to specify portions of the glyph are relative to the origin (0,0) at the
240 * lower left corner of this square, while the upper right corner is located at (m,m), where m
241 * is an integer value defined with the font, and returned by this function. */
unitsPerEm() const242 int PhysicalFont::unitsPerEm() const {
243 if (type() == MF)
244 return 1000;
245 FontEngine::instance().setFont(*this);
246 return FontEngine::instance().getUnitsPerEM();
247 }
248
249
hAdvance() const250 int PhysicalFont::hAdvance () const {
251 if (type() == MF)
252 return 0;
253 FontEngine::instance().setFont(*this);
254 return FontEngine::instance().getHAdvance();
255 }
256
257
hAdvance(int c) const258 double PhysicalFont::hAdvance (int c) const {
259 if (type() == MF)
260 return unitsPerEm()*charWidth(c)/designSize();
261 FontEngine::instance().setFont(*this);
262 if (const FontMap::Entry *entry = fontMapEntry())
263 if (Subfont *sf = entry->subfont)
264 c = sf->decode(c);
265 return FontEngine::instance().getHAdvance(decodeChar(c));
266 }
267
268
vAdvance(int c) const269 double PhysicalFont::vAdvance (int c) const {
270 if (type() == MF)
271 return unitsPerEm()*charWidth(c)/designSize();
272 FontEngine::instance().setFont(*this);
273 if (const FontMap::Entry *entry = fontMapEntry())
274 if (Subfont *sf = entry->subfont)
275 c = sf->decode(c);
276 return FontEngine::instance().getVAdvance(decodeChar(c));
277 }
278
279
glyphName(int c) const280 string PhysicalFont::glyphName (int c) const {
281 if (type() == MF)
282 return "";
283 FontEngine::instance().setFont(*this);
284 if (const FontMap::Entry *entry = fontMapEntry())
285 if (Subfont *sf = entry->subfont)
286 c = sf->decode(c);
287 return FontEngine::instance().getGlyphName(decodeChar(c));
288 }
289
290
scaledAscent() const291 double PhysicalFont::scaledAscent() const {
292 return ascent()*scaledSize()/unitsPerEm();
293 }
294
295
ascent() const296 int PhysicalFont::ascent () const {
297 if (type() == MF)
298 return 0;
299 FontEngine::instance().setFont(*this);
300 return FontEngine::instance().getAscender();
301 }
302
303
descent() const304 int PhysicalFont::descent () const {
305 if (type() == MF)
306 return 0;
307 FontEngine::instance().setFont(*this);
308 return FontEngine::instance().getDescender();
309 }
310
311
312 /** Extracts the glyph outlines of a given character.
313 * @param[in] c character code of requested glyph
314 * @param[out] glyph path segments of the glyph outline
315 * @param[in] cb optional callback object for tracer class
316 * @return true if outline could be computed */
getGlyph(int c,GraphicPath<Int32> & glyph,GFGlyphTracer::Callback * cb) const317 bool PhysicalFont::getGlyph (int c, GraphicPath<Int32> &glyph, GFGlyphTracer::Callback *cb) const {
318 if (type() == MF) {
319 const Glyph *cached_glyph=0;
320 if (CACHE_PATH) {
321 _cache.write(CACHE_PATH);
322 _cache.read(name().c_str(), CACHE_PATH);
323 cached_glyph = _cache.getGlyph(c);
324 }
325 if (cached_glyph) {
326 glyph = *cached_glyph;
327 return true;
328 }
329 else {
330 string gfname;
331 if (createGF(gfname)) {
332 try {
333 double ds = getMetrics() ? getMetrics()->getDesignSize() : 1;
334 GFGlyphTracer tracer(gfname, unitsPerEm()/ds, cb);
335 tracer.setGlyph(glyph);
336 tracer.executeChar(c);
337 glyph.closeOpenSubPaths();
338 if (CACHE_PATH)
339 _cache.setGlyph(c, glyph);
340 return true;
341 }
342 catch (GFException &e) {
343 // @@ print error message
344 }
345 }
346 else {
347 Message::wstream(true) << "failed creating " << name() << ".gf\n";
348 }
349 }
350 }
351 else { // vector fonts (OTF, PFB, TTF, TTC)
352 bool ok=true;
353 FontEngine::instance().setFont(*this);
354 if (const FontMap::Entry *entry = fontMapEntry())
355 if (Subfont *sf = entry->subfont)
356 c = sf->decode(c);
357 ok = FontEngine::instance().traceOutline(decodeChar(c), glyph, false);
358 glyph.closeOpenSubPaths();
359 return ok;
360 }
361 return false;
362 }
363
364
365 /** Creates a GF file for this font object.
366 * @param[out] gfname name of GF font file
367 * @return true on success */
createGF(string & gfname) const368 bool PhysicalFont::createGF (string &gfname) const {
369 SignalHandler::instance().check();
370 gfname = name()+".gf";
371 MetafontWrapper mf(name());
372 bool ok = mf.make("ljfour", METAFONT_MAG); // call Metafont if necessary
373 return ok && mf.success() && getMetrics();
374 }
375
376
377 /** Traces all glyphs of the current font and stores them in the cache. If caching is disabled, nothing happens.
378 * @param[in] includeCached if true, glyphs already cached are traced again
379 * @param[in] cb optional callback methods called by the tracer
380 * @return number of glyphs traced */
traceAllGlyphs(bool includeCached,GFGlyphTracer::Callback * cb) const381 int PhysicalFont::traceAllGlyphs (bool includeCached, GFGlyphTracer::Callback *cb) const {
382 int count = 0;
383 if (type() == MF && CACHE_PATH) {
384 if (const FontMetrics *metrics = getMetrics()) {
385 int fchar = metrics->firstChar();
386 int lchar = metrics->lastChar();
387 string gfname;
388 Glyph glyph;
389 if (createGF(gfname)) {
390 _cache.read(name().c_str(), CACHE_PATH);
391 double ds = getMetrics() ? getMetrics()->getDesignSize() : 1;
392 GFGlyphTracer tracer(gfname, unitsPerEm()/ds, cb);
393 tracer.setGlyph(glyph);
394 for (int i=fchar; i <= lchar; i++) {
395 if (includeCached || !_cache.getGlyph(i)) {
396 glyph.clear();
397 tracer.executeChar(i);
398 glyph.closeOpenSubPaths();
399 _cache.setGlyph(i, glyph);
400 ++count;
401 }
402 }
403 _cache.write(CACHE_PATH);
404 }
405 }
406 }
407 return count;
408 }
409
410
411 /** Computes the exact bounding box of a glyph.
412 * @param[in] c character code of the glyph
413 * @param[out] bbox the computed bounding box
414 * @param[in] cb optional calback object forwarded to the tracer
415 * @return true if the box could be computed successfully */
getExactGlyphBox(int c,BoundingBox & bbox,GFGlyphTracer::Callback * cb) const416 bool PhysicalFont::getExactGlyphBox(int c, BoundingBox& bbox, GFGlyphTracer::Callback* cb) const {
417 Glyph glyph;
418 if (getGlyph(c, glyph, cb)) {
419 glyph.computeBBox(bbox);
420 double s = scaledSize()/unitsPerEm();
421 bbox.scale(s, s);
422 return true;
423 }
424 return false;
425 }
426
427
getExactGlyphBox(int c,GlyphMetrics & metrics,bool vertical,GFGlyphTracer::Callback * cb) const428 bool PhysicalFont::getExactGlyphBox (int c, GlyphMetrics &metrics, bool vertical, GFGlyphTracer::Callback *cb) const {
429 BoundingBox charbox;
430 if (!getExactGlyphBox(c, charbox, cb))
431 return false;
432 if ((metrics.wl = -charbox.minX()) < 0) metrics.wl=0;
433 if ((metrics.wr = charbox.maxX()) < 0) metrics.wr=0;
434 if ((metrics.h = charbox.maxY()) < 0) metrics.h=0;
435 if ((metrics.d = -charbox.minY()) < 0) metrics.d=0;
436 if (vertical) { // vertical text orientation
437 if (verticalLayout()) { // font designed for vertical layout?
438 metrics.wl = metrics.wr = (metrics.wl+metrics.wr)/2;
439 metrics.d += metrics.h;
440 metrics.h = 0;
441 }
442 else {
443 double depth = metrics.d;
444 metrics.d = metrics.wr;
445 metrics.wr = metrics.h;
446 metrics.h = metrics.wl;
447 metrics.wl = depth;
448 }
449 }
450 return true;
451 }
452
453
create(string name,UInt32 checksum,double dsize,double ssize)454 Font* VirtualFont::create (string name, UInt32 checksum, double dsize, double ssize) {
455 return new VirtualFontImpl(name, checksum, dsize, ssize);
456 }
457
458
459 //////////////////////////////////////////////////////////////////////////////
460
461
PhysicalFontImpl(string name,int fontindex,UInt32 cs,double ds,double ss,PhysicalFont::Type type)462 PhysicalFontImpl::PhysicalFontImpl (string name, int fontindex, UInt32 cs, double ds, double ss, PhysicalFont::Type type)
463 : TFMFont(name, cs, ds, ss),
464 _filetype(type), _fontIndex(fontindex), _fontMapEntry(Font::fontMapEntry()), _encodingPair(Font::encoding()), _localCharMap(0)
465 {
466 }
467
468
~PhysicalFontImpl()469 PhysicalFontImpl::~PhysicalFontImpl () {
470 if (CACHE_PATH)
471 _cache.write(CACHE_PATH);
472 if (!KEEP_TEMP_FILES)
473 tidy();
474 delete _localCharMap;
475 }
476
477
encoding() const478 const FontEncoding* PhysicalFontImpl::encoding () const {
479 if (!_encodingPair.enc1())
480 return 0;
481 return &_encodingPair;
482 }
483
484
findAndAssignBaseFontMap()485 bool PhysicalFontImpl::findAndAssignBaseFontMap () {
486 const FontEncoding *enc = encoding();
487 if (enc && enc->mapsToCharIndex()) {
488 // try to find a base font map that maps from character indexes to a suitable
489 // target encoding supported by the font file
490 if (const FontEncoding *bfmap = enc->findCompatibleBaseFontMap(this, _charmapID))
491 _encodingPair.assign(bfmap);
492 else
493 return false;
494 }
495 else if (type() != MF) {
496 FontEngine::instance().setFont(*this);
497 if ((_localCharMap = FontEngine::instance().createCustomToUnicodeMap()) != 0)
498 _charmapID = FontEngine::instance().setCustomCharMap();
499 else
500 _charmapID = FontEngine::instance().setUnicodeCharMap();
501 }
502 return true;
503 }
504
505
unicode(UInt32 c) const506 UInt32 PhysicalFontImpl::unicode (UInt32 c) const {
507 if (type() == MF)
508 return Font::unicode(c);
509 Character chr = decodeChar(c);
510 if (chr.type() == Character::NAME || chr.number() == 0)
511 return Font::unicode(c);
512
513 if (_localCharMap) {
514 if (UInt32 mapped_char = _localCharMap->valueAt(chr.number()))
515 return mapped_char;
516 // No unicode equivalent found in font file.
517 // Now we should look for a smart alternative but at the moment
518 // it's sufficient to simply choose a valid unused unicode value...
519 // Can we use the charcode itself as a unicode replacement?
520 if (!_localCharMap->valueExists(chr.number()) && Unicode::isValidCodepoint(chr.number()))
521 return chr.number();
522 }
523 if (Unicode::isValidCodepoint(chr.number()))
524 return chr.number();
525 return Font::unicode(chr.number());
526 }
527
528
529 /** Delete all temporary font files created by Metafont. */
tidy() const530 void PhysicalFontImpl::tidy () const {
531 if (type() == MF) {
532 const char *ext[] = {"gf", "tfm", "log", 0};
533 for (const char **p=ext; *p; ++p) {
534 if (FileSystem::exists((name()+"."+(*p)).c_str()))
535 FileSystem::remove(name()+"."+(*p));
536 }
537 }
538 }
539
540 //////////////////////////////////////////////////////////////////////////////
541
uniqueName(const string & path,const FontStyle & style)542 string NativeFont::uniqueName (const string &path, const FontStyle &style) {
543 static map<string, int> ids;
544 ostringstream oss;
545 oss << path << "b" << style.bold << "e" << style.extend << "s" << style.slant;
546 map<string, int>::iterator it = ids.find(oss.str());
547 int id = ids.size();
548 if (it == ids.end())
549 ids[oss.str()] = id;
550 else
551 id = it->second;
552 oss.str("");
553 oss << "nf" << id;
554 return oss.str();
555 }
556
557
name() const558 string NativeFont::name () const {
559 return uniqueName(path(), _style);
560 }
561
562
type() const563 PhysicalFont::Type NativeFont::type () const {
564 if (const char *filepath = path()) {
565 if (const char *p =strrchr(filepath, '.')) {
566 string ext = p+1;
567 if (ext == "otf")
568 return PhysicalFont::OTF;
569 if (ext == "ttf")
570 return PhysicalFont::TTF;
571 if (ext == "pfb")
572 return PhysicalFont::PFB;
573 }
574 }
575 return PhysicalFont::UNKNOWN;
576 }
577
578
charWidth(int c) const579 double NativeFont::charWidth (int c) const {
580 FontEngine::instance().setFont(*this);
581 int upem = FontEngine::instance().getUnitsPerEM();
582 double w = upem ? (scaledSize()*FontEngine::instance().getAdvance(c)/upem*_style.extend) : 0;
583 w += fabs(_style.slant*charHeight(c));
584 return w;
585 }
586
587
charHeight(int c) const588 double NativeFont::charHeight (int c) const {
589 FontEngine::instance().setFont(*this);
590 int upem = FontEngine::instance().getUnitsPerEM();
591 return upem ? (scaledSize()*FontEngine::instance().getAscender()/upem) : 0;
592 }
593
594
charDepth(int c) const595 double NativeFont::charDepth (int c) const {
596 FontEngine::instance().setFont(*this);
597 int upem = FontEngine::instance().getUnitsPerEM();
598 return upem ? (-scaledSize()*FontEngine::instance().getDescender()/upem) : 0;
599 }
600
601
findAndAssignBaseFontMap()602 bool NativeFontImpl::findAndAssignBaseFontMap () {
603 FontEngine &fe = FontEngine::instance();
604 fe.setFont(*this);
605 fe.setUnicodeCharMap();
606 fe.buildCharMap(_toUnicodeMap);
607 if (!_toUnicodeMap.addMissingMappings(fe.getNumGlyphs()))
608 Message::wstream(true) << "incomplete unicode mapping for native font " << name() << " (" << filename() << ")\n";
609 return true;
610 }
611
612
decodeChar(UInt32 c) const613 Character NativeFontImpl::decodeChar (UInt32 c) const {
614 return Character(Character::INDEX, c);
615 }
616
617
unicode(UInt32 c) const618 UInt32 NativeFontImpl::unicode (UInt32 c) const {
619 UInt32 ucode = _toUnicodeMap.valueAt(c);
620 return Unicode::isValidCodepoint(ucode) ? ucode : 0x3400+ucode;
621 }
622
623 //////////////////////////////////////////////////////////////////////////////
624
VirtualFontImpl(string name,UInt32 cs,double ds,double ss)625 VirtualFontImpl::VirtualFontImpl (string name, UInt32 cs, double ds, double ss)
626 : TFMFont(name, cs, ds, ss)
627 {
628 }
629
630
~VirtualFontImpl()631 VirtualFontImpl::~VirtualFontImpl () {
632 // delete dvi vectors received by VFReaderAction
633 for (map<UInt32, DVIVector*>::iterator i=_charDefs.begin(); i != _charDefs.end(); ++i)
634 delete i->second;
635 }
636
637
path() const638 const char* VirtualFontImpl::path () const {
639 return FileFinder::lookup(name()+".vf");
640 }
641
642
assignChar(UInt32 c,DVIVector * dvi)643 void VirtualFontImpl::assignChar (UInt32 c, DVIVector *dvi) {
644 if (dvi) {
645 if (_charDefs.find(c) == _charDefs.end())
646 _charDefs[c] = dvi;
647 else
648 delete dvi;
649 }
650 }
651
652
getDVI(int c) const653 const vector<UInt8>* VirtualFontImpl::getDVI (int c) const {
654 map<UInt32,DVIVector*>::const_iterator it = _charDefs.find(c);
655 return (it == _charDefs.end() ? 0 : it->second);
656 }
657
658