about summary refs log tree commit diff
path: root/lib/libpbmfontdump.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-07-04 15:15:43 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-07-04 15:15:43 +0000
commite4e6614dfa133420adb1763a962fff8ea04ab941 (patch)
tree4525ff694a98283e2ea2532e4ea3dda0a0da5f2f /lib/libpbmfontdump.c
parent333ca756cb899f193aa450a1033fde8cbe318081 (diff)
downloadnetpbm-mirror-e4e6614dfa133420adb1763a962fff8ea04ab941.tar.gz
netpbm-mirror-e4e6614dfa133420adb1763a962fff8ea04ab941.tar.xz
netpbm-mirror-e4e6614dfa133420adb1763a962fff8ea04ab941.zip
Rewrite font processing for proper memory management; make built-in fonts work with wide characters; fix wild pointer dereference with invalid BDF input
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3291 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpbmfontdump.c')
-rw-r--r--lib/libpbmfontdump.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/lib/libpbmfontdump.c b/lib/libpbmfontdump.c
new file mode 100644
index 00000000..f0c950f7
--- /dev/null
+++ b/lib/libpbmfontdump.c
@@ -0,0 +1,96 @@
+/*
+**
+** Font routines.
+**
+** BDF font code Copyright 1993 by George Phillips.
+**
+** Copyright (C) 1991 by Jef Poskanzer.
+**
+** Permission to use, copy, modify, and distribute this software and its
+** documentation for any purpose and without fee is hereby granted, provided
+** that the above copyright notice appear in all copies and that both that
+** copyright notice and this permission notice appear in supporting
+** documentation.  This software is provided "as is" without express or
+** implied warranty.
+**
+** BDF font specs available from:
+** https://partners.adobe.com/public/developer/en/font/5005.BDF_Spec.pdf
+** Glyph Bitmap Distribution Format (BDF) Specification
+** Version 2.2
+** 22 March 1993
+** Adobe Developer Support
+*/
+
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "netpbm/pm_c_util.h"
+#include "netpbm/mallocvar.h"
+#include "netpbm/nstring.h"
+
+#include "pbmfont.h"
+#include "pbm.h"
+
+
+void
+pbm_dumpfont(struct font * const fontP,
+             FILE *        const ofP) {
+/*----------------------------------------------------------------------------
+  Dump out font as C source code.
+-----------------------------------------------------------------------------*/
+    unsigned int i;
+    unsigned int ng;
+
+    if (fontP->oldfont)
+        pm_message("Netpbm no longer has the capability to generate "
+                   "a font in long hexadecimal data format");
+
+    for (i = 0, ng = 0; i < PM_FONT_MAXGLYPH +1; ++i) {
+        if (fontP->glyph[i])
+            ++ng;
+    }
+
+    printf("static struct glyph _g[%d] = {\n", ng);
+
+    for (i = 0; i < PM_FONT_MAXGLYPH + 1; ++i) {
+        struct glyph * const glyphP = fontP->glyph[i];
+        if (glyphP) {
+            unsigned int j;
+            printf(" { %d, %d, %d, %d, %d, \"", glyphP->width, glyphP->height,
+                   glyphP->x, glyphP->y, glyphP->xadd);
+
+            for (j = 0; j < glyphP->width * glyphP->height; ++j) {
+                if (glyphP->bmap[j])
+                    printf("\\1");
+                else
+                    printf("\\0");
+            }
+            --ng;
+            printf("\" }%s\n", ng ? "," : "");
+        }
+    }
+    printf("};\n");
+
+    printf("struct font XXX_font = { %d, %d, %d, %d, {\n",
+           fontP->maxwidth, fontP->maxheight, fontP->x, fontP->y);
+
+    {
+        unsigned int i;
+
+        for (i = 0; i < PM_FONT_MAXGLYPH + 1; ++i) {
+            if (fontP->glyph[i])
+                printf(" _g + %d", ng++);
+            else
+                printf(" NULL");
+
+            if (i != PM_FONT_MAXGLYPH) printf(",");
+            printf("\n");
+        }
+    }
+
+    printf(" }\n};\n");
+}
+
+
+