[Dev-luatex] pdfliteral after text/rules

Hartmut Henkel hartmut_henkel at gmx.de
Thu Sep 15 23:56:40 CEST 2005


Hi,

here ist the problem, that the "page" mode of \pdfliteral and \latelua
does not by itself guarantee, that the result goes relative to the lower
left corner (the PDF origin):


\nopagenumbers
\pdfcompresslevel=0

X\latelua{
  x={};y={};
  c=72/72.27/65536;
  x[1]=pdf.geth()*c; y[1]=pdf.getv()*c
}
\input tufte
X\latelua page{
  x[2]=pdf.geth()*c; y[2]=pdf.getv()*c
}

\hrule

\latelua page{
tex.print(x[1], " ", y[1],
  " m ", x[2], " ", y[2], " l S")
}

\input tufte
\bye


The above example works as intended only, if you remove the \hrule.
Reason is, that for setting a rule, a transform "cm" is done away from
the origin, then the rule is placed, but there is no transforms back to
the origin. The next placements are done after a transform relative to
the placement point of the rule...

Text is always typeset with the transform matrix "cm" set to the origin,
and inside the BT...ET group the Td operator does the local transform.

There seems to be currently no \pdfliteral (or \latelua) mode that
guarantees positioning relative to the PDF origin. But positioning
relative to the origin would be nice to have since we now have the
pdf.geth/v() lua functions. Else one would have to think what was the
state (text or rule?) just before using \pdfliteral page...

To solve this ambiguity, i have tried the attached patch, which puts any
rule into a qQ group and does "cm" transforms inside this group. So the
rules are handled like text, which is also grouped (inside BT...ET).

That means, that the global working reference point is (hopefully :)
always (?) at the origin. With the rule.ch patch the above example works
apparently ok. This also means, that when using \pdfliteral page, one
gets stuff placed at the origin, and still without transform (which
should be ok). This would spare to invent yet another \pdfliteral mode.

No idea how general it is. And wonder, how backward-compatible? We would
need to check also \pdfrefximage...

Just for discussion...

Regards, Hartmut


P.S. Let's see how the attachment is handled. Never tried this before.
-------------- next part --------------
%$Id: rule.ch,v 1.3 2005/09/15 21:31:40 hahe Exp hahe $
% rule in a group
%***********************************************************************

@x 15882
@p procedure pdf_set_origin; {set the origin to |cur_h|, |cur_v|}
begin
    if (abs(cur_h - pdf_origin_h) >= min_bp_val) or
        (abs(cur_v - pdf_origin_v) >= min_bp_val) then begin
        pdf_print("1 0 0 1 ");
        pdf_print_bp(cur_h - pdf_origin_h);
        pdf_origin_h := pdf_origin_h + scaled_out;
        pdf_out(" ");
        pdf_print_bp(pdf_origin_v - cur_v);
        pdf_origin_v := pdf_origin_v - scaled_out;
        pdf_print_ln(" cm");
    end;
    pdf_h := pdf_origin_h;
    pdf_last_h := pdf_origin_h;
    pdf_v := pdf_origin_v;
    pdf_last_v := pdf_origin_v;
end;
@y
@p procedure pdf_set_origin; {set the origin to |cur_h|, |cur_v|}
begin
    if (abs(cur_h - pdf_origin_h) >= min_bp_val) or
        (abs(cur_v - pdf_origin_v) >= min_bp_val) then begin
        pdf_print("1 0 0 1 ");
        pdf_print_bp(cur_h - pdf_origin_h);
        pdf_origin_h := pdf_origin_h + scaled_out;
        pdf_out(" ");
        pdf_print_bp(pdf_origin_v - cur_v);
        pdf_origin_v := pdf_origin_v - scaled_out;
        pdf_print_ln(" cm");
    end;
    pdf_h := pdf_origin_h;
    pdf_last_h := pdf_origin_h;
    pdf_v := pdf_origin_v;
    pdf_last_v := pdf_origin_v;
end;

@
@p procedure pdf_set_origin_temp; {set the origin to |cur_h|, |cur_v| inside group}
var h_bp, v_bp: scaled; {current position (bp system)}
begin
    if (abs(cur_h - pdf_origin_h) >= min_bp_val) or
        (abs(cur_v - pdf_origin_v) >= min_bp_val) then begin
        pdf_print("1 0 0 1 ");
        pdf_print_bp(cur_h - pdf_origin_h);
        pdf_out(" ");
        pdf_print_bp(pdf_origin_v - cur_v);
        pdf_print_ln(" cm");
    end;
end;
@z

%***********************************************************************

@x 16045
procedure pdf_set_rule(x, y, w, h: scaled); {draw a rule}
begin
    pdf_end_text;
    pdf_set_origin;
    if h <= one_bp then begin
        pdf_print_ln("q");
        pdf_print_ln("[]0 d");
        pdf_print_ln("0 J");
        pdf_print_bp(h); pdf_print_ln(" w");
        pdf_print("0 "); pdf_print_bp((h + 1)/2); pdf_print_ln(" m");
        pdf_print_bp(w); pdf_print(" "); pdf_print_bp((h + 1)/2);
        pdf_print_ln(" l");
        pdf_print_ln("S");
        pdf_print_ln("Q");
    end
    else if w <= one_bp then begin
        pdf_print_ln("q");
        pdf_print_ln("[]0 d");
        pdf_print_ln("0 J");
        pdf_print_bp(w); pdf_print_ln(" w");
        pdf_print_bp((w + 1)/2); pdf_print_ln(" 0 m");
        pdf_print_bp((w + 1)/2); pdf_print(" "); pdf_print_bp(h);
        pdf_print_ln(" l");
        pdf_print_ln("S");
        pdf_print_ln("Q");
    end
    else begin
        pdf_print_bp(pdf_x(x)); pdf_out(" ");
        pdf_print_bp(pdf_y(y)); pdf_out(" ");
        pdf_print_bp(w); pdf_out(" ");
        pdf_print_bp(h); pdf_print_ln(" re f");
    end;
end;

@y
procedure pdf_set_rule(x, y, w, h: scaled); {draw a rule}
var temp_cur_h, temp_cur_v: scaled;
begin
    pdf_end_text;
    pdf_print_ln("q");
    pdf_set_origin_temp;
    if h <= one_bp then begin
        pdf_print("[]0 d 0 J ");
        pdf_print_bp(h); pdf_print_ln(" w");
        pdf_print("0 "); pdf_print_bp((h + 1)/2); pdf_print(" m ");
        pdf_print_bp(w); pdf_print(" "); pdf_print_bp((h + 1)/2);
        pdf_print_ln(" l S");
    end
    else if w <= one_bp then begin
        pdf_print("[]0 d 0 J ");
        pdf_print_bp(w); pdf_print_ln(" w");
        pdf_print_bp((w + 1)/2); pdf_print(" 0 m ");
        pdf_print_bp((w + 1)/2); pdf_print(" "); pdf_print_bp(h);
        pdf_print_ln(" l S");
    end
    else begin
        pdf_print_bp(0); pdf_out(" ");
        pdf_print_bp(0); pdf_out(" ");
        pdf_print_bp(w); pdf_out(" ");
        pdf_print_bp(h); pdf_print_ln(" re f");
    end;
    pdf_print_ln("Q");
end;
@z

%***********************************************************************


More information about the Dev-luatex mailing list