home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / languages / bob / !ArmBob / progs / h / draw / file < prev    next >
Encoding:
Text File  |  1994-12-31  |  7.3 KB  |  367 lines

  1. /*******************************************************
  2.  *                                                     *
  3.  *  draw.file Library        GCW  25/12/94             *
  4.  *                                                     *
  5.  *******************************************************/
  6.  
  7. /* Uses draw.object */
  8.  
  9. class drawfile
  10. {
  11.   obj, bbx_lo, bby_lo, bbx_hi, bby_hi;
  12. }
  13.  
  14. drawfile::drawfile()
  15. {
  16.  obj = new object(16<<10);
  17.  bbx_lo = bby_lo = &7fffffff;
  18.  bbx_hi = bby_hi = &80000000;
  19.  return this;
  20. }
  21.  
  22. drawfile::adjust_box(x_lo,y_lo,x_hi,y_hi)
  23. {
  24.  bbx_lo = min(bbx_lo,x_lo);
  25.  bby_lo = min(bby_lo,y_lo);
  26.  bbx_hi = max(bbx_hi,x_hi);
  27.  bby_hi = max(bby_hi,y_hi);
  28. }
  29.  
  30. min(a,b)
  31. { return (a<b)?a:b; }
  32.  
  33. max(a,b)
  34. { return (a<b)?b:a; }
  35.  
  36. drawfile::file_header()
  37. {
  38.  obj->push_word(&77617244);
  39.  obj->push_word(201);
  40.  obj->push_word(0);
  41.  obj->push_string(pad("Armbob",12,' '));
  42.  obj->push_word(0);        // bounding box x_lo
  43.  obj->push_word(0);        // bounding box y_lo
  44.  obj->push_word(0);        // bounding box x_hi
  45.  obj->push_word(0);        // bounding box y_hi
  46. }
  47.  
  48. drawfile::object_header(type,size)
  49. {
  50.  local adr;
  51.  adr = obj->here();
  52.  obj->push_word(type);
  53.  obj->push_word(size);
  54.  obj->push_word(0);        // bounding box x_lo
  55.  obj->push_word(0);        // bounding box y_lo
  56.  obj->push_word(0);        // bounding box x_hi
  57.  obj->push_word(0);        // bounding box y_hi
  58.  return adr;
  59. }
  60.  
  61. set_box(a,x_lo,y_lo,x_hi,y_hi)
  62. {
  63.  in (a+8) put { x_lo; y_lo; x_hi; y_hi; }
  64. }
  65.  
  66. drawfile::options()
  67. {
  68.  local adr, i;
  69.  adr = this->object_header(11,88);
  70.  obj->push_word(&500);        // A4 paper
  71.  for (i = 0; i < 15; i++)
  72.       obj->push_word(0);
  73.  ££(adr+64,1);            // zoom multiplier
  74.  ££(adr+68,1);            // zoom divider
  75.  ££(adr+80,128);          // select mode
  76.  return adr;
  77. }
  78.  
  79. drawfile::fonts()
  80. {
  81.  local adr;
  82.  obj->push_word(0);
  83.  adr = obj->here();
  84.  obj->push_word(0);     // size
  85.  obj->push_byte(1);
  86.  obj->push_string("Trinity.Medium"+0);
  87.  obj->push_byte(2);
  88.  obj->push_string("Trinity.Medium.Italic"+0);
  89.  obj->push_byte(3);
  90.  obj->push_string("Trinity.Bold"+0);
  91.  obj->push_byte(4);
  92.  obj->push_string("Trinity.Bold.Italic"+0);
  93.  obj->push_byte(5);
  94.  obj->push_string("Corpus.Medium"+0);
  95.  obj->push_byte(6);
  96.  obj->push_string("Corpus.Medium.Oblique"+0);
  97.  obj->push_byte(7); 
  98.  obj->push_string("Corpus.Bold"+0);
  99.  obj->push_byte(8);
  100.  obj->push_string("Corpus.Bold.Oblique"+0);
  101.  obj->push_byte(9);
  102.  obj->push_string("Homerton.Medium"+0);
  103.  obj->push_byte(10);
  104.  obj->push_string("Homerton.Medium.Oblique"+0);
  105.  obj->push_byte(11);
  106.  obj->push_string("Homerton.Bold"+0);
  107.  obj->push_byte(12);
  108.  obj->push_string("Homerton.Bold.Oblique"+0);
  109.  while(obj->here()%4)
  110.     obj->push_byte(0);
  111.  ££(adr,4+(obj->here()) - adr);
  112. }
  113.  
  114. /* <<<<<<<<<<<<<<< text >>>>>>>>>>>>>>> */
  115. drawfile::text(s,x,y)
  116. {
  117.  local len,adr,x1,y1;
  118.  x *= 640; y *= 640;   // 1 point units
  119.  len = sizeof(s);
  120.  s = zero_align(s);
  121.  adr = this->object_header(1, 52+sizeof(s));
  122.  obj->push_word(colour_trans(7));   // text colour
  123.  obj->push_word(colour_trans(0));   // background colour
  124.  obj->push_word(0);                 // system font
  125.  obj->push_word(6400);              // 10 point fontsize_x
  126.  obj->push_word(6400);              // 10 point fontsize_y
  127.  obj->push_word(x);
  128.  obj->push_word(y);
  129.  obj->push_string(s);
  130.  set_box(adr,x,y,(x1 = x+len*£(adr+36)),(y1 = y+£(adr+40)));
  131.  this->adjust_box(x,y,x1,y1);
  132.  return adr;
  133. }
  134.  
  135. colour(adr,n)
  136. { ££(adr+24,colour_trans(n)); }
  137.  
  138. font(adr,n)
  139. { ££(adr+32,n); }
  140.  
  141. drawfile::font_x(adr,n)        // n in points
  142. {
  143.  local len, x, y, x1, y1;
  144.  ££(adr+36,640*n);
  145.  len = £(adr+4)-52;
  146.  set_box(adr, (x = £(adr+44)), (y = £(adr+48)),
  147.       (x1 = x + len*£(adr+36)),(y1 = y + £(adr+40)));
  148.  this->adjust_box(x,y,x1,y1);
  149. }
  150.  
  151. drawfile::font_y(adr,n)
  152. {
  153.  local len, x, y, x1, y1;
  154.  ££(adr+40, 640*n);
  155.  len = £(adr+4)-52;
  156.  set_box(adr, (x = £(adr+44)), (y = £(adr+48)),
  157.    (x1 = x + len*£(adr+36)),(y1 = y + £(adr+40)));
  158.  this->adjust_box(x,y,x1,y1);
  159. }
  160.  
  161. /* <<<<<<<<<<<<<< path >>>>>>>>>>>>>> */
  162. drawfile::path()
  163. {
  164.  local adr;
  165.  adr = this->object_header(2,0);
  166.  obj->push_word(-1);              // fill colour
  167.  obj->push_word(colour_trans(7)); // outline colour
  168.  obj->push_word(640);             // width
  169.  obj->push_word(0);               // style
  170.  return adr;
  171. }
  172.  
  173. fill(adr,n)
  174. { ££(adr+24,colour_trans(n)); }
  175.  
  176. outline(adr,n)
  177. { ££(adr+28,colour_trans(n)); }
  178.  
  179. linewidth(adr,n)
  180. { ££(adr+32,640*n); }
  181.  
  182. join_style(adr,n)
  183. { ££(adr+36,(&fffffffc & £(adr+36))|(n%3)); }
  184.  
  185. endcap_style(adr,n)
  186. { ££(adr+36,((~12)& £(adr+36))|((n%3)<<2)); }
  187.  
  188. startcap_style(adr,n)
  189. { ££(adr+36,((~48)& £(adr+36))|((n%3)<<4)); }
  190.  
  191. winding_rule(adr,n)
  192. { ££(adr+36,((~64)& £(adr+36))|((n%2)<<6)); }
  193.  
  194. drawfile::endpath(adr)
  195. {
  196.  obj->push_word(0);
  197.  ££(adr+4,(obj->here())-adr);
  198.  ££(adr+8,bbx_lo);
  199.  ££(adr+12,bby_lo);
  200.  ££(adr+16,bbx_hi);
  201.  ££(adr+20,bby_hi);
  202. }
  203.  
  204. drawfile::close_with_line()
  205. { obj->push_word(5); }
  206.  
  207. drawfile::move(x,y)
  208.  x *= 640;
  209.  y *= 640;
  210.  obj->push_word(2);
  211.  obj->push_word(x);
  212.  obj->push_word(y);
  213.  this->adjust_box(x,y,x,y);
  214.  
  215. drawfile::draw(x,y)
  216.  x *= 640;
  217.  y *= 640; 
  218.  obj->push_word(8);
  219.  obj->push_word(x);
  220.  obj->push_word(y);
  221.  this->adjust_box(x,y,x,y);
  222. }
  223.  
  224. drawfile::bezier(x1,y1,x2,y2,x3,y3)
  225.  x1 *= 640;
  226.  y1 *= 640;
  227.  x2 *= 640;
  228.  y2 *= 640;
  229.  x3 *= 640;
  230.  y3 *= 640;
  231.  obj->push_word(6);
  232.  obj->push_word(x1);
  233.  obj->push_word(y1);
  234.  obj->push_word(x2);
  235.  obj->push_word(y2);
  236.  obj->push_word(x3);
  237.  obj->push_word(y3);
  238.  this->adjust_box(x1,y1,x1,y1);
  239.  this->adjust_box(x2,y2,x2,y2);
  240.  this->adjust_box(x3,y3,x3,y3);
  241.  
  242. /* <<<<<<<<<<<<<<<< group >>>>>>>>>>>>>>> */
  243. drawfile::group()
  244. {
  245.  local adr;
  246.  adr = this->object_header(6,0);
  247.  obj->push_word(&20202020);
  248.  obj->push_word(&20202020);
  249.  obj->push_word(&20202020);
  250.  return adr;
  251. }
  252.  
  253. drawfile::endgroup(adr)
  254. {
  255.  ££(adr+4,(obj->here())-adr);
  256.  ££(adr+8,bbx_lo);
  257.  ££(adr+12,bby_lo);
  258.  ££(adr+16,bbx_hi);
  259.  ££(adr+20,bby_hi);
  260. }
  261.  
  262. /* <<<<<<<<<<<<<<<<< begin >>>>>>>>>>>>>>> */
  263. drawfile::begin()
  264. {
  265.  init_names();
  266.  this->file_header();
  267.  this->fonts(); 
  268.  this->options();
  269. }
  270.  
  271. /* <<<<<<<<<<<<<<<<< show >>>>>>>>>>>>>>>> */ 
  272. drawfile::end(filename)
  273. {
  274.  obj->write(24,bbx_lo);
  275.  obj->write(28,bby_lo);
  276.  obj->write(32,bbx_hi);
  277.  obj->write(36,bby_hi);
  278.  save(obj->start(), obj->here(), filename, &aff);
  279.  oscli("set Draw$Options P4 T- MS");
  280.  oscli("filer_run "+filename);
  281. }
  282.  
  283. save(from,to,file,type)
  284. {
  285.  local r;
  286.  r = newvector(8);
  287.  r[0] = 10;
  288.  r[1] = @(file);
  289.  r[2] = type;
  290.  r[4] = from;
  291.  r[5] = to;
  292.  swi(8|(1<<17),r);
  293.  
  294. align(n)
  295. { return (n%4)?((1+(n>>2))<<2):n; }
  296.  
  297. /* pad string s out to n characters with character c */
  298. pad(s,n,c)
  299. {
  300.  local t, i;
  301.  if (sizeof(s) >= n)
  302.   for ( t = "", i = 0; i < n; t += s[i++]);
  303.  else
  304.   for ( t = s; sizeof(t) < n; t += c);
  305.  return t;
  306. }
  307.  
  308. zero_align(s)
  309. {
  310.  local t;
  311.  t = s+0;
  312.  while (sizeof(t)%4)
  313.     t += 0;
  314.  return t;
  315. }
  316.  
  317. colour_trans(n)
  318. {
  319.  local r;
  320.  if (n == -1) return n;
  321.  (r = newvector(8))[1] = @(newstring(80));
  322.  swi("Wimp_ReadPalette",r);
  323.  return (&ffffff00)&£(r[1]+4*n);
  324. }
  325.  
  326. init_names()
  327. {
  328.  none = -1;
  329.  white = 0;
  330.  black = 7;
  331.  blue = 8;
  332.  yellow = 9;
  333.  green = 10;
  334.  red = 11;
  335.  cream = 12;
  336.  olive = 13;
  337.  orange = 14;
  338.  azure = 15;
  339.  System = 0;
  340.  Trinity_Medium = 1;
  341.  Trinity_Medium_Italic = 2;
  342.  Trinity_Bold = 3;
  343.  Trinity_Bold_Italic = 4;
  344.  Corpus_Medium = 5;
  345.  Corpus_Medium_Oblique = 6;
  346.  Corpus_Bold = 7;
  347.  Corpus_Bold_Oblique = 8;
  348.  Homerton_Medium = 9;
  349.  Homerton_Medium_Oblique = 10;
  350.  Homerton_Bold = 11;
  351.  Homerton_Bold_Oblique = 12;
  352.  Mitred = 0;
  353.  Round = 1;
  354.  Bevelled = 2;
  355.  Butt = 0;
  356.  Square = 2;
  357.  Non_Zero = 0;
  358.  Even_Odd = 1;
  359. }
  360.  
  361. /* ------------ end of file definitions --------- */