From: "Wolfgang Schuster" <schuster.wolfgang@googlemail.com>
To: "mailing list for ConTeXt users" <ntg-context@ntg.nl>
Subject: Re: fitting a picture to the available space
Date: Fri, 12 Sep 2008 09:14:36 +0200 [thread overview]
Message-ID: <115224fb0809120014w21fdf697n1f4221d9a4d3839c@mail.gmail.com> (raw)
In-Reply-To: <6CC7A5A8-9679-4501-B8D0-34571BD72038@uni-bonn.de>
On Thu, Sep 11, 2008 at 11:50 PM, Thomas A. Schmitz
<thomas.schmitz@uni-bonn.de> wrote:
>
> On Sep 11, 2008, at 7:59 PM, Thomas A. Schmitz wrote:
>
>>
>> On Sep 11, 2008, at 6:20 PM, Thomas A. Schmitz wrote:
>>
>>>> \starttext
>>>>
>>>> \start
>>>>
>>>> \setbox\scratchbox\vbox{\externalfigure[mill]}
>>>>
>>>> \dimen0=\wd\scratchbox
>>>> \dimen2=\ht\scratchbox
>>>>
>>>> \framed[frame=on,strut=no,width=8cm,height=2cm]
>>>> {\dimen1=\hsize \divide\dimen1 by \dimen0
>>>> \dimen3=\vsize \divide\dimen3 by \dimen2
>>>> \ifdim\dimen1>\dimen3
>>>> \externalfigure[mill][height=\vsize]
>>>> \else
>>>> \externalfigure[mill][width=\hsize]
>>>> \fi}
>>>>
>>>> \framed[frame=on,strut=no,width=2cm,height=8cm]
>>>> {\dimen1=\hsize \divide\dimen1 by \dimen0
>>>> \dimen3=\vsize \divide\dimen3 by \dimen2
>>>> \ifdim\dimen1>\dimen3
>>>> \externalfigure[mill][height=\vsize]
>>>> \else
>>>> \externalfigure[mill][width=\hsize]
>>>> \fi}
>>>>
>>>> \stop
>>>>
>>>> \stoptext
>>>>
>>>> Wolfgang
>>>
>>> Wolfgang,
>>>
>>> as always, you're a source of wisdom and knowledge... Just I
>>> understand this correctly and can adapt it to my macro: \dimen1=
>>> \hsize: here \hsize refers to the size of the \framed inside which
>>> we're operating, right?
>>
>> And another question: I get an error "! Illegal unit of measure (pt
>> inserted)." Is it really possible to divide a dimension by another
>> dimension? Not according to what I read here: http://www.tug.org/utilities/plain/cseq.html#divide-rp
>> "must be a nonzero integer." See, I'm far from being a native
>> speaker of TeX...
>>
> I now have something along these lines (ugly code ahead!):
>
> \setbox\scratchbox\vbox{\externalfigure[mill]%
> \dimen0=\wd\scratchbox%
> \def\@WD{\withoutpt{\the\dimen0}}%
> \def\@@WD{\integerrounding{\@WD}}%
> \dimen4=\textwidth \divide\dimen4 by \@@WD%
> \dimen2=\ht\scratchbox%
> \def\@HT{\withoutpt{\the\dimen2}}%
> \def\@@HT{\integerrounding{\@HT}}%
> \dimen6=\textheight \divide\dimen6 by \@@HT%
> \ifdim\dimen4>\dimen6%
> \def\Myheight{\textheight}\def\Mywidth{}%
> \else%
> \def\Mywidth{\textwidth}\def\Myheight{}%
> \fi
>
> and then use height=\Myheight,width=\Mywidth. Bu there's still a
> problem... Anyway, does it make sense in general?
You should close the box before you want to get it's dimensions.
\unprotect
\def\????bf{@@@@bf}
\presetlocalframed[\????bf]
\def\boxfigure[#1][#2]%
{\bgroup
\setbox\scratchbox\hbox{\externalfigure[#1]}%
\!!dimena\wd\scratchbox
\!!dimenb\ht\scratchbox
\localframed
[\????bf]
[\c!strut=\v!no,
\c!width=8cm,
\c!height=6cm,
#2]
\bgroup
\!!dimena\dimexpr\hsize/\!!dimena\relax
\!!dimenb\dimexpr\vsize/\!!dimenb\relax
\ifdim\!!dimena>\!!dimenb
\externalfigure[mill][height=\vsize]
\else
\externalfigure[mill][width=\hsize]
\fi
\egroup
\egroup}
\protect
\starttext
\boxfigure[mill][width=8cm,height=2cm]
\boxfigure[mill][width=2cm,height=8cm]
\stoptext
Wolfgang
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2008-09-12 7:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-10 22:06 Thomas A. Schmitz
2008-09-11 7:28 ` Hans Hagen
2008-09-11 8:04 ` Thomas A. Schmitz
2008-09-11 13:28 ` Thomas A. Schmitz
2008-09-11 14:01 ` Peter Rolf
2008-09-11 14:40 ` Thomas A. Schmitz
2008-09-11 14:56 ` Hans Hagen
2008-09-11 14:13 ` Wolfgang Schuster
2008-09-11 16:20 ` Thomas A. Schmitz
2008-09-11 16:39 ` Hans Hagen
2008-09-11 17:59 ` Thomas A. Schmitz
2008-09-11 21:50 ` Thomas A. Schmitz
2008-09-12 7:14 ` Wolfgang Schuster [this message]
2008-09-12 12:37 ` Thomas A. Schmitz
2008-09-11 16:31 ` Mojca Miklavec
2008-09-12 10:02 ` Wolfgang Schuster
2008-09-12 15:20 ` Mojca Miklavec
2008-09-12 15:37 ` Hans Hagen
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=115224fb0809120014w21fdf697n1f4221d9a4d3839c@mail.gmail.com \
--to=schuster.wolfgang@googlemail.com \
--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).