about summary refs log tree commit diff
path: root/other/ppmddumpfont.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-08-19 03:12:28 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-08-19 03:12:28 +0000
commit1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch)
tree64c8c96cf54d8718847339a403e5e67b922e8c3f /other/ppmddumpfont.c
downloadnetpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz
netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz
netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'other/ppmddumpfont.c')
-rw-r--r--other/ppmddumpfont.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/other/ppmddumpfont.c b/other/ppmddumpfont.c
new file mode 100644
index 00000000..3ab477ab
--- /dev/null
+++ b/other/ppmddumpfont.c
@@ -0,0 +1,89 @@
+#include <stdio.h>
+#include <assert.h>
+
+#include "ppm.h"
+#include "ppmdfont.h"
+
+
+
+static int
+untwos(unsigned char const arg) {
+
+    if (arg >= 128)
+        return arg - 256;
+    else
+        return arg;
+}
+
+
+
+static void
+dumpHeader(struct ppmd_fontHeader const fontHeader) {
+    
+    pm_message("Font has %u characters", fontHeader.characterCount);
+    pm_message("Font has code points %u through %u",
+               fontHeader.firstCodePoint,
+               fontHeader.firstCodePoint + fontHeader.characterCount - 1);
+}
+
+
+
+static void
+dumpGlyph(struct ppmd_glyph const glyph) {
+
+    unsigned int commandNum;
+
+    pm_message("  skip before: %u pixels; skip after: %u pixels; "
+               "%u commands:", 
+               glyph.header.skipBefore,
+               glyph.header.skipAfter,
+               glyph.header.commandCount);
+
+    for (commandNum = 0;
+         commandNum < glyph.header.commandCount;
+         ++commandNum) {
+         
+        struct ppmd_glyphCommand const glyphCommand =
+            glyph.commandList[commandNum];
+        
+        const char * verbDisp;
+
+        switch (glyphCommand.verb) {
+        case CMD_NOOP:     verbDisp = "NOOP";     break;
+        case CMD_DRAWLINE: verbDisp = "DRAWLINE"; break;
+        case CMD_MOVEPEN:  verbDisp = "MOVEPEN";  break;
+        }
+
+        pm_message("    %s %d %d",
+                   verbDisp, untwos(glyphCommand.x), untwos(glyphCommand.y));
+    }
+}
+
+
+
+int
+main(int argc, char **argv) {
+
+    const struct ppmd_font * fontP;
+    unsigned int relativeCodePoint;
+
+    ppm_init(&argc, argv);
+
+    ppmd_read_font(stdin, &fontP);
+
+    dumpHeader(fontP->header);
+
+    for (relativeCodePoint = 0;
+         relativeCodePoint < fontP->header.characterCount;
+         ++relativeCodePoint) {
+
+        pm_message("Code point %u:",
+                   fontP->header.firstCodePoint + relativeCodePoint);
+
+        dumpGlyph(fontP->glyphTable[relativeCodePoint]);
+    }
+
+    ppmd_free_font(fontP);
+    
+    return 0;
+}