opcode.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. // Copyright ©2021 The star-tex Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE-STAR-TEX file.
  4. package dvi
  5. import "fmt"
  6. const (
  7. dviEOF = 223
  8. dviVersion = 2
  9. )
  10. type opCode uint8
  11. const (
  12. opSetChar000 opCode = iota // typeset a character and move right
  13. opSetChar001 // typeset a character and move right
  14. opSetChar002 // typeset a character and move right
  15. opSetChar003 // typeset a character and move right
  16. opSetChar004 // typeset a character and move right
  17. opSetChar005 // typeset a character and move right
  18. opSetChar006 // typeset a character and move right
  19. opSetChar007 // typeset a character and move right
  20. opSetChar008 // typeset a character and move right
  21. opSetChar009 // typeset a character and move right
  22. opSetChar010 // typeset a character and move right
  23. opSetChar011 // typeset a character and move right
  24. opSetChar012 // typeset a character and move right
  25. opSetChar013 // typeset a character and move right
  26. opSetChar014 // typeset a character and move right
  27. opSetChar015 // typeset a character and move right
  28. opSetChar016 // typeset a character and move right
  29. opSetChar017 // typeset a character and move right
  30. opSetChar018 // typeset a character and move right
  31. opSetChar019 // typeset a character and move right
  32. opSetChar020 // typeset a character and move right
  33. opSetChar021 // typeset a character and move right
  34. opSetChar022 // typeset a character and move right
  35. opSetChar023 // typeset a character and move right
  36. opSetChar024 // typeset a character and move right
  37. opSetChar025 // typeset a character and move right
  38. opSetChar026 // typeset a character and move right
  39. opSetChar027 // typeset a character and move right
  40. opSetChar028 // typeset a character and move right
  41. opSetChar029 // typeset a character and move right
  42. opSetChar030 // typeset a character and move right
  43. opSetChar031 // typeset a character and move right
  44. opSetChar032 // typeset a character and move right
  45. opSetChar033 // typeset a character and move right
  46. opSetChar034 // typeset a character and move right
  47. opSetChar035 // typeset a character and move right
  48. opSetChar036 // typeset a character and move right
  49. opSetChar037 // typeset a character and move right
  50. opSetChar038 // typeset a character and move right
  51. opSetChar039 // typeset a character and move right
  52. opSetChar040 // typeset a character and move right
  53. opSetChar041 // typeset a character and move right
  54. opSetChar042 // typeset a character and move right
  55. opSetChar043 // typeset a character and move right
  56. opSetChar044 // typeset a character and move right
  57. opSetChar045 // typeset a character and move right
  58. opSetChar046 // typeset a character and move right
  59. opSetChar047 // typeset a character and move right
  60. opSetChar048 // typeset a character and move right
  61. opSetChar049 // typeset a character and move right
  62. opSetChar050 // typeset a character and move right
  63. opSetChar051 // typeset a character and move right
  64. opSetChar052 // typeset a character and move right
  65. opSetChar053 // typeset a character and move right
  66. opSetChar054 // typeset a character and move right
  67. opSetChar055 // typeset a character and move right
  68. opSetChar056 // typeset a character and move right
  69. opSetChar057 // typeset a character and move right
  70. opSetChar058 // typeset a character and move right
  71. opSetChar059 // typeset a character and move right
  72. opSetChar060 // typeset a character and move right
  73. opSetChar061 // typeset a character and move right
  74. opSetChar062 // typeset a character and move right
  75. opSetChar063 // typeset a character and move right
  76. opSetChar064 // typeset a character and move right
  77. opSetChar065 // typeset a character and move right
  78. opSetChar066 // typeset a character and move right
  79. opSetChar067 // typeset a character and move right
  80. opSetChar068 // typeset a character and move right
  81. opSetChar069 // typeset a character and move right
  82. opSetChar070 // typeset a character and move right
  83. opSetChar071 // typeset a character and move right
  84. opSetChar072 // typeset a character and move right
  85. opSetChar073 // typeset a character and move right
  86. opSetChar074 // typeset a character and move right
  87. opSetChar075 // typeset a character and move right
  88. opSetChar076 // typeset a character and move right
  89. opSetChar077 // typeset a character and move right
  90. opSetChar078 // typeset a character and move right
  91. opSetChar079 // typeset a character and move right
  92. opSetChar080 // typeset a character and move right
  93. opSetChar081 // typeset a character and move right
  94. opSetChar082 // typeset a character and move right
  95. opSetChar083 // typeset a character and move right
  96. opSetChar084 // typeset a character and move right
  97. opSetChar085 // typeset a character and move right
  98. opSetChar086 // typeset a character and move right
  99. opSetChar087 // typeset a character and move right
  100. opSetChar088 // typeset a character and move right
  101. opSetChar089 // typeset a character and move right
  102. opSetChar090 // typeset a character and move right
  103. opSetChar091 // typeset a character and move right
  104. opSetChar092 // typeset a character and move right
  105. opSetChar093 // typeset a character and move right
  106. opSetChar094 // typeset a character and move right
  107. opSetChar095 // typeset a character and move right
  108. opSetChar096 // typeset a character and move right
  109. opSetChar097 // typeset a character and move right
  110. opSetChar098 // typeset a character and move right
  111. opSetChar099 // typeset a character and move right
  112. opSetChar100 // typeset a character and move right
  113. opSetChar101 // typeset a character and move right
  114. opSetChar102 // typeset a character and move right
  115. opSetChar103 // typeset a character and move right
  116. opSetChar104 // typeset a character and move right
  117. opSetChar105 // typeset a character and move right
  118. opSetChar106 // typeset a character and move right
  119. opSetChar107 // typeset a character and move right
  120. opSetChar108 // typeset a character and move right
  121. opSetChar109 // typeset a character and move right
  122. opSetChar110 // typeset a character and move right
  123. opSetChar111 // typeset a character and move right
  124. opSetChar112 // typeset a character and move right
  125. opSetChar113 // typeset a character and move right
  126. opSetChar114 // typeset a character and move right
  127. opSetChar115 // typeset a character and move right
  128. opSetChar116 // typeset a character and move right
  129. opSetChar117 // typeset a character and move right
  130. opSetChar118 // typeset a character and move right
  131. opSetChar119 // typeset a character and move right
  132. opSetChar120 // typeset a character and move right
  133. opSetChar121 // typeset a character and move right
  134. opSetChar122 // typeset a character and move right
  135. opSetChar123 // typeset a character and move right
  136. opSetChar124 // typeset a character and move right
  137. opSetChar125 // typeset a character and move right
  138. opSetChar126 // typeset a character and move right
  139. opSetChar127 // typeset a character and move right
  140. opSet1 // typeset a character and move right
  141. opSet2 // typeset a character and move right
  142. opSet3 // typeset a character and move right
  143. opSet4 // typeset a character and move right
  144. opSetRule // typeset a rule and move right
  145. opPut1 // typeset a character
  146. opPut2 // typeset a character
  147. opPut3 // typeset a character
  148. opPut4 // typeset a character
  149. opPutRule // typeset a rule
  150. opNOP // no operation
  151. opBOP // beginning of page
  152. opEOP // ending of page
  153. opPush // save the current positions
  154. opPop // restore previous positions
  155. opRight1 // move right
  156. opRight2 // move right
  157. opRight3 // move right
  158. opRight4 // move right
  159. opW0 // move right by w
  160. opW1 // move right and set w
  161. opW2 // move right and set w
  162. opW3 // move right and set w
  163. opW4 // move right and set w
  164. opX0 // move right by x
  165. opX1 // move right and set x
  166. opX2 // move right and set x
  167. opX3 // move right and set x
  168. opX4 // move right and set x
  169. opDown1 // move down
  170. opDown2 // move down
  171. opDown3 // move down
  172. opDown4 // move down
  173. opY0 // move down by y
  174. opY1 // move down and set y
  175. opY2 // move down and set y
  176. opY3 // move down and set y
  177. opY4 // move down and set y
  178. opZ0 // move down by z
  179. opZ1 // move down and set z
  180. opZ2 // move down and set z
  181. opZ3 // move down and set z
  182. opZ4 // move down and set z
  183. opFntNum00 // set current font to i
  184. opFntNum01 // set current font to i
  185. opFntNum02 // set current font to i
  186. opFntNum03 // set current font to i
  187. opFntNum04 // set current font to i
  188. opFntNum05 // set current font to i
  189. opFntNum06 // set current font to i
  190. opFntNum07 // set current font to i
  191. opFntNum08 // set current font to i
  192. opFntNum09 // set current font to i
  193. opFntNum10 // set current font to i
  194. opFntNum11 // set current font to i
  195. opFntNum12 // set current font to i
  196. opFntNum13 // set current font to i
  197. opFntNum14 // set current font to i
  198. opFntNum15 // set current font to i
  199. opFntNum16 // set current font to i
  200. opFntNum17 // set current font to i
  201. opFntNum18 // set current font to i
  202. opFntNum19 // set current font to i
  203. opFntNum20 // set current font to i
  204. opFntNum21 // set current font to i
  205. opFntNum22 // set current font to i
  206. opFntNum23 // set current font to i
  207. opFntNum24 // set current font to i
  208. opFntNum25 // set current font to i
  209. opFntNum26 // set current font to i
  210. opFntNum27 // set current font to i
  211. opFntNum28 // set current font to i
  212. opFntNum29 // set current font to i
  213. opFntNum30 // set current font to i
  214. opFntNum31 // set current font to i
  215. opFntNum32 // set current font to i
  216. opFntNum33 // set current font to i
  217. opFntNum34 // set current font to i
  218. opFntNum35 // set current font to i
  219. opFntNum36 // set current font to i
  220. opFntNum37 // set current font to i
  221. opFntNum38 // set current font to i
  222. opFntNum39 // set current font to i
  223. opFntNum40 // set current font to i
  224. opFntNum41 // set current font to i
  225. opFntNum42 // set current font to i
  226. opFntNum43 // set current font to i
  227. opFntNum44 // set current font to i
  228. opFntNum45 // set current font to i
  229. opFntNum46 // set current font to i
  230. opFntNum47 // set current font to i
  231. opFntNum48 // set current font to i
  232. opFntNum49 // set current font to i
  233. opFntNum50 // set current font to i
  234. opFntNum51 // set current font to i
  235. opFntNum52 // set current font to i
  236. opFntNum53 // set current font to i
  237. opFntNum54 // set current font to i
  238. opFntNum55 // set current font to i
  239. opFntNum56 // set current font to i
  240. opFntNum57 // set current font to i
  241. opFntNum58 // set current font to i
  242. opFntNum59 // set current font to i
  243. opFntNum60 // set current font to i
  244. opFntNum61 // set current font to i
  245. opFntNum62 // set current font to i
  246. opFntNum63 // set current font to i
  247. opFnt1 // set current font
  248. opFnt2 // set current font
  249. opFnt3 // set current font
  250. opFnt4 // set current font
  251. opXXX1 // extension to DVI primitives
  252. opXXX2 // extension to DVI primitives
  253. opXXX3 // extension to DVI primitives
  254. opXXX4 // extension to DVI primitives
  255. opFntDef1 // define the meaning of a font number
  256. opFntDef2 // define the meaning of a font number
  257. opFntDef3 // define the meaning of a font number
  258. opFntDef4 // define the meaning of a font number
  259. opPre // preambule
  260. opPost // postamble beginning
  261. opPostPost // postamble ending
  262. )
  263. func (op opCode) cmd() Cmd {
  264. switch op {
  265. case opSetChar000, opSetChar001, opSetChar002, opSetChar003, opSetChar004,
  266. opSetChar005, opSetChar006, opSetChar007, opSetChar008, opSetChar009,
  267. opSetChar010, opSetChar011, opSetChar012, opSetChar013, opSetChar014,
  268. opSetChar015, opSetChar016, opSetChar017, opSetChar018, opSetChar019,
  269. opSetChar020, opSetChar021, opSetChar022, opSetChar023, opSetChar024,
  270. opSetChar025, opSetChar026, opSetChar027, opSetChar028, opSetChar029,
  271. opSetChar030, opSetChar031, opSetChar032, opSetChar033, opSetChar034,
  272. opSetChar035, opSetChar036, opSetChar037, opSetChar038, opSetChar039,
  273. opSetChar040, opSetChar041, opSetChar042, opSetChar043, opSetChar044,
  274. opSetChar045, opSetChar046, opSetChar047, opSetChar048, opSetChar049,
  275. opSetChar050, opSetChar051, opSetChar052, opSetChar053, opSetChar054,
  276. opSetChar055, opSetChar056, opSetChar057, opSetChar058, opSetChar059,
  277. opSetChar060, opSetChar061, opSetChar062, opSetChar063, opSetChar064,
  278. opSetChar065, opSetChar066, opSetChar067, opSetChar068, opSetChar069,
  279. opSetChar070, opSetChar071, opSetChar072, opSetChar073, opSetChar074,
  280. opSetChar075, opSetChar076, opSetChar077, opSetChar078, opSetChar079,
  281. opSetChar080, opSetChar081, opSetChar082, opSetChar083, opSetChar084,
  282. opSetChar085, opSetChar086, opSetChar087, opSetChar088, opSetChar089,
  283. opSetChar090, opSetChar091, opSetChar092, opSetChar093, opSetChar094,
  284. opSetChar095, opSetChar096, opSetChar097, opSetChar098, opSetChar099,
  285. opSetChar100, opSetChar101, opSetChar102, opSetChar103, opSetChar104,
  286. opSetChar105, opSetChar106, opSetChar107, opSetChar108, opSetChar109,
  287. opSetChar110, opSetChar111, opSetChar112, opSetChar113, opSetChar114,
  288. opSetChar115, opSetChar116, opSetChar117, opSetChar118, opSetChar119,
  289. opSetChar120, opSetChar121, opSetChar122, opSetChar123, opSetChar124,
  290. opSetChar125, opSetChar126, opSetChar127:
  291. return &CmdSetChar{}
  292. case opSet1:
  293. return &CmdSet1{}
  294. case opSet2:
  295. return &CmdSet2{}
  296. case opSet3:
  297. return &CmdSet3{}
  298. case opSet4:
  299. return &CmdSet4{}
  300. case opSetRule:
  301. return &CmdSetRule{}
  302. case opPut1:
  303. return &CmdPut1{}
  304. case opPut2:
  305. return &CmdPut2{}
  306. case opPut3:
  307. return &CmdPut3{}
  308. case opPut4:
  309. return &CmdPut4{}
  310. case opPutRule:
  311. return &CmdPutRule{}
  312. case opNOP:
  313. return &CmdNOP{}
  314. case opBOP:
  315. return &CmdBOP{}
  316. case opEOP:
  317. return &CmdEOP{}
  318. case opPush:
  319. return &CmdPush{}
  320. case opPop:
  321. return &CmdPop{}
  322. case opRight1:
  323. return &CmdRight1{}
  324. case opRight2:
  325. return &CmdRight2{}
  326. case opRight3:
  327. return &CmdRight3{}
  328. case opRight4:
  329. return &CmdRight4{}
  330. case opW0:
  331. return &CmdW0{}
  332. case opW1:
  333. return &CmdW1{}
  334. case opW2:
  335. return &CmdW2{}
  336. case opW3:
  337. return &CmdW3{}
  338. case opW4:
  339. return &CmdW4{}
  340. case opX0:
  341. return &CmdX0{}
  342. case opX1:
  343. return &CmdX1{}
  344. case opX2:
  345. return &CmdX2{}
  346. case opX3:
  347. return &CmdX3{}
  348. case opX4:
  349. return &CmdX4{}
  350. case opDown1:
  351. return &CmdDown1{}
  352. case opDown2:
  353. return &CmdDown2{}
  354. case opDown3:
  355. return &CmdDown3{}
  356. case opDown4:
  357. return &CmdDown4{}
  358. case opY0:
  359. return &CmdY0{}
  360. case opY1:
  361. return &CmdY1{}
  362. case opY2:
  363. return &CmdY2{}
  364. case opY3:
  365. return &CmdY3{}
  366. case opY4:
  367. return &CmdY4{}
  368. case opZ0:
  369. return &CmdZ0{}
  370. case opZ1:
  371. return &CmdZ1{}
  372. case opZ2:
  373. return &CmdZ2{}
  374. case opZ3:
  375. return &CmdZ3{}
  376. case opZ4:
  377. return &CmdZ4{}
  378. case opFntNum00, opFntNum01, opFntNum02, opFntNum03, opFntNum04,
  379. opFntNum05, opFntNum06, opFntNum07, opFntNum08, opFntNum09,
  380. opFntNum10, opFntNum11, opFntNum12, opFntNum13, opFntNum14,
  381. opFntNum15, opFntNum16, opFntNum17, opFntNum18, opFntNum19,
  382. opFntNum20, opFntNum21, opFntNum22, opFntNum23, opFntNum24,
  383. opFntNum25, opFntNum26, opFntNum27, opFntNum28, opFntNum29,
  384. opFntNum30, opFntNum31, opFntNum32, opFntNum33, opFntNum34,
  385. opFntNum35, opFntNum36, opFntNum37, opFntNum38, opFntNum39,
  386. opFntNum40, opFntNum41, opFntNum42, opFntNum43, opFntNum44,
  387. opFntNum45, opFntNum46, opFntNum47, opFntNum48, opFntNum49,
  388. opFntNum50, opFntNum51, opFntNum52, opFntNum53, opFntNum54,
  389. opFntNum55, opFntNum56, opFntNum57, opFntNum58, opFntNum59,
  390. opFntNum60, opFntNum61, opFntNum62, opFntNum63:
  391. return &CmdFntNum{}
  392. case opFnt1:
  393. return &CmdFnt1{}
  394. case opFnt2:
  395. return &CmdFnt2{}
  396. case opFnt3:
  397. return &CmdFnt3{}
  398. case opFnt4:
  399. return &CmdFnt4{}
  400. case opXXX1:
  401. return &CmdXXX1{}
  402. case opXXX2:
  403. return &CmdXXX2{}
  404. case opXXX3:
  405. return &CmdXXX3{}
  406. case opXXX4:
  407. return &CmdXXX4{}
  408. case opFntDef1:
  409. return &CmdFntDef1{}
  410. case opFntDef2:
  411. return &CmdFntDef2{}
  412. case opFntDef3:
  413. return &CmdFntDef3{}
  414. case opFntDef4:
  415. return &CmdFntDef4{}
  416. case opPre:
  417. return &CmdPre{}
  418. case opPost:
  419. return &CmdPost{}
  420. case opPostPost:
  421. return &CmdPostPost{}
  422. default:
  423. panic(fmt.Errorf("dvi: unknown opcode 0x%x (%d)", op, op))
  424. }
  425. }