aboutsummaryrefslogtreecommitdiff
path: root/splash/SplashFontFile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'splash/SplashFontFile.cc')
-rw-r--r--splash/SplashFontFile.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/splash/SplashFontFile.cc b/splash/SplashFontFile.cc
new file mode 100644
index 0000000..2d260e3
--- /dev/null
+++ b/splash/SplashFontFile.cc
@@ -0,0 +1,84 @@
+//========================================================================
+//
+// SplashFontFile.cc
+//
+// Copyright 2003-2013 Glyph & Cog, LLC
+//
+//========================================================================
+
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
+#pragma implementation
+#endif
+
+#include <stdio.h>
+#ifndef _WIN32
+# include <unistd.h>
+#endif
+#include "gmempp.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,
+ SplashFontType fontTypeA,
+#if LOAD_FONTS_FROM_MEM
+ GString *fontBufA
+#else
+ char *fileNameA, GBool deleteFileA
+#endif
+ ) {
+ id = idA;
+ fontType = fontTypeA;
+#if LOAD_FONTS_FROM_MEM
+ fontBuf = fontBufA;
+#else
+ fileName = new GString(fileNameA);
+ deleteFile = deleteFileA;
+#endif
+ refCnt = 0;
+}
+
+SplashFontFile::~SplashFontFile() {
+#if LOAD_FONTS_FROM_MEM
+ delete fontBuf;
+#else
+ if (deleteFile) {
+ unlink(fileName->getCString());
+ }
+ delete fileName;
+#endif
+ delete id;
+}
+
+void SplashFontFile::incRefCnt() {
+#if MULTITHREADED
+ gAtomicIncrement(&refCnt);
+#else
+ ++refCnt;
+#endif
+}
+
+void SplashFontFile::decRefCnt() {
+ GBool done;
+
+#if MULTITHREADED
+ done = gAtomicDecrement(&refCnt) == 0;
+#else
+ done = --refCnt == 0;
+#endif
+ if (done) {
+ delete this;
+ }
+}