home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 8 < prev    next >
Encoding:
Text File  |  1993-09-02  |  44.2 KB  |  1,542 lines

  1. Article 99 of comp.sources.misc:
  2. Relay-Version: version B 2.10.3 alpha 5/22/85; site osu-eddie.UUCP
  3. Path: osu-eddie!cbosgd!ihnp4!ptsfa!ames!necntc!ncoast!allbery
  4. From: rcb@rti.UUCP (Randy Buckland)
  5. Newsgroups: comp.sources.misc
  6. Subject: VMS DVI preview (part 2 of 3)
  7. Message-ID: <2808@ncoast.UUCP>
  8. Date: 7 Jul 87 01:47:31 GMT
  9. Date-Received: 8 Jul 87 03:35:01 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Lines: 1525
  12. Approved: allbery@ncoast.UUCP
  13. X-Archive: comp.sources.misc/8707/8
  14.  
  15. This is the second part of the DVI previewer code for VMS.
  16.  
  17. ----------------------------cut here------------------------------
  18. $ write sys$output "Creating [.src]dvi_def_.ada"
  19. $ create [.src]dvi_def_.ada
  20. $ deck
  21. ---------------------------------------------------------------------------
  22. --|                                    |--
  23. --| Title:  Dvi_def                            |--
  24. --| Date:    9-JUN-1987                            |--
  25. --| Name:   Randy Buckland                        |--
  26. --|                                    |--
  27. --| Purpose:    Defintions related to DVI file format.            |--
  28. --|                                    |--
  29. ---------------------------------------------------------------------------
  30. --|                                    |--
  31. --| Revision History                            |--
  32. --|                                    |--
  33. --| Who        Date    Description                    |--
  34. --| ---        ----    -----------                    |--
  35. --| rcb         9-JUN-1987    New file.                    |--
  36. --|                                    |--
  37. ---------------------------------------------------------------------------
  38. --|                                    |--
  39. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  40. --| Written by Randy Buckland. Not derived from licensed software.    |--
  41. --|                                    |--
  42. --| Permission is granted to anyone to use this software for any    |--
  43. --| purpose on any computer system, and to redistribute it freely,    |--
  44. --| subject to the following restrictions.                |--
  45. --|                                    |--
  46. --| 1. Research Triangle Institute supplies this software "as is",    |--
  47. --|    without any warranty. The author and the Institute do not    |--
  48. --|    accept any responsibility for any damage caused by use or    |--
  49. --|    mis-use of this program.                    |--
  50. --| 2. The copyright notice must remain a part of all sources files.    |--
  51. --| 3. This software may not be sold in any fashion.            |--
  52. --|                                    |--
  53. ---------------------------------------------------------------------------
  54. with font_def;
  55. use  font_def;
  56.  
  57. with unchecked_deallocation;
  58.  
  59. package dvi_def is
  60.  
  61. ---------------------------------------------------------------------------
  62. --|                                    |--
  63. --| Global types.                            |--
  64. --|                                    |--
  65. ---------------------------------------------------------------------------
  66. type page_array (size : integer) is record
  67.     height      : integer;
  68.     width       : integer;
  69.     page_number : integer;
  70.     bits        : pixel_array (1..size);
  71. end record;
  72.  
  73. type page_ptr is access page_array;
  74.  
  75. procedure free is new unchecked_deallocation (page_array, page_ptr);
  76.  
  77. ---------------------------------------------------------------------------
  78. --|                                    |--
  79. --| Global variables.                            |--
  80. --|                                    |--
  81. ---------------------------------------------------------------------------
  82. --|
  83. --| Scaling parameters
  84. --|
  85. dvi_to_nano_meter : float;
  86. magstep           : float;
  87.  
  88. page_height : integer;
  89. page_width  : integer;
  90.  
  91. temp_page : page_ptr := null;
  92. prev_page : page_ptr := null;
  93. curr_page : page_ptr := null;
  94. next_page : page_ptr := null;
  95.  
  96. ---------------------------------------------------------------------------
  97. --|                                    |--
  98. --| Constant definitions.                        |--
  99. --|                                    |--
  100. ---------------------------------------------------------------------------
  101. --|
  102. --| Misc constants
  103. --|
  104. resolution : constant := 78.0;
  105. --|
  106. --| Dvi commands
  107. --|
  108. set_char_0   : constant := 0;
  109. set_char_127 : constant := 127;
  110. set1         : constant := 128;
  111. set2         : constant := 129;
  112. set3         : constant := 130;
  113. set4         : constant := 131;
  114. set_rule     : constant := 132;
  115. put1         : constant := 133;
  116. put2         : constant := 134;
  117. put3         : constant := 135;
  118. put4         : constant := 136;
  119. put_rule     : constant := 137;
  120. nop         : constant := 138;
  121. bop         : constant := 139;
  122. eop         : constant := 140;
  123. push         : constant := 141;
  124. pop         : constant := 142;
  125. right1         : constant := 143;
  126. right2         : constant := 144;
  127. right3         : constant := 145;
  128. right4         : constant := 146;
  129. w0         : constant := 147;
  130. w1         : constant := 148;
  131. w2         : constant := 149;
  132. w3         : constant := 150;
  133. w4         : constant := 151;
  134. x0         : constant := 152;
  135. x1         : constant := 153;
  136. x2         : constant := 154;
  137. x3         : constant := 155;
  138. x4         : constant := 156;
  139. down1         : constant := 157;
  140. down2         : constant := 158;
  141. down3         : constant := 159;
  142. down4         : constant := 160;
  143. y0         : constant := 161;
  144. y1         : constant := 162;
  145. y2         : constant := 163;
  146. y3         : constant := 164;
  147. y4         : constant := 165;
  148. z0         : constant := 166;
  149. z1         : constant := 167;
  150. z2         : constant := 168;
  151. z3         : constant := 169;
  152. z4         : constant := 170;
  153. fnt_num_0    : constant := 171;
  154. fnt_num_63   : constant := 234;
  155. fnt1         : constant := 235;
  156. fnt2         : constant := 236;
  157. fnt3         : constant := 237;
  158. fnt4         : constant := 238;
  159. xxx1         : constant := 239;
  160. xxx2         : constant := 240;
  161. xxx3         : constant := 241;
  162. xxx4         : constant := 242;
  163. fnt_def1     : constant := 243;
  164. fnt_def2     : constant := 244;
  165. fnt_def3     : constant := 245;
  166. fnt_def4     : constant := 246;
  167. preamble     : constant := 247;
  168. postamble    : constant := 248;
  169. post_post    : constant := 249;
  170.  
  171. end;
  172. $ eod
  173. $ checksum [.src]dvi_def_.ada
  174. $ if checksum$checksum .nes. "1919110043" then write sys$output -
  175.     "    ******Checksum error for file [.src]dvi_def_.ada******"
  176. $ write sys$output "Creating [.src]dvi_io.ada"
  177. $ create [.src]dvi_io.ada
  178. $ deck
  179. ---------------------------------------------------------------------------
  180. --|                                    |--
  181. --| Title:  Dvi_io                            |--
  182. --| Date:    9-JUN-1987                            |--
  183. --| Name:   Randy Buckland                        |--
  184. --|                                    |--
  185. --| Purpose:    Handle input of DVI file.                |--
  186. --|                                    |--
  187. ---------------------------------------------------------------------------
  188. --|                                    |--
  189. --| Revision History                            |--
  190. --|                                    |--
  191. --| Who        Date    Description                    |--
  192. --| ---        ----    -----------                    |--
  193. --| rcb         9-JUN-1987    New file.                    |--
  194. --|                                    |--
  195. ---------------------------------------------------------------------------
  196. --|                                    |--
  197. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  198. --| Written by Randy Buckland. Not derived from licensed software.    |--
  199. --|                                    |--
  200. --| Permission is granted to anyone to use this software for any    |--
  201. --| purpose on any computer system, and to redistribute it freely,    |--
  202. --| subject to the following restrictions.                |--
  203. --|                                    |--
  204. --| 1. Research Triangle Institute supplies this software "as is",    |--
  205. --|    without any warranty. The author and the Institute do not    |--
  206. --|    accept any responsibility for any damage caused by use or    |--
  207. --|    mis-use of this program.                    |--
  208. --| 2. The copyright notice must remain a part of all sources files.    |--
  209. --| 3. This software may not be sold in any fashion.            |--
  210. --|                                    |--
  211. ---------------------------------------------------------------------------
  212. with text_io, sys, system;
  213. use  text_io, sys, system;
  214.  
  215. with direct_io;
  216.  
  217. package body dvi_io is
  218.  
  219. ---------------------------------------------------------------------------
  220. --|                                    |--
  221. --| Instantiations.                            |--
  222. --|                                    |--
  223. ---------------------------------------------------------------------------
  224. type dvi_block is array(0..511) of unsigned_byte;
  225. package block_io is new direct_io (dvi_block); use block_io;
  226. ---------------------------------------------------------------------------
  227. --|                                    |--
  228. --| Static variables.                            |--
  229. --|                                    |--
  230. ---------------------------------------------------------------------------
  231. --|
  232. --| File access variables.
  233. --|
  234. dvi_file   : block_io.file_type;
  235. dvi_record : block_io.count := 0;
  236. dvi_offset : integer := 511;
  237. dvi_buffer : dvi_block;
  238.  
  239. ---------------------------------------------------------------------------
  240. --|                                    |--
  241. --| Open                                |--
  242. --|                                    |--
  243. ---------------------------------------------------------------------------
  244. --|                                    |--
  245. --| Parameters:        1. Name of DVI file to open.            |--
  246. --|                                    |--
  247. --| Description:    Open the DVI file.                    |--
  248. --|                                    |--
  249. ---------------------------------------------------------------------------
  250. procedure open (
  251.     name : in string) is
  252.  
  253. begin
  254.     open (dvi_file, in_file, name, "file; default_name *.dvi");
  255.  
  256. exception
  257.     when others =>
  258.     put_line ("Error opening file " & name);
  259.     sys_exit (16#1000002c#);
  260. end;
  261.  
  262. ---------------------------------------------------------------------------
  263. --|                                    |--
  264. --| Find_post                                |--
  265. --|                                    |--
  266. ---------------------------------------------------------------------------
  267. --|                                    |--
  268. --| Description:    Find the postamble and position at the POST byte.    |--
  269. --|                                    |--
  270. ---------------------------------------------------------------------------
  271. procedure find_post is
  272.  
  273. last_good_record : block_io.count;
  274. offset           : block_io.count;
  275.  
  276. begin
  277. --|
  278. --| Probe past end of file.
  279. --|
  280.     begin
  281.     dvi_record := 1;
  282.     loop
  283.         read (dvi_file, dvi_buffer, dvi_record);
  284.         last_good_record := dvi_record;
  285.         dvi_record := dvi_record * 2;
  286.     end loop;
  287.     exception
  288.     when block_io.end_error => null;
  289.     end;
  290. --|
  291. --| Divide difference until end of file is found.
  292. --|
  293.     offset := (dvi_record - last_good_record)/2;
  294.     while (offset /= 0) loop
  295.     begin
  296.         read (dvi_file, dvi_buffer, last_good_record + offset);
  297.         last_good_record := last_good_record + offset;
  298.     exception
  299.         when block_io.end_error => null;
  300.     end;
  301.     offset := offset / 2;
  302.     end loop;
  303. --|
  304. --| Scan backwards in buffer until byte with value of 2 is found.
  305. --|
  306.     dvi_offset := 511;
  307.     dvi_record := last_good_record;
  308.     
  309.     while (dvi_buffer (dvi_offset) = 223) loop
  310.     dvi_offset := dvi_offset - 1;
  311.     if (dvi_offset < 0) then
  312.         dvi_record := dvi_record - 1;
  313.         dvi_offset := 511;
  314.         read (dvi_file, dvi_buffer, dvi_record);
  315.     end if;
  316.     end loop;
  317. --|
  318. --| Get position of POST byte and go there
  319. --|
  320.     go_to (integer((dvi_record-1)*512)+dvi_offset-4);
  321.     go_to (get_4byte);
  322. end;
  323.  
  324. ---------------------------------------------------------------------------
  325. --|                                    |--
  326. --| Go_to                                |--
  327. --|                                    |--
  328. ---------------------------------------------------------------------------
  329. --|                                    |--
  330. --| Parameters:        1. Offset to goto.                    |--
  331. --|                                    |--
  332. --| Description:    Goto specified offset in file.            |--
  333. --|                                    |--
  334. ---------------------------------------------------------------------------
  335. procedure go_to (
  336.     offset : in integer) is
  337.  
  338. begin
  339.     if (dvi_record /= block_io.count((offset/512)+1)) then
  340.     dvi_record := block_io.count((offset/512)+1);
  341.     read (dvi_file, dvi_buffer, dvi_record);
  342.     end if;
  343.     dvi_offset := offset mod 512;
  344. end;
  345.  
  346. ---------------------------------------------------------------------------
  347. --|                                    |--
  348. --| Get_byte                                |--
  349. --|                                    |--
  350. ---------------------------------------------------------------------------
  351. --|                                    |--
  352. --| Description:    Return the next 1-4 bytes as an integer.        |--
  353. --|                                    |--
  354. ---------------------------------------------------------------------------
  355. function get_byte 
  356.     return integer is
  357.  
  358. temp : integer;
  359.  
  360. begin
  361.     if (dvi_offset > 511) then
  362.     dvi_record := dvi_record + 1;
  363.     read (dvi_file, dvi_buffer, dvi_record);
  364.     dvi_offset := 0;
  365.     end if;
  366.     
  367.     temp := integer (dvi_buffer (dvi_offset));
  368.     dvi_offset := dvi_offset + 1;
  369.     return temp;
  370. end;
  371. --|
  372. --| Get a 2 byte value
  373. --|
  374. function get_2byte
  375.     return integer is
  376.  
  377. temp : integer := 0;
  378.  
  379. begin
  380.     for i in 1..2 loop
  381.     temp := temp*256 + get_byte;
  382.     end loop;
  383.     return temp;
  384. end;
  385. --|
  386. --| Get a 3 byte value
  387. --|
  388. function get_3byte
  389.     return integer is
  390.  
  391. temp : integer := 0;
  392.  
  393. begin
  394.     for i in 1..3 loop
  395.     temp := temp*256 + get_byte;
  396.     end loop;
  397.     return temp;
  398. end;
  399. --|
  400. --| Get a 4 byte value
  401. --|
  402. function get_4byte 
  403.     return integer is
  404.  
  405. temp : bit_array_32;
  406.  
  407. begin
  408.     for i in reverse 0..3 loop
  409.     temp(i*8..i*8+7) := to_bit_array_8 (unsigned_byte (get_byte));
  410.     end loop;
  411.     return integer (to_unsigned_longword (temp));
  412. end;
  413.  
  414. ---------------------------------------------------------------------------
  415. --|                                    |--
  416. --| Get_s_byte                                |--
  417. --|                                    |--
  418. ---------------------------------------------------------------------------
  419. --|                                    |--
  420. --| Description:    Get a sign extended value of 1-4 bytes in        |--
  421. --|            length and return it as an integer.            |--
  422. --|                                    |--
  423. ---------------------------------------------------------------------------
  424. function get_s_byte 
  425.     return integer is
  426.  
  427. temp : bit_array_32;
  428.  
  429. begin
  430.     temp := to_bit_array_32 (unsigned_longword (get_byte));
  431.     temp (8..31) := (8..31 => temp(7));
  432.     return integer (to_unsigned_longword (temp));
  433. end;
  434. --|
  435. --| Get a 2 byte value
  436. --|
  437. function get_s_2byte 
  438.     return integer is
  439.  
  440. temp : bit_array_32;
  441.  
  442. begin
  443.     temp := to_bit_array_32 (unsigned_longword (get_2byte));
  444.     temp (16..31) := (16..31 => temp(15));
  445.     return integer (to_unsigned_longword (temp));
  446. end;
  447. --|
  448. --| Get a 3 byte value
  449. --|
  450. function get_s_3byte 
  451.     return integer is
  452.  
  453. temp : bit_array_32;
  454.  
  455. begin
  456.     temp := to_bit_array_32 (unsigned_longword (get_3byte));
  457.     temp (24..31) := (24..31 => temp(23));
  458.     return integer (to_unsigned_longword (temp));
  459. end;
  460.  
  461. ---------------------------------------------------------------------------
  462. --|                                    |--
  463. --| Close                                |--
  464. --|                                    |--
  465. ---------------------------------------------------------------------------
  466. --|                                    |--
  467. --| Description:    Close the DVI file.                    |--
  468. --|                                    |--
  469. ---------------------------------------------------------------------------
  470. procedure close is
  471.  
  472. begin
  473.     close (dvi_file);
  474. end;
  475.  
  476. end;
  477. $ eod
  478. $ checksum [.src]dvi_io.ada
  479. $ if checksum$checksum .nes. "707123688" then write sys$output -
  480.     "    ******Checksum error for file [.src]dvi_io.ada******"
  481. $ write sys$output "Creating [.src]dvi_io_.ada"
  482. $ create [.src]dvi_io_.ada
  483. $ deck
  484. ---------------------------------------------------------------------------
  485. --|                                    |--
  486. --| Title:  Dvi_io                            |--
  487. --| Date:    9-JUN-1987                            |--
  488. --| Name:   Randy Buckland                        |--
  489. --|                                    |--
  490. --| Purpose:    Handle input of DVI file.                |--
  491. --|                                    |--
  492. ---------------------------------------------------------------------------
  493. --|                                    |--
  494. --| Revision History                            |--
  495. --|                                    |--
  496. --| Who        Date    Description                    |--
  497. --| ---        ----    -----------                    |--
  498. --| rcb         9-JUN-1987    New file.                    |--
  499. --|                                    |--
  500. ---------------------------------------------------------------------------
  501. --|                                    |--
  502. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  503. --| Written by Randy Buckland. Not derived from licensed software.    |--
  504. --|                                    |--
  505. --| Permission is granted to anyone to use this software for any    |--
  506. --| purpose on any computer system, and to redistribute it freely,    |--
  507. --| subject to the following restrictions.                |--
  508. --|                                    |--
  509. --| 1. Research Triangle Institute supplies this software "as is",    |--
  510. --|    without any warranty. The author and the Institute do not    |--
  511. --|    accept any responsibility for any damage caused by use or    |--
  512. --|    mis-use of this program.                    |--
  513. --| 2. The copyright notice must remain a part of all sources files.    |--
  514. --| 3. This software may not be sold in any fashion.            |--
  515. --|                                    |--
  516. ---------------------------------------------------------------------------
  517. package dvi_io is
  518.  
  519. ---------------------------------------------------------------------------
  520. --|                                    |--
  521. --| Routine definitions.                        |--
  522. --|                                    |--
  523. ---------------------------------------------------------------------------
  524. procedure open (name : in string);
  525.  
  526. procedure find_post;
  527. procedure go_to (offset : in integer);
  528.  
  529. function get_byte return integer;
  530. function get_2byte return integer;
  531. function get_3byte return integer;
  532. function get_4byte return integer;
  533.  
  534. function get_s_byte return integer;
  535. function get_s_2byte return integer;
  536. function get_s_3byte return integer;
  537.  
  538. procedure close;
  539.  
  540. end;
  541. $ eod
  542. $ checksum [.src]dvi_io_.ada
  543. $ if checksum$checksum .nes. "1701279364" then write sys$output -
  544.     "    ******Checksum error for file [.src]dvi_io_.ada******"
  545. $ write sys$output "Creating [.src]dvi_tasks.ada"
  546. $ create [.src]dvi_tasks.ada
  547. $ deck
  548. ---------------------------------------------------------------------------
  549. --|                                    |--
  550. --| Title:  Dvi_tasks                            |--
  551. --| Date:    9-JUN-1987                            |--
  552. --| Name:   Randy Buckland                        |--
  553. --|                                    |--
  554. --| Purpose:    Task manager for DVI file related operations.        |--
  555. --|                                    |--
  556. ---------------------------------------------------------------------------
  557. --|                                    |--
  558. --| Revision History                            |--
  559. --|                                    |--
  560. --| Who        Date    Description                    |--
  561. --| ---        ----    -----------                    |--
  562. --| rcb         9-JUN-1987    New file.                    |--
  563. --|                                    |--
  564. ---------------------------------------------------------------------------
  565. --|                                    |--
  566. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  567. --| Written by Randy Buckland. Not derived from licensed software.    |--
  568. --|                                    |--
  569. --| Permission is granted to anyone to use this software for any    |--
  570. --| purpose on any computer system, and to redistribute it freely,    |--
  571. --| subject to the following restrictions.                |--
  572. --|                                    |--
  573. --| 1. Research Triangle Institute supplies this software "as is",    |--
  574. --|    without any warranty. The author and the Institute do not    |--
  575. --|    accept any responsibility for any damage caused by use or    |--
  576. --|    mis-use of this program.                    |--
  577. --| 2. The copyright notice must remain a part of all sources files.    |--
  578. --| 3. This software may not be sold in any fashion.            |--
  579. --|                                    |--
  580. ---------------------------------------------------------------------------
  581. with dvi_io, font_tasks, text_io, sys, str, dvi_translate, ots;
  582. use  dvi_io, font_tasks, text_io, sys, str, dvi_translate, ots;
  583.  
  584. package body dvi_tasks is
  585.  
  586. ---------------------------------------------------------------------------
  587. --|                                    |--
  588. --| Private types.                            |--
  589. --|                                    |--
  590. ---------------------------------------------------------------------------
  591. type page_list_array is array (integer range <>) of integer;
  592. type page_list_ptr is access page_list_array;
  593.  
  594. ---------------------------------------------------------------------------
  595. --|                                    |--
  596. --| Static variables.                            |--
  597. --|                                    |--
  598. ---------------------------------------------------------------------------
  599. --|
  600. --| Page information
  601. --|
  602. page_list : page_list_ptr;
  603.  
  604. ---------------------------------------------------------------------------
  605. --|                                    |--
  606. --| Read_pre                                |--
  607. --|                                    |--
  608. ---------------------------------------------------------------------------
  609. --|                                    |--
  610. --| Description:    Read the preamble and get scaling values.        |--
  611. --|                                    |--
  612. ---------------------------------------------------------------------------
  613. procedure read_pre (
  614.     magnification : in float) is
  615.  
  616. n : float;
  617. d : float;
  618. m : float;
  619.  
  620. begin
  621. --|
  622. --| Check file type is dvi file
  623. --|
  624.     go_to (0);
  625.     if (get_byte /= preamble)
  626.     or else (get_byte /= 2) then
  627.     put_line ("Bad dvi file");
  628.     sys_exit (16#1000002c#);
  629.     end if;
  630. --|
  631. --| Load scaling parameters
  632. --|
  633.     n := float (get_4byte);
  634.     d := float (get_4byte);
  635.     m := float (get_4byte);
  636.     
  637.     dvi_to_nano_meter := n/d;
  638.     magstep := m/1000.0*magnification;
  639. end;
  640.  
  641. ---------------------------------------------------------------------------
  642. --|                                    |--
  643. --| Load_font                                |--
  644. --|                                    |--
  645. ---------------------------------------------------------------------------
  646. --|                                    |--
  647. --| Parameters:        1. Font load command.                |--
  648. --|                                    |--
  649. --| Description:    Read font definition and cause it to be loaded    |--
  650. --|            by the font_load task                |--
  651. --|                                    |--
  652. ---------------------------------------------------------------------------
  653. procedure load_font (
  654.     command : in integer) is
  655.  
  656. font_number : integer;
  657. name        : string(1..60);
  658. size        : integer;
  659. scale       : float;
  660. trash        : integer;
  661.  
  662. begin
  663.     case command is
  664.     when fnt_def1 => font_number := get_byte;
  665.     when fnt_def2 => font_number := get_2byte;
  666.     when fnt_def3 => font_number := get_3byte;
  667.     when fnt_def4 => font_number := get_4byte;
  668.     when others   => null;
  669.     end case;
  670.     
  671.     trash := get_4byte;            -- Trash checksum
  672.     scale := float (get_4byte);
  673.     scale := scale / float (get_4byte);
  674.     size := get_byte + get_byte;
  675.     
  676.     for i in 1..size loop
  677.     name(i) := character'val(get_byte);
  678.     end loop;
  679.     copy (name(size+1..60), integer'image (integer (scale*magstep*resolution)) &
  680.     "PK");
  681.     name(size+1) := '.';
  682.     for i in name'range loop
  683.     size := i-1;
  684.     exit when (name(i) = ' ');
  685.     end loop;
  686.     
  687.     font_load.add_font (name(1..size), font_number);
  688. end;
  689.  
  690. ---------------------------------------------------------------------------
  691. --|                                    |--
  692. --| Read_post                                |--
  693. --|                                    |--
  694. ---------------------------------------------------------------------------
  695. --|                                    |--
  696. --| Description:    Read the postamble and activate the font loader.    |--
  697. --|                                    |--
  698. ---------------------------------------------------------------------------
  699. procedure read_post (
  700.     magnification : in float) is
  701.  
  702. trash      : integer;
  703. page_count : integer;
  704. command    : integer;
  705. last_page  : integer;
  706.  
  707. begin
  708. --|
  709. --| Trash header stuff
  710. --|
  711.     trash := get_byte;        -- Trash POST command
  712.     last_page := get_4byte;
  713.     trash := get_4byte;        -- Trash numerator
  714.     trash := get_4byte;        -- Trash denominator
  715.     trash := get_4byte;        -- Trash magnification
  716.     trash := get_4byte;        -- Trash max length
  717.     trash := get_4byte;        -- Trash max width
  718.     trash := get_2byte;        -- Trash max stack depth
  719.     page_count := get_2byte;
  720. --|
  721. --| Process font definitions.
  722. --|
  723.     loop
  724.     command := get_byte;
  725.     case command is
  726.         when post_post          => exit;
  727.         when nop                => null;
  728.         when fnt_def1..fnt_def4 => load_font (command);
  729.  
  730.         when others =>
  731.         put_line ("Unknown command in postamble" & 
  732.             integer'image(command));
  733.         sys_exit (16#1000002c#);
  734.     end case;
  735.     end loop;
  736. --|
  737. --| Build page list
  738. --|
  739.     page_list := new page_list_array (1..page_count);
  740.     page_list(page_count) := last_page;
  741.     loop
  742.     page_count := page_count - 1;
  743.     exit when (page_count = 0);
  744.     go_to (last_page+41);
  745.     last_page := get_4byte;
  746.     exit when (last_page = -1);
  747.     page_list (page_count) := last_page;
  748.     end loop;
  749. end;
  750.  
  751. ---------------------------------------------------------------------------
  752. --|                                    |--
  753. --| Reset_page                                |--
  754. --|                                    |--
  755. ---------------------------------------------------------------------------
  756. --|                                    |--
  757. --| Parameters:        1. Pointer to page.                    |--
  758. --|                                    |--
  759. --| Description:    Reset the data in a page description.        |--
  760. --|                                    |--
  761. ---------------------------------------------------------------------------
  762. procedure reset_page (
  763.     page : in page_ptr) is
  764.  
  765. begin
  766.     page.height := page_height;
  767.     page.width := page_width;
  768.     page.page_number := 0;
  769.     move5 (0, page.bits'address, 0, (page.size+7)/8, page.bits'address);
  770. end;
  771.  
  772. ---------------------------------------------------------------------------
  773. --|                                    |--
  774. --| Load_page                                |--
  775. --|                                    |--
  776. ---------------------------------------------------------------------------
  777. --|                                    |--
  778. --| Parameters:        1. Page number to load.                |--
  779. --|            2. Page pointer to place page into.            |--
  780. --|                                    |--
  781. --| Description:    Load a page from a DVI file.            |--
  782. --|                                    |--
  783. ---------------------------------------------------------------------------
  784. procedure load_page (
  785.     page_number : in     integer;
  786.     page    : in out page_ptr) is
  787.  
  788. begin
  789.     go_to (page_list(page_number));
  790.     reset_page (page);
  791.     page.page_number := page_number;
  792.     build_page (page);
  793. end;
  794.  
  795. ---------------------------------------------------------------------------
  796. --|                                    |--
  797. --| Dvi_read                                |--
  798. --|                                    |--
  799. ---------------------------------------------------------------------------
  800. --|                                    |--
  801. --| Description:    Task to handle reading of DVI file and building    |--
  802. --|            page images in memory.                |--
  803. --|                                    |--
  804. ---------------------------------------------------------------------------
  805. task body dvi_read is
  806.  
  807. do_load : boolean;
  808.  
  809. begin
  810. --|
  811. --| Initialize file reader
  812. --|
  813.     accept init (file_name : in string; magnification : in float;
  814.     page_count : out integer) do
  815.     
  816.     open (file_name);
  817.     read_pre (magnification);
  818.     find_post;
  819.     read_post (magnification);
  820.     font_load.get_fonts;
  821.     
  822.     page_height := integer (11.0 * resolution * magstep);
  823.     page_width := integer (8.5 * resolution * magstep);
  824.     page_width := (page_width+7)/8;
  825.     page_width := page_width*8;
  826.     page_count := page_list'last;
  827.     end;
  828. --|
  829. --| Main page loop
  830. --|
  831.     loop
  832.     select
  833.         accept get_next (page : out page_ptr) do
  834.         if (next_page.page_number = 0) then
  835.             page := curr_page;
  836.         else
  837.             temp_page := prev_page;
  838.             prev_page := curr_page;
  839.             curr_page := next_page;
  840.             next_page := temp_page;
  841.             next_page.page_number := 0;
  842.         end if;
  843.         page := curr_page;
  844.         end;
  845.         if (curr_page.page_number < page_list.all'last) then
  846.         load_page (curr_page.page_number+1, next_page);
  847.         end if;
  848.     or
  849.         accept get_prev (page : out page_ptr) do
  850.         if (prev_page.page_number = 0) then
  851.             page := curr_page;
  852.         else
  853.             temp_page := next_page;
  854.             next_page := curr_page;
  855.             curr_page := prev_page;
  856.             prev_page := temp_page;
  857.             prev_page.page_number := 0;
  858.         end if;
  859.         page := curr_page;
  860.         end;
  861.         if (curr_page.page_number > 1) then
  862.         load_page (curr_page.page_number-1, prev_page);
  863.         end if;
  864.     or
  865.         accept get_page (page_num : in integer; page : out page_ptr) do
  866.         if (page_num in page_list'range) then
  867.             load_page (page_num, curr_page);
  868.             do_load := true;
  869.         else
  870.             do_load := false;
  871.         end if;
  872.         page := curr_page;
  873.         end;
  874.         if (curr_page.page_number > 1) then
  875.         load_page (curr_page.page_number-1, prev_page);
  876.         else
  877.         prev_page.page_number := 0;
  878.         end if;
  879.         
  880.         if (curr_page.page_number < page_list.all'last) then
  881.         load_page (curr_page.page_number+1, next_page);
  882.         else
  883.         next_page.page_number := 0;
  884.         end if;
  885.     or
  886.         terminate;
  887.     end select;
  888.     end loop;
  889. end;
  890.  
  891. end;
  892. $ eod
  893. $ checksum [.src]dvi_tasks.ada
  894. $ if checksum$checksum .nes. "1332153152" then write sys$output -
  895.     "    ******Checksum error for file [.src]dvi_tasks.ada******"
  896. $ write sys$output "Creating [.src]dvi_tasks_.ada"
  897. $ create [.src]dvi_tasks_.ada
  898. $ deck
  899. ---------------------------------------------------------------------------
  900. --|                                    |--
  901. --| Title:  Dvi_tasks                            |--
  902. --| Date:    9-JUN-1987                            |--
  903. --| Name:   Randy Buckland                        |--
  904. --|                                    |--
  905. --| Purpose:    Task manager for DVI file related operations.        |--
  906. --|                                    |--
  907. ---------------------------------------------------------------------------
  908. --|                                    |--
  909. --| Revision History                            |--
  910. --|                                    |--
  911. --| Who        Date    Description                    |--
  912. --| ---        ----    -----------                    |--
  913. --| rcb         9-JUN-1987    New file.                    |--
  914. --|                                    |--
  915. ---------------------------------------------------------------------------
  916. --|                                    |--
  917. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  918. --| Written by Randy Buckland. Not derived from licensed software.    |--
  919. --|                                    |--
  920. --| Permission is granted to anyone to use this software for any    |--
  921. --| purpose on any computer system, and to redistribute it freely,    |--
  922. --| subject to the following restrictions.                |--
  923. --|                                    |--
  924. --| 1. Research Triangle Institute supplies this software "as is",    |--
  925. --|    without any warranty. The author and the Institute do not    |--
  926. --|    accept any responsibility for any damage caused by use or    |--
  927. --|    mis-use of this program.                    |--
  928. --| 2. The copyright notice must remain a part of all sources files.    |--
  929. --| 3. This software may not be sold in any fashion.            |--
  930. --|                                    |--
  931. ---------------------------------------------------------------------------
  932. with dvi_def;
  933. use  dvi_def;
  934.  
  935. package dvi_tasks is
  936.  
  937. ---------------------------------------------------------------------------
  938. --|                                    |--
  939. --| Task definitions.                            |--
  940. --|                                    |--
  941. ---------------------------------------------------------------------------
  942. procedure reset_page (page : in page_ptr);
  943.  
  944. task dvi_read is
  945.     pragma priority(6);
  946.     entry init (file_name : in string; magnification : in float;
  947.     page_count : out integer);
  948.     entry get_next (page : out page_ptr);
  949.     entry get_prev (page : out page_ptr);
  950.     entry get_page (page_num : in integer; page : out page_ptr);
  951. end;
  952.  
  953. end;
  954. $ eod
  955. $ checksum [.src]dvi_tasks_.ada
  956. $ if checksum$checksum .nes. "1763783910" then write sys$output -
  957.     "    ******Checksum error for file [.src]dvi_tasks_.ada******"
  958. $ write sys$output "Creating [.src]dvi_translate.ada"
  959. $ create [.src]dvi_translate.ada
  960. $ deck
  961. ---------------------------------------------------------------------------
  962. --|                                    |--
  963. --| Title:  Dvi_translate                        |--
  964. --| Date:   12-JUN-1987                            |--
  965. --| Name:   Randy Buckland                        |--
  966. --|                                    |--
  967. --| Purpose:    Translate DVI commands into a bitmap.            |--
  968. --|                                    |--
  969. ---------------------------------------------------------------------------
  970. --|                                    |--
  971. --| Revision History                            |--
  972. --|                                    |--
  973. --| Who        Date    Description                    |--
  974. --| ---        ----    -----------                    |--
  975. --| rcb        12-JUN-1987    New file.                    |--
  976. --|                                    |--
  977. ---------------------------------------------------------------------------
  978. --|                                    |--
  979. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  980. --| Written by Randy Buckland. Not derived from licensed software.    |--
  981. --|                                    |--
  982. --| Permission is granted to anyone to use this software for any    |--
  983. --| purpose on any computer system, and to redistribute it freely,    |--
  984. --| subject to the following restrictions.                |--
  985. --|                                    |--
  986. --| 1. Research Triangle Institute supplies this software "as is",    |--
  987. --|    without any warranty. The author and the Institute do not    |--
  988. --|    accept any responsibility for any damage caused by use or    |--
  989. --|    mis-use of this program.                    |--
  990. --| 2. The copyright notice must remain a part of all sources files.    |--
  991. --| 3. This software may not be sold in any fashion.            |--
  992. --|                                    |--
  993. ---------------------------------------------------------------------------
  994. with dvi_io, text_io, sys, font_tasks, font_def;
  995. use  dvi_io, text_io, sys, font_tasks, font_def;
  996.  
  997. with unchecked_deallocation;
  998.  
  999. package body dvi_translate is
  1000.  
  1001. ---------------------------------------------------------------------------
  1002. --|                                    |--
  1003. --| Local_types.                            |--
  1004. --|                                    |--
  1005. ---------------------------------------------------------------------------
  1006. type stack_node;
  1007. type stack_ptr is access stack_node;
  1008.  
  1009. type stack_node is record
  1010.     h : integer;
  1011.     v : integer;
  1012.     w : integer;
  1013.     x : integer;
  1014.     y : integer;
  1015.     z : integer;
  1016.     next : stack_ptr;
  1017. end record;
  1018.  
  1019. procedure free is new unchecked_deallocation (stack_node, stack_ptr);
  1020. ---------------------------------------------------------------------------
  1021. --|                                    |--
  1022. --| Static values.                            |--
  1023. --|                                    |--
  1024. ---------------------------------------------------------------------------
  1025. --|
  1026. --| Positioning parameters.
  1027. --|
  1028. h : integer;
  1029. v : integer;
  1030. w : integer;
  1031. x : integer;
  1032. y : integer;
  1033. z : integer;
  1034.  
  1035. stack_head : stack_ptr := null;
  1036. --|
  1037. --| Misc variables
  1038. --|
  1039. curr_font : font_ptr;
  1040. curr_page : page_ptr;
  1041. trash     : integer;
  1042. command   : integer;
  1043.  
  1044. ---------------------------------------------------------------------------
  1045. --|                                    |--
  1046. --| Push_stack                                |--
  1047. --|                                    |--
  1048. ---------------------------------------------------------------------------
  1049. --|                                    |--
  1050. --| Description:    Push current positions onto stack.            |--
  1051. --|                                    |--
  1052. ---------------------------------------------------------------------------
  1053. procedure push_stack is
  1054.  
  1055. temp : stack_ptr;
  1056.  
  1057. begin
  1058.     temp := new stack_node;
  1059.     temp.h := h;
  1060.     temp.v := v;
  1061.     temp.w := w;
  1062.     temp.x := x;
  1063.     temp.y := y;
  1064.     temp.z := z;
  1065.     temp.next := stack_head;
  1066.     stack_head := temp;
  1067. end;
  1068.  
  1069. ---------------------------------------------------------------------------
  1070. --|                                    |--
  1071. --| Pop_stack                                |--
  1072. --|                                    |--
  1073. ---------------------------------------------------------------------------
  1074. --|                                    |--
  1075. --| Description:    Pop top stack positions and place into        |--
  1076. --|            position variables.                    |--
  1077. --|                                    |--
  1078. ---------------------------------------------------------------------------
  1079. procedure pop_stack is
  1080.  
  1081. temp : stack_ptr;
  1082.  
  1083. begin
  1084.     if (stack_head /= null) then
  1085.     temp := stack_head;
  1086.     stack_head := temp.next;
  1087.     h := temp.h;
  1088.     v := temp.v;
  1089.     w := temp.w;
  1090.     x := temp.x;
  1091.     y := temp.y;
  1092.     z := temp.z;
  1093.     free (temp);
  1094.     end if;
  1095. end;
  1096.  
  1097. ---------------------------------------------------------------------------
  1098. --|                                    |--
  1099. --| Dvi_to_pixel                            |--
  1100. --|                                    |--
  1101. ---------------------------------------------------------------------------
  1102. --|                                    |--
  1103. --| Parameters:        1. Dvi units value to convert.            |--
  1104. --|                                    |--
  1105. --| Description:    Convert a DVI units value to a pixel count.        |--
  1106. --|                                    |--
  1107. ---------------------------------------------------------------------------
  1108. function dvi_to_pixel (
  1109.     dvi_value : in integer)
  1110.     return integer is
  1111.  
  1112. temp : integer;
  1113.  
  1114. begin
  1115.     temp := integer(float(dvi_value)*
  1116.     (((dvi_to_nano_meter*magstep)/100000.0/2.54)*resolution));
  1117.     return temp;
  1118. end;
  1119.  
  1120. ---------------------------------------------------------------------------
  1121. --|                                    |--
  1122. --| Pixel_to_dvi                            |--
  1123. --|                                    |--
  1124. ---------------------------------------------------------------------------
  1125. --|                                    |--
  1126. --| Parameters:        1. Pixel count to convert to DVI units.        |--
  1127. --|                                    |--
  1128. --| Description:    Convert a pixel count to DVI units.            |--
  1129. --|                                    |--
  1130. ---------------------------------------------------------------------------
  1131. function pixel_to_dvi (
  1132.     pixel_value : in float)
  1133.     return integer is
  1134.  
  1135. temp : integer;
  1136.  
  1137. begin
  1138.     temp := integer(pixel_value/
  1139.     (((dvi_to_nano_meter*magstep)/100000.0/2.54)*resolution));
  1140.     return temp;
  1141. end;
  1142.  
  1143. ---------------------------------------------------------------------------
  1144. --|                                    |--
  1145. --| Set_font                                |--
  1146. --|                                    |--
  1147. ---------------------------------------------------------------------------
  1148. --|                                    |--
  1149. --| Parameters:        1. Font number.                    |--
  1150. --|                                    |--
  1151. --| Description:    Set current font to desired font number.        |--
  1152. --|                                    |--
  1153. ---------------------------------------------------------------------------
  1154. procedure set_font (
  1155.     font_number : in integer) is
  1156.  
  1157. begin
  1158.     font_search.find_font (font_number, curr_font);
  1159. end;
  1160.  
  1161. ---------------------------------------------------------------------------
  1162. --|                                    |--
  1163. --| Set_character                            |--
  1164. --|                                    |--
  1165. ---------------------------------------------------------------------------
  1166. --|                                    |--
  1167. --| Parameters:        1. Character to set.                |--
  1168. --|                                    |--
  1169. --| Description:    Set a character at current position on the        |--
  1170. --|            bit map and advance the H value.            |--
  1171. --|                                    |--
  1172. ---------------------------------------------------------------------------
  1173. procedure set_character (
  1174.     char : in integer) is
  1175.  
  1176. x_pos : integer;
  1177. y_pos : integer;
  1178.  
  1179. char_width : integer;
  1180. char_index : integer;
  1181. page_index : integer;
  1182.  
  1183. begin
  1184.     x_pos := dvi_to_pixel (h) + integer(resolution*magstep) +
  1185.     curr_font(char).x_offset;
  1186.     y_pos := dvi_to_pixel (v) + integer(resolution*magstep) -
  1187.     (curr_font(char).height + curr_font(char).y_offset);
  1188.     
  1189.     char_width := curr_font(char).width;
  1190.     char_index := 1;
  1191.     page_index := (y_pos-1)*curr_page.width + x_pos;
  1192.     
  1193.     for i in 1..curr_font(char).height loop
  1194.     curr_page.bits(page_index..page_index+char_width-1) :=
  1195.         curr_font(char).bits(char_index..char_index+char_width-1);
  1196.  
  1197.     char_index := char_index + char_width;
  1198.     page_index := page_index + curr_page.width;
  1199.     end loop;
  1200.     
  1201.     h := h + pixel_to_dvi (curr_font(char).x_delta);
  1202. end;
  1203.  
  1204. ---------------------------------------------------------------------------
  1205. --|                                    |--
  1206. --| Put_character                            |--
  1207. --|                                    |--
  1208. ---------------------------------------------------------------------------
  1209. --|                                    |--
  1210. --| Parameters:        1. Character to set.                |--
  1211. --|                                    |--
  1212. --| Description:    Put  a character at current position on the        |--
  1213. --|            bit map.                        |--
  1214. --|                                    |--
  1215. ---------------------------------------------------------------------------
  1216. procedure put_character (
  1217.     char : in integer) is
  1218.  
  1219. x_pos : integer;
  1220. y_pos : integer;
  1221.  
  1222. char_width : integer;
  1223. char_index : integer;
  1224. page_index : integer;
  1225.  
  1226. begin
  1227.     x_pos := dvi_to_pixel (h) + integer(resolution*magstep) + 
  1228.     curr_font(char).x_offset;
  1229.     y_pos := dvi_to_pixel (v) + integer(resolution*magstep) -
  1230.     (curr_font(char).height + curr_font(char).y_offset);
  1231.     
  1232.     char_width := curr_font(char).width;
  1233.     char_index := 1;
  1234.     page_index := (y_pos-1)*curr_page.width + x_pos;
  1235.     
  1236.     for i in 1..curr_font(char).height loop
  1237.     curr_page.bits(page_index..page_index+char_width-1) :=
  1238.         curr_font(char).bits(char_index..char_index+char_width-1);
  1239.  
  1240.     char_index := char_index + char_width;
  1241.     page_index := page_index + curr_page.width;
  1242.     end loop;
  1243. end;
  1244.  
  1245. ---------------------------------------------------------------------------
  1246. --|                                    |--
  1247. --| Trash_fnt_def                            |--
  1248. --|                                    |--
  1249. ---------------------------------------------------------------------------
  1250. --|                                    |--
  1251. --| Parameters:        1. Font number being defined.            |--
  1252. --|                                    |--
  1253. --| Description:    Read and ignore a font definition since the        |--
  1254. --|            fonts are already being loaded by the font        |--
  1255. --|            tasks.                        |--
  1256. --|                                    |--
  1257. ---------------------------------------------------------------------------
  1258. procedure trash_fnt_def (
  1259.     font_number : in integer) is
  1260.  
  1261. trash : integer;
  1262. size  : integer;
  1263.  
  1264. begin
  1265.     trash := get_4byte;
  1266.     trash := get_4byte;
  1267.     trash := get_4byte;
  1268.     size := get_byte + get_byte;
  1269.     for i in 1..size loop
  1270.     trash := get_byte;
  1271.     end loop;
  1272. end;
  1273.  
  1274. ---------------------------------------------------------------------------
  1275. --|                                    |--
  1276. --| Do_special                                |--
  1277. --|                                    |--
  1278. ---------------------------------------------------------------------------
  1279. --|                                    |--
  1280. --| Parameters:        1. Length of special command            |--
  1281. --|                                    |--
  1282. --| Description:    Read and discard special commands since they    |--
  1283. --|            are not to be implemented yet.            |--
  1284. --|                                    |--
  1285. ---------------------------------------------------------------------------
  1286. procedure do_special (
  1287.     size : in integer) is
  1288.  
  1289. temp : string(1..size);
  1290.  
  1291. begin
  1292.     for i in 1..size loop
  1293.     temp(i) := character'val(get_byte);
  1294.     end loop;
  1295. end;
  1296.  
  1297. ---------------------------------------------------------------------------
  1298. --|                                    |--
  1299. --| Set_rule_box                            |--
  1300. --|                                    |--
  1301. ---------------------------------------------------------------------------
  1302. --|                                    |--
  1303. --| Description:    Set a rule box on the page and advance the        |--
  1304. --|            horizontal position.                |--
  1305. --|                                    |--
  1306. ---------------------------------------------------------------------------
  1307. procedure set_rule_box is
  1308.  
  1309. x_pos : integer;
  1310. y_pos : integer;
  1311.  
  1312. x_offset : integer;
  1313. y_offset : integer;
  1314.  
  1315. page_index : integer;
  1316. row_count  : integer;
  1317. row_width  : integer;
  1318.  
  1319. begin
  1320.     x_pos := dvi_to_pixel (h) + integer(resolution*magstep);
  1321.     y_pos := dvi_to_pixel (v) + integer(resolution*magstep);
  1322.  
  1323.     y_offset := get_4byte;
  1324.     x_offset := get_4byte;
  1325.     
  1326.     if (x_offset > 0)
  1327.     and (y_offset > 0) then
  1328.     page_index := (y_pos-1)*curr_page.width + x_pos;
  1329.     row_count := dvi_to_pixel (y_offset);
  1330.     row_width := dvi_to_pixel (x_offset);
  1331.     
  1332.     if (row_count < 1) then row_count := 1; end if;
  1333.     if (row_width < 1) then row_width := 1; end if;
  1334.     
  1335.     for i in 1..row_count loop
  1336.         if (row_width = 1) then
  1337.         curr_page.bits(page_index) := true;
  1338.         else
  1339.         curr_page.bits(page_index..page_index+row_width-1) :=
  1340.             (1..row_width => true);
  1341.         end if;
  1342.         page_index := page_index - curr_page.width;
  1343.     end loop;
  1344.     end if;
  1345.  
  1346.     h := h + x_offset;
  1347. end;
  1348.  
  1349. ---------------------------------------------------------------------------
  1350. --|                                    |--
  1351. --| Put_rule_box                            |--
  1352. --|                                    |--
  1353. ---------------------------------------------------------------------------
  1354. --|                                    |--
  1355. --| Description:    Put a rule box on the page.                |--
  1356. --|                                    |--
  1357. ---------------------------------------------------------------------------
  1358. procedure put_rule_box is
  1359.  
  1360. x_pos : integer;
  1361. y_pos : integer;
  1362.  
  1363. x_offset : integer;
  1364. y_offset : integer;
  1365.  
  1366. page_index : integer;
  1367. row_count  : integer;
  1368. row_width  : integer;
  1369.  
  1370. begin
  1371.     x_pos := dvi_to_pixel (h) + integer(resolution*magstep);
  1372.     y_pos := dvi_to_pixel (v) + integer(resolution*magstep);
  1373.  
  1374.     y_offset := get_4byte;
  1375.     x_offset := get_4byte;
  1376.     
  1377.     if (x_offset > 0)
  1378.     and (y_offset > 0) then
  1379.     page_index := (y_pos-1)*curr_page.width + x_pos;
  1380.     row_count := dvi_to_pixel (y_offset);
  1381.     row_width := dvi_to_pixel (x_offset);
  1382.     
  1383.     if (row_count < 1) then row_count := 1; end if;
  1384.     if (row_width < 1) then row_width := 1; end if;
  1385.     
  1386.     for i in 1..row_count loop
  1387.         if (row_width = 1) then
  1388.         curr_page.bits(page_index) := true;
  1389.         else
  1390.         curr_page.bits(page_index..page_index+row_width-1) :=
  1391.             (1..row_width => true);
  1392.         end if;
  1393.         page_index := page_index - curr_page.width;
  1394.     end loop;
  1395.     end if;
  1396. end;
  1397.  
  1398. ---------------------------------------------------------------------------
  1399. --|                                    |--
  1400. --| Build_page                                |--
  1401. --|                                    |--
  1402. ---------------------------------------------------------------------------
  1403. --|                                    |--
  1404. --| Parameters:        1. Pointer to page.                    |--
  1405. --|                                    |--
  1406. --| Description:    Build a bitmap representation of current page of    |--
  1407. --|            DVI file. Next byte of DVI file should be BOP    |--
  1408. --|            command.                        |--
  1409. --|                                    |--
  1410. ---------------------------------------------------------------------------
  1411. procedure build_page (
  1412.     page : in page_ptr) is
  1413.  
  1414. temp : stack_ptr;
  1415.  
  1416. begin
  1417. --|
  1418. --| Check for valid page start.
  1419. --|
  1420.     if (get_byte /= bop) then
  1421.     put_line ("Invalid DVI file. Can't find BOP.");
  1422.     sys_exit;
  1423.     end if;
  1424. --|
  1425. --| Set to start state.
  1426. --|
  1427.     curr_page := page;
  1428.     
  1429.     h := 0;
  1430.     v := 0;
  1431.     w := 0;
  1432.     x := 0;
  1433.     y := 0;
  1434.     z := 0;
  1435.     
  1436.     while (stack_head /= null) loop
  1437.     temp := stack_head;
  1438.     stack_head := stack_head.next;
  1439.     free (temp);
  1440.     end loop;
  1441.     
  1442.     curr_font := null;
  1443. --|
  1444. --| Trash BOP parameters
  1445. --|
  1446.     for i in 1..11 loop
  1447.     trash := get_4byte;
  1448.     end loop;
  1449. --|
  1450. --| Main command loop
  1451. --|
  1452.     loop
  1453.     command := get_byte;
  1454.     case command is
  1455.     
  1456.         when set_char_0..set_char_127 => set_character (command);
  1457.  
  1458.         when set1 => set_character (get_byte);
  1459.         when set2 => set_character (get_2byte);
  1460.         when set3 => set_character (get_3byte);
  1461.         when set4 => set_character (get_4byte);
  1462.         
  1463.         when set_rule => set_rule_box;
  1464.         
  1465.         when put1 => put_character (get_byte);
  1466.         when put2 => put_character (get_2byte);
  1467.         when put3 => put_character (get_3byte);
  1468.         when put4 => put_character (get_4byte);
  1469.         
  1470.         when put_rule => put_rule_box;
  1471.         
  1472.         when nop => null;
  1473.         when eop => exit;
  1474.         when push => push_stack;
  1475.         when pop  => pop_stack;
  1476.         
  1477.         when right1 => h := h + get_s_byte;
  1478.         when right2 => h := h + get_s_2byte;
  1479.         when right3 => h := h + get_s_3byte;
  1480.         when right4 => h := h + get_4byte;
  1481.         
  1482.         when w0 => h := h + w;
  1483.         when w1 => w := get_s_byte;  h := h + w;
  1484.         when w2 => w := get_s_2byte; h := h + w;
  1485.         when w3 => w := get_s_3byte; h := h + w;
  1486.         when w4 => w := get_4byte;   h := h + w;
  1487.  
  1488.         when x0 => h := h + x;
  1489.         when x1 => x := get_s_byte;  h := h + x;
  1490.         when x2 => x := get_s_2byte; h := h + x;
  1491.         when x3 => x := get_s_3byte; h := h + x;
  1492.         when x4 => x := get_4byte;   h := h + x;
  1493.         
  1494.         when down1 => v := v + get_s_byte;
  1495.         when down2 => v := v + get_s_2byte;
  1496.         when down3 => v := v + get_s_3byte;
  1497.         when down4 => v := v + get_4byte;
  1498.         
  1499.         when y0 => v := v + y;
  1500.         when y1 => y := get_s_byte;  v := v + y;
  1501.         when y2 => y := get_s_2byte; v := v + y;
  1502.         when y3 => y := get_s_3byte; v := v + y;
  1503.         when y4 => y := get_4byte;   v := v + y;
  1504.  
  1505.         when z0 => v := v + z;
  1506.         when z1 => z := get_s_byte;  v := v + z;
  1507.         when z2 => z := get_s_2byte; v := v + z;
  1508.         when z3 => z := get_s_3byte; v := v + z;
  1509.         when z4 => z := get_4byte;   v := v + z;
  1510.         
  1511.         when fnt_num_0..fnt_num_63 => set_font (command - fnt_num_0);
  1512.         
  1513.         when fnt1 => set_font (get_byte);
  1514.         when fnt2 => set_font (get_2byte);
  1515.         when fnt3 => set_font (get_3byte);
  1516.         when fnt4 => set_font (get_4byte);
  1517.         
  1518.         when xxx1 => do_special (get_byte);
  1519.         when xxx2 => do_special (get_2byte);
  1520.         when xxx3 => do_special (get_3byte);
  1521.         when xxx4 => do_special (get_4byte);
  1522.         
  1523.         when fnt_def1 => trash_fnt_def (get_byte);
  1524.         when fnt_def2 => trash_fnt_def (get_2byte);
  1525.         when fnt_def3 => trash_fnt_def (get_3byte);
  1526.         when fnt_def4 => trash_fnt_def (get_4byte);
  1527.  
  1528.         when others =>
  1529.         put_line ("Invalid command while setting page.");
  1530.         sys_exit (16#1000002c#);
  1531.     end case;
  1532.     end loop;
  1533. end;
  1534.  
  1535. end;
  1536. $ eod
  1537. $ checksum [.src]dvi_translate.ada
  1538. $ if checksum$checksum .nes. "947875448" then write sys$output -
  1539.     "    ******Checksum error for file [.src]dvi_translate.ada******"
  1540.  
  1541.  
  1542.