Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F86111
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
22 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..1bdb44d
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.0)
+project(TTFPATCH)
+add_executable(ttfpatch main.cpp woktools.cpp woktools.h)
+IF (UNIX)
+ install(TARGETS ttfpatch RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
+ELSE()
+ install(TARGETS ttfpatch RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
+ENDIF()
\ No newline at end of file
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..481f313
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+ttfpatch (1.0~chris1) groovy; urgency=medium
+
+ * Initial release.
+
+ -- Chris <dpkg@chris-nz.com> Sat, 17 Apr 2021 22:57:04 +1200
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..ed0c52c
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,16 @@
+Source: ttfpatch
+Section: devel
+Priority: optional
+Maintainer: Chris <dpkg@chris-nz.com>
+Build-Depends: debhelper-compat (= 13)
+Standards-Version: 4.5.0
+Homepage: http://www.derwok.de/downloads/ttfpatch/
+Rules-Requires-Root: no
+
+Package: ttfpatch
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Set permissions flags in truetype fonts
+ TrueType fonts contain a bitmask indicating licensing terms.
+ TTFPATCH provides a command which can set or correct the
+ value of this bitmask.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..5e298e0
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,47 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: TTFPATCH
+Upstream-Contact: Wolfram Esser <wok@derwok.de>
+Source: http://www.derwok.de/downloads/ttfpatch/
+
+Files: *
+Copyright: 2001 Wolfram Esser <wok@derwok.de>
+License: WOKPL
+ LICENCE
+ This programm and ist sourcecode are freeware.
+ You may do everything you want with the source / binary, as long
+ as you keep my (C)opyright notice unchanged and as long as
+ you agree to the following disclaimer:
+ .
+ DISCLAIMER
+ THIS FREEWARE PROGRAM IS PROVIDED BY WOLFRAM ESSER "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL
+ WOLFRAM ESSER OR HIS CONTRIBUTORS BE HELD LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES, LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ IF YOUR LOCALITY DOES NOT ALLOW THESE WARRANTY CONDITIONS, YOU ARE
+ NOT GRANTED PERMISSION TO USE.
+ .
+ TrueType Font, TTF and Microsoft are registered trademarks of Microsoft Corp.
+ Adobe, Acrobat, PDF are registered trademarks of Acrobat Corp.
+ OS/2 is a registered trademark of IBM Corp.
+ .
+ Wuerzburg, Germany 2001-02-23
+
+Files: debian/*
+Copyright: 2021 Chris <dpkg@chris-nz.com>
+License: ChrisPL
+ The debianization is free software: you can redistribute it and/or modify
+ it under the terms of any license you choose, and the author makes no
+ demand for attribution.
+ .
+ This package is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
diff --git a/debian/files b/debian/files
new file mode 100644
index 0000000..4b1e8ef
--- /dev/null
+++ b/debian/files
@@ -0,0 +1,3 @@
+ttfpatch-dbgsym_1.0~chris1_amd64.ddeb debug optional automatic=yes
+ttfpatch_1.0~chris1_amd64.buildinfo devel optional
+ttfpatch_1.0~chris1_amd64.deb devel optional
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..1d05518
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,18 @@
+#!/usr/bin/make -f
+
+export DH_VERBOSE = 1
+
+
+# see FEATURE AREAS in dpkg-buildflags(1)
+export DEB_BUILD_MAINT_OPTIONS = hardening=+all
+
+# see ENVIRONMENT in dpkg-buildflags(1)
+# package maintainers to append CFLAGS
+export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
+# package maintainers to append LDFLAGS
+export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
+
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..9f67427
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
\ No newline at end of file
diff --git a/debian/ttfpatch.1 b/debian/ttfpatch.1
new file mode 100644
index 0000000..8cd9058
--- /dev/null
+++ b/debian/ttfpatch.1
@@ -0,0 +1,57 @@
+.\" Hey, EMACS: -*- nroff -*-
+.\" Man Page (C) Copyright 2021 Chris <dpkg@chris-nz.com>,
+.\"
+.\" First parameter, NAME, should be all caps
+.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
+.\" other parameters are allowed: see man(7), man(1)
+.TH TTFPATCH 1 "April 17 2021"
+.\" Please adjust this date whenever revising the manpage.
+.\"
+.\" Some roff macros, for reference:
+.\" .nh disable hyphenation
+.\" .hy enable hyphenation
+.\" .ad l left justify
+.\" .ad b justify to both left and right margins
+.\" .nf disable filling
+.\" .fi enable filling
+.\" .br insert line break
+.\" .sp <n> insert n+1 empty lines
+.\" for manpage-specific macros, see man(7)
+.SH NAME
+ttfpatch \- set ttf permissions flags
+.SH SYNOPSIS
+.B ttfpatch
+.RI <TrueTypeFontFile>
+[NewFsTypeValue]
+.SH DESCRIPTION
+This manual page documents briefly the
+.B ttfpatch
+command.
+.PP
+.\" TeX users may be more comfortable with the \fB<whatever>\fP and
+.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
+.\" respectively.
+\fBttfpatch\fP is a program that provides an easy way for
+font designers to set the 'embeddable' flags of their own true type fonts.
+If you want to prohibit embedding of your font e.g. in Acrobat PDF
+files, simply run: 'ttfpatch myfont.ttf 2'
+.SH OPTIONS
+Below is a list of known fsType values:
+.br
+.B 0:
+embedding for permanent installation
+.B 1:
+reserved - do not use!
+.br
+.B 2:
+embedding restricted (not allowed!)
+.br
+.B 4:
+embedding for preview & printing allowed
+.br
+.B 8:
+embedding for editing allowed
+.SH SEE ALSO
+Refer to
+.BR https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
+for further information about the fsType values.
diff --git a/debian/ttfpatch.manpages b/debian/ttfpatch.manpages
new file mode 100644
index 0000000..3731246
--- /dev/null
+++ b/debian/ttfpatch.manpages
@@ -0,0 +1 @@
+debian/ttfpatch.1
\ No newline at end of file
diff --git a/debian/ttfpatch/DEBIAN/control b/debian/ttfpatch/DEBIAN/control
new file mode 100644
index 0000000..2ad0c0f
--- /dev/null
+++ b/debian/ttfpatch/DEBIAN/control
@@ -0,0 +1,13 @@
+Package: ttfpatch
+Version: 1.0~chris1
+Architecture: amd64
+Maintainer: Chris <dpkg@chris-nz.com>
+Installed-Size: 28
+Depends: libc6 (>= 2.4), libstdc++6 (>= 4.1.1)
+Section: devel
+Priority: optional
+Homepage: http://www.derwok.de/downloads/ttfpatch/
+Description: Set permissions flags in truetype fonts
+ TrueType fonts contain a bitmask indicating licensing terms.
+ TTFPATCH provides a command which can set or correct the
+ value of this bitmask.
diff --git a/debian/ttfpatch/DEBIAN/md5sums b/debian/ttfpatch/DEBIAN/md5sums
new file mode 100644
index 0000000..0b94b13
--- /dev/null
+++ b/debian/ttfpatch/DEBIAN/md5sums
@@ -0,0 +1,4 @@
+9b7af5f0888db154612aebbb71f070a8 usr/bin/ttfpatch
+360d4de280ee17f38ccfd46a5df87202 usr/share/doc/ttfpatch/changelog.gz
+d7cbfbdf9bb6abe9121b7bcb72f4058f usr/share/doc/ttfpatch/copyright
+9b4ba9a23fc5e925eeb5daeb30cb66be usr/share/man/man1/ttfpatch.1.gz
diff --git a/debian/ttfpatch/usr/bin/ttfpatch b/debian/ttfpatch/usr/bin/ttfpatch
new file mode 100755
index 0000000..7410dc6
Binary files /dev/null and b/debian/ttfpatch/usr/bin/ttfpatch differ
diff --git a/debian/ttfpatch/usr/share/doc/ttfpatch/changelog.gz b/debian/ttfpatch/usr/share/doc/ttfpatch/changelog.gz
new file mode 100644
index 0000000..539a13a
Binary files /dev/null and b/debian/ttfpatch/usr/share/doc/ttfpatch/changelog.gz differ
diff --git a/debian/ttfpatch/usr/share/doc/ttfpatch/copyright b/debian/ttfpatch/usr/share/doc/ttfpatch/copyright
new file mode 100644
index 0000000..5e298e0
--- /dev/null
+++ b/debian/ttfpatch/usr/share/doc/ttfpatch/copyright
@@ -0,0 +1,47 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: TTFPATCH
+Upstream-Contact: Wolfram Esser <wok@derwok.de>
+Source: http://www.derwok.de/downloads/ttfpatch/
+
+Files: *
+Copyright: 2001 Wolfram Esser <wok@derwok.de>
+License: WOKPL
+ LICENCE
+ This programm and ist sourcecode are freeware.
+ You may do everything you want with the source / binary, as long
+ as you keep my (C)opyright notice unchanged and as long as
+ you agree to the following disclaimer:
+ .
+ DISCLAIMER
+ THIS FREEWARE PROGRAM IS PROVIDED BY WOLFRAM ESSER "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL
+ WOLFRAM ESSER OR HIS CONTRIBUTORS BE HELD LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES, LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ IF YOUR LOCALITY DOES NOT ALLOW THESE WARRANTY CONDITIONS, YOU ARE
+ NOT GRANTED PERMISSION TO USE.
+ .
+ TrueType Font, TTF and Microsoft are registered trademarks of Microsoft Corp.
+ Adobe, Acrobat, PDF are registered trademarks of Acrobat Corp.
+ OS/2 is a registered trademark of IBM Corp.
+ .
+ Wuerzburg, Germany 2001-02-23
+
+Files: debian/*
+Copyright: 2021 Chris <dpkg@chris-nz.com>
+License: ChrisPL
+ The debianization is free software: you can redistribute it and/or modify
+ it under the terms of any license you choose, and the author makes no
+ demand for attribution.
+ .
+ This package is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
diff --git a/debian/ttfpatch/usr/share/man/man1/ttfpatch.1.gz b/debian/ttfpatch/usr/share/man/man1/ttfpatch.1.gz
new file mode 100644
index 0000000..69057d4
Binary files /dev/null and b/debian/ttfpatch/usr/share/man/man1/ttfpatch.1.gz differ
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..7a0d132
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,292 @@
+// ttfpatch.cpp
+//
+// changes the fsType (16-bit, Bigendian) value of a Truetype font
+// the fsType value defines, whether or not a TTF is embeddable
+// a fsType of decimal 2 prohibits embedding of the font in a PDF
+// a fsType of decimal 0, 4 and 8 enables the embedding of the font in a PDF
+//
+// 2001-02-23 by Wolfram Esser wok@derwok.de
+
+#include <cstdlib>
+#include <cstring>
+
+#include "woktools.h"
+
+
+int readheader();
+void printlicencebits(unsigned short fstype);
+void pause();
+
+
+// globals
+char* filename;
+FILE* fontfile;
+unsigned long tab_fsType_pos; // offset of fsType in TTF file
+unsigned short tab_fsType; // <<<--- We will change THIS !!!
+unsigned long ttf_filesize;
+char* ttf_allbytes;
+
+
+
+int main(int argc, char* argv[])
+{
+ unsigned short wanted_fsType;
+ filename = argv[1];
+
+ printf("\n\nTTFPATCH v1.0 - (C) by Wolfram Esser [wok@derwok.de] 2001-02-23\n");
+
+
+ if (argc != 2 && argc != 3) // usage
+ {
+ printf("Provides an easy way for font designers to set the 'embeddable' flags\n");
+ printf("of their own true type fonts. If you want to prohibit embedding of your\n");
+ printf("font e.g. in Acrobat PDF files, simply run: 'ttfpatch myfont.ttf 2'\n\n");
+ printf ("Usage: ttfpatch TrueTypeFontFile [NewFsTypeValue]\n");
+ printf ("\n");
+ printf ("fsType values:\n");
+ printf (" 0: embedding for permanent installation\n");
+ printf (" 1: reserved - do not use!\n");
+ printf (" 2: embedding restricted (not allowed!)\n");
+ printf (" 4: embedding for preview & printing allowed\n");
+ printf (" 8: embedding for editing allowed\n");
+
+ pause();
+ return 1;
+ }
+
+
+ fontfile = fopen(filename, "rb"); // open font for analysis
+ if(! fontfile)
+ {
+ printf ("\nError: Could not open fontfile '%s' for reading\n", filename);
+ pause();
+ return 1;
+ }
+
+ printf ("\n");
+ printf ("- Opened: '%s'\n", filename);
+ if (readheader()) // now read the header and find value and position of fsType
+ {
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+
+ if(argc == 3) // user wants to change fsType
+ {
+ wanted_fsType = strtol(argv[2], nullptr, 10);
+ printf ("- Wanted fsType: hex:'%04x'\n", wanted_fsType);
+ printlicencebits((unsigned short)wanted_fsType);
+
+ if(wanted_fsType & 0x0001) // allowed bit combination?
+ {
+ printf ("\nError: fsType & 0x0001 bit is reserved. must be zero!\n");
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+
+ // allowed bit combination?
+ if((wanted_fsType & 0x0002) && ((wanted_fsType & 0x0004) || (wanted_fsType & 0x0008)))
+ {
+ printf ("\nError: fsType & 0x0002 bit set, and (embedding allowed 0x0004 or 0x0008)\n");
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+
+ // anything to change???
+ if(wanted_fsType == tab_fsType)
+ {
+ printf ("\nNothing to do... wanted fsType %d already stored in TTF file!\n", wanted_fsType);
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+
+
+ // OK - now read the WHOLE TTF file into memory
+ printf ("- TTF filesize: '%lu' bytes\n", ttf_filesize);
+
+ fseek(fontfile, 0, SEEK_SET); // rewind
+ ttf_allbytes = new char[ttf_filesize]; // get memory to hold the fonts bytes
+ if(! ttf_allbytes)
+ {
+ printf("\nError: Internal error: could not get enough memory for file\n");
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+
+ // now read all the bytes
+ unsigned long bytesread = fread(ttf_allbytes, 1, ttf_filesize, fontfile);
+
+ if(bytesread != ttf_filesize)
+ {
+ printf ("\nError: Could not read %lu bytes from fontfile (read: %lu)\n", ttf_filesize, bytesread);
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+ printf("- OK: read: '%lu' bytes from file\n", bytesread);
+
+ // now store the new value
+ char* Pwanted_fsType = (char*) (&wanted_fsType);
+ ttf_allbytes[tab_fsType_pos+1] = *Pwanted_fsType; // swap bytes for big-endian!
+ ttf_allbytes[tab_fsType_pos] = *(Pwanted_fsType+1);
+
+ // reopen file - now for writing!!!
+ fclose(fontfile);
+ fontfile = fopen(filename, "wb");
+ if(! fontfile)
+ {
+ printf ("\nError: Could not open fontfile '%s' for reading\n", filename);
+ pause();
+ return 1;
+ }
+ unsigned long byteswritten = fwrite(ttf_allbytes, 1, ttf_filesize, fontfile);
+
+ if(byteswritten != ttf_filesize)
+ {
+ printf ("\nError: Could not write %lu bytes to fontfile (written: %lu)\n", ttf_filesize, byteswritten);
+ fclose(fontfile);
+ pause();
+ return 1;
+ }
+ printf("- OK: written: '%lu' bytes to file\n", byteswritten);
+ }
+ else
+ {
+ printf("\nNothing changed! - No new fsType value specified\n");
+ printf("Run program without any arguments to get usage hints\n");
+ }
+
+
+ pause();
+ return 0;
+}
+
+
+
+
+
+// reads the TTF header, seraches for the table with table tag 'OS/2'
+// fseeks to that table and reads the fsType value (16 bit, Big-Ednian Motorola style) from there
+// remembers file-position of fsType start
+int readheader()
+{
+
+ unsigned long version; // Global Data
+ unsigned long numtables;
+
+ char tabtag[5]; // Table Position
+ unsigned long taboffset;
+
+ unsigned short tabversion; // must be 0x0001
+
+ version = readBE4(fontfile);
+ printf ("- Fileformat version: hex: '%08lx'\n", version);
+ if (version != 0x00010000)
+ {
+ printf ("\nError: Fileformat version must be '0x00010000'\n");
+ return 1;
+ }
+
+ numtables = readBE2(fontfile);
+ printf ("- Number of Infotables: %lu\n", numtables);
+ if (numtables <= 9)
+ {
+ printf ("\nError: numtables must be greater than '9'\n");
+ return 1;
+ }
+
+ readBE2(fontfile); // search range - not needed
+ readBE2(fontfile); // entry selector - not needed
+ readBE2(fontfile); // range shift - not needed
+
+ int found_os2_table = 0;
+ unsigned long tables_checked = 0;
+ while (tables_checked < numtables && !found_os2_table)
+ {
+ fread (tabtag, 4, 1, fontfile); // read the table-name (we look for 'OS/2')
+ tabtag[4] = '\0';
+ readBE4(fontfile); // checksum - not needed
+ taboffset = readBE4(fontfile); // we need THIS!
+ readBE4(fontfile); // length - not needed
+
+ if (strcmp(tabtag, "OS/2") == 0)
+ {
+ printf ("- Found 'OS/2' table\n");
+ found_os2_table = 1;
+ }
+ tables_checked ++;
+ }
+
+ printf ("- Tableoffset: hex:'%08lx'\n", taboffset);
+ fseek(fontfile, (long) taboffset, SEEK_SET); // Jump to OS/2 table
+ tabversion = (unsigned short) readBE2(fontfile); // 0x0001 Version
+ if(tabversion != 0x0001)
+ {
+ if((tabversion == 0x0000) || (tabversion == 0x0002))
+ {
+ printf ("\nWarning: OS/2 tableversion is not '0x0001' but '0x0000'\n");
+ }
+ else
+ {
+ printf ("\nError: OS/2 tableversion must be 0, 1 or 2 and is hex:%04x\n", tabversion);
+ return 1;
+ }
+ }
+
+ readBE2(fontfile); // average char width - not needed
+ readBE2(fontfile); // weight class - not needed
+ readBE2(fontfile); // widht class - not needed
+
+
+ tab_fsType_pos = ftell(fontfile); // remember 0-based position of fsType (16 bit)
+
+ /////////////////////////////
+ tab_fsType = (unsigned short) readBE2(fontfile); // <<<--- We will change THIS !!!
+ /////////////////////////////
+
+ printf ("- Curret fsType: hex:'%04x'\n", tab_fsType);
+ printlicencebits(tab_fsType);
+
+ fseek(fontfile, 0, SEEK_END);
+ ttf_filesize = ftell(fontfile);
+
+ return 0;
+}
+
+
+
+
+
+
+void printlicencebits(unsigned short fstype)
+{
+ if (fstype == 0x0000)
+ printf (" 0: embedding for permanent installation allowed\n");
+
+ if ((fstype & 0x0001) == 0x0001)
+ printf (" 1: reserved - not to be used, must be zero!\n");
+
+ if (fstype & 0x0002)
+ printf (" 2: embedding restricted (not allowed, at all!)\n");
+
+ if (fstype & 0x0004)
+ printf (" 4: embedding for preview & printing allowed\n");
+
+ if (fstype & 0x0008)
+ printf (" 8: embedding for editing allowed\n");
+}
+
+
+
+void pause()
+{
+// char c;
+// printf("\nHit any key...");
+// c = getc(stdin);
+// printf("\n");
+}
diff --git a/woktools.cpp b/woktools.cpp
new file mode 100644
index 0000000..ac29d3f
--- /dev/null
+++ b/woktools.cpp
@@ -0,0 +1,124 @@
+/*
+ woktools.c
+
+ Some helper routines
+
+ (C) Wolfram Esser, 4.2.1999
+*/
+
+#include "woktools.h"
+
+void fatal_error(char* message, int status)
+{
+ fprintf (stderr, "***FATAL ERROR: %s\n", message);
+ exit(status);
+}
+
+
+void writeLE4(signed long value, FILE* outFile) // little-endian: Intel-style, 4 byte
+{
+ unsigned char raw[4];
+
+ raw[0] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[1] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[2] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[3] = (char) (value & 0xFF);
+
+ fwrite(raw, 1, 4, outFile);
+}
+
+
+void writeLE2(signed long value, FILE* outFile) // little-endian: Intel-style, 2 byte
+{
+ unsigned char raw[2];
+
+ raw[0] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[1] = (char) (value & 0xFF);
+
+ fwrite(raw, 1, 2, outFile);
+}
+
+
+void writeBE4(signed long value, FILE* outFile) // big-endian: RISC-style, 4 byte
+{
+ unsigned char raw[4];
+
+ raw[3] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[2] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[1] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[0] = (char) (value & 0xFF);
+
+ fwrite(raw, 1, 4, outFile);
+}
+
+
+void writeBE2(signed long value, FILE* outFile) // big-endian: RISC-style, 2 byte
+{
+ unsigned char raw[2];
+
+ raw[1] = (char) (value & 0xFF);
+ value = value >> 8;
+ raw[0] = (char) (value & 0xFF);
+
+ fwrite(raw, 1, 2, outFile);
+}
+
+
+// ****************************************************************************************************
+
+unsigned long readLE4(FILE* inFile) // little-Endian: Intel-style, 4 byte
+{
+ unsigned long retval;
+ unsigned char raw[4];
+ fread(raw, 1, 4, inFile);
+
+ retval = ((unsigned long)raw[3]<<24)
+ | ((unsigned long)raw[2]<<16)
+ | ((unsigned long)raw[1]<<8)
+ | ((unsigned long)raw[0]);
+ return retval;
+}
+
+unsigned long readLE2(FILE* inFile) // little-endian: Intel-style, 2 byte
+{
+ unsigned long retval;
+ unsigned char raw[2];
+ fread(raw, 1, 2, inFile);
+
+ retval = ((unsigned long)raw[1]<<8)
+ | ((unsigned long)raw[0]);
+ return retval;
+}
+
+
+unsigned long readBE4(FILE* inFile) // big-Endian: RISC-style, 4 byte
+{
+ unsigned long retval;
+ unsigned char raw[4];
+ fread(raw, 1, 4, inFile);
+
+ retval = ((unsigned long)raw[0]<<24)
+ | ((unsigned long)raw[1]<<16)
+ | ((unsigned long)raw[2]<<8)
+ | ((unsigned long)raw[3]);
+ return retval;
+}
+
+unsigned long readBE2(FILE* inFile) // big-endian: RISC-style, 2 byte
+{
+ unsigned long retval;
+ unsigned char raw[2];
+ fread(raw, 1, 2, inFile);
+
+ retval = ((unsigned long)raw[0]<<8)
+ | ((unsigned long)raw[1]);
+ return retval;
+}
+
diff --git a/woktools.h b/woktools.h
new file mode 100644
index 0000000..b5542a2
--- /dev/null
+++ b/woktools.h
@@ -0,0 +1,27 @@
+/*
+ woktools.h
+
+ Some helper routines
+
+ (C) Wolfram Esser, 4.2.1999
+*/
+
+#include <iostream>
+
+void fatal_error(char* message, int status);
+
+void writeLE4(unsigned long value, FILE* outFile); // little-endian: Intel-style, 4 byte
+void writeLE2(unsigned long value, FILE* outFile); // little-endian: Intel-style, 2 byte
+
+void writeBE4(unsigned long value, FILE* outFile); // big-endian: RISC-style, 4 byte
+void writeBE2(unsigned long value, FILE* outFile); // big-endian: RISC-style, 2 byte
+
+
+unsigned long readLE4(FILE* inFile); // little-Endian: Intel-style, 4 byte
+unsigned long readLE2(FILE* inFile); // little-endian: Intel-style, 2 byte
+
+unsigned long readBE4(FILE* inFile); // big-Endian: RISC-style, 4 byte
+unsigned long readBE2(FILE* inFile); // big-endian: RISC-style, 2 byte
+
+
+
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 11, 12:45 PM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42656
Default Alt Text
(22 KB)
Attached To
Mode
R81 ttfpatch
Attached
Detach File
Event Timeline
Log In to Comment