summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-07 15:22:02 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-05-07 15:22:02 +0000
commita98d8fb5e49436c6fedea37797225293284b9894 (patch)
treef140662044f20668b937c9f3b451c56345678108 /src/utils.c
downloadttf2f-a98d8fb5e49436c6fedea37797225293284b9894.tar.gz
ttf2f-a98d8fb5e49436c6fedea37797225293284b9894.tar.bz2
Import TTF2f. Don't expect this to link; I've prevented it building main.c.
svn path=/trunk/tools/ttf2f/; revision=7427
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..1aea66f
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,39 @@
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "utils.h"
+
+char *strndup(const char *s, size_t n)
+{
+ /* this assumes s is NUL terminated - if not,
+ * some silly value will be returned */
+ size_t len = strlen(s);
+ char *res;
+
+ /* limit to n */
+ if (len > n || n == 0)
+ len = n;
+
+ res = (char *) malloc(len + 1);
+ if (res == NULL)
+ return NULL;
+
+ res[len] = '\0';
+ return (char *) memcpy(res, s, len);
+}
+
+/**
+ * Convert raw font units to units normalised with a design size of 1000
+ *
+ * \param raw Raw value from file
+ * \param ppem Design size of font
+ * \return Converted value
+ */
+long convert_units(long raw, long ppem)
+{
+ if (ppem == 1000)
+ return raw;
+
+ return (raw * 1000) / ppem;
+}