Closed davidcarlisle closed 1 year ago
We could use the same approach as for dvipdfmx
and use extractbb
- slightly slower but is works well enough
and use extractbb
I don't think shell escape is available
Incidentally pdftex, luatex and xetex/xdvipdfmx all agree on how to infer an intrinsic size of a bitmap, so it would be good if hitex could do the same so that example-image.png
and example-image.jpg
could both be included without specifying a size, producing a 400bp x 300bp box in both cases.
the texlive extractbb manual says:
extractbb (from dvipdfmx) uses density information if present. Otherwise, it generates bounding box with 100px = 100bp. This is what pdfTeX does.
Hi, the \HINTimage primitive works like an improved \input so you the file name needs to be terminated by a space or \relax. The equal sign is optional. I just changed the code so that all double quotes in the name are ignored but protect spaces in the file name. The present code allows quotes only at the beginning and the end. If the file name starts with { it can be any general text up to the closing } brace. So all this is leagal code
\hbox{\HINTimage = ei.jpg }% needs a space to terminate the name
\hbox{\HINTimage ei.jpg }% needs a space to terminate the name
\hbox{\HINTimage = ei.jpg\relax} %\relax terminates
\hbox{\HINTimage = "e i.jpg" } % needs a terminating space or \relax if quoted
\hbox{\HINTimage = {ei.jpg}} % no space if given as general text
\hbox{\HINTimage{ei.jpg}}
\hbox{\HINTimage = {prosa/ei.jpg}}
\hbox{\HINTimage = prosa/ei.jpg\relax}
Reading the image dimension from image files:
hitex can determine the size of an image file if the size is given. Both PNG and JPG files will always specify the dimension in pixels and may optionaly specify the resolution.
PNG may optionally specify the resolution either using pixel/meter as unit or with an undefined unit. The present code will not use the resolution if the unit is undefined. The new code will assume that the unit is pixel/inch. Because this is how it is used most of the time. If no resolution is given in the file, the new code will use the image dimension in pixel and assumes a resolution of 72.27 pixel/inch so 1pixel is 1pt
JPG may optionaly specify the resolution either using pixel/centimeter or pixel/inch as unit or again with an undefined unit. The present code will not use the resolution if the unit is undefined. The new code will ignore the undefined unit as before and proceeds as if no resolution was given. If no resolution is given in the file, the new code will use the image dimension in pixel and assumes a resolution of 72.27 pixel/inch so 1pixel is 1pt. If someone has a better idea what to do with a resolution in an undefined unit, please let me know. I will commit the new code (next week) after some more testing to the TeX Live repository and provide new executables in this repository.
The new code for hitex is now in the TeX Live repo. The current code for hintview (and binaries) are on https://github.com/ruckertm/HINT/ There are also four new testfiles under https://github.com/ruckertm/HINT/tree/main/hilatex/tests namely planimage1.tex plainimage2.tex lxtimage1.tex and ltximage2.tex
The sizes issue is fixed. Just remove the line \def\Gin@urx{72}\let\Gin@ury\Gin@urx from hitex.def
I moved the color problem to a separate issue
in
hint
branches I have started to sketch agraphics.cfg
to default hitex backend if latex is used , and ahitex.def
backend file for latexcolor
andgraphicx
packages.https://github.com/latex3/graphics-cfg/blob/hint/graphics.cfg
https://github.com/latex3/graphics-def/blob/hint/hitex.def
Latex supports
\includegraphics[height=5cm]{example-image.png}
and
\includegraphics[scale=2]{example-image.png}
For most backends height is not supported and so latex converts
height=5cm
toscale=(5cm/<natural height>)
similarly if
scale
is not supported (as is the case with hitex) latex would convertscale=2
toheight=(2*<natural height>)
Either way, latex currently assumes it can get the natural height (the natural size can be passed as an option, but such an option is not needed by currently used back ends)
Is it possible to get the natural size of an image?
Using copies of
/usr/local/texlive/2023/texmf-dist/tex/latex/mwe/example-image{.jpg,.png}
for testing,these images are 400bp by 300bp.
I hoped
\setbox0\hbox{\HINTimage=example-image.jpg}
might work, but
gives
and if I explicitly terminate the
\HINTimage
with\relax
I get no error but 0pt:produces no error but
To avoid division by zero errors the draft
hitex.def
arbitrarily sets the natural size to 1in x 1in, this allowsto include the image, and a scaled version, but the actual sizes are wrong.
Not directly related but the color mapping in the windows hintview seems off for png files,
views as a brown png: