ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jens-Uwe Morawski <morawski@gmx.net>
Subject: Re: MetaFun questions
Date: Fri, 28 Feb 2003 15:22:56 +0100	[thread overview]
Message-ID: <20030228152256.02da080c.morawski@gmx.net> (raw)
In-Reply-To: <5.1.0.14.1.20030227155333.02435320@server-1>

On Thu, 27 Feb 2003 15:55:41 +0100
Hans Hagen <pragma@wxs.nl> wrote:

> At 02:09 PM 2/27/2003 +0100, you wrote:
> 
> >- if i can draw a gradient/shading with two RGBA colors, for example,
> >   a gradient starting with red=1 and alpha=0.5 and ending with green=1
> >   and alpha=0.7
> 
> in supp-mpe.tex seatch for:
> 
>   CircularShade  LinearShade  DuotoneShade


i know linear_shade, circular_shade...; the question is how can
i use them with transparency:

\definecolor[sa][r=1,t=0.7,a=1]
\definecolor[ea][g=1,t=0.5,a=1]

\definecolor[s][r=1]
\definecolor[e][g=1]

\startMPgraphic
  path p ; p := unitsquare xscaled 5cm yscaled 5cm ;
  fill p shifted (4cm,4cm) withcolor .7white ;
  fill p shifted (-3cm,-3cm) withcolor .8white ;

  linear_shade(p,0,\MPcolor{s},\MPcolor{e});
\stopMPgraphic

\loadcurrentMPgraphic\placeMPgraphic

the code above draws a gradient for colors s and e but not for colors
 sa and ea. Is this because gradients _and_ transparency together
are not supported or is it because i do it the wrong way.
 
> >- if it is possible to add some capabilities to texutil, or where else
> >   it is needed, so that
> >   externalfigure "somefile" scaled 2 ;
> >
> >   has the original figure-size scaled 2 and not unitsquare scaled 2
> 
> can you be a bit more explicit

for example, if i have a PNG graphic with width 216 pixels and height of
144 pixels, then the ratio of width/height is 3/2. If i scale this
figure with factor 2 using \externalfigure in ConTeXt then the
aspectratio is kept.
Using the

externalfigure("figurefile") scaled 2

in MetaPost results in figure with a size of
unitsquare scaled 2

Neither the ratio of width and height nor the size of the original
graphic are maintained or have any influence on the output.

Thus, i would like to suggest something that:

- assuming following MP code:
  externalfigure("mygraphic.png") scaled 2 ;
  externalfigure("anothergraphic.pdf"") scaled 5 ;
 
- in a first metapost-run each "externalfigure" writes the name
  of the graphic file in a temporary file, for example
  <jobname>-extfigures.tmp

- texutil, or something else, reads this file, determines the
  original size of the graphics and writes an input file
  (<jobname>-extfigures.mp) for the following MP
  run that contains for example:

numeric numof_externalfigures, widthof_externalfigure[],
        heightof_externalfigure[] ;
string nameof_externalfigure[] ;

numof_externalfigures:=2 ;
nameof_externalfigure[1]  := "mygraphic.png" ;
widthof_externalfigure[1] := 2cm ;
heightof_externalfigure[1]:= 4cm ;

nameof_externalfigure[2]  := "anothergraphic.pdf" ;
widthof_externalfigure[2] := 3cm ;
heightof_externalfigure[2]:= 5cm ;

- then the macro "doexternalfigure" could be :

def doexternalfigure (expr filename) text transformation =
  begingroup ; save p, t ; picture p ; transform t ;

%% here comes the part that writes the filename to
%% <jobname>-extfigures.tmp

%%>> added
   save w_, h_ ; numeric w_, h_ ;
   w_ := 1 ; h_ := 1 ;
   if (known numof_externalfigures):
     if (numof_externalfigures>0):
       for i=1 upto numof_externalfigures:
         if (nameof_externalfigure[i]=filename):
            w_ := widthof_externalfigure[i] ;
            h_ := heightof_externalfigure[i] ;
         fi;
       endfor;
     fi;
   fi;
%%<<

%%>> changed
%
% original:
%
% p := nullpicture ; t := identity transformation ;
%
  p := nullpicture ; t := ( (identity xscaled w_) yscaled h_ ) transformation ;
%%<<

  flush_special(10, 9,
    dddecimal (xxpart t, yxpart t, xypart t) & " " &
    dddecimal (yypart t,  xpart t,  ypart t) & " " & filename) ;

   addto p contour unitsquare scaled 0 ;
   setbounds p to unitsquare transformed t ;
  _color_counter_ := _color_counter_ + 1 ;
  draw p withcolor (_special_signal_/1000,_color_counter_/1000,_special_counter_/1000) ;
  endgroup ;
enddef ;

This should allow to maintain size and aspectratio of external figures, even
in MP. The problem is, how can texutil determine the original size of the
figures?! Is it possible to implement this?

Best,
  Jens

  parent reply	other threads:[~2003-02-28 14:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-27 13:09 Jens-Uwe Morawski
2003-02-27 14:55 ` Hans Hagen
2003-02-27 19:05   ` Nigel King
2003-02-28  7:43     ` Hans Hagen
2003-02-28  9:17       ` Nigel King
2003-03-06 13:13         ` Hans Hagen
2003-03-06 17:16           ` Jens-Uwe Morawski
2003-03-07 10:21             ` Hans Hagen
2003-02-28 14:22   ` Jens-Uwe Morawski [this message]
2003-03-03 21:10     ` Hans Hagen
2003-03-06 18:10       ` Jens-Uwe Morawski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030228152256.02da080c.morawski@gmx.net \
    --to=morawski@gmx.net \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).