001: package de.anomic.ymage;
002:
003: public class ymageToolPrint {
004:
005: private static long[] font = new long[] { 0x00000000000000L,
006: 0x00300C03000030L, 0x00CC3300000000L, 0x00CCFFCCCFFCCCL,
007: 0x02FFCC2FE0CFFEL, 0x00C3CF0FC3CF0CL, 0x02FCE02ECCE2ECL,
008: 0x00300C00000000L, 0x00030380C03803L, 0x0300B00C0B0000L,
009: 0x0000332BA03000L, 0x00000C0FC0C000L, 0x0000000302C0C0L,
010: 0x0000000FC00000L, 0x00000000000030L, 0x00030383838380L,
011: 0x00FCE3F33F2CFCL, 0x00303C0300C0FCL, 0x00FCE2CBEB83FFL,
012: 0x00FCE2C0EE2CFCL, 0x00BCBB3FF0300CL, 0x03FFC03FC02FFCL,
013: 0x00FCE03FEE2CFCL, 0x03FF0B8380C030L, 0x00FCE2EFCE2CFCL,
014: 0x00FCE2EFF02CFCL, 0x00000C0000C000L, 0x00000C0002C0C0L,
015: 0x000E0E0E00E00EL, 0x0000FFC00FFC00L, 0x02C02C02C2C2C0L,
016: 0x00FC0B03000030L, 0x02FEFCFBEE00FCL, 0x00B8BBB8BFFF03L,
017: 0x03F8CB3FEC2FFCL, 0x00FCE0300E00FCL, 0x03FCC2F03C2FFCL,
018: 0x03FFC03F0C03FFL, 0x03FFC03F0C0300L, 0x00FCE033FC2CFCL,
019: 0x0303C0FFFC0F03L, 0x03FF0C0300C3FFL, 0x03FF00C03E2CFCL,
020: 0x030BCB3F0CB30BL, 0x0300C0300C03FFL, 0x0303F3FBBC8F03L,
021: 0x0383F8FBBCBF0BL, 0x00FCE2F03E2CFCL, 0x03FCC2FFCC0300L,
022: 0x00FCE2F3BEB8FBL, 0x03FCC2FFCCB30BL, 0x00FEE00FC02EFCL,
023: 0x03FF0C0300C030L, 0x0303C0F03E2CFCL, 0x0303C0F8B3B030L,
024: 0x0303C0F23EECCCL, 0x038BBB8B8BBB8BL, 0x0303B38B80C030L,
025: 0x03FF0B8B8B83FFL, 0x003F0C0300C03FL, 0x0380B80B80B80BL,
026: 0x03F00C0300C3F0L, 0x00B8BBB8B00000L, 0x000000000003FFL,
027: 0x00E02C00000000L, 0x0000002FFE0CFFL, 0x0300C03FCC2FFCL,
028: 0x0000000FFE00FFL, 0x000300CFFE0CFFL, 0x0000BE32CEE0FFL,
029: 0x003C0E0FC0C030L, 0x00002F8E32EFFCL, 0x0300C03BEFAF83L,
030: 0x0030000300C030L, 0x0030000302C0E0L, 0x0300C032FFE32FL,
031: 0x00300C0300C030L, 0x0000000ECEEF33L, 0x0000000FCE2F03L,
032: 0x0000000FCE2CFCL, 0x0000FF30BFF300L, 0x00003FF833FC03L,
033: 0x00000B0380C030L, 0x0000000BCBAFACL, 0x00303F0300C030L,
034: 0x000000303E2CFCL, 0x00000038BBB8B8L, 0x000000333EECECL,
035: 0x0000000EC2E0ECL, 0x0000000EC2E030L, 0x0000000FF2E3FCL,
036: 0x000F0B8B80B80FL, 0x00300C0300C030L, 0x03C0B80B8B83C0L,
037: 0x0000B83BB0B800L, 0x03FFC0F03C0FFFL };
038:
039: private static void print(ymageMatrix matrix, int x, int y,
040: int angle, char letter) {
041: int index = (int) letter - 0x20;
042: if (index >= font.length)
043: return;
044: long character = font[index];
045: long row;
046: long c;
047: for (int i = 0; i < 5; i++) {
048: row = character & 0x3FFL;
049: character = character >> 10;
050: if (angle == 0) {
051: for (int j = 0; j < 5; j++) {
052: c = row & 3L;
053: if (c == 3)
054: matrix.plot(x + 5 - j, y, 100);
055: if (c == 2)
056: matrix.plot(x + 5 - j, y, 35);
057: row = row >> 2;
058: }
059: y--;
060: }
061: if (angle == 90) {
062: for (int j = 0; j < 5; j++) {
063: c = row & 3L;
064: if (c == 3)
065: matrix.plot(x, y - 5 + j, 100);
066: if (c == 2)
067: matrix.plot(x, y - 5 + j, 35);
068: row = row >> 2;
069: }
070: x--;
071: }
072: }
073: }
074:
075: public static void print(ymageMatrix matrix, int x, int y,
076: int angle, String message, int align) {
077: // align = -1 : left
078: // align = 1 : right
079: // align = 0 : center
080: int xx = 0, yy = 0;
081: if (angle == 0) {
082: xx = (align == -1) ? x : (align == 1) ? x - 6
083: * message.length() : x - 3 * message.length();
084: yy = y;
085: } else if (angle == 90) {
086: xx = x;
087: yy = (align == -1) ? y : (align == 1) ? y + 6
088: * message.length() : y + 3 * message.length();
089: }
090: for (int i = 0; i < message.length(); i++) {
091: print(matrix, xx, yy, angle, message.charAt(i));
092: if (angle == 0)
093: xx += 6;
094: else if (angle == 90)
095: yy -= 6;
096: }
097: }
098:
099: private static final int arcDist = 8;
100:
101: public static void arcPrint(ymageMatrix matrix, int cx, int cy,
102: int radius, int angle, String message) {
103: int x = cx
104: + (int) ((radius + 1) * Math.cos(Math.PI * angle / 180));
105: int y = cy
106: - (int) ((radius + 1) * Math.sin(Math.PI * angle / 180));
107: int yp = y + 3;
108: if ((angle > arcDist) && (angle < 180 - arcDist))
109: yp = y;
110: if ((angle > 180 + arcDist) && (angle < 360 - arcDist))
111: yp = y + 6;
112: if ((angle > (90 - arcDist)) && (angle < (90 + arcDist)))
113: yp -= 6;
114: if ((angle > (270 - arcDist)) && (angle < (270 + arcDist)))
115: yp += 6;
116: int xp = x - 3 * message.length();
117: if ((angle > (90 + arcDist)) && (angle < (270 - arcDist)))
118: xp = x - 6 * message.length();
119: if ((angle < (90 - arcDist)) || (angle > (270 + arcDist)))
120: xp = x;
121: print(matrix, xp, yp, 0, message, -1);
122: }
123:
124: }
|