chiark / gitweb /
Add a 'palt' feature providing alternative metrics for proportional
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 11 Oct 2009 09:29:11 +0000 (10:29 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 11 Oct 2009 09:29:11 +0000 (10:29 +0100)
spacing.  They're generated automatically (of course), but they work
quite well.  Also apply what I think is a correction to the script
lists for 'salt' and 'aalt'.

ttxt.c

diff --git a/ttxt.c b/ttxt.c
index 0db0143d80b077128f4cf5af484714c93c0fbb96..3db4359eea9e6c3f2a2600ca2c914f36f7252c54 100644 (file)
--- a/ttxt.c
+++ b/ttxt.c
@@ -599,9 +599,11 @@ main(int argc, char **argv)
        /* Force monochrome at 10 and 20 pixels, and greyscale elsewhere. */
        printf("GaspTable: 5 9 2 10 0 19 3 20 0 65535 3\n");
        printf("Lookup: 1 0 0 \"salt: stylistic alternates\" {\"salt\"} "
-           "['salt' ('DFLT' <'dflt'>)]\n");
+           "['salt' ('DFLT' <'dflt'> 'arab' <'dflt'> 'latn' <'dflt'>)]\n");
        printf("Lookup: 3 0 0 \"aalt: all alternates\" {\"aalt\"} "
-           "['aalt' ('DFLT' <'dflt'>)]\n");
+           "['aalt' ('DFLT' <'dflt'> 'arab' <'dflt'> 'latn' <'dflt'>)]\n");
+       printf("Lookup: 257 4 0 \"palt: proportional metrics\" {\"palt\"} "
+           "['palt' ('DFLT' <'dflt'> 'arab' <'dflt'> 'latn' <'dflt'>)]\n");
        printf("Lookup: 1 0 0 \"smcp: lower-case to small caps\" {\"smcp\"} "
            "['smcp' ('latn' <'dflt'>)]\n");
        printf("Lookup: 1 0 0 \"c2sc: upper-case to small caps\" {\"c2sc\"} "
@@ -634,7 +636,39 @@ main(int argc, char **argv)
        return 0;
 }
 
-void
+static void
+dopalt(struct glyph *g)
+{
+       int i;
+       unsigned char cols = 0;
+       int dx = 0, dh = 0;
+
+       /*
+        * For proportional layout, we'd like a left side-bearing of
+        * one pixel, and a right side-bearing of zero.  Space
+        * characters get an advance width of three pixels.
+        */
+       for (i = 0; i < YSIZE; i++)
+               cols |= g->data[i];
+       if (cols == 0)
+               dh = 3 - XSIZE;
+       else {
+               while (!(cols & 1 << (XSIZE - 2))) {
+                       cols <<= 1;
+                       dx--;
+               }
+               while (!(cols & 1)) {
+                       cols >>= 1;
+                       dh--;
+               }
+       }
+       if (dx || dh)
+               printf("Position2: \"palt\" dx=%d dy=0 dh=%d dv=0\n",
+                   dx * 100, dh * 100);
+}
+
+
+static void
 dolookups(struct glyph *g)
 {
        char glyphname[32];
@@ -673,6 +707,7 @@ dolookups(struct glyph *g)
                        glyphname);
                        break;
        }
+       dopalt(g);
 }
 
 typedef struct vec {