texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Texmacs-dev] gs_to_png broken -- how to fix?


From: Joris van der Hoeven
Subject: Re: [Texmacs-dev] gs_to_png broken -- how to fix?
Date: Fri, 3 Dec 2010 17:14:52 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

Dear Norbert,

Thanks for the fix; I applied it. Please make one further correction and
avoid running grep, which is not available under windows; we try to minimize
our dependency on external Unix commands, also for security reasons.

There are many problems with the images... ;^(

In fact, David Michel (who has left the team by now) made several modifications
in the image support: see the #ifdefs in the routine image_size (in 
image_files.cpp).
The intention is good, but the actual implementation bugged in different ways 
for
the various possibilities. If you could carefully test the various cases and
correct these bugs, then that would be great. I attach a few files of mine
in which the images are displayed wrongly.

Best, --Joris


On Fri, Dec 03, 2010 at 03:19:28PM +0100, Norbert Nemec wrote:
> Sorry about the overly complicated description. Here is a patch that fixes 
> the problem for me. It should not break any working document and -- as I 
> believe -- restore the old behavior.
> 
> -------- Original-Nachricht --------
> > Datum: Fri, 3 Dec 2010 14:56:25 +0100
> > Von: Gubinelli Massimiliano <address@hidden>
> > An: address@hidden
> > Betreff: Re: [Texmacs-dev] gs_to_png broken -- how to fix?
> 
> > Hi Norbert,
> >   I'm not quite able to follow your description now but the code in Qt  
> > is broken with respect positioning of ps images so if you can fix it  
> > that would be nice. As a comparison, the X11 code should be considered  
> > correct (unless you remark also there some inconsistencies). I think  
> > the most important thing is to preserve appearence of old documents  
> > (again unless hard arguments are put forward against).
> > 
> > best
> > max
> > 
> > 
> > On 3 déc. 10, at 14:52, Norbert Nemec wrote:
> > 
> > > Hi there,
> > >
> > > i just wondered why several old documents that used to work fine do  
> > > not properly display the linked EPS images any more. I identified  
> > > the problem as an inconsistency in using Ghostscript:
> > >
> > > The routine gs_image_size uses 'gs -sDEVICE=bbox' to obtain the  
> > > image size. This command ignores the bbox saved in the header of the  
> > > eps image and instead analyses the contents to find the smallest  
> > > rectangle containing the image.
> > >
> > > Lateron the image is scaled with gs setting the computed resolution  
> > > via the '-r' option. In this context, Ghostscript honors the bbox in  
> > > the EPS header.
> > >
> > > The result is that EPS files that contain an empty border within the  
> > > specified bounding box around the actual content are displayed  
> > > shifted and cropped within TeXmacs.
> > >
> > > Before trying to fix this inconsistency: what behavior is intended?  
> > > Should the specified bbox be honored or should TeXmacs determine the  
> > > bbox from the content?
> > >
> > > Perhaps, the best solution would be to honor an existing bbox and  
> > > determine the bbox from the content if none is given within the EPS  
> > > file. This may cause problems with EPS files that specify a bad  
> > > bbox, but at least it will work correctly with intentionally non- 
> > > minimal bbox settings.
> > >
> > > Opinions?
> > >
> > > Norbert Nemec
> > > -- 
> > > Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
> > > Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
> > >
> > > _______________________________________________
> > > Texmacs-dev mailing list
> > > address@hidden
> > > http://lists.gnu.org/mailman/listinfo/texmacs-dev
> > 
> > 
> > _______________________________________________
> > Texmacs-dev mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/texmacs-dev
> 
> -- 
> GMX DSL Doppel-Flat ab 19,99 &euro;/mtl.! Jetzt auch mit 
> gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl

> >From 0eea8c36d0518005ed069e1fec538141fb2ce58e Mon Sep 17 00:00:00 2001
> From: Norbert Nemec <address@hidden>
> Date: Fri, 3 Dec 2010 15:14:53 +0100
> Subject: [PATCH] Fix eps_to_png to read bbox from file
> 
> ---
>  src/src/Plugins/Ghostscript/gs_utilities.cpp |   30 +++++++++++++++----------
>  1 files changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/src/src/Plugins/Ghostscript/gs_utilities.cpp 
> b/src/src/Plugins/Ghostscript/gs_utilities.cpp
> index 859decc..7459b7d 100644
> --- a/src/src/Plugins/Ghostscript/gs_utilities.cpp
> +++ b/src/src/Plugins/Ghostscript/gs_utilities.cpp
> @@ -25,17 +25,25 @@ gs_supports (url image) {
>  
>  void
>  gs_image_size (url image, int& w_pt, int& h_pt) {
> -#if defined (__MINGW__) || defined (__MINGW32__)
> -  string cmd= "\"";
> -  cmd << get_env ("TEXMACS_PATH") << string ("\\bin\\gswin32c\" ");
> -#else
> -  string cmd= "gs ";
> -#endif
> -  cmd << "-dQUIET -dNOPAUSE -dBATCH -dSAFER -dEPSCrop -sDEVICE=bbox ";
> +  string cmd;
> +  cmd= "grep -m 1 '^%%BoundingBox: ' ";
>    cmd << sys_concretize (image);
>    string buf= eval_system (cmd);
>    int pos= 0;
>    int ok= read (buf, pos, "%%BoundingBox: ");
> +  if (!ok) {
> +#if defined (__MINGW__) || defined (__MINGW32__)
> +    cmd= "\"";
> +    cmd << get_env ("TEXMACS_PATH") << string ("\\bin\\gswin32c\" ");
> +#else
> +    cmd= "gs ";
> +#endif
> +    cmd << "-dQUIET -dNOPAUSE -dBATCH -dSAFER -dEPSCrop -sDEVICE=bbox ";
> +    cmd << sys_concretize (image);
> +    string buf= eval_system (cmd);
> +    int pos= 0;
> +    int ok= read (buf, pos, "%%BoundingBox: ");
> +  }
>    if (ok) {
>      int x1, y1, x2, y2;
>      skip_spaces (buf, pos);
> @@ -69,12 +77,10 @@ gs_to_png (url image, url png, int w, int h) {
>    cmd << "-sDEVICE=png16m -dGraphicsAlphaBits=4 -dEPSCrop ";
>    cmd << "-g" << as_string (w) << "x" << as_string (h) << " ";
>    int bbw, bbh;
> -  double rw, rh;
> +  int rw, rh;
>    gs_image_size (image, bbw, bbh);
> -  rw= (double)w*72/bbw;
> -  rh= (double)h*72/bbh;
> -  if ((int)rw < rw) rw= (int)rw+1; else rw= (int)rw;
> -  if ((int)rh < rh) rh= (int)rh+1; else rh= (int)rh;
> +  rw= (w*72-1)/bbw+1;
> +  rh= (h*72-1)/bbh+1;
>    cmd << "-r" << as_string (rw) << "x" << as_string (rh) << " ";  
>    cmd << "-sOutputFile=" << sys_concretize (png) << " ";
>    cmd << sys_concretize (image);
> -- 
> 1.7.1
> 

> _______________________________________________
> Texmacs-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/texmacs-dev

Attachment: Auron.tar.gz
Description: Binary data

Attachment: noeth.tar.gz
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]