omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / aienux / allen / font.om
| 1 | note Handwritten bounded Allen stroke rasterizer. Legacy C is an external oracle only. |
| 2 | global Af ulong 6 |
| 3 | global Ab long 4 |
| 4 | global Ag long 640 |
| 5 | global Alpha uchar 65536 |
| 6 | global Asin long 91 |
| 7 | global Afpos ulong 2 |
| 8 | global Apen long 2 |
| 9 | global Arc long 6 |
| 10 | fn afsqrt value ulong to ulong |
| 11 | r = ulong 0 |
| 12 | bit = shl ulong 1 62 |
| 13 | while gt bit value |
| 14 | bit = shr bit 2 |
| 15 | end |
| 16 | while ne bit 0 |
| 17 | if ge value add r bit |
| 18 | value = sub value add r bit |
| 19 | r = add shr r 1 bit |
| 20 | else |
| 21 | r = shr r 1 |
| 22 | end |
| 23 | bit = shr bit 2 |
| 24 | end |
| 25 | ret r |
| 26 | end |
| 27 | fn afsin deg long to long |
| 28 | a = rem deg 360 |
| 29 | if lt a 0 |
| 30 | a = add a 360 |
| 31 | end |
| 32 | if le a 90 |
| 33 | ret get Asin ulong a |
| 34 | end |
| 35 | if le a 180 |
| 36 | ret get Asin ulong sub long 180 a |
| 37 | end |
| 38 | if le a 270 |
| 39 | ret neg get Asin ulong sub a 180 |
| 40 | end |
| 41 | ret neg get Asin ulong sub long 360 a |
| 42 | end |
| 43 | fn afcos deg long to long |
| 44 | ret afsin add rem deg 360 90 |
| 45 | end |
| 46 | fn afinit cap ulong wt ulong to bool |
| 47 | if or eq cap 0 gt cap 64 |
| 48 | ret false |
| 49 | end |
| 50 | if or eq wt 0 gt wt 2500 |
| 51 | ret false |
| 52 | end |
| 53 | for i ulong 6 |
| 54 | put Af i 0 |
| 55 | end |
| 56 | put Af 0 div mul cap 256 20 |
| 57 | put Af 1 div mul wt get Af 0 1000 |
| 58 | v = long 0 |
| 59 | slot = ulong 0 |
| 60 | for i ulong len Afsines |
| 61 | c = get Afsines i |
| 62 | if eq c 32 |
| 63 | put Asin slot v |
| 64 | slot = add slot 1 |
| 65 | v = 0 |
| 66 | else |
| 67 | v = add mul v 10 sub long c 48 |
| 68 | end |
| 69 | end |
| 70 | ret eq slot 91 |
| 71 | end |
| 72 | fn afpick c uchar to bool |
| 73 | if or lt c 32 gt c 126 |
| 74 | c = 63 |
| 75 | end |
| 76 | wanted = sub ulong c 32 |
| 77 | slot = ulong 0 |
| 78 | startat = ulong 0 |
| 79 | for i ulong len Afdata |
| 80 | if eq get Afdata i 124 |
| 81 | if eq slot wanted |
| 82 | put Afpos 0 startat |
| 83 | put Afpos 1 i |
| 84 | ret true |
| 85 | end |
| 86 | slot = add slot 1 |
| 87 | startat = add i 1 |
| 88 | end |
| 89 | end |
| 90 | ret false |
| 91 | end |
| 92 | fn afnum to long |
| 93 | p = get Afpos 0 |
| 94 | minus = false |
| 95 | if eq get Afdata p 45 |
| 96 | minus = true |
| 97 | p = add p 1 |
| 98 | end |
| 99 | v = long 0 |
| 100 | go = true |
| 101 | while and lt p get Afpos 1 go |
| 102 | c = get Afdata p |
| 103 | if and ge c 48 le c 57 |
| 104 | v = add mul v 10 sub long c 48 |
| 105 | p = add p 1 |
| 106 | else |
| 107 | go = false |
| 108 | end |
| 109 | end |
| 110 | if lt p get Afpos 1 |
| 111 | if eq get Afdata p 44 |
| 112 | p = add p 1 |
| 113 | end |
| 114 | end |
| 115 | put Afpos 0 p |
| 116 | if minus |
| 117 | ret neg v |
| 118 | end |
| 119 | ret v |
| 120 | end |
| 121 | fn afseg nx long ny long to bool |
| 122 | n = get Af 2 |
| 123 | if ge n 160 |
| 124 | ret false |
| 125 | end |
| 126 | at = mul n 4 |
| 127 | put Ag at get Apen 0 |
| 128 | put Ag add at 1 get Apen 1 |
| 129 | put Ag add at 2 nx |
| 130 | put Ag add at 3 ny |
| 131 | put Apen 0 nx |
| 132 | put Apen 1 ny |
| 133 | put Af 2 add n 1 |
| 134 | ret true |
| 135 | end |
| 136 | fn afpoint a long first bool to bool |
| 137 | s = long get Af 0 |
| 138 | x = mul get Arc 0 s |
| 139 | x = add x div mul mul get Arc 2 s afcos a 16384 |
| 140 | y = mul sub get Arc 1 20 s |
| 141 | y = add y div mul mul get Arc 3 s afsin a 16384 |
| 142 | if first |
| 143 | put Apen 0 x |
| 144 | put Apen 1 y |
| 145 | ret true |
| 146 | end |
| 147 | ret afseg x y |
| 148 | end |
| 149 | fn afarc to bool |
| 150 | for i ulong 6 |
| 151 | put Arc i afnum |
| 152 | end |
| 153 | span = sub get Arc 5 get Arc 4 |
| 154 | if lt span 0 |
| 155 | span = neg span |
| 156 | end |
| 157 | steps = div span 9 |
| 158 | if lt steps 2 |
| 159 | steps = 2 |
| 160 | end |
| 161 | for k ulong ulong add steps 1 |
| 162 | a = sub get Arc 5 get Arc 4 |
| 163 | a = add get Arc 4 div mul a long k steps |
| 164 | if not afpoint a eq k 0 |
| 165 | ret false |
| 166 | end |
| 167 | end |
| 168 | ret true |
| 169 | end |
| 170 | fn afcmd cmd uchar to bool |
| 171 | if eq cmd 32 |
| 172 | ret true |
| 173 | end |
| 174 | if eq cmd 119 |
| 175 | put Af 5 mul ulong afnum get Af 0 |
| 176 | ret true |
| 177 | end |
| 178 | if eq cmd 65 |
| 179 | ret afarc |
| 180 | end |
| 181 | x = mul afnum long get Af 0 |
| 182 | y = mul sub afnum 20 long get Af 0 |
| 183 | if or eq cmd 77 eq cmd 68 |
| 184 | put Apen 0 x |
| 185 | put Apen 1 y |
| 186 | end |
| 187 | if eq cmd 77 |
| 188 | ret true |
| 189 | end |
| 190 | if or eq cmd 76 eq cmd 68 |
| 191 | ret afseg x y |
| 192 | end |
| 193 | ret false |
| 194 | end |
| 195 | fn affloor value long to long |
| 196 | if ge value 0 |
| 197 | ret div value 256 |
| 198 | end |
| 199 | ret neg div add neg value 255 256 |
| 200 | end |
| 201 | fn afbound x long y long to void |
| 202 | if lt x get Ab 0 |
| 203 | put Ab 0 x |
| 204 | end |
| 205 | if lt y get Ab 1 |
| 206 | put Ab 1 y |
| 207 | end |
| 208 | if gt x get Ab 2 |
| 209 | put Ab 2 x |
| 210 | end |
| 211 | if gt y get Ab 3 |
| 212 | put Ab 3 y |
| 213 | end |
| 214 | end |
| 215 | fn afbox to bool |
| 216 | put Ab 0 get Ag 0 |
| 217 | put Ab 2 get Ag 0 |
| 218 | put Ab 1 get Ag 1 |
| 219 | put Ab 3 get Ag 1 |
| 220 | for i ulong get Af 2 |
| 221 | at = mul i 4 |
| 222 | afbound get Ag at get Ag add at 1 |
| 223 | afbound get Ag add at 2 get Ag add at 3 |
| 224 | end |
| 225 | pad = add long get Af 1 256 |
| 226 | x0 = affloor sub get Ab 0 pad |
| 227 | y0 = affloor sub get Ab 1 pad |
| 228 | x1 = add affloor add get Ab 2 pad 1 |
| 229 | y1 = add affloor add get Ab 3 pad 1 |
| 230 | put Ab 0 x0 |
| 231 | put Ab 1 y0 |
| 232 | put Af 3 ulong sub x1 x0 |
| 233 | put Af 4 ulong sub y1 y0 |
| 234 | ret le mul get Af 3 get Af 4 len Alpha |
| 235 | end |
| 236 | fn afproj qx long qy long dx long dy long to ulong |
| 237 | len2 = add mul dx dx mul dy dy |
| 238 | ex = qx |
| 239 | ey = qy |
| 240 | if ne len2 0 |
| 241 | t = add mul qx dx mul qy dy |
| 242 | if gt t 0 |
| 243 | if ge t len2 |
| 244 | ex = sub qx dx |
| 245 | ey = sub qy dy |
| 246 | else |
| 247 | ex = sub qx div mul dx t len2 |
| 248 | ey = sub qy div mul dy t len2 |
| 249 | end |
| 250 | end |
| 251 | end |
| 252 | ret ulong add mul ex ex mul ey ey |
| 253 | end |
| 254 | fn afdist slot ulong px long py long to ulong |
| 255 | at = mul slot 4 |
| 256 | dx = sub get Ag add at 2 get Ag at |
| 257 | dy = sub get Ag add at 3 get Ag add at 1 |
| 258 | qx = sub px get Ag at |
| 259 | qy = sub py get Ag add at 1 |
| 260 | ret afproj qx qy dx dy |
| 261 | end |
| 262 | fn afalpha px long py long to uchar |
| 263 | best = ulong 18446744073709551615 |
| 264 | for i ulong get Af 2 |
| 265 | d2 = afdist i px py |
| 266 | if lt d2 best |
| 267 | best = d2 |
| 268 | end |
| 269 | end |
| 270 | d = long afsqrt best |
| 271 | cov = sub add long get Af 1 128 d |
| 272 | if le cov 0 |
| 273 | ret 0 |
| 274 | end |
| 275 | if ge cov 256 |
| 276 | ret 255 |
| 277 | end |
| 278 | ret uchar div mul cov 255 256 |
| 279 | end |
| 280 | fn afrow y ulong to void |
| 281 | py = add mul add get Ab 1 long y 256 128 |
| 282 | for x ulong get Af 3 |
| 283 | px = add mul add get Ab 0 long x 256 128 |
| 284 | at = add mul y get Af 3 x |
| 285 | put Alpha at afalpha px py |
| 286 | end |
| 287 | end |
| 288 | fn afpaint to void |
| 289 | for y ulong get Af 4 |
| 290 | afrow y |
| 291 | end |
| 292 | end |
| 293 | fn afglyph c uchar to bool |
| 294 | if eq get Af 0 0 |
| 295 | ret false |
| 296 | end |
| 297 | if not afpick c |
| 298 | ret false |
| 299 | end |
| 300 | for i ulong 65536 |
| 301 | put Alpha i 0 |
| 302 | end |
| 303 | put Af 2 0 |
| 304 | put Af 3 0 |
| 305 | put Af 4 1 |
| 306 | put Af 5 0 |
| 307 | put Ab 0 0 |
| 308 | put Ab 1 0 |
| 309 | put Apen 0 0 |
| 310 | put Apen 1 0 |
| 311 | while lt get Afpos 0 get Afpos 1 |
| 312 | cmd = get Afdata get Afpos 0 |
| 313 | put Afpos 0 add get Afpos 0 1 |
| 314 | if not afcmd cmd |
| 315 | ret false |
| 316 | end |
| 317 | end |
| 318 | if eq get Af 2 0 |
| 319 | ret true |
| 320 | end |
| 321 | if not afbox |
| 322 | ret false |
| 323 | end |
| 324 | afpaint |
| 325 | ret true |
| 326 | end |