[dev-context] two dvipos fixes so that it works with ConTeXt

Sanjoy Mahajan sanjoy at mrao.cam.ac.uk
Sun Jan 7 03:58:43 CET 2007


[Karl and Norbert CC'ed in case dvipos is going into their trees]

The dvipos I have (cvs'ed from cvs.ktug.or.kr:/home/cvsroot) needs two
fixes for it to work with the 2007.01.02 context (and maybe with earlier
versions too).  This is on Ubuntu i386, texlive 2005.  

Try this file with 'texexec --dvi --nobackend' to see the problems -- or
if there are none, let me know why it works for you!

=================== begin: to-dvi.tex ==================
\defineoverlay [foregraphics] [\positionoverlay{foregraphics}]
\setupbackgrounds
  [page]
  [background={foreground,foregraphics}]

\starttext

\hpos{r23}{7} \quad \hpos{r24}{8} 

\startMPpositiongraphic{mypos:line}
  mpprocset := 0;  % context doesn't yet handle the new mpprocsets
  path pa, pb, pab ; numeric na, nb ;
  initialize_box(\MPpos{\MPvar{from}}) ;
  na := nxy ; pa := llxy..lrxy..urxy..ulxy..cycle ;
  initialize_box(\MPpos{\MPvar{to}}) ;
  nb := nxy ; pb := llxy..lrxy..urxy..ulxy..cycle ;
  if na=nb :
    pab := center pa -- center pb ;
    pab := pab cutbefore (pab intersectionpoint pa) ;
    pab := pab cutafter (pab intersectionpoint pb) ;
    pickup pencircle;
    draw pab;
    anchor_box(\MPanchor{\MPvar{from}}) ;
  fi ;
\stopMPpositiongraphic

\startpositionoverlay{foregraphics}
  \setMPpositiongraphic{r23}{mypos:line}{to=r24}
\stoppositionoverlay

The pattern.

\stoptext
===================   end: to-dvi.tex ==================

Problems:

1. The dvipos output is in sp (but without labelling that), which
   confuses the next run of ConTeXt.  So the first patch makes dvipos
   append 'sp' to the coordinates it outputs.  That change was easier
   than hacking the tex macros that parses the output.

2. After that is fixed, the coordinates are wrong, so running the above
   file again crashes because the boxes are in the wrong place and the
   paths no longer intersect.  The second patch corrects this problem,
   which is caused by dvipos parsing the dvi file incorrectly.  

   Maybe ConTeXt used to output the dimens in the pos: \special in sp?
   Anyway, the special now looks like (see to-dvi.dvi):

     pos:pxywhd "text:1" 426.78743pt 597.51323pt 0.0pt

   which was being parsed by dvipos as 426 etc. and assumed to be sp, so
   it was writing junk to to-dvi.tuo file, and the next run was failing
   becaues the boxes were in the wrong location.  So I made dvipos read
   in floats with 'pt' appended, then convert them to sp.

By the way, what is the 'list' that dvipos is looking for after the
three dimens above?  If anything needs a \pospxyplus, it'll be in
trouble since I think 'list' scanf target is not being parsed, so the
var remains uninitialized.

-Sanjoy

`A nation of slaves is always prepared to applaud the clemency of their
 master who, in the abuse of absolute power, does not proceed to the
 last extremes of injustice and oppression.'  (Gibbon)  


# HG changeset patch
# User Sanjoy Mahajan <sanjoy at mrao.cam.ac.uk>
# Date 1168136989 18000
# Node ID 13a3c8c608ddcfbb569f1925fc0a64fcd25f7344
# Parent  c184bfb52c9425d7e7a87105e9f17ac874be657e
Append sp (scaled point) unit to un-dimensioned coordinates

diff -r c184bfb52c94 -r 13a3c8c608dd dvicore.c
--- a/dvicore.c	Sat Jan 06 21:28:59 2007 -0500
+++ b/dvicore.c	Sat Jan 06 21:29:49 2007 -0500
@@ -924,11 +924,11 @@ static void do_pos_special (unsigned cha
   y = max_v - dvi_state.v;
 
   if (strcmp(cmd, "pos:pxy") == 0)
-    fprintf(outfp, "\\pospxy{%s}{%d}{%ld}{%ld}\n", tag, current_page, x, y);
+    fprintf(outfp, "\\pospxy{%s}{%d}{%ldsp}{%ldsp}\n", tag, current_page, x, y);
   else if (strcmp(cmd, "pos:pxywhd") == 0)
-    fprintf(outfp, "\\pospxywhd{%s}{%d}{%ld}{%ld}{%ld}{%ld}{%ld}\n", tag, current_page, x, y, w, h, d);
+    fprintf(outfp, "\\pospxywhd{%s}{%d}{%ldsp}{%ldsp}{%ldsp}{%ldsp}{%ldsp}\n", tag, current_page, x, y, w, h, d);
   else if (strcmp(cmd, "pos:pxyplus") == 0)
-    fprintf(outfp, "\\pospxyplus{%s}{%d}{%ld}{%ld}{%ld}{%ld}{%ld}{%ld}\n", tag, current_page, x, y, w, h, d, list);
+    fprintf(outfp, "\\pospxyplus{%s}{%d}{%ldsp}{%ldsp}{%ldsp}{%ldsp}{%ldsp}{%ld}\n", tag, current_page, x, y, w, h, d, list);
   else if (strcmp(cmd, "pos:begbox") == 0)
     new_bbox(tag, BOX_TYPE);
   else if (strcmp(cmd, "pos:endbox") == 0)

# HG changeset patch
# User Sanjoy Mahajan <sanjoy at mrao.cam.ac.uk>
# Date 1168137910 18000
# Node ID f30b6ea9f33e3b3825c4e2b923fd73d88869ae1e
# Parent  13a3c8c608ddcfbb569f1925fc0a64fcd25f7344
Read w,h,d in pt (not sp) from dvi file
Maybe ConTeXt used to give the dimens in the \specials in sp?
Anyway, the special now looks like:
  pos:pxywhd "text:1" 426.78743pt 597.51323pt 0.0pt
which was being parsed before as 426 etc. and assumed to be sp.

diff -r 13a3c8c608dd -r f30b6ea9f33e dvicore.c
--- a/dvicore.c	Sat Jan 06 21:29:49 2007 -0500
+++ b/dvicore.c	Sat Jan 06 21:45:10 2007 -0500
@@ -918,7 +918,15 @@ static void do_pos_special (unsigned cha
   for (p++; p - buffer < buffer_len && isspace(*p); p++)
     ; /* skip white chars */
   if (p - buffer < buffer_len)
-    sscanf(p, "%ld %ld %ld %ld", &w, &h, &d, &list);
+    {
+      float w_f, h_f, d_f;	/* in pt */
+      /* what the hell is list? */
+      sscanf(p, "%fpt %fpt %fpt %ld", &w_f, &h_f, &d_f, &list);
+      /* convert to sp.  Forget about rounding (add 0.5 if you want it). */
+      w = w_f * 65536;
+      h = h_f * 65536;
+      d = d_f * 65536;
+    }
 
   x = dvi_state.h + denominator / 100;
   y = max_v - dvi_state.v;


More information about the dev-context mailing list