1 //========================================================================
2 //
3 // SplashFontFile.cc
4 //
5 //========================================================================
6
7 //========================================================================
8 //
9 // Modified under the Poppler project - http://poppler.freedesktop.org
10 //
11 // All changes made under the Poppler project to this file are licensed
12 // under GPL version 2 or later
13 //
14 // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
15 // Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
16 //
17 // To see a description of the changes please see the Changelog file that
18 // came with your tarball or type make ChangeLog if you are building from git
19 //
20 //========================================================================
21
22 #include <config.h>
23
24 #ifdef USE_GCC_PRAGMAS
25 #pragma implementation
26 #endif
27
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32 #include "goo/gmem.h"
33 #include "goo/GooString.h"
34 #include "SplashFontFile.h"
35 #include "SplashFontFileID.h"
36
37 #ifdef VMS
38 #if (__VMS_VER < 70000000)
39 extern "C" int unlink(char *filename);
40 #endif
41 #endif
42
43 //------------------------------------------------------------------------
44 // SplashFontFile
45 //------------------------------------------------------------------------
46
SplashFontFile(SplashFontFileID * idA,SplashFontSrc * srcA)47 SplashFontFile::SplashFontFile(SplashFontFileID *idA, SplashFontSrc *srcA) {
48 id = idA;
49 src = srcA;
50 src->ref();
51 refCnt = 0;
52 doAdjustMatrix = gFalse;
53 }
54
~SplashFontFile()55 SplashFontFile::~SplashFontFile() {
56 src->unref();
57 delete id;
58 }
59
incRefCnt()60 void SplashFontFile::incRefCnt() {
61 ++refCnt;
62 }
63
decRefCnt()64 void SplashFontFile::decRefCnt() {
65 if (!--refCnt) {
66 delete this;
67 }
68 }
69
70 //
71
SplashFontSrc()72 SplashFontSrc::SplashFontSrc() {
73 isFile = gFalse;
74 deleteSrc = gFalse;
75 fileName = NULL;
76 buf = NULL;
77 refcnt = 1;
78 }
79
~SplashFontSrc()80 SplashFontSrc::~SplashFontSrc() {
81 if (deleteSrc) {
82 if (isFile) {
83 if (fileName)
84 unlink(fileName->getCString());
85 } else {
86 if (buf)
87 gfree(buf);
88 }
89 }
90
91 if (isFile && fileName)
92 delete fileName;
93 }
94
ref()95 void SplashFontSrc::ref() {
96 refcnt++;
97 }
98
unref()99 void SplashFontSrc::unref() {
100 if (! --refcnt)
101 delete this;
102 }
103
setFile(GooString * file,GBool del)104 void SplashFontSrc::setFile(GooString *file, GBool del)
105 {
106 isFile = gTrue;
107 fileName = file->copy();
108 deleteSrc = del;
109 }
110
setFile(const char * file,GBool del)111 void SplashFontSrc::setFile(const char *file, GBool del)
112 {
113 isFile = gTrue;
114 fileName = new GooString(file);
115 deleteSrc = del;
116 }
117
setBuf(char * bufA,int bufLenA,GBool del)118 void SplashFontSrc::setBuf(char *bufA, int bufLenA, GBool del)
119 {
120 isFile = gFalse;
121 buf = bufA;
122 bufLen = bufLenA;
123 deleteSrc = del;
124 }
125