On Sat, Apr 13, 2024 at 05:25:17PM +0800, Qian Yun wrote:
> One of the problems of postscript files generated by "draw" is that
> it is not proper "embedded postscript file", aka "eps".
> 
> When trying to include such image files in latex document, there are
> huge padding around image.
> 
> The problem is caused by "BoundingBox".  We have "BoundingBox" in
> generated PS file, but almost all utilities such as "ps2pdf",
> "epstopdf" only recognize "BoundingBox" in the header comment section.
> 
> FriCAS generates "BoundingBox" in the middle of the PS file.
> 
> Following patch is a proof of concept to fix this issue.
> 
> After this patch, I can use "epstopdf" to convert PS file to
> properly cropped pdf file.

Thanks for looking into this.
 
> I think for a proper fix, a better way is to split "headerps"
> into two and add a "boundingbox" patch in between?

Hmm, I would remove the '%!PS-Adobe-2.0' comment from 'header.ps'
(as you do).  IIUC 'BoundingBox' comment is supposed to appear
just after '%!PS-Adobe-2.0', so it is natural to print both
together, like you do.

I have some doubts concerning use 'vwInfo.height' and 'vwInfo.width'.
Namely, 'Gdraws_setDimension' clearly make some effort to fit
image onto page (it put appropriate rescaling operation into .ps file).
So, it seems that 'Gdraws_setDimension' computes _real_ bounding
box and we should use it in 'BoundingBox' comment.  Currently,
as you noted 'BoundingBox' comment is ignored and typical
images fit inside page, so nothing bad happens due to possibly
incorrect bouding box.  But for people with big screens and
in case we make 'Gdraws_setDimension' smarter we should use
dimensions computed in 'Gdraws_setDimension' when emiting
'BoundingBox' comment.  Which probably means that we should
propagate information from 'Gdraws_setDimension' to
'PSCreateFile'.


> 
> 
> - Qian
> 
> diff --git a/src/graph/Gdraws/Gfun.c b/src/graph/Gdraws/Gfun.c
> index 808822aa..027e1dbe 100644
> --- a/src/graph/Gdraws/Gfun.c
> +++ b/src/graph/Gdraws/Gfun.c
> @@ -98,6 +98,11 @@ PSCreateFile(
>      return (psError);
>    }
>    else {
> +    fprintf(ofp, "%%!PS-Adobe-2.0\n");
> +    XWindowAttributes vwInfo;
> +    XGetWindowAttributes(dsply, vw, &vwInfo);
> +    /* Write a Bounding Box for psfig etc. */
> +    fprintf(fp, "%%%%BoundingBox: 0 0 %d %d\n", vwInfo.height,
> vwInfo.width);
>      i = 1;
>      while (i < psDrawNo) {  /* loops through each file/procedure */
>        if (psData[i].flag) { /* if set, procedure/file is used */
> @@ -226,10 +231,6 @@ Gdraws_setDimension(
>    fprintf(fp, "\t%d\t%d\t%d\tsetDim\n", twInfo.height - vwInfo.height,
>            vwInfo.height, vwInfo.width);
> 
> -  /* Write a Bounding Box for psfig etc. */
> -
> -  fprintf(fp, "%%%%BoundingBox: 0 0 %d %d\n", vwInfo.height, vwInfo.width);
> -
>    fprintf(fp, "\tmaxX maxY\t0 0\trectangle\tclip\t%% set clip path\n\n");
>    return (fclose(fp));
>  }
> diff --git a/src/graph/Gdraws/ps_files/header.ps
> b/src/graph/Gdraws/ps_files/header.ps
> index e945bec4..037914ac 100644
> --- a/src/graph/Gdraws/ps_files/header.ps
> +++ b/src/graph/Gdraws/ps_files/header.ps
> @@ -1,4 +1,3 @@
> -%!PS-Adobe-2.0
>  %%DocumentFonts: Times-Roman
>  %%Creator: FriCAS
>  %%CreationDate: today
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to fricas-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/fricas-devel/613e7b4e-d8b1-4283-9339-d57765b29cde%40gmail.com.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZhqFO3dJGnSTXFJE%40fricas.org.

Reply via email to