From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: ntg-context@ntg.nl
Subject: Re: checking whether file is landscape or portrait
Date: Tue, 28 Jan 2020 17:46:58 +0100 [thread overview]
Message-ID: <20200128174658.d9d5ab40891239ab05f50a4a@gmail.com> (raw)
In-Reply-To: <69FAAE50-CEBA-4409-AAEA-C16CCCFFF738@elvenkind.com>
On Tue, 28 Jan 2020 17:04:52 +0100
Taco Hoekwater <taco@elvenkind.com> wrote:
> Hi Pablo,
>
> I have had lots of problems with getting the correct figure dimensions
> for external images. In the end, I now use the code below. It is just
> as low-level and much more inefficient than your code, but it has not
> failed me yet.
>
> \newdimen\MYfigurewidth
> \newdimen\MYfigureheight
> \unexpanded\def\MYgetfiguredimensions
> {\dodoubleempty\MYdogetfiguredimensions}
>
> \def\MYdogetfiguredimensions[#1][#2]%
> {\setbox0=\hbox{\externalfigure[#1][#2]}%
> \MYfigurewidth=\wd0
> \MYfigureheight=\ht0 }
>
> And used like:
>
> \MYgetfiguredimensions[cow.pdf][page=1]
> \ifdim\MYfigurewidth>\MYfigureheight
> …
> \fi
>
> and I only use Hans’ \getfiguredimensions when I need to know a pdf page count.
>
> It is not that Hans’ macro is bad, but external figures (especially PDF,
> but also PNGs) can be very misbehaved.
>
> Actually forcing the inclusion into a box is crude but at least it will
> always return results identical to any actual desired inclusion.
I modified your code a bit to give it the ConTeXt touch.
Alternative 1:
\setupexternalfigures[location=default]
\starttext
\unexpanded\def\doifelselandscape
{\dowithnextbox
{\ifdim\nextboxwd>\nextboxht
\expandafter\firstoftwoarguments
\else
\expandafter\secondoftwoarguments
\fi}
\hbox}
\doifelselandscape{\externalfigure[cow.pdf]}{YES}{NO}
\doifelselandscape{\externalfigure[mill.png]}{YES}{NO}
\blank
\unexpanded\def\doifelselandscapefigure#1#2%
{\doifelselandscape{\externalfigure[#1][#2]}}
\doifelselandscapefigure{cow.pdf}{}{YES}{NO}
\doifelselandscapefigure{mill.png}{}{YES}{NO}
\stoptext
Alternative 2:
\setupexternalfigures[location=default]
\newif\iflandscape
\unexpanded\def\checkiflandscape
{\dowithnextbox
{\ifdim\nextboxwd>\nextboxht
\landscapetrue
\else
\landscapefalse
\fi}
\hbox}
\starttext
\checkiflandscape{\externalfigure[cow.pdf]}
\iflandscape
YES
\else
NO
\fi
\checkiflandscape{\externalfigure[mill.png]}
\iflandscape
YES
\else
NO
\fi
\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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2020-01-28 16:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 15:51 Pablo Rodriguez
2020-01-28 16:04 ` Taco Hoekwater
2020-01-28 16:39 ` Pablo Rodriguez
2020-01-28 16:46 ` Wolfgang Schuster [this message]
2020-01-28 16:15 ` Wolfgang Schuster
2020-01-28 16:43 ` Pablo Rodriguez
2020-01-29 13:31 ` Arthur Reutenauer
2020-01-29 15:44 ` Pablo Rodriguez
2020-01-30 12:08 ` context
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=20200128174658.d9d5ab40891239ab05f50a4a@gmail.com \
--to=wolfgang.schuster.lists@gmail.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).