Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: an interface for BBox attribute #763

Open
dohyunkim opened this issue Nov 19, 2024 · 6 comments
Open

feature request: an interface for BBox attribute #763

dohyunkim opened this issue Nov 19, 2024 · 6 comments

Comments

@dohyunkim
Copy link

As suggested in lualatex/luamplib#151, I propose a new interface for adding BBox attribute to a structure.

To support tagged PDF in luamplib package, I encountered the need to add BBox attribute to Figure structures. I also found that the relevant code exists already in latex-lab-testphase-graphic.sty. The only missing point is a user interface accessing this code.

It seems that the interface should accept a required argument of a box register and an optional argument of dimensional values to correct the BBox. The optional argument is needed because MetaPost has its setbounds command which makes a picture lie about its bounding box.

It would be much convenient if you kindly provide the interface for generating BBox attribute, which can be used in luamplib or any other packages that need this feature as well.

@u-fischer
Copy link
Member

I'm not sure if a simple public variant of \picture@tag@bbox@attribute is the right interface.

As background: the BBox attribute describes the absolute coordinates of a picture on a page (this allows application like html derivation to make a "screenshot" and catch the picture). A BBox is only needed if the graphic is actually tagged as a Figure, if it is an artifact or a Span one can drop it.

So the code has to use some \pdfsavepos variant to get the absolute position on the page, needs to know the size of the picture, then has to calculate from both sensible absolute left bottom and right upper coordinates and at last adds that (if wanted) to the structure object.

How the "calculation" is done varies. E.g. for includegraphics it is rather complicated as I tried to follow rotations and shifts, the picture code on the other side simply uses the declared bounding box, both use a standard pdfsavepos; in the tikz code, that is currently under development, I reused their remember picture code to get an absolute position and take the internal bounding box they calculate and do not handle a box at all.

So do you actually need code to add a savepos and to calculate the BBox values, or do you only need an interface to add this values to the structure object? That is would something like \tag_graphic_add_BBox:nn{structure number}{value1,value2,value3,value4} be enough for you?

@dohyunkim
Copy link
Author

Thanks for the detailed explanation.
I think that the simple interface to add the BBox values to the structure is enough for me.

@u-fischer
Copy link
Member

@hvoss49 this discussion is also relevant for pstricks imho.

@hvoss49
Copy link

hvoss49 commented Nov 20, 2024

Ulrike, this Email is from July:

I've taken the options from L3 code into pstricks.tex

\ExplSyntaxOn
\define@key[psset]{pstricks}{alt}[]{\tl_set:Ne\l__tag_graphic_alt_tl{\text_purify:n{#1}}}
%\define@boolkey[psset]{pstricks}[]{artifact}[true]{}%.   für L3 wohl sinnlos
\define@key[psset]{pstricks}{artifact}{%
    \bool_set_true:N \l__tag_graphic_artifact_bool
    \bool_set_false:N \l__tag_graphic_BBox_bool
}
\define@key[psset]{pstricks}{actualtext}[]{%
    \tl_set:Ne\l__tag_graphic_actual_tl{\text_purify:n{#1}}
    \bool_set_false:N \l__tag_graphic_BBox_bool
}
\define@key[psset]{pstricks}{correct-BBox}{%
    \bool_set_true:N \l__tag_graphic_bboxcorr_bool
\seq_set_split:Nnn\l__tag_graphic_bboxcorr_seq{~}{#1~0pt~0pt~0pt~0pt}%
}
\define@key[psset]{pstricks}{tag}[]{%
    \str_case:nnF {#1}{
      {artifact}
            {
               \bool_set_true:N \l__tag_graphic_artifact_bool
               \bool_set_false:N \l__tag_graphic_BBox_bool
            }
            {false}{\tag_stop:}
          }
          {\tl_set:Nn\l__tag_graphic_struct_tl{#1}}
      }

\ExplSyntaxOff

Similiar to picture a box is used.

Can I use the extensions found in

\RenewDocumentCommand\picture{O{}m} ... ,
\def\@picture(#1,#2)(#3,#4){%. ...

and

\def\endpicture{% ...

???

I suppose that \newcommand\picture@tag@bbox@attribute . must also be changed??

@u-fischer
Copy link
Member

u-fischer commented Nov 20, 2024

Ulrike, this Email is from July:

@hvoss49 Hm. I can't remember an email about that. I don't have time now, but next week we should discuss it.

Btw: you should define the artifact key so, that it can be used without value. \begin{pspicture}[artifact](-3.4,-3.4)(3.4,3.4) currently errors (probably you need the second optional argument \define@key[psset]{pstricks}{artifact}[]{...}

@hvoss49
Copy link

hvoss49 commented Nov 21, 2024

It depends on what should be the default. For example:

\define@key[psset]{pstricks}{actualtext}[]{%
    \tl_set:Ne\l__tag_graphic_actual_tl{\text_purify:n{#1}}
    \bool_set_false:N \l__tag_graphic_BBox_bool
}

is \l__tag_graphic_BBox_bool always set by the L3 to a default value? If yes, then PSTricks must not set any default values for the tagging parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants