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 // Copyright (C) 2019 Christian Persch <chpe@src.gnome.org>
17 //
18 // To see a description of the changes please see the Changelog file that
19 // came with your tarball or type make ChangeLog if you are building from git
20 //
21 //========================================================================
22
23 #include <config.h>
24
25 #include <cstdio>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include "goo/gmem.h"
30 #include "goo/GooString.h"
31 #include "SplashFontFile.h"
32 #include "SplashFontFileID.h"
33
34 //------------------------------------------------------------------------
35 // SplashFontFile
36 //------------------------------------------------------------------------
37
SplashFontFile(SplashFontFileID * idA,SplashFontSrc * srcA)38 SplashFontFile::SplashFontFile(SplashFontFileID *idA, SplashFontSrc *srcA)
39 {
40 id = idA;
41 src = srcA;
42 src->ref();
43 refCnt = 0;
44 doAdjustMatrix = false;
45 }
46
~SplashFontFile()47 SplashFontFile::~SplashFontFile()
48 {
49 src->unref();
50 delete id;
51 }
52
incRefCnt()53 void SplashFontFile::incRefCnt()
54 {
55 ++refCnt;
56 }
57
decRefCnt()58 void SplashFontFile::decRefCnt()
59 {
60 if (!--refCnt) {
61 delete this;
62 }
63 }
64
65 //
66
SplashFontSrc()67 SplashFontSrc::SplashFontSrc()
68 {
69 isFile = false;
70 deleteSrc = false;
71 fileName = nullptr;
72 buf = nullptr;
73 refcnt = 1;
74 }
75
~SplashFontSrc()76 SplashFontSrc::~SplashFontSrc()
77 {
78 if (deleteSrc) {
79 if (isFile) {
80 if (fileName)
81 unlink(fileName->c_str());
82 } else {
83 if (buf)
84 gfree(buf);
85 }
86 }
87
88 if (isFile && fileName)
89 delete fileName;
90 }
91
ref()92 void SplashFontSrc::ref()
93 {
94 refcnt++;
95 }
96
unref()97 void SplashFontSrc::unref()
98 {
99 if (!--refcnt)
100 delete this;
101 }
102
setFile(GooString * file,bool del)103 void SplashFontSrc::setFile(GooString *file, bool del)
104 {
105 isFile = true;
106 fileName = file->copy();
107 deleteSrc = del;
108 }
109
setFile(const char * file,bool del)110 void SplashFontSrc::setFile(const char *file, bool del)
111 {
112 isFile = true;
113 fileName = new GooString(file);
114 deleteSrc = del;
115 }
116
setBuf(char * bufA,int bufLenA,bool del)117 void SplashFontSrc::setBuf(char *bufA, int bufLenA, bool del)
118 {
119 isFile = false;
120 buf = bufA;
121 bufLen = bufLenA;
122 deleteSrc = del;
123 }
124