| 1 |
//======================================================================== |
| 2 |
// |
| 3 |
// SplashFontFile.cc |
| 4 |
// |
| 5 |
// Copyright 2003-2013 Glyph & Cog, LLC |
| 6 |
// |
| 7 |
//======================================================================== |
| 8 |
|
| 9 |
#include <aconf.h> |
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#ifndef _WIN32 |
| 13 |
# include <unistd.h> |
| 14 |
#endif |
| 15 |
#include "gmempp.h" |
| 16 |
#include "GString.h" |
| 17 |
#include "SplashFontFile.h" |
| 18 |
#include "SplashFontFileID.h" |
| 19 |
|
| 20 |
#ifdef VMS |
| 21 |
#if (__VMS_VER < 70000000) |
| 22 |
extern "C" int unlink(char *filename); |
| 23 |
#endif |
| 24 |
#endif |
| 25 |
|
| 26 |
//------------------------------------------------------------------------ |
| 27 |
// SplashFontFile |
| 28 |
//------------------------------------------------------------------------ |
| 29 |
|
| 30 |
SplashFontFile::SplashFontFile(SplashFontFileID *idA, |
| 31 |
SplashFontType fontTypeA, |
| 32 |
#if LOAD_FONTS_FROM_MEM |
| 33 |
GString *fontBufA |
| 34 |
#else |
| 35 |
char *fileNameA, GBool deleteFileA |
| 36 |
#endif |
| 37 |
) { |
| 38 |
id = idA; |
| 39 |
fontType = fontTypeA; |
| 40 |
#if LOAD_FONTS_FROM_MEM |
| 41 |
fontBuf = fontBufA; |
| 42 |
#else |
| 43 |
fileName = new GString(fileNameA); |
| 44 |
deleteFile = deleteFileA; |
| 45 |
#endif |
| 46 |
refCnt = 0; |
| 47 |
} |
| 48 |
|
| 49 |
SplashFontFile::~SplashFontFile() { |
| 50 |
#if LOAD_FONTS_FROM_MEM |
| 51 |
delete fontBuf; |
| 52 |
#else |
| 53 |
if (deleteFile) { |
| 54 |
unlink(fileName->getCString()); |
| 55 |
} |
| 56 |
delete fileName; |
| 57 |
#endif |
| 58 |
delete id; |
| 59 |
} |
| 60 |
|
| 61 |
void SplashFontFile::incRefCnt() { |
| 62 |
#if MULTITHREADED |
| 63 |
gAtomicIncrement(&refCnt); |
| 64 |
#else |
| 65 |
++refCnt; |
| 66 |
#endif |
| 67 |
} |
| 68 |
|
| 69 |
void SplashFontFile::decRefCnt() { |
| 70 |
GBool done; |
| 71 |
|
| 72 |
#if MULTITHREADED |
| 73 |
done = gAtomicDecrement(&refCnt) == 0; |
| 74 |
#else |
| 75 |
done = --refCnt == 0; |
| 76 |
#endif |
| 77 |
if (done) { |
| 78 |
delete this; |
| 79 |
} |
| 80 |
} |