const char * (UsageLines [] ) = { "p4label37: Reads text from standard input,", "writes P4 pbm to standard output using fixed-width.", "Usage: p4label37 (output image width) (output image height)", "Only ASCII characters are recognized.", "", "January 4, 2023. Latest at gopher://sdf.org/1/users/julianbr", }; const int NumUsageLines = sizeof (UsageLines)/sizeof (UsageLines [0] ); #define NUM_ROWS 37 #define LETTER_SPACING 3 #define LINE_SPACING 3 #define MARGIN 15 int MaxNumColumns; int (Outlines [] ) [NUM_ROWS] = { {6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, 6, 15, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ! */ {51, 51, 51, 51, 51, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* \ */ {0, 0, 0, 0, 0, 0, 0, 66, 66, 198, 198, 198, 198, 1023, 1023, 462, 462, 462, 1023, 1023, 1023, 396, 396, 396, 264, 264, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* # */ {48, 48, 48, 48, 120, 510, 510, 951, 951, 816, 816, 944, 944, 496, 252, 126, 62, 55, 55, 51, 51, 951, 438, 510, 252, 120, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, }, /* $ */ {387, 963, 2019, 1639, 1638, 1646, 2030, 972, 988, 24, 56, 48, 112, 112, 96, 224, 192, 478, 414, 959, 947, 819, 1847, 1599, 1566, 1036, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* % */ {96, 240, 248, 472, 472, 472, 408, 216, 248, 496, 1008, 992, 864, 1904, 1904, 1584, 1592, 1595, 1823, 1823, 1823, 782, 910, 508, 252, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* & */ {3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ' */ {0, 3, 7, 7, 14, 12, 12, 28, 28, 24, 24, 24, 24, 24, 24, 24, 24, 28, 28, 12, 12, 14, 7, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ( */ {0, 24, 28, 30, 14, 6, 6, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 6, 6, 14, 30, 28, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ) */ {195, 195, 231, 102, 126, 60, 255, 255, 255, 60, 126, 231, 231, 195, 195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* * */ {0, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 255, 255, 24, 24, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* + */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, }, /* , */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* - */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* . */ {1, 3, 3, 3, 7, 7, 6, 14, 14, 12, 12, 28, 24, 24, 56, 48, 48, 112, 112, 96, 224, 224, 192, 192, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* / */ {496, 1016, 2044, 3870, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7399, 7399, 7399, 7399, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 3870, 2044, 1016, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 0 */ {6, 14, 30, 30, 30, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 31, 31, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 1 */ {1016, 2044, 4094, 7695, 7175, 7175, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 15, 30, 60, 120, 240, 480, 960, 8191, 8191, 8191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 2 */ {1016, 2044, 4094, 7695, 7175, 7175, 7175, 7, 7, 7, 15, 30, 252, 252, 254, 15, 7, 7, 7, 7175, 7175, 7175, 7695, 4094, 2044, 1016, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 3 */ {28, 60, 124, 252, 252, 476, 412, 924, 1820, 1820, 3612, 8191, 8191, 8191, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 4 */ {8191, 8191, 8191, 7168, 7168, 7168, 7168, 7168, 7168, 8176, 8184, 8188, 30, 15, 7, 7, 7, 7, 7, 7, 15, 30, 60, 8184, 8176, 8160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 5 */ {63, 127, 255, 480, 960, 1920, 3840, 7680, 7168, 7168, 7168, 7672, 8188, 8190, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 4094, 2044, 1016, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 6 */ {8191, 8191, 8191, 15, 14, 14, 30, 28, 60, 56, 120, 112, 240, 224, 480, 448, 960, 896, 1920, 1792, 3840, 3584, 7680, 7168, 7168, 7168, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 7 */ {1016, 2044, 4094, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 3870, 2044, 2044, 3870, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 4094, 2044, 1016, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 8 */ {1016, 2044, 4094, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 4095, 2047, 1015, 7, 7, 7, 14, 30, 60, 120, 240, 8160, 8128, 8064, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* 9 */ {0, 0, 0, 0, 0, 0, 0, 6, 15, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* : */ {0, 0, 0, 0, 0, 0, 0, 6, 15, 15, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, }, /* ; */ {3, 3, 7, 14, 14, 28, 24, 56, 112, 112, 224, 192, 192, 192, 192, 224, 112, 112, 56, 24, 28, 14, 14, 7, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* < */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* = */ {0, 0, 0, 0, 192, 224, 112, 56, 28, 30, 14, 7, 3, 3, 7, 14, 28, 60, 56, 112, 224, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* > */ {120, 252, 462, 390, 903, 903, 771, 3, 3, 7, 7, 14, 30, 28, 48, 48, 48, 48, 48, 48, 0, 0, 48, 120, 120, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ? */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 496, 1016, 792, 1912, 1912, 1788, 1788, 1788, 1912, 1912, 796, 1022, 511, 227, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* @ */ {224, 224, 496, 496, 952, 952, 952, 1820, 1820, 1820, 3598, 3598, 3598, 4094, 4094, 8191, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* A */ {8176, 8184, 8188, 7198, 7183, 7175, 7175, 7175, 7175, 7183, 7198, 8188, 8184, 8184, 7228, 7198, 7183, 7175, 7175, 7175, 7175, 7183, 7198, 8188, 8184, 8176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* B */ {496, 1016, 2044, 3870, 7695, 7175, 7175, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7175, 7175, 7695, 3870, 2044, 1016, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* C */ {8128, 8160, 8176, 7288, 7228, 7198, 7183, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7183, 7198, 7228, 8184, 8176, 8160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* D */ {8191, 8191, 8191, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 8184, 8184, 8184, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 8191, 8191, 8191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* E */ {8191, 8191, 8191, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 8184, 8184, 8184, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* F */ {496, 1016, 2044, 3870, 7695, 7175, 7175, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7199, 7199, 7199, 7175, 7175, 7175, 7175, 7695, 3870, 2044, 1016, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* G */ {7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 8191, 8191, 8191, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* H */ {31, 31, 31, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 31, 31, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* I */ {31, 31, 31, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 3598, 3598, 3870, 2044, 1016, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* J */ {7175, 7175, 7183, 7198, 7228, 7288, 7408, 7648, 8128, 8064, 7936, 7680, 7168, 7168, 7680, 7936, 8064, 8128, 7648, 7408, 7288, 7228, 7198, 7183, 7175, 7175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* K */ {7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 8191, 8191, 8191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* L */ {49155, 57351, 57351, 61455, 61455, 63519, 63519, 64575, 64575, 64575, 65151, 61047, 61047, 58983, 59367, 59367, 58311, 58311, 57799, 57799, 57799, 57351, 57351, 57351, 57351, 57351, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* M */ {14343, 14343, 15367, 15879, 16135, 16135, 16263, 15239, 15303, 14791, 14791, 14823, 14567, 14567, 14567, 14455, 14455, 14399, 14399, 14399, 14367, 14367, 14367, 14351, 14343, 14343, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* N */ {496, 1016, 2044, 3870, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 3870, 2044, 1016, 496, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* O */ {7664, 8184, 8188, 7710, 7183, 7175, 7175, 7175, 7183, 7710, 8188, 8184, 7664, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 7168, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* P */ {1016, 2044, 4094, 7695, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 3870, 2044, 1016, 508, 30, 14, 14, 14, 14, 14, 14, 0, 0, 0, 0, }, /* Q */ {8184, 8188, 8190, 7183, 7175, 7175, 7175, 7175, 7175, 7183, 7198, 8188, 8184, 8176, 7648, 7392, 7392, 7280, 7224, 7224, 7196, 7182, 7182, 7183, 7175, 7175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* R */ {1016, 2044, 4094, 7695, 7175, 7175, 7168, 7168, 7168, 7168, 7680, 3840, 2040, 1020, 510, 15, 7, 7, 7, 7, 7175, 7183, 7710, 4092, 2040, 1008, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* S */ {8191, 8191, 8191, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* T */ {7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 4094, 2044, 1016, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* U */ {7175, 7175, 7175, 7175, 7175, 7175, 7175, 7695, 3598, 3598, 3870, 1820, 1820, 1820, 1820, 1820, 1820, 792, 792, 952, 952, 496, 496, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* V */ {57351, 57351, 57351, 57351, 57351, 57351, 57351, 57351, 57351, 57351, 57351, 57799, 57799, 57799, 57799, 58311, 58311, 59367, 59366, 30318, 32382, 31868, 14396, 14364, 14364, 14364, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* W */ {7175, 7175, 7175, 7175, 3598, 3598, 1820, 1820, 952, 1016, 496, 496, 224, 224, 496, 496, 1016, 952, 1820, 1820, 3598, 3598, 7175, 7175, 7175, 7175, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* X */ {7175, 7175, 7175, 3598, 3598, 1548, 1820, 952, 1016, 496, 496, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* Y */ {8191, 8191, 8191, 7, 14, 14, 28, 28, 56, 56, 112, 112, 224, 224, 448, 448, 896, 896, 1792, 1792, 3584, 3584, 7168, 8191, 8191, 8191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* Z */ {63, 63, 63, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 63, 63, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* [ */ {128, 192, 192, 192, 224, 224, 96, 112, 112, 48, 48, 56, 24, 24, 28, 12, 12, 14, 14, 6, 7, 7, 3, 3, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* \ */ {63, 63, 63, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 63, 63, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ] */ {24, 60, 60, 126, 126, 102, 231, 231, 195, 195, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ^ */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2047, 2047, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* _ */ {8, 8, 12, 12, 14, 6, 7, 3, 3, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ` */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 126, 127, 7, 3, 3, 511, 1023, 1023, 903, 903, 903, 1023, 1023, 507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* a */ {896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 956, 1022, 1023, 967, 903, 903, 903, 903, 903, 903, 903, 967, 1022, 1022, 828, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* b */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 254, 511, 967, 903, 896, 768, 768, 768, 896, 903, 967, 511, 254, 124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* c */ {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 247, 511, 1023, 911, 903, 903, 903, 903, 903, 903, 903, 911, 1023, 511, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* d */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 252, 510, 975, 903, 903, 1023, 1023, 1023, 896, 896, 967, 511, 254, 124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* e */ {124, 254, 511, 967, 903, 896, 896, 896, 896, 896, 896, 1020, 1020, 1020, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* f */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 511, 1023, 911, 903, 903, 903, 903, 903, 903, 903, 911, 1023, 511, 247, 7, 7, 7, 7, 7, 7, 903, 975, 1022, 508, 120, }, /* g */ {896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 958, 1023, 1023, 967, 903, 903, 903, 903, 903, 903, 903, 903, 903, 903, 903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* h */ {0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* i */ {0, 0, 0, 0, 7, 7, 7, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 455, 455, 455, 511, 254, 124, }, /* j */ {896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 903, 911, 927, 952, 1008, 992, 960, 896, 960, 992, 1008, 952, 927, 911, 903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* k */ {15, 15, 15, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* l */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29692, 32766, 32767, 31175, 29127, 29127, 29127, 29127, 29127, 29127, 29127, 29127, 29127, 29127, 29127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* m */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 956, 1022, 1023, 967, 903, 903, 903, 903, 903, 903, 903, 903, 903, 903, 903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* n */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 252, 510, 975, 903, 903, 903, 903, 903, 903, 903, 975, 510, 252, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* o */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 956, 1022, 1023, 967, 903, 903, 903, 903, 903, 903, 903, 967, 1023, 1022, 956, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, }, /* p */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 511, 1023, 911, 903, 903, 903, 903, 903, 903, 903, 911, 1023, 511, 247, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, }, /* q */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 956, 1022, 1023, 967, 903, 896, 896, 896, 896, 896, 896, 896, 896, 896, 896, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* r */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252, 510, 1023, 903, 896, 896, 504, 252, 126, 7, 7, 903, 1023, 510, 252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* s */ {0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 224, 1020, 1020, 1020, 224, 224, 224, 224, 224, 224, 224, 224, 231, 255, 126, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* t */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 903, 903, 903, 903, 903, 903, 903, 903, 903, 903, 903, 911, 1023, 511, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* u */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 903, 903, 903, 903, 903, 903, 903, 462, 462, 462, 252, 252, 120, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* v */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29127, 29127, 29127, 29127, 29127, 29127, 29127, 29671, 29671, 32767, 16254, 7740, 7740, 3640, 3096, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* w */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 903, 903, 975, 462, 204, 252, 120, 120, 120, 252, 204, 462, 975, 903, 903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* x */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 903, 903, 903, 903, 903, 455, 455, 455, 487, 231, 231, 255, 127, 62, 28, 28, 28, 28, 28, 28, 60, 60, 120, 240, 480, 448, }, /* y */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1023, 1023, 14, 14, 30, 60, 120, 240, 480, 448, 448, 1023, 1023, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* z */ {7, 15, 31, 60, 56, 56, 60, 28, 28, 28, 56, 56, 112, 112, 56, 56, 28, 28, 28, 60, 56, 56, 60, 31, 15, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* { */ {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* | */ {112, 120, 124, 30, 14, 14, 30, 28, 28, 30, 14, 14, 7, 7, 14, 14, 30, 28, 28, 30, 14, 14, 30, 124, 120, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* } */ {120, 252, 510, 975, 903, 903, 975, 510, 252, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 192, 480, 1008, 816, 51, 63, 30, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, /* ~ */ }; int NumOutlines = sizeof (Outlines) / sizeof (Outlines [0] ); #include <stdlib.h> #include <stdio.h> void WriteLabel (unsigned char (* TextLine) [NUM_ROWS] , int width, int height) { int * Outline; int c, i, j, byte, NumTextLines, NumImageLines, NumChars, MaxNumChars, PowerOf2; int row, position, NumColumns; NumImageLines = 0; printf ("P4\n"); printf ("%d %d\n", width, height); for (i = 0; i < MARGIN; i++) { if (NumImageLines < height) { for (byte = 0; byte < (width + 7)/8; byte++) putchar (0); } NumImageLines++; } NumTextLines = 0; MaxNumChars = 0; c = getchar (); while (c != EOF) { NumChars = 0; for (i = 0; i < NUM_ROWS; i++) { for (byte = 0; byte < (width + 7)/8; byte++) TextLine [byte] [i] = 0; } while (c != '\n' && c != EOF) { if (c - '!' >= 0 && c - '!' < NumOutlines) { PowerOf2 = 1; NumColumns = 0; Outline = Outlines [c - '!']; for (i = 0; i < NUM_ROWS; i++) { row = Outline [i]; while (PowerOf2 <= row) { PowerOf2 *= 2; NumColumns++; } } if (NumColumns > MaxNumColumns) NumColumns = MaxNumColumns; for (i = 0; i < NumColumns; i++) { position = MARGIN + NumChars*(MaxNumColumns + LETTER_SPACING) + (MaxNumColumns - NumColumns)/2 + i; if (position < width) { byte = position/8; for (j = 0; j < NUM_ROWS; j++) { row = Outline [j]; if (row & (1 << (NumColumns - i - 1) ) ) TextLine [byte] [j] += (1 << (7 - position%8) ); } } } } NumChars++; c = getchar (); } for (i = 0; i < NUM_ROWS; i++) { if (NumImageLines < height) { for (byte = 0; byte < (width + 7)/8; byte++) putchar (TextLine [byte] [i] ); } NumImageLines++; } for (i = 0; i < LINE_SPACING; i++) { if (NumImageLines < height) { for (byte = 0; byte < (width + 7)/8; byte++) putchar (0); } NumImageLines++; } if (MaxNumChars < NumChars) MaxNumChars = NumChars; NumTextLines++; if (c != EOF) c = getchar (); } while (NumImageLines < height) { for (byte = 0; byte < (width + 7)/8; byte++) putchar (0); NumImageLines++; } fprintf (stderr, "p4label37: Fits"); fprintf (stderr, " %d", 2*MARGIN + MaxNumChars*MaxNumColumns + LETTER_SPACING*(MaxNumChars - 1) ); fprintf (stderr, "x%d,", 2*MARGIN + (NumTextLines - 1)*LINE_SPACING + NumTextLines*NUM_ROWS); fprintf (stderr, " writing %dx%d.\n", width, height); } int main (int argc, char * * argv) { unsigned char (* TextLine) [NUM_ROWS]; int i, j, width, height, PowerOf2, row; char c; PowerOf2 = 1; MaxNumColumns = 0; for (i = 0; i < NumOutlines; i++) { for (j = 0; j < NUM_ROWS; j++) { row = Outlines [i] [j]; while (PowerOf2 <= row) { PowerOf2 *= 2; MaxNumColumns++; } } } if (argc == 1) { for (i = 0; i < NumUsageLines; i++) printf ("%s\n", UsageLines [i] ); printf ("Each character %dx%d,", MaxNumColumns, NUM_ROWS); printf (" letter spacing %d, line spacing %d,", LETTER_SPACING, LINE_SPACING); printf (" margin %d.\n", MARGIN); } else if (argc == 3) { if ( sscanf (argv [1], "%d%c", & width, & c) != 1 || sscanf (argv [2], "%d%c", & height, & c) != 1 || width <= 0 || height <= 0) { fprintf (stderr, "p4label3728: Improper \"%s\" \"%s\",", argv [1], argv [2] ); fprintf (stderr, " expecting width and height.\n"); } else { TextLine = malloc (NUM_ROWS*((width + 7)/8) ); if (TextLine == NULL) fprintf (stderr, "***p4label37: Not enough memory.\n"); else { WriteLabel (TextLine, width, height); free (TextLine); } } } else printf ("Usage: %s: (width) (height)\n", argv [0] ); return 0; }