POV-Ray : Newsgroups : povray.general : Centring a text object declaring a directive Server Time
14 Oct 2024 04:43:46 EDT (-0400)
  Centring a text object declaring a directive (Message 1 to 5 of 5)  
From: Kima
Subject: Centring a text object declaring a directive
Date: 19 Apr 2023 07:40:00
Message: <web.643fd2662f53e92c65103170d427f3e5@news.povray.org>
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.


Post a reply to this message

From: jr
Subject: Re: Centring a text object declaring a directive
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

From: Kima
Subject: Re: Centring a text object declaring a directive
Date: 19 Apr 2023 19:15:00
Message: <web.644074f459e0b66565103170d427f3e5@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

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


Your solution works like a charm. My problem was exactly the text. It is easier
to find the middle point for an object as we design them, but for texts, we rely
on font metrics.

Thanks!


Post a reply to this message

From: jr
Subject: Re: Centring a text object declaring a directive
Date: 20 Apr 2023 04:55:00
Message: <web.6440fd1159e0b6654301edef6cde94f1@news.povray.org>
hi,

"Kima" <nomail@nomail> wrote:
> ...
> Your solution works like a charm. My problem was exactly the text. It is easier
> to find the middle point for an object as we design them, but for texts, we rely
> on font metrics.
>
> Thanks!

great :-)  pleasure.


regards, jr.


Post a reply to this message

From: kurtz le pirate
Subject: Re: Centring a text object declaring a directive
Date: 23 Apr 2023 04:13:04
Message: <6444e890@news.povray.org>
On 19/04/2023 14:49, jr wrote:
> 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_}


Following jr's good idea and even if you have to use macro, you might as
well make a "complete" one :

#macro MakeCentetText (pText, pFont, pThickness, pOffset, pTexture)
 #local _t = text { ttf pFont pText pThickness, pOffset }
 #local _l = (max_extent(_t).x-min_extent(_t).x)*0.50;
 object { _t translate -_l*x texture { pTexture } }
#end


and using it like this :

object {
 MakeCentetText("some more text", "timrom.ttf", 0.10, 0, myTexture )
 }





-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

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