|
49 | 49 | [sub, sup] = sub.split("^");
|
50 | 50 | }
|
51 | 51 | let vert = Math.max(sub.length, sup.length, main.length) >= 3 && sub.length > 0;
|
52 |
| - let fontSize = 18; |
53 |
| - while (fontSize > 6) { |
54 |
| - let bigFont = fontSize + 'pt serif'; |
55 |
| - let smallFont = (fontSize * 0.75) + 'pt serif'; |
| 52 | + let bigFontSize = 18; |
| 53 | + let smallFontSize = 18 * 0.75; |
| 54 | + while (bigFontSize > 6) { |
| 55 | + let bigFont = bigFontSize + 'pt serif'; |
| 56 | + let smallFont = (smallFontSize * 0.75) + 'pt serif'; |
56 | 57 | ctx.font = bigFont;
|
57 | 58 | let w_main = ctx.measureText(main).width;
|
58 | 59 | ctx.font = smallFont;
|
59 | 60 | let w_sub = ctx.measureText(sub).width;
|
60 | 61 | let w_sup = ctx.measureText(sup).width;
|
61 | 62 | let w_subsup = Math.max(ctx.measureText(sub).width, ctx.measureText(sup).width);
|
62 |
| - let w_total = vert ? Math.max(w_main, w_subsup) : w_main + w_subsup; |
63 |
| - if (w_total < 32) { |
64 |
| - if (vert) { |
65 |
| - let dy = 0; |
66 |
| - if (w_sub < w_main * 0.8) { |
67 |
| - smallFont = bigFont; |
68 |
| - dy = -2; |
69 |
| - } |
70 |
| - ctx.fillStyle = stroke; |
71 |
| - ctx.font = bigFont; |
72 |
| - ctx.textBaseline = 'middle' |
73 |
| - ctx.fillText(main, x * 32 + 16 - w_main / 2, y * 32 + 11); |
74 |
| - ctx.font = smallFont; |
75 |
| - ctx.textBaseline = 'bottom'; |
76 |
| - ctx.fillText(sub, x * 32 + 16 - w_sub / 2, y * 32 + 34 + dy); |
77 |
| - ctx.textBaseline = 'hanging'; |
78 |
| - ctx.fillText(sup, x * 32 + 16 - w_sup / 2, y * 32); |
79 |
| - } else { |
80 |
| - ctx.fillStyle = stroke; |
81 |
| - ctx.font = bigFont; |
82 |
| - ctx.textBaseline = 'middle' |
83 |
| - ctx.fillText(main, x * 32 + 16 - w_main / 2 - w_subsup / 2, y * 32 + 18); |
84 |
| - ctx.font = smallFont; |
85 |
| - ctx.textBaseline = 'bottom'; |
86 |
| - ctx.fillText(sub, x * 32 + 16 + w_main / 2 - w_sub / 2, y * 32 + (sup !== "" ? 34 : 32)); |
87 |
| - ctx.textBaseline = 'hanging'; |
88 |
| - ctx.fillText(sup, x * 32 + 16 + w_main / 2 - w_sup / 2, y * 32); |
| 63 | + if (vert) { |
| 64 | + if (w_main > 32) { |
| 65 | + bigFontSize -= 1; |
| 66 | + smallFontSize -= 0.75; |
| 67 | + continue; |
| 68 | + } else if (w_subsup > 32) { |
| 69 | + smallFontSize -= 0.75; |
| 70 | + continue; |
89 | 71 | }
|
90 |
| - break; |
| 72 | + } else { |
| 73 | + if (w_main + w_subsup > 32) { |
| 74 | + bigFontSize -= 1; |
| 75 | + smallFontSize -= 0.75; |
| 76 | + continue; |
| 77 | + } |
| 78 | + } |
| 79 | + if (vert) { |
| 80 | + let dy = 0; |
| 81 | + if (w_sub < w_main * 0.8) { |
| 82 | + smallFont = bigFont; |
| 83 | + dy = -2; |
| 84 | + } |
| 85 | + ctx.fillStyle = stroke; |
| 86 | + ctx.font = bigFont; |
| 87 | + ctx.textBaseline = 'middle' |
| 88 | + ctx.fillText(main, x * 32 + 16 - w_main / 2, y * 32 + 11); |
| 89 | + ctx.font = smallFont; |
| 90 | + ctx.textBaseline = 'bottom'; |
| 91 | + ctx.fillText(sub, x * 32 + 16 - w_sub / 2, y * 32 + 34 + dy); |
| 92 | + ctx.textBaseline = 'hanging'; |
| 93 | + ctx.fillText(sup, x * 32 + 16 - w_sup / 2, y * 32); |
| 94 | + } else { |
| 95 | + ctx.fillStyle = stroke; |
| 96 | + ctx.font = bigFont; |
| 97 | + ctx.textBaseline = 'middle' |
| 98 | + ctx.fillText(main, x * 32 + 16 - w_main / 2 - w_subsup / 2, y * 32 + 18); |
| 99 | + ctx.font = smallFont; |
| 100 | + ctx.textBaseline = 'bottom'; |
| 101 | + ctx.fillText(sub, x * 32 + 16 + w_main / 2 - w_sub / 2, y * 32 + (sup !== "" ? 34 : 32)); |
| 102 | + ctx.textBaseline = 'hanging'; |
| 103 | + ctx.fillText(sup, x * 32 + 16 + w_main / 2 - w_sup / 2, y * 32); |
91 | 104 | }
|
92 |
| - fontSize--; |
| 105 | + break; |
93 | 106 | }
|
94 | 107 | }
|
95 | 108 |
|
|
197 | 210 | drawRect(ctx, "sweep_X", "#FEE", "#000", n++);
|
198 | 211 | drawRect(ctx, "sweep_Y", "#EFE", "#000", n++);
|
199 | 212 | drawRect(ctx, "sweep_Z", "#EEF", "#000", n++);
|
| 213 | + n += 2; |
| 214 | + drawRect(ctx, "I_ERR", "#FFF", "#000", n++); |
200 | 215 |
|
201 | 216 | n = 128 + 16;
|
202 | 217 | drawRect(ctx, "I", "#FFF", "#000", n++);
|
|
223 | 238 | drawRect(ctx, "SPP_X†", "#F44", "#000", n++);
|
224 | 239 | drawRect(ctx, "SPP_Y†", "#4F4", "#000", n++);
|
225 | 240 | drawRect(ctx, "SPP_Z†", "#44F", "#000", n++);
|
| 241 | + drawRect(ctx, "C_NXYZ", "#FFA", "#000", n++); |
| 242 | + drawRect(ctx, "C_XNYZ", "#FFA", "#000", n++); |
| 243 | + drawRect(ctx, "C_XYNZ", "#FFA", "#000", n++); |
| 244 | + drawRect(ctx, "C_NZYX", "#AFF", "#000", n++); |
| 245 | + drawRect(ctx, "C_ZNYX", "#AFF", "#000", n++); |
| 246 | + drawRect(ctx, "C_ZYNX", "#AFF", "#000", n++); |
| 247 | + drawRect(ctx, "H_NXY", "#FAA", "#000", n++); |
| 248 | + drawRect(ctx, "H_NXZ", "#AFA", "#000", n++); |
| 249 | + drawRect(ctx, "H_NYZ", "#AAF", "#000", n++); |
| 250 | + drawRect(ctx, "II", "#FFF", "#000", n++); |
226 | 251 |
|
227 | 252 | n = 128 + 48;
|
228 | 253 | drawCpp(ctx, 'I', 'X', n++);
|
|
240 | 265 | drawCpp(ctx, 'Z', 'X', n++);
|
241 | 266 | drawCpp(ctx, 'Z', 'Y', n++);
|
242 | 267 | drawCpp(ctx, 'Z', 'Z', n++);
|
| 268 | + drawRect(ctx, "II_ERR", "#FFF", "#000", n++); |
243 | 269 | }
|
244 | 270 |
|
245 | 271 | draw(document.getElementById('cv').getContext('2d'))
|
|
0 commit comments