ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Bounding box of picture returned by textext() in METAPOST
@ 2020-04-04 20:58 Gerben Wierda
  2020-04-05 16:04 ` Gerben Wierda
  0 siblings, 1 reply; 2+ messages in thread
From: Gerben Wierda @ 2020-04-04 20:58 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2104 bytes --]

I have this METAPOST macro:

vardef makeTeXLabel( expr w, h, name) =
  if debugProgram or debugLabels: show "NAME makeTeXLabel:", name, tostring 0.8w, tostring 0.8h; fi
  save p; picture p;
  p := textext( "\startframedtext[middle]" &
    "[align=middle,frame=on" &
    ",width=" & tostring 0.8w & "bp" &
    ",height=" & tostring 0.8h & "bp]" &
    name & "\stopframedtext");
  save b; path b; b := boundingbox p;
  save dim; pair dim;
  dim := (urcorner b) - (llcorner b);
  save width, height; numeric width, height;
  width := xpart dim;
  height = ypart dim;
  if debugLabels: show "PLACE:", w, h, width, height; fi
  if (width > 0.8w) or (height > 0.8h):
    if (width > height):
      if debugLabels: show "XSCALING:", (0.8w/width,0.8w/width); fi
      p:= p xyscaled (0.8w/width,0.8w/width);
    else:
      if debugLabels: show "YSCALING:", (0.8h/height,0.8h/height); fi
      p:= p xyscaled (0.8h/height,0.8h/height);
    fi
  fi
  p
enddef;

It gets called with w=133 and h=53 (I am working in METAPOST native units, so bp)

So, the textext() command gets something like 106bp x 42bp, which seems to be the case:

metapost log    > >> "NAME makeTeXLabel:"
metapost log    > >> "My 'Application' Function"
metapost log    > >> "106.40000000000001"
cld             > tex > w : - : \MPLIBsetNtextX{1}{\startframedtext [middle][align=middle,frame=on,width=106.40000000000001bp,height=42.400000000000006bp]My 'Application' Function\stopframedtext }
cld             > tex > F : - : \startblankhandling
cld             > tex > w : - : \setblankcategory{6}
cld             > tex > F : - : \flushblankhandling
cld             > tex > F : - : \stopblankhandling
metapost log    > >> "42.400000000000006"
metapost log    > >> "PLACE:"
metapost log    > >> 133
metapost log    > >> 53
metapost log    > >> 511.08659908200002
metapost log    > >> 42.399990514000002

But the bounding box is 511bp wide (something like 7in or 18cm, probably textwidth) but I’m asking for a box that is 106bp wide.

What happens here? And how do I get it right? 

G



[-- Attachment #1.2: Type: text/html, Size: 5853 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bounding box of picture returned by textext() in METAPOST
  2020-04-04 20:58 Bounding box of picture returned by textext() in METAPOST Gerben Wierda
@ 2020-04-05 16:04 ` Gerben Wierda
  0 siblings, 0 replies; 2+ messages in thread
From: Gerben Wierda @ 2020-04-05 16:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2820 bytes --]

Nobody?

> On 4 Apr 2020, at 22:58, Gerben Wierda <gerben.wierda@rna.nl> wrote:
> 
> I have this METAPOST macro:
> 
> vardef makeTeXLabel( expr w, h, name) =
>   if debugProgram or debugLabels: show "NAME makeTeXLabel:", name, tostring 0.8w, tostring 0.8h; fi
>   save p; picture p;
>   p := textext( "\startframedtext[middle]" &
>     "[align=middle,frame=on" &
>     ",width=" & tostring 0.8w & "bp" &
>     ",height=" & tostring 0.8h & "bp]" &
>     name & "\stopframedtext");
>   save b; path b; b := boundingbox p;
>   save dim; pair dim;
>   dim := (urcorner b) - (llcorner b);
>   save width, height; numeric width, height;
>   width := xpart dim;
>   height = ypart dim;
>   if debugLabels: show "PLACE:", w, h, width, height; fi
>   if (width > 0.8w) or (height > 0.8h):
>     if (width > height):
>       if debugLabels: show "XSCALING:", (0.8w/width,0.8w/width); fi
>       p:= p xyscaled (0.8w/width,0.8w/width);
>     else:
>       if debugLabels: show "YSCALING:", (0.8h/height,0.8h/height); fi
>       p:= p xyscaled (0.8h/height,0.8h/height);
>     fi
>   fi
>   p
> enddef;
> 
> It gets called with w=133 and h=53 (I am working in METAPOST native units, so bp)
> 
> So, the textext() command gets something like 106bp x 42bp, which seems to be the case:
> 
> metapost log    > >> "NAME makeTeXLabel:"
> metapost log    > >> "My 'Application' Function"
> metapost log    > >> "106.40000000000001"
> cld             > tex > w : - : \MPLIBsetNtextX{1}{\startframedtext [middle][align=middle,frame=on,width=106.40000000000001bp,height=42.400000000000006bp]My 'Application' Function\stopframedtext }
> cld             > tex > F : - : \startblankhandling
> cld             > tex > w : - : \setblankcategory{6}
> cld             > tex > F : - : \flushblankhandling
> cld             > tex > F : - : \stopblankhandling
> metapost log    > >> "42.400000000000006"
> metapost log    > >> "PLACE:"
> metapost log    > >> 133
> metapost log    > >> 53
> metapost log    > >> 511.08659908200002
> metapost log    > >> 42.399990514000002
> 
> But the bounding box is 511bp wide (something like 7in or 18cm, probably textwidth) but I’m asking for a box that is 106bp wide.
> 
> What happens here? And how do I get it right? 
> 
> G
> 
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________


[-- Attachment #1.2: Type: text/html, Size: 7299 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-05 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-04 20:58 Bounding box of picture returned by textext() in METAPOST Gerben Wierda
2020-04-05 16:04 ` Gerben Wierda

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).