summaryrefslogtreecommitdiffstats
path: root/kpdf/xpdf/splash/SplashFontFile.cpp
blob: c66447bb0bc8a575570a6a1306ac264d4c8633e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//========================================================================
//
// SplashFontFile.cpp
//
//========================================================================

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif

#include <stdio.h>
#ifndef WIN32
#  include <unistd.h>
#endif
#include "gmem.h"
#include "GString.h"
#include "SplashFontFile.h"
#include "SplashFontFileID.h"

#ifdef VMS
#if (__VMS_VER < 70000000)
extern "C" int unlink(char *filename);
#endif
#endif

//------------------------------------------------------------------------
// SplashFontFile
//------------------------------------------------------------------------

SplashFontFile::SplashFontFile(SplashFontFileID *idA, SplashFontSrc *srcA) {
  id = idA;
  src = srcA;
  src->ref();
  refCnt = 0;
}

SplashFontFile::~SplashFontFile() {
  src->unref();
  delete id;
}

void SplashFontFile::incRefCnt() {
  ++refCnt;
}

void SplashFontFile::decRefCnt() {
  if (!--refCnt) {
    delete this;
  }
}

//

SplashFontSrc::SplashFontSrc() {
  isFile = gFalse;
  deleteSrc = gFalse;
  fileName = NULL;
  buf = NULL;
  refcnt = 1;
}

SplashFontSrc::~SplashFontSrc() {
  if (deleteSrc) {
    if (isFile) {
      if (fileName)
	unlink(fileName->getCString());
    } else {
      if (buf)
	gfree(buf);
    }
  }

  if (isFile && fileName)
    delete fileName;
}

void SplashFontSrc::ref() {
  refcnt++;
}

void SplashFontSrc::unref() {
  if (! --refcnt)
    delete this;
}

void SplashFontSrc::setFile(GString *file, GBool del)
{
  isFile = gTrue;
  fileName = file->copy();
  deleteSrc = del;
}

void SplashFontSrc::setFile(const char *file, GBool del)
{
  isFile = gTrue;
  fileName = new GString(file);
  deleteSrc = del;
}

void SplashFontSrc::setBuf(char *bufA, int bufLenA, GBool del)
{
  isFile = gFalse;
  buf = bufA;
  bufLen = bufLenA;
  deleteSrc = del;
}