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

  1. Article 100 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 3 of 3)
  7. Message-ID: <2809@ncoast.UUCP>
  8. Date: 7 Jul 87 01:48:48 GMT
  9. Date-Received: 8 Jul 87 03:35:38 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Lines: 1682
  12. Approved: allbery@ncoast.UUCP
  13. X-Archive: comp.sources.misc/8707/9
  14.  
  15. $ write sys$output "Creating [.src]dvi_translate_.ada"
  16. $ create [.src]dvi_translate_.ada
  17. $ deck
  18. ---------------------------------------------------------------------------
  19. --|                                    |--
  20. --| Title:  Dvi_translate                        |--
  21. --| Date:   12-JUN-1987                            |--
  22. --| Name:   Randy Buckland                        |--
  23. --|                                    |--
  24. --| Purpose:    Read and translate DVI commands into bitmap.        |--
  25. --|                                    |--
  26. ---------------------------------------------------------------------------
  27. --|                                    |--
  28. --| Revision History                            |--
  29. --|                                    |--
  30. --| Who        Date    Description                    |--
  31. --| ---        ----    -----------                    |--
  32. --| rcb        12-JUN-1987    New file.                    |--
  33. --|                                    |--
  34. ---------------------------------------------------------------------------
  35. --|                                    |--
  36. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  37. --| Written by Randy Buckland. Not derived from licensed software.    |--
  38. --|                                    |--
  39. --| Permission is granted to anyone to use this software for any    |--
  40. --| purpose on any computer system, and to redistribute it freely,    |--
  41. --| subject to the following restrictions.                |--
  42. --|                                    |--
  43. --| 1. Research Triangle Institute supplies this software "as is",    |--
  44. --|    without any warranty. The author and the Institute do not    |--
  45. --|    accept any responsibility for any damage caused by use or    |--
  46. --|    mis-use of this program.                    |--
  47. --| 2. The copyright notice must remain a part of all sources files.    |--
  48. --| 3. This software may not be sold in any fashion.            |--
  49. --|                                    |--
  50. ---------------------------------------------------------------------------
  51. with dvi_def;
  52. use  dvi_def;
  53.  
  54. package dvi_translate is
  55.  
  56. ---------------------------------------------------------------------------
  57. --|                                    |--
  58. --| Routine definitions.                        |--
  59. --|                                    |--
  60. ---------------------------------------------------------------------------
  61. procedure build_page (
  62.     page : in page_ptr);
  63.  
  64. end;
  65. $ eod
  66. $ checksum [.src]dvi_translate_.ada
  67. $ if checksum$checksum .nes. "1813187772" then write sys$output -
  68.     "    ******Checksum error for file [.src]dvi_translate_.ada******"
  69. $ write sys$output "Creating [.src]font.ada"
  70. $ create [.src]font.ada
  71. $ deck
  72. ---------------------------------------------------------------------------
  73. --|                                    |--
  74. --| Title:  Font                            |--
  75. --| Date:   30-OCT-1986                            |--
  76. --| Name:   Randy Buckland                        |--
  77. --|                                    |--
  78. --| Purpose:    Display a font picture                    |--
  79. --|                                    |--
  80. ---------------------------------------------------------------------------
  81. --|                                    |--
  82. --| Revision History                            |--
  83. --|                                    |--
  84. --| Who        Date    Description                    |--
  85. --| ---        ----    -----------                    |--
  86. --| rcb        30-OCT-1986    New file.                    |--
  87. --| rcb        23-JUN-1987    Modify to use version 2 I/O code.        |--
  88. --|                                    |--
  89. ---------------------------------------------------------------------------
  90. --|                                    |--
  91. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  92. --| Written by Randy Buckland. Not derived from licensed software.    |--
  93. --|                                    |--
  94. --| Permission is granted to anyone to use this software for any    |--
  95. --| purpose on any computer system, and to redistribute it freely,    |--
  96. --| subject to the following restrictions.                |--
  97. --|                                    |--
  98. --| 1. Research Triangle Institute supplies this software "as is",    |--
  99. --|    without any warranty. The author and the Institute do not    |--
  100. --|    accept any responsibility for any damage caused by use or    |--
  101. --|    mis-use of this program.                    |--
  102. --| 2. The copyright notice must remain a part of all sources files.    |--
  103. --| 3. This software may not be sold in any fashion.            |--
  104. --|                                    |--
  105. ---------------------------------------------------------------------------
  106. with font_def, font_io, uis, text_io, cli, str, condition_handling, sys;
  107. use  font_def, font_io, uis, text_io, cli, str, condition_handling, sys;
  108.  
  109. with starlet, system, tasking_services;
  110. use  starlet, system, tasking_services;
  111.  
  112. procedure font is
  113.  
  114. ---------------------------------------------------------------------------
  115. --|                                    |--
  116. --| Static variables.                            |--
  117. --|                                    |--
  118. ---------------------------------------------------------------------------
  119. type terminator is (up, down, done);
  120.  
  121. term      : terminator;
  122. term_chan : channel_type;
  123. status    : cond_value_type;
  124.  
  125. chars : char_set;
  126. char  : integer;
  127.  
  128. display : display_type;
  129. window  : window_type;
  130.  
  131. x_mag : float;
  132. y_mag : float;
  133.  
  134. font_file : d_string;
  135.  
  136. ---------------------------------------------------------------------------
  137. --|                                    |--
  138. --| Get_command                                |--
  139. --|                                    |--
  140. ---------------------------------------------------------------------------
  141. --|                                    |--
  142. --| Parameters:        1. Command code.                    |--
  143. --|                                    |--
  144. --| Description:    Get bytes from the terminal and see if they        |--
  145. --|            form a known command.                |--
  146. --|                                    |--
  147. ---------------------------------------------------------------------------
  148. procedure get_command (
  149.     term : in out terminator) is
  150.  
  151. trash : integer;
  152.  
  153. function get_char
  154.     return integer is
  155.  
  156. code   : integer := 0;
  157. status : cond_value_type;
  158.  
  159. begin
  160.     task_qiow (
  161.     status => status,
  162.     chan   => term_chan,
  163.     func   => io_readvblk or io_m_noecho,
  164.     p1     => to_unsigned_longword (code'address),
  165.     p2     => 1);
  166.     return code;
  167. end;    
  168.  
  169. begin
  170.     loop
  171.     case get_char is
  172.         when 26 => term := done; exit;
  173.         when 27 =>
  174.         case get_char is
  175.             when 91 =>
  176.             case get_char is
  177.                 when 65 => term := up;        exit;
  178.                 when 66 => term := down;      exit;
  179.                 when others => put_line ("Invalid command.");
  180.             end case;
  181.             when others => put_line ("Invalid command.");
  182.         end case;
  183.         when others => put_line ("Invalid command.");
  184.     end case;
  185.     end loop;
  186. end;
  187.  
  188. ---------------------------------------------------------------------------
  189. --|                                    |--
  190. --| Main program.                            |--
  191. --|                                    |--
  192. ---------------------------------------------------------------------------
  193. begin
  194. --|
  195. --| Open channel to terminal
  196. --|
  197.     assign (status, "tt:", term_chan);
  198.     if not success(status) then
  199.     sys_exit (status);
  200.     end if;
  201.  
  202.     put_line ("Font display");
  203. --|
  204. --| Get parameters
  205. --|
  206.     get_value (status, "font_file", font_file);
  207.     chars := load_font (value (font_file));
  208.     
  209.     display := create_display (0.0, 0.0, 11.0, 22.0, 11.0, 22.0);
  210.     window  := create_window (display, "sys$workstation", "Font display");
  211. --|
  212. --| Find first character
  213. --|
  214.     char := 0;
  215.     while (chars(char) = null) and (char < 256) loop
  216.     char := char + 1;
  217.     end loop;
  218. --|
  219. --| Main program loop
  220. --|
  221.     loop
  222.     erase (display);
  223.  
  224.     x_mag := float(chars(char).width)/float(chars(char).height);
  225.     if (x_mag > 1.0) then x_mag := 1.0; end if;
  226.  
  227.     y_mag := float(chars(char).height)/float(chars(char).width);
  228.     if (y_mag > 1.0) then y_mag := 1.0; end if;
  229.  
  230.     image (display, 0, 1.0, 12.0, 9.0*x_mag+1.0, 9.0*y_mag+12.0, 
  231.         chars(char).width, chars(char).height, 1, 
  232.         chars(char).bits'address);
  233.         
  234.     image_dc(window, 0, 10, 10, chars(char).width+10, 
  235.         chars(char).height+10, chars(char).width, 
  236.         chars(char).height, 1, chars(char).bits'address);
  237.  
  238.     put_line ("Character" & integer'image(char));
  239.     get_command(term);
  240.     case term is
  241.         
  242.         when done => exit;
  243.         
  244.         when down =>
  245.         for i in reverse 0..char-1 loop
  246.             if (chars(i) /= null) then
  247.             char := i;
  248.             exit;
  249.             end if;
  250.         end loop;
  251.             
  252.         when up =>
  253.         for i in char+1..255 loop
  254.             if (chars(i) /= null) then
  255.             char := i;
  256.             exit;
  257.             end if;
  258.         end loop;
  259.             
  260.         when others =>
  261.         put_line ("Unknown command");
  262.         
  263.     end case;
  264.     end loop;
  265. end;
  266. $ eod
  267. $ checksum [.src]font.ada
  268. $ if checksum$checksum .nes. "1782057255" then write sys$output -
  269.     "    ******Checksum error for file [.src]font.ada******"
  270. $ write sys$output "Creating [.src]font_def_.ada"
  271. $ create [.src]font_def_.ada
  272. $ deck
  273. ---------------------------------------------------------------------------
  274. --|                                    |--
  275. --| Title:  Font_def                            |--
  276. --| Date:   28-AUG-1986                            |--
  277. --| Name:   Randy Buckland                        |--
  278. --|                                    |--
  279. --| Purpose:    Define internal font structures.            |--
  280. --|                                    |--
  281. ---------------------------------------------------------------------------
  282. --|                                    |--
  283. --| Revision History                            |--
  284. --|                                    |--
  285. --| Who        Date    Description                    |--
  286. --| ---        ----    -----------                    |--
  287. --| rcb        28-AUG-1986    New file.                    |--
  288. --| rcb         2-JUN-1987    Change storage for V2 previewer.        |--
  289. --|                                    |--
  290. ---------------------------------------------------------------------------
  291. --|                                    |--
  292. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  293. --| Written by Randy Buckland. Not derived from licensed software.    |--
  294. --|                                    |--
  295. --| Permission is granted to anyone to use this software for any    |--
  296. --| purpose on any computer system, and to redistribute it freely,    |--
  297. --| subject to the following restrictions.                |--
  298. --|                                    |--
  299. --| 1. Research Triangle Institute supplies this software "as is",    |--
  300. --|    without any warranty. The author and the Institute do not    |--
  301. --|    accept any responsibility for any damage caused by use or    |--
  302. --|    mis-use of this program.                    |--
  303. --| 2. The copyright notice must remain a part of all sources files.    |--
  304. --| 3. This software may not be sold in any fashion.            |--
  305. --|                                    |--
  306. ---------------------------------------------------------------------------
  307. with unchecked_deallocation;
  308.  
  309. package font_def is
  310.  
  311. ---------------------------------------------------------------------------
  312. --|                                    |--
  313. --| Font type definitions.                        |--
  314. --|                                    |--
  315. ---------------------------------------------------------------------------
  316. type pixel_array is array (integer range <>) of boolean;
  317. pragma pack (pixel_array);
  318.  
  319. type char_array (size : integer) is record
  320.     height   : integer;
  321.     width    : integer;
  322.     x_offset : integer;
  323.     y_offset : integer;
  324.     x_delta  : float;
  325.     bits     : pixel_array (1..size);
  326. end record;
  327.  
  328. type char_ptr is access char_array;
  329. type char_set is array (0..255) of char_ptr;
  330.  
  331. procedure free is new unchecked_deallocation (char_array, char_ptr);
  332.  
  333. type font_ptr is access char_set;
  334. procedure free is new unchecked_deallocation (char_set, font_ptr);
  335.  
  336. end;
  337. $ eod
  338. $ checksum [.src]font_def_.ada
  339. $ if checksum$checksum .nes. "1392846240" then write sys$output -
  340.     "    ******Checksum error for file [.src]font_def_.ada******"
  341. $ write sys$output "Creating [.src]font_io_.ada"
  342. $ create [.src]font_io_.ada
  343. $ deck
  344. ---------------------------------------------------------------------------
  345. --|                                    |--
  346. --| Title:  Font_io                            |--
  347. --| Date:   28-AUG-1986                            |--
  348. --| Name:   Randy Buckland                        |--
  349. --|                                    |--
  350. --| Purpose:    Handle all I/O to font files.                |--
  351. --|                                    |--
  352. ---------------------------------------------------------------------------
  353. --|                                    |--
  354. --| Revision History                            |--
  355. --|                                    |--
  356. --| Who        Date    Description                    |--
  357. --| ---        ----    -----------                    |--
  358. --| rcb        28-AUG-1986    New file.                    |--
  359. --| rcb         2-JUN-1987    Modified for version 2 previewer.        |--
  360. --|                                    |--
  361. ---------------------------------------------------------------------------
  362. --|                                    |--
  363. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  364. --| Written by Randy Buckland. Not derived from licensed software.    |--
  365. --|                                    |--
  366. --| Permission is granted to anyone to use this software for any    |--
  367. --| purpose on any computer system, and to redistribute it freely,    |--
  368. --| subject to the following restrictions.                |--
  369. --|                                    |--
  370. --| 1. Research Triangle Institute supplies this software "as is",    |--
  371. --|    without any warranty. The author and the Institute do not    |--
  372. --|    accept any responsibility for any damage caused by use or    |--
  373. --|    mis-use of this program.                    |--
  374. --| 2. The copyright notice must remain a part of all sources files.    |--
  375. --| 3. This software may not be sold in any fashion.            |--
  376. --|                                    |--
  377. ---------------------------------------------------------------------------
  378. with font_def;
  379. use  font_def;
  380.  
  381. package font_io is
  382.  
  383. ---------------------------------------------------------------------------
  384. --|                                    |--
  385. --| Routine defintions.                            |--
  386. --|                                    |--
  387. ---------------------------------------------------------------------------
  388. function load_font (
  389.     name : in string)
  390.     return char_set;
  391.  
  392. end;
  393. $ eod
  394. $ checksum [.src]font_io_.ada
  395. $ if checksum$checksum .nes. "2816" then write sys$output -
  396.     "    ******Checksum error for file [.src]font_io_.ada******"
  397. $ write sys$output "Creating [.src]font_io_pk.ada"
  398. $ create [.src]font_io_pk.ada
  399. $ deck
  400. ---------------------------------------------------------------------------
  401. --|                                    |--
  402. --| Title:  Font_io_pk                            |--
  403. --| Date:   28-AUG-1986                            |--
  404. --| Name:   Randy Buckland                        |--
  405. --|                                    |--
  406. --| Purpose:    Handle all I/O to PK format font files.            |--
  407. --|                                    |--
  408. ---------------------------------------------------------------------------
  409. --|                                    |--
  410. --| Revision History                            |--
  411. --|                                    |--
  412. --| Who        Date    Description                    |--
  413. --| ---        ----    -----------                    |--
  414. --| rcb        28-AUG-1986    New file.                    |--
  415. --| rcb         7-MAY-1987    Modified GF font reader to be PK font reader.    |--
  416. --| rcb         2-JUN-1987    Modified for version 2 of previewer        |--
  417. --|                                    |--
  418. ---------------------------------------------------------------------------
  419. --|                                    |--
  420. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  421. --| Written by Randy Buckland. Not derived from licensed software.    |--
  422. --|                                    |--
  423. --| Permission is granted to anyone to use this software for any    |--
  424. --| purpose on any computer system, and to redistribute it freely,    |--
  425. --| subject to the following restrictions.                |--
  426. --|                                    |--
  427. --| 1. Research Triangle Institute supplies this software "as is",    |--
  428. --|    without any warranty. The author and the Institute do not    |--
  429. --|    accept any responsibility for any damage caused by use or    |--
  430. --|    mis-use of this program.                    |--
  431. --| 2. The copyright notice must remain a part of all sources files.    |--
  432. --| 3. This software may not be sold in any fashion.            |--
  433. --|                                    |--
  434. ---------------------------------------------------------------------------
  435. with system, condition_handling, sys, text_io, ots;
  436. use  system, condition_handling, sys, text_io, ots;
  437.  
  438. with sequential_io;
  439.  
  440. package body font_io is
  441.  
  442. ---------------------------------------------------------------------------
  443. --|                                    |--
  444. --| Constants                                |--
  445. --|                                    |--
  446. ---------------------------------------------------------------------------
  447. --|
  448. --| PK commands
  449. --|
  450. preamble  : constant := 247;
  451. postamble : constant := 245;
  452. pk_format : constant := 89;
  453. ---------------------------------------------------------------------------
  454. --|                                    |--
  455. --| Static variables.                            |--
  456. --|                                    |--
  457. ---------------------------------------------------------------------------
  458. type font_node is array(1..512) of unsigned_byte;
  459. package block_io is new sequential_io (font_node); use block_io;
  460.  
  461. font_file : block_io.file_type;
  462. --font_rec  : block_io.count;
  463. font_byte : integer;
  464. font_buff : font_node;
  465.  
  466. low_nibble  : boolean;
  467. high_nibble : integer;
  468.  
  469. dyn_f         : integer;        -- Dynamic packing factor.
  470. black_first  : boolean;        -- Start character with black pixels
  471. repeat_count : integer := 0;    -- Number of repeats for current row.
  472.  
  473. ---------------------------------------------------------------------------
  474. --|                                    |--
  475. --| Get_byte                                |--
  476. --|                                    |--
  477. ---------------------------------------------------------------------------
  478. --|                                    |--
  479. --| Description:    Return a byte from the file.            |--
  480. --|                                    |--
  481. ---------------------------------------------------------------------------
  482. function get_byte
  483.     return integer is
  484.  
  485. begin
  486.     font_byte := font_byte + 1;
  487.     if (font_byte > 512) then
  488.     font_byte := 1;
  489. --    font_rec := font_rec + 1;
  490.     read (font_file, font_buff);
  491.     end if;
  492.     
  493.     return integer (font_buff(font_byte));
  494. end;
  495.  
  496. ---------------------------------------------------------------------------
  497. --|                                    |--
  498. --| Get_2byte                                |--
  499. --|                                    |--
  500. ---------------------------------------------------------------------------
  501. --|                                    |--
  502. --| Description:    Return a 2 byte value from the file.        |--
  503. --|                                    |--
  504. ---------------------------------------------------------------------------
  505. function get_2byte
  506.     return integer is
  507.  
  508. temp : integer;
  509.  
  510. begin
  511.     temp := get_byte;
  512.     temp := temp*256 + get_byte;
  513.     return temp;
  514. end;
  515.  
  516. ---------------------------------------------------------------------------
  517. --|                                    |--
  518. --| Get_3byte                                |--
  519. --|                                    |--
  520. ---------------------------------------------------------------------------
  521. --|                                    |--
  522. --| Description:    Return a 3 byte value from the file.        |--
  523. --|                                    |--
  524. ---------------------------------------------------------------------------
  525. function get_3byte
  526.     return integer is
  527.  
  528. temp : integer;
  529.  
  530. begin
  531.     temp := get_byte;
  532.     temp := temp*256 + get_byte;
  533.     temp := temp*256 + get_byte;
  534.     return temp;
  535. end;
  536.  
  537. ---------------------------------------------------------------------------
  538. --|                                    |--
  539. --| Get_4byte                                |--
  540. --|                                    |--
  541. ---------------------------------------------------------------------------
  542. --|                                    |--
  543. --| Description:    Return a 4 byte value from the file.        |--
  544. --|                                    |--
  545. ---------------------------------------------------------------------------
  546. function get_4byte
  547.     return integer is
  548.  
  549. temp : bit_array_32;
  550.  
  551. begin
  552.     temp(24..31) := to_bit_array_8 (unsigned_byte (get_byte));
  553.     temp(16..23) := to_bit_array_8 (unsigned_byte (get_byte));
  554.     temp(8..15) := to_bit_array_8 (unsigned_byte (get_byte));
  555.     temp(0..7) := to_bit_array_8 (unsigned_byte (get_byte));
  556.     return integer (to_unsigned_longword (temp));
  557. end;
  558.  
  559. ---------------------------------------------------------------------------
  560. --|                                    |--
  561. --| Get_nibble                                |--
  562. --|                                    |--
  563. ---------------------------------------------------------------------------
  564. --|                                    |--
  565. --| Description:    Return the next nibble from the file.        |--
  566. --|                                    |--
  567. ---------------------------------------------------------------------------
  568. function get_nibble
  569.     return integer is
  570.  
  571. temp : integer;
  572.  
  573. begin
  574.     if not low_nibble then
  575.     low_nibble := true;
  576.     return high_nibble;
  577.     else
  578.     low_nibble := false;
  579.     temp := get_byte;
  580.     high_nibble := temp mod 16;
  581.     return (temp / 16);
  582.     end if;
  583. end;
  584.  
  585. ---------------------------------------------------------------------------
  586. --|                                    |--
  587. --| Get_run                                |--
  588. --|                                    |--
  589. ---------------------------------------------------------------------------
  590. --|                                    |--
  591. --| Description:    Get the next run count value from the file.        |--
  592. --|                                    |--
  593. ---------------------------------------------------------------------------
  594. function get_run 
  595.     return integer is
  596.  
  597. temp  : integer;
  598. count : integer := 0;
  599.  
  600. begin
  601.     temp := get_nibble;
  602.     if (temp = 0) then
  603.     loop
  604.         temp := get_nibble;
  605.         count := count + 1;
  606.         exit when (temp /= 0);
  607.     end loop;
  608.     for i in 1..count loop
  609.         temp := temp*16+get_nibble;
  610.     end loop;
  611.     return (temp - 15 + (13 - dyn_f)*16 + dyn_f);
  612.     else
  613.     if (temp <= dyn_f) then
  614.         return temp;
  615.     else
  616.         if (temp < 14) then
  617.         return ((temp - dyn_f - 1)*16 + get_nibble + dyn_f + 1);
  618.         else
  619.         if (repeat_count /= 0) then
  620.             put_line ("Second repeat count for a row");
  621.             sys_exit;
  622.         end if;
  623.         if (temp = 14) then
  624.             repeat_count := get_run;
  625.         else
  626.             repeat_count := 1;
  627.         end if;
  628.         return get_run;
  629.         end if;
  630.     end if;
  631.     end if;
  632. end;
  633.  
  634. ---------------------------------------------------------------------------
  635. --|                                    |--
  636. --| Get_bits                                |--
  637. --|                                    |--
  638. ---------------------------------------------------------------------------
  639. --|                                    |--
  640. --| Parameters:        1. Character array entry to get bits for.        |--
  641. --|                                    |--
  642. --| Description:    Get the bit image of a character.            |--
  643. --|                                    |--
  644. ---------------------------------------------------------------------------
  645. procedure get_bits (
  646.     char : in out char_array) is
  647.  
  648. line   : pixel_array (1..char.width);
  649. pixel  : boolean := not black_first;
  650. row    : integer := 1;
  651. count  : integer := 0;
  652.  
  653. bit_row   : bit_array_8;
  654. bit_count : integer := -1;
  655.  
  656. begin
  657. --|
  658. --| Check for a straight bitmap
  659. --|
  660.     if (dyn_f = 14) then
  661.     for row in 1..char.height loop
  662.         for column in 1..char.width loop
  663.         if (bit_count = -1) then
  664.             bit_row := to_bit_array_8 (unsigned_byte (get_byte));
  665.             bit_count := 7;
  666.         end if;
  667.         
  668.         char.bits((row-1)*char.width+column) := bit_row(bit_count);
  669.         bit_count := bit_count - 1;
  670.         end loop;
  671.     end loop;
  672. --|
  673. --| Get run-encoded character
  674. --|
  675.     else
  676.     while (row <= char.height) loop
  677.         repeat_count := 0;
  678.         for column in 1..char.width loop
  679.         if (count = 0) then
  680.             count := get_run;
  681.             pixel := not pixel;
  682.         end if;
  683.         
  684.         line(column) := pixel;
  685.         count := count - 1;
  686.         end loop;
  687.         for i in 0..repeat_count loop
  688.         char.bits((row-1)*char.width+1..row*char.width) := 
  689.             line(1..char.width);
  690.         row := row + 1;
  691.         end loop;
  692.     end loop;
  693.     end if;
  694. end;
  695.  
  696. ---------------------------------------------------------------------------
  697. --|                                    |--
  698. --| Load_font                                |--
  699. --|                                    |--
  700. ---------------------------------------------------------------------------
  701. --|                                    |--
  702. --| Parameters:        1. Name of font file.                |--
  703. --|                                    |--
  704. --| Description:    Read in font file and convert it to internal    |--
  705. --|            raster representation.                |--
  706. --|                                    |--
  707. ---------------------------------------------------------------------------
  708. function load_font (
  709.     name : in string)
  710.     return char_set is
  711.  
  712. new_chars : char_set := (others => null);   -- Output character array
  713.  
  714. design_size : integer;        -- Design size of font in points * 2e16
  715. hppp        : integer;        -- Horizontal pixels per point * 2e16
  716. vppp        : integer;        -- Vertical pixels per point * 2e16
  717. pix_ratio   : float;        -- Design size in pixels
  718.  
  719. size     : integer;        -- Size of a string/packet
  720. trash    : integer;        -- Any garbage value
  721. x_size   : integer;        -- Width of character
  722. y_size   : integer;        -- Height of character
  723. x_offset : integer;        -- Horizontal offset from top-left to reference
  724. y_offset : integer;        -- Vertical offset from top-left to reference
  725. char     : integer;        -- Character number.
  726. tfm      : integer;        -- TFM file width
  727.  
  728. begin
  729. --|
  730. --| Open font file
  731. --|
  732.     begin
  733.     put_line ("Opening font file " & name & ".");
  734.     open (font_file, in_file, "tex_vs_fonts:" & name);
  735. --    font_rec := 0;
  736.     font_byte := 512;
  737.     exception
  738.     when others =>
  739.         put_line ("Font file " & name & " not found.");
  740.         sys_exit;
  741.     end;
  742. --|
  743. --| Get and trash preamble
  744. --|
  745.     if      (get_byte /= preamble)
  746.     or else (get_byte /= pk_format) then
  747.     put_line ("File " & name & " is not PK file format.");
  748.     sys_exit;
  749.     end if;
  750.     
  751.     size := get_byte;
  752.     for i in 1..size loop
  753.     trash := get_byte;
  754.     end loop;
  755.     
  756.     design_size := get_4byte;
  757.     trash       := get_4byte;
  758.     hppp        := get_4byte;
  759.     vppp        := get_4byte;
  760.  
  761.     pix_ratio := (float(design_size) / 1048576.0) * 
  762.     (float(hppp) / 1048576.0);
  763. ---------------------------------------------------------------------------
  764. --|                                    |--
  765. --| Main character get loop.                        |--
  766. --|                                    |--
  767. ---------------------------------------------------------------------------
  768.     loop
  769.     trash := get_byte;
  770.     if (trash >= 240) then
  771.         loop
  772.         case trash is
  773.             when 240 => size := get_byte;
  774.             when 241 => size := get_2byte;
  775.             when 242 => size := get_3byte;
  776.             when 243 => size := get_4byte;
  777.             when 244 => size := 4;
  778.             when postamble => size := -1;
  779.             when others => size := 0;
  780.         end case;
  781.         for i in 1..size+1 loop
  782.             trash := get_byte;
  783.         end loop;
  784.         exit when (trash < 240) or (trash = postamble);
  785.         end loop;
  786.     end if;
  787.  
  788.     exit when (trash = postamble);
  789. --|
  790. --| Get character header
  791. --|
  792.     dyn_f := trash / 16;        -- Get dynamic packing factor
  793.     trash := trash mod 16;
  794.     
  795.     if (trash / 8 = 0) then        -- Get black first value
  796.         black_first := false;
  797.     else
  798.         black_first := true;
  799.     end if;
  800.     trash := trash mod 8;
  801.     
  802.     if (trash < 4) then        -- One byte parameters
  803.         size     := get_byte + ((trash mod 4)*256) - 8;
  804.         char     := get_byte;
  805.         tfm      := get_3byte;
  806.         trash    := get_byte;
  807.         x_size   := get_byte;
  808.         y_size   := get_byte;
  809.         x_offset := get_byte;
  810.         y_offset := get_byte;
  811.         
  812.         if (x_offset > 127) then x_offset := x_offset - 256; end if;
  813.         if (y_offset > 127) then y_offset := y_offset - 256; end if;
  814.  
  815.     elsif (trash = 7) then        -- Four byte parameters
  816.         size     := get_4byte - 28;
  817.         char     := get_4byte;
  818.         tfm      := get_4byte;
  819.         trash    := get_4byte;
  820.         trash    := get_4byte;
  821.         x_size   := get_4byte;
  822.         y_size   := get_4byte;
  823.         x_offset := get_4byte;
  824.         y_offset := get_4byte;
  825.     
  826.     else                -- Two byte parameters
  827.         size     := get_2byte + ((trash mod 4)*65536) - 13;
  828.         char     := get_byte;
  829.         tfm      := get_3byte;
  830.         trash    := get_2byte;
  831.         x_size   := get_2byte;
  832.         y_size   := get_2byte;
  833.         x_offset := get_2byte;
  834.         y_offset := get_2byte;
  835.         
  836.         if (x_offset > 32767) then x_offset := x_offset - 65536; end if;
  837.         if (y_offset > 32767) then y_offset := y_offset - 65536; end if;
  838.     end if;
  839. --|
  840. --| Create character
  841. --|
  842.     new_chars(char) := new char_array (y_size*x_size);
  843.     new_chars(char).height := y_size;
  844.     new_chars(char).width := x_size;
  845.     new_chars(char).x_offset := -x_offset;
  846.     new_chars(char).y_offset := y_offset - new_chars(char).height + 1;
  847.     new_chars(char).x_delta := (float(tfm) / 65536.0) * pix_ratio;
  848.     move5 (0, new_chars(char).bits'address, 0, (new_chars(char).size+7)/8,
  849.         new_chars(char).bits'address);
  850.     
  851.     low_nibble := true;
  852.     get_bits (new_chars(char).all);
  853.     end loop;
  854. --|
  855. --| Finish up
  856. --|
  857.     close (font_file);
  858.     return new_chars;
  859. end;
  860.  
  861. end;
  862. $ eod
  863. $ checksum [.src]font_io_pk.ada
  864. $ if checksum$checksum .nes. "155960583" then write sys$output -
  865.     "    ******Checksum error for file [.src]font_io_pk.ada******"
  866. $ write sys$output "Creating [.src]font_tasks.ada"
  867. $ create [.src]font_tasks.ada
  868. $ deck
  869. ---------------------------------------------------------------------------
  870. --|                                    |--
  871. --| Title:  Font_tasks                            |--
  872. --| Date:    2-JUN-1987                            |--
  873. --| Name:   Randy Buckland                        |--
  874. --|                                    |--
  875. --| Purpose:    Driving tasks for font manipulation.            |--
  876. --|                                    |--
  877. ---------------------------------------------------------------------------
  878. --|                                    |--
  879. --| Revision History                            |--
  880. --|                                    |--
  881. --| Who        Date    Description                    |--
  882. --| ---        ----    -----------                    |--
  883. --| rcb         2-JUN-1987    New file.                    |--
  884. --|                                    |--
  885. ---------------------------------------------------------------------------
  886. --|                                    |--
  887. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  888. --| Written by Randy Buckland. Not derived from licensed software.    |--
  889. --|                                    |--
  890. --| Permission is granted to anyone to use this software for any    |--
  891. --| purpose on any computer system, and to redistribute it freely,    |--
  892. --| subject to the following restrictions.                |--
  893. --|                                    |--
  894. --| 1. Research Triangle Institute supplies this software "as is",    |--
  895. --|    without any warranty. The author and the Institute do not    |--
  896. --|    accept any responsibility for any damage caused by use or    |--
  897. --|    mis-use of this program.                    |--
  898. --| 2. The copyright notice must remain a part of all sources files.    |--
  899. --| 3. This software may not be sold in any fashion.            |--
  900. --|                                    |--
  901. ---------------------------------------------------------------------------
  902. with font_io, str, text_io, sys;
  903. use  font_io, str, text_io, sys;
  904.  
  905. package body font_tasks is
  906.  
  907. ---------------------------------------------------------------------------
  908. --|                                    |--
  909. --| Static types and variables.                        |--
  910. --|                                    |--
  911. ---------------------------------------------------------------------------
  912. --|
  913. --| Font list types
  914. --|
  915. type font_node;
  916. type font_node_ptr is access font_node;
  917. type font_node is record
  918.     font_number : integer := 0;
  919.     font_name   : d_string;
  920.     font        : font_ptr := null;
  921.     next        : font_node_ptr := null;
  922. end record;
  923.  
  924. font_head : font_node_ptr := null;
  925. font_tail : font_node_ptr := null;
  926.  
  927. ---------------------------------------------------------------------------
  928. --|                                    |--
  929. --| Font_load                                |--
  930. --|                                    |--
  931. ---------------------------------------------------------------------------
  932. --|                                    |--
  933. --| Description:    Load a set of fonts in the background.        |--
  934. --|                                    |--
  935. ---------------------------------------------------------------------------
  936. task body font_load is
  937.  
  938. temp  : font_node_ptr;
  939. temp2 : font_ptr;
  940.  
  941. begin
  942.     loop
  943.     select
  944. --|
  945. --| Add new font to list
  946. --|
  947.         accept add_font (font_name : in string; font_number : in integer) do
  948.         temp := new font_node;
  949.         temp.font_number := font_number;
  950.         copy (temp.font_name, font_name);
  951.         if (font_head = null) then
  952.             font_head := temp;
  953.         else
  954.             font_tail.next := temp;
  955.         end if;
  956.         font_tail := temp;
  957.         end;
  958.     or
  959. --|
  960. --| Go get fonts
  961. --|
  962.         accept get_fonts;
  963.         exit;
  964.     or
  965.         terminate;
  966.     end select;
  967.     end loop;
  968. ---------------------------------------------------------------------------
  969. --|                                    |--
  970. --| Main loop to get all fonts.                        |--
  971. --|                                    |--
  972. ---------------------------------------------------------------------------
  973.     temp := font_head;
  974.     while (temp /= null) loop
  975.     temp2 := new char_set;
  976.     temp2.all := load_font (value (temp.font_name));
  977.     temp.font := temp2;
  978.     font_search.check_again;
  979.     temp := temp.next;
  980.     end loop;
  981.     font_search.load_done;
  982. end;
  983.  
  984. ---------------------------------------------------------------------------
  985. --|                                    |--
  986. --| Font_search                                |--
  987. --|                                    |--
  988. ---------------------------------------------------------------------------
  989. --|                                    |--
  990. --| Description:    Search for a font and see if it has been        |--
  991. --|            loaded yet.                        |--
  992. --|                                    |--
  993. ---------------------------------------------------------------------------
  994. task body font_search is
  995.  
  996. temp : font_node_ptr;
  997. done : boolean := false;
  998.  
  999. begin
  1000.     loop
  1001. --|
  1002. --| Accept status calls outside of a search.
  1003. --|
  1004.     select
  1005.         accept check_again;
  1006.     or
  1007.         accept load_done;
  1008.         done := true;
  1009.     or
  1010. --|
  1011. --| Search for a font by number
  1012. --|
  1013.         accept find_font (font_number : in integer; font : out font_ptr) do
  1014.         temp := font_head;
  1015.         while (temp /= null) loop
  1016.             exit when (temp.font_number = font_number);
  1017.             temp := temp.next;
  1018.         end loop;
  1019.         
  1020.         if (temp = null) then
  1021.             put_line ("Font" & integer'image(font_number) & 
  1022.             " not found.");
  1023.             sys_exit;
  1024.         end if;
  1025. --|
  1026. --| Either return font pointer or wait for it to be loaded.
  1027. --|
  1028.         if (temp.font = null) then
  1029.             loop
  1030.             if (done) then
  1031.                 put_line ("Font not being loaded");
  1032.                 sys_exit;
  1033.             end if;
  1034.             
  1035.             select
  1036.                 accept check_again;
  1037.             or
  1038.                 accept load_done;
  1039.                 done := true;
  1040.             or 
  1041.                 terminate;
  1042.             end select;
  1043.             
  1044.             exit when (temp.font /= null);
  1045.             end loop;
  1046.         end if;
  1047.         font := temp.font;
  1048.         end;
  1049.     or
  1050.         terminate;
  1051.     end select;
  1052.     end loop;
  1053. end;
  1054.  
  1055. end;
  1056. $ eod
  1057. $ checksum [.src]font_tasks.ada
  1058. $ if checksum$checksum .nes. "1429518831" then write sys$output -
  1059.     "    ******Checksum error for file [.src]font_tasks.ada******"
  1060. $ write sys$output "Creating [.src]font_tasks_.ada"
  1061. $ create [.src]font_tasks_.ada
  1062. $ deck
  1063. ---------------------------------------------------------------------------
  1064. --|                                    |--
  1065. --| Title:  Font_tasks                            |--
  1066. --| Date:    2-JUN-1987                            |--
  1067. --| Name:   Randy Buckland                        |--
  1068. --|                                    |--
  1069. --| Purpose:    Driving tasks for font manipulation.            |--
  1070. --|                                    |--
  1071. ---------------------------------------------------------------------------
  1072. --|                                    |--
  1073. --| Revision History                            |--
  1074. --|                                    |--
  1075. --| Who        Date    Description                    |--
  1076. --| ---        ----    -----------                    |--
  1077. --| rcb         2-JUN-1987    New file.                    |--
  1078. --|                                    |--
  1079. ---------------------------------------------------------------------------
  1080. --|                                    |--
  1081. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  1082. --| Written by Randy Buckland. Not derived from licensed software.    |--
  1083. --|                                    |--
  1084. --| Permission is granted to anyone to use this software for any    |--
  1085. --| purpose on any computer system, and to redistribute it freely,    |--
  1086. --| subject to the following restrictions.                |--
  1087. --|                                    |--
  1088. --| 1. Research Triangle Institute supplies this software "as is",    |--
  1089. --|    without any warranty. The author and the Institute do not    |--
  1090. --|    accept any responsibility for any damage caused by use or    |--
  1091. --|    mis-use of this program.                    |--
  1092. --| 2. The copyright notice must remain a part of all sources files.    |--
  1093. --| 3. This software may not be sold in any fashion.            |--
  1094. --|                                    |--
  1095. ---------------------------------------------------------------------------
  1096. with font_def;
  1097. use  font_def;
  1098.  
  1099. package font_tasks is
  1100.  
  1101. ---------------------------------------------------------------------------
  1102. --|                                    |--
  1103. --| Task definitions.                            |--
  1104. --|                                    |--
  1105. ---------------------------------------------------------------------------
  1106. task font_load is
  1107.     pragma priority(5);
  1108.     entry add_font (font_name : in string; font_number : in integer);
  1109.     entry get_fonts;
  1110. end;
  1111.  
  1112. task font_search is
  1113.     pragma priority(6);
  1114.     entry find_font (font_number : in integer; font : out font_ptr);
  1115.     entry check_again;
  1116.     entry load_done;
  1117. end;
  1118.  
  1119. end;
  1120. $ eod
  1121. $ checksum [.src]font_tasks_.ada
  1122. $ if checksum$checksum .nes. "823410064" then write sys$output -
  1123.     "    ******Checksum error for file [.src]font_tasks_.ada******"
  1124. $ write sys$output "Creating [.src]preview.ada"
  1125. $ create [.src]preview.ada
  1126. $ deck
  1127. ---------------------------------------------------------------------------
  1128. --|                                    |--
  1129. --| Title:  Preview                            |--
  1130. --| Date:    3-SEP-1986                            |--
  1131. --| Name:   Randy Buckland                        |--
  1132. --|                                    |--
  1133. --| Purpose:    Preview a dvi file on a vaxstation.            |--
  1134. --|                                    |--
  1135. ---------------------------------------------------------------------------
  1136. --|                                    |--
  1137. --| Revision History                            |--
  1138. --|                                    |--
  1139. --| Who        Date    Description                    |--
  1140. --| ---        ----    -----------                    |--
  1141. --| rcb         3-SEP-1986    New file.                    |--
  1142. --| rcb        20-NOV-1986    Changed shift size to half of visable area.    |--
  1143. --| rcb         2-JUN-1987    Modified to version 2 previewer.        |--
  1144. --|                                    |--
  1145. ---------------------------------------------------------------------------
  1146. --|                                    |--
  1147. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  1148. --| Written by Randy Buckland. Not derived from licensed software.    |--
  1149. --|                                    |--
  1150. --| Permission is granted to anyone to use this software for any    |--
  1151. --| purpose on any computer system, and to redistribute it freely,    |--
  1152. --| subject to the following restrictions.                |--
  1153. --|                                    |--
  1154. --| 1. Research Triangle Institute supplies this software "as is",    |--
  1155. --|    without any warranty. The author and the Institute do not    |--
  1156. --|    accept any responsibility for any damage caused by use or    |--
  1157. --|    mis-use of this program.                    |--
  1158. --| 2. The copyright notice must remain a part of all sources files.    |--
  1159. --| 3. This software may not be sold in any fashion.            |--
  1160. --|                                    |--
  1161. ---------------------------------------------------------------------------
  1162. with cli, str, text_io, integer_text_io, condition_handling, float_text_io;
  1163. use  cli, str, text_io, integer_text_io, condition_handling, float_text_io;
  1164.  
  1165. with dvi_tasks, dvi_def, uis, starlet, tasking_services, system, sys;
  1166. use  dvi_tasks, dvi_def, uis, starlet, tasking_services, system, sys;
  1167.  
  1168. procedure preview is
  1169. pragma priority (7);
  1170.  
  1171. ---------------------------------------------------------------------------
  1172. --|                                    |--
  1173. --| Static variables                            |--
  1174. --|                                    |--
  1175. ---------------------------------------------------------------------------
  1176. type terminator is (up, down, left, right, nxt_page, prv_page, goto_page, 
  1177.     grid, done);
  1178.  
  1179. term      : terminator;
  1180. term_chan : channel_type;
  1181. status    : cond_value_type;
  1182. in_line   : d_string;
  1183. --|
  1184. --| Cli variables
  1185. --|
  1186. dvi_file : d_string;
  1187. temp     : d_string;
  1188. magstep  : integer;
  1189. magnify  : float := 1.0;
  1190. last     : natural;
  1191. --|
  1192. --| Display variables
  1193. --|
  1194. display_page  : page_ptr := null;
  1195. curr_page_num : integer := 0;
  1196. next_page_num : integer := 0;
  1197. page_count    : integer := 0;
  1198. redisplay     : boolean := true;
  1199. display       : uis.display_type;
  1200. window        : uis.window_type;
  1201.  
  1202. grid_active : boolean := false;
  1203. grid_size   : float;
  1204. grid_gap    : integer;
  1205. grid_temp   : integer;
  1206.  
  1207. max_height     : constant float := 27.0;
  1208. height         : float := 28.05;
  1209. visible_height : float := 28.05;
  1210. llx           : integer;
  1211. urx           : integer;
  1212. delta_x           : integer;
  1213. min_x           : integer;
  1214.  
  1215. max_width      : constant float := 33.0;
  1216. width          : float := 21.7;
  1217. visible_width  : float := 21.7;
  1218. curr_offset    : integer := 1;
  1219. max_offset     : integer;
  1220. pixel_height   : integer;
  1221.  
  1222. cent_to_pix : constant float := 30.588;
  1223.  
  1224. ---------------------------------------------------------------------------
  1225. --|                                    |--
  1226. --| Get_command                                |--
  1227. --|                                    |--
  1228. ---------------------------------------------------------------------------
  1229. --|                                    |--
  1230. --| Parameters:        1. Command code.                    |--
  1231. --|                                    |--
  1232. --| Description:    Get bytes from the terminal and see if they        |--
  1233. --|            form a known command.                |--
  1234. --|                                    |--
  1235. ---------------------------------------------------------------------------
  1236. procedure get_command (
  1237.     term : in out terminator) is
  1238.  
  1239. trash : integer;
  1240.  
  1241. function get_char
  1242.     return integer is
  1243.  
  1244. code   : integer := 0;
  1245. status : cond_value_type;
  1246.  
  1247. begin
  1248.     task_qiow (
  1249.     status => status,
  1250.     chan   => term_chan,
  1251.     func   => io_readvblk or io_m_noecho,
  1252.     p1     => to_unsigned_longword (code'address),
  1253.     p2     => 1);
  1254.     return code;
  1255. end;    
  1256.  
  1257. begin
  1258.     loop
  1259.     case get_char is
  1260.         when 26 => term := done; exit;
  1261.         when 27 =>
  1262.         case get_char is
  1263.             when 91 =>
  1264.             case get_char is
  1265.                 when 65 => term := up;        exit;
  1266.                 when 66 => term := down;      exit;
  1267.                 when 67 => term := right;     exit;
  1268.                 when 68 => term := left;      exit;
  1269.                 when 49 => term := grid;      exit;
  1270.                 when 52 => term := goto_page; exit;
  1271.                 when 53 => term := prv_page;  exit;
  1272.                 when 54 => term := nxt_page;  exit;
  1273.                 when others => put_line ("Invalid command.");
  1274.             end case;
  1275.             when others => put_line ("Invalid command.");
  1276.         end case;
  1277.         when others => put_line ("Invalid command.");
  1278.     end case;
  1279.     end loop;
  1280.     
  1281.     if (term in nxt_page..grid) then
  1282.     trash := get_char;
  1283.     end if;
  1284. end;
  1285.  
  1286. ---------------------------------------------------------------------------
  1287. --|                                    |--
  1288. --| Main program                            |--
  1289. --|                                    |--
  1290. ---------------------------------------------------------------------------
  1291. begin
  1292.     put_line ("Dvi Previewer");
  1293. --|
  1294. --| Get parameters
  1295. --|
  1296.     get_value (status, "dvi_file", dvi_file);
  1297.     get_value (status, "magstep", temp);
  1298.     get (value (temp), magstep, last);
  1299.     
  1300.     for i in 1..magstep loop
  1301.     magnify := magnify * 1.2;
  1302.     end loop;
  1303. --|
  1304. --| Activate dvi display code
  1305. --|
  1306.     dvi_read.init (value (dvi_file), magnify, page_count);
  1307.     prev_page := new page_array (page_width*page_height);
  1308.     reset_page (prev_page);
  1309.     curr_page := new page_array (page_width*page_height);
  1310.     reset_page (curr_page);
  1311.     next_page := new page_array (page_width*page_height);
  1312.     reset_page (next_page);
  1313. --|
  1314. --| Open channel to terminal
  1315. --|
  1316.     assign (status, "tt:", term_chan);
  1317.     if not success(status) then
  1318.     sys_exit (status);
  1319.     end if;
  1320. --|
  1321. --| Start UIS stuff
  1322. --|
  1323.     height := height * magnify;
  1324.     if (height > max_height) then 
  1325.     visible_height := max_height;
  1326.     else
  1327.     visible_height := height;
  1328.     end if;
  1329.     
  1330.     width := width * magnify;
  1331.     if (width > max_width) then 
  1332.     visible_width := max_width;
  1333.     else
  1334.     visible_width := width;
  1335.     end if;
  1336.  
  1337.     display := create_display (0.0, 0.0, visible_width, visible_height,
  1338.     visible_width, visible_height);
  1339.     disable_display_list (display);
  1340.     window := create_window (display, "sys$workstation", "Dvi Previewer");
  1341.     
  1342.     delta_x := integer(visible_width/2.0*cent_to_pix);
  1343.     min_x := integer((visible_width-width)*cent_to_pix);
  1344.     llx := 0;
  1345.     urx := integer(visible_width * cent_to_pix);
  1346.  
  1347.     pixel_height := integer(visible_height*cent_to_pix);
  1348.     max_offset := (page_height-pixel_height)*page_width + 1;
  1349.     
  1350.     set_writing_mode (display, 0, 1, 3);
  1351.     set_line_style (display, 1, 1, 16#11111111#);
  1352. --|
  1353. --| Get first page
  1354. --|
  1355.     dvi_read.get_page (1, display_page);
  1356.     curr_page_num := 1;
  1357.     put_line ("Page" & integer'image (curr_page_num) & " of" &
  1358.     integer'image (page_count));
  1359.  
  1360. ---------------------------------------------------------------------------
  1361. --|                                    |--
  1362. --| Main loop                                |--
  1363. --|                                    |--
  1364. ---------------------------------------------------------------------------
  1365.     loop
  1366.     if redisplay then
  1367.         image_dc (window, 0, llx, 0, urx, pixel_height,
  1368.         page_width, pixel_height, 1, 
  1369.         display_page.bits(curr_offset)'address);
  1370.         redisplay := false;
  1371.         grid_active := false;
  1372.     end if;
  1373.     
  1374.     get_command (term);
  1375.     case term is
  1376. --|
  1377. --| Exit program
  1378. --|
  1379.         when done => exit;
  1380. --|
  1381. --| Goto next page.
  1382. --|
  1383.         when nxt_page =>
  1384.         if (curr_page_num < page_count) then
  1385.             erase_dc (window);
  1386.             dvi_read.get_next (display_page);
  1387.             redisplay := true;
  1388.             curr_page_num := curr_page_num + 1;
  1389.             put_line ("Page" & integer'image (curr_page_num) &
  1390.             " of" & integer'image (page_count));
  1391.         else
  1392.             put_line ("No next page.");
  1393.         end if;
  1394. --|
  1395. --| Goto previous page
  1396. --|
  1397.         when prv_page =>
  1398.         if (curr_page_num > 1) then
  1399.             erase_dc (window);
  1400.             dvi_read.get_prev (display_page);
  1401.             redisplay := true;
  1402.             curr_page_num := curr_page_num - 1;
  1403.             put_line ("Page" & integer'image (curr_page_num) &
  1404.             " of" & integer'image (page_count));
  1405.         else
  1406.             put_line ("No previous page.");
  1407.         end if;
  1408. --|
  1409. --| Goto arbitrary page
  1410. --|
  1411.         when goto_page =>
  1412.         put ("Enter page number: ");
  1413.         begin
  1414.             get (next_page_num);
  1415.         exception
  1416.             when others => next_page_num := 0;
  1417.         end;
  1418.         
  1419.         if (next_page_num in 1..page_count) then
  1420.             erase_dc (window);
  1421.             curr_page_num := next_page_num;
  1422.             dvi_read.get_page (curr_page_num, display_page);
  1423.             redisplay := true;
  1424.             put_line ("Page" & integer'image (curr_page_num) &
  1425.             " of" & integer'image (page_count));
  1426.         else
  1427.             put_line ("Invalid page number" & integer'image(next_page_num));
  1428.         end if;
  1429. --|
  1430. --| Go up on page
  1431. --|
  1432.         when up =>
  1433.         curr_offset := curr_offset - 
  1434.             integer(visible_height/2.0*cent_to_pix)*page_width;
  1435.         if (curr_offset < 1) then
  1436.             curr_offset := 1;
  1437.         end if;
  1438.         erase_dc (window);
  1439.         redisplay := true;
  1440. --|
  1441. --| Go down on page
  1442. --|
  1443.         when down =>
  1444.         curr_offset := curr_offset +
  1445.             integer(visible_height/2.0*cent_to_pix)*page_width;
  1446.         if (curr_offset > max_offset) then
  1447.             curr_offset := max_offset;
  1448.         end if;
  1449.         erase_dc (window);
  1450.         redisplay := true;
  1451. --|
  1452. --| Go right on page
  1453. --|
  1454.         when right =>
  1455.         llx := llx - delta_x;
  1456.         if (llx < min_x) then
  1457.             llx := min_x;
  1458.         end if;
  1459.         erase_dc (window);
  1460.         redisplay := true;
  1461. --|
  1462. --| Go left on page
  1463. --|
  1464.         when left =>
  1465.         llx := llx + delta_x;
  1466.         if (llx > 0) then
  1467.             llx := 0;
  1468.         end if;
  1469.         erase_dc (window);
  1470.         redisplay := true;
  1471. --|
  1472. --| Overlay display with grid
  1473. --|
  1474.         when grid =>
  1475.         if not grid_active then
  1476.             put ("Grid size (in inches)? ");
  1477.             begin
  1478.             get_line (in_line);
  1479.             get (value(in_line), grid_size, last);
  1480.             exception
  1481.             when others => grid_size := 1.0;
  1482.             end;
  1483.         end if;
  1484.         
  1485.         grid_active := not grid_active;
  1486.         grid_gap := integer(grid_size*resolution*magnify);
  1487.         if (grid_gap < 1) then
  1488.             grid_gap := 1;
  1489.         end if;
  1490.  
  1491.         grid_temp := 0;
  1492.         while (grid_temp < display_page.width) loop
  1493.             plot_dc (window, 1, grid_temp+llx, 0, grid_temp+llx, 
  1494.                 integer(visible_height*cent_to_pix));
  1495.             grid_temp := grid_temp + grid_gap;
  1496.         end loop;
  1497.  
  1498.         grid_temp := pixel_height-page_height+(curr_offset/page_width);
  1499.         while (grid_temp < display_page.height) loop
  1500.             plot_dc (window, 1, 0, grid_temp,
  1501.             integer(visible_width*cent_to_pix), grid_temp);
  1502.             grid_temp := grid_temp + grid_gap;
  1503.         end loop;
  1504.  
  1505.     end case;
  1506.     end loop;
  1507. end;
  1508. $ eod
  1509. $ checksum [.src]preview.ada
  1510. $ if checksum$checksum .nes. "320031064" then write sys$output -
  1511.     "    ******Checksum error for file [.src]preview.ada******"
  1512. $ write sys$output "Creating [.src]uis_.ada"
  1513. $ create [.src]uis_.ada
  1514. $ deck
  1515. ---------------------------------------------------------------------------
  1516. --|                                    |--
  1517. --| Title:  Uis                                |--
  1518. --| Date:   28-AUG-1986                            |--
  1519. --| Name:   Randy Buckland                        |--
  1520. --|                                    |--
  1521. --| Purpose:    Define UIS routines.                    |--
  1522. --|                                    |--
  1523. ---------------------------------------------------------------------------
  1524. --|                                    |--
  1525. --| Revision History                            |--
  1526. --|                                    |--
  1527. --| Who        Date    Description                    |--
  1528. --| ---        ----    -----------                    |--
  1529. --| rcb        28-AUG-1986    New file.                    |--
  1530. --|                                    |--
  1531. ---------------------------------------------------------------------------
  1532. --|                                    |--
  1533. --| Copyright (c) 1987 by Research Triangle Institute.            |--
  1534. --| Written by Randy Buckland. Not derived from licensed software.    |--
  1535. --|                                    |--
  1536. --| Permission is granted to anyone to use this software for any    |--
  1537. --| purpose on any computer system, and to redistribute it freely,    |--
  1538. --| subject to the following restrictions.                |--
  1539. --|                                    |--
  1540. --| 1. Research Triangle Institute supplies this software "as is",    |--
  1541. --|    without any warranty. The author and the Institute do not    |--
  1542. --|    accept any responsibility for any damage caused by use or    |--
  1543. --|    mis-use of this program.                    |--
  1544. --| 2. The copyright notice must remain a part of all sources files.    |--
  1545. --| 3. This software may not be sold in any fashion.            |--
  1546. --|                                    |--
  1547. ---------------------------------------------------------------------------
  1548. with system;
  1549. use  system;
  1550.  
  1551. package uis is
  1552.  
  1553. ---------------------------------------------------------------------------
  1554. --|                                    |--
  1555. --| Type definitions                            |--
  1556. --|                                    |--
  1557. ---------------------------------------------------------------------------
  1558. subtype display_type is integer;
  1559. subtype window_type is integer;
  1560.  
  1561. ---------------------------------------------------------------------------
  1562. --|                                    |--
  1563. --| Routine defintions                            |--
  1564. --|                                    |--
  1565. ---------------------------------------------------------------------------
  1566. function create_display (
  1567.     llx : in float;
  1568.     lly : in float;
  1569.     urx : in float;
  1570.     ury : in float;
  1571.     width  : in float;
  1572.     height : in float)
  1573.     return display_type;
  1574.  
  1575. pragma interface (rtl, create_display);
  1576. pragma import_function (create_display, "uis$create_display");
  1577.  
  1578. function create_window (
  1579.     display : in display_type;
  1580.     name    : in string := "sys$workstation";
  1581.     label   : in string := "";
  1582.     llx     : in float := float'null_parameter;
  1583.     lly     : in float := float'null_parameter;
  1584.     urx     : in float := float'null_parameter;
  1585.     ury     : in float := float'null_parameter;
  1586.     width   : in float := float'null_parameter;
  1587.     height  : in float := float'null_parameter)
  1588.     return window_type;
  1589.  
  1590. pragma interface (rtl, create_window);
  1591. pragma import_function (create_window, "uis$create_window");
  1592.  
  1593. procedure disable_display_list (
  1594.     display : in display_type;
  1595.     flags   : in integer := integer'null_parameter);
  1596.  
  1597. pragma interface (rtl, disable_display_list);
  1598. pragma import_procedure (disable_display_list, "uis$disable_display_list");
  1599.  
  1600. procedure erase_dc (
  1601.     window : in window_type);
  1602.  
  1603. pragma interface (rtl, erase_dc);
  1604. pragma import_procedure (erase_dc, "uisdc$erase");
  1605.  
  1606. procedure erase (
  1607.     display : in display_type);
  1608.  
  1609. pragma interface (rtl, erase);
  1610. pragma import_procedure (erase, "uis$erase");
  1611.  
  1612.  
  1613. procedure image (
  1614.     display    : in display_type;
  1615.     attribute  : in integer := 0;
  1616.     llx        : in float;
  1617.     lly        : in float;
  1618.     urx        : in float;
  1619.     ury        : in float;
  1620.     width      : in integer;
  1621.     height     : in integer;
  1622.     pixel_bits : in integer := 1;
  1623.     buffer     : in address);
  1624.  
  1625. pragma interface (rtl, image);
  1626. pragma import_procedure (image, "uis$image",
  1627.     (display_type, integer, float, float, float, float, integer, 
  1628.     integer, integer, address),
  1629.     (reference, reference, reference, reference, reference, reference,
  1630.     reference, reference, reference, value));
  1631.  
  1632. procedure image_dc (
  1633.     window     : in window_type;
  1634.     attribute  : in integer := 0;
  1635.     llx        : in integer;
  1636.     lly        : in integer;
  1637.     urx        : in integer;
  1638.     ury        : in integer;
  1639.     width      : in integer;
  1640.     height     : in integer;
  1641.     pixel_bits : in integer := 1;
  1642.     buffer     : in address);
  1643.  
  1644. pragma interface (rtl, image_dc);
  1645. pragma import_procedure (image_dc, "uisdc$image",
  1646.     (window_type, integer, integer, integer, integer, integer, integer, 
  1647.     integer, integer, address),
  1648.     (reference, reference, reference, reference, reference, reference,
  1649.     reference, reference, reference, value));
  1650.  
  1651. procedure plot (
  1652.     display : in display_type;
  1653.     attr    : in integer;
  1654.     x1      : in float;
  1655.     y1      : in float;
  1656.     x2      : in float;
  1657.     y2      : in float);
  1658.  
  1659. pragma interface (rtl, plot);
  1660. pragma import_procedure (plot, "uis$plot");
  1661.  
  1662. procedure plot_dc (
  1663.     window  : in window_type;
  1664.     attr    : in integer;
  1665.     x1      : in integer;
  1666.     y1      : in integer;
  1667.     x2      : in integer;
  1668.     y2      : in integer);
  1669.  
  1670. pragma interface (rtl, plot_dc);
  1671. pragma import_procedure (plot_dc, "uisdc$plot");
  1672.  
  1673. procedure set_line_style (
  1674.     display  : in display_type;
  1675.     in_attr  : in integer;
  1676.     out_attr : in integer;
  1677.     pattern  : in integer);
  1678.  
  1679. pragma interface (rtl, set_line_style);
  1680. pragma import_procedure (set_line_style, "uis$set_line_style");
  1681.  
  1682. procedure set_writing_mode (
  1683.     display  : in display_type;
  1684.     in_attr  : in integer;
  1685.     out_attr : in integer;
  1686.     pattern  : in integer);
  1687.  
  1688. pragma interface (rtl, set_writing_mode);
  1689. pragma import_procedure (set_writing_mode, "uis$set_writing_mode");
  1690.  
  1691. end;
  1692. $ eod
  1693. $ checksum [.src]uis_.ada
  1694. $ if checksum$checksum .nes. "1212495686" then write sys$output -
  1695.     "    ******Checksum error for file [.src]uis_.ada******"
  1696. $ exit
  1697.  
  1698.  
  1699.