POV-Ray : Newsgroups : povray.general : Centring a text object declaring a directive : Re: Centring a text object declaring a directive Server Time
2 Mar 2024 21:23:22 EST (-0500)
  Re: Centring a text object declaring a directive  
From: jr
Date: 19 Apr 2023 08:55:00
Message: <web.643fe36e59e0b6654301edef6cde94f1@news.povray.org>
hi,

"Kima" <nomail@nomail> wrote:
> I align a text object as
>
> local MyText=text {ttf "timrom.ttf", "Some text",1,0 }
>
> object { MyText
>    translate -(min_extent(MyText) + max_extent(MyText)) / 2
> }
>
> `Center_Trans` in transforms.inc is also based on the same approach.
>
> I wonder if there is a way to do so without defining the directive of `MyText`.
>
> I mean something like `min_extent()` of the current object.

not sure about objects in general, but with a text{} you could "cheat" using a
macro, eg:

#macro textLen(font_,s_)
  #local t_ = text {ttf font_, s_, 1, 0};
  (max_extent(t_).x - min_extent(t_).x)
#end

#declare txt_ = text {
  ttf "timrom.ttf", "some more text", .1, 0
  texture {texture_}
  translate <-(textLen("timrom.ttf","some more text")) / 2,-2,0>
};
object {txt_}


regards, jr.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.