POV-Ray : Newsgroups : povray.general : Centring a text object declaring a directive : Re: Centring a text object declaring a directive Server Time
18 Apr 2024 00:17:27 EDT (-0400)
  Re: Centring a text object declaring a directive  
From: kurtz le pirate
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.