|
|
> I have searched everywhere, but could not find anything about this topic.
> I want to create a Multiline text object.that I can use for further use as a
> whole.
> How can I create such an object? Is it possible to get the text lines centered
> within that object?
> Thanks in advance for your help.
> Regards, Didiw
>
>
>
>
Define an array containing your lines of text, one per element.
#declare your text objects normaly. Once placed, you can reuse the
identifier.
Use max_extent to find the top right point of your lines. The text start
at <0,0,0> and extend toward +X with the front along the X-Y plane. The
thickness extend toward +Z.
To center your text, use translate -max_extent(Your_Text)/2*x or
-max_extent(Your_Text).x/2
To place the lines verticaly, you use the y component returned my
max_extent. Using a given font, all lines should have the same hight.
I recomend creating a macro to create and place your lines.
Next, bind all individual lines into an union.
That way, you can manipulate them all as a single object. If all text is
to have the same texture, apply the texture to the union, not to each
individual lines.
Sample:
#declare My_Text= array[2]
{"First line of text"
,"and a somewhat longer text for the second line"
,"The last line."
}
#declare The_Text= union{
#declare Line=0;
#while(Line<3)
#declare One_line= text{"arial.ttf" My_Text[Line], 1, 0}
#decalre Size= max_extent(One_Line);
object{One_line translate <-Size.x/2, (Size.y*2-Size.y*Line), 0>}
#declare Line=Line+1;
#end
texture{Your_Texture}
}
This will create a 3 lines of text object, with the bottom line on the
X-Z plane centered relative to the Y axis.
Alain
Post a reply to this message
|
|
|
|
Alain <kua### [at] videotronca> writes:
> Le 14-02-21 12:59, didiw a écrit :
>> I have searched everywhere, but could not find anything about this topic.
>> I want to create a Multiline text object.that I can use for further use as a
>> whole.
>> How can I create such an object? Is it possible to get the text lines centered
>> within that object?
>> Thanks in advance for your help.
>> Regards, Didiw
>>
>>
>>
>>
>
> Define an array containing your lines of text, one per element.
> #declare your text objects normaly. Once placed, you can reuse the
> identifier.
> Use max_extent to find the top right point of your lines. The text
> start at <0,0,0> and extend toward +X with the front along the X-Y
> plane. The thickness extend toward +Z.
>
> To center your text, use translate -max_extent(Your_Text)/2*x or
> -max_extent(Your_Text).x/2
>
> To place the lines verticaly, you use the y component returned my
> max_extent. Using a given font, all lines should have the same hight.
>
> I recomend creating a macro to create and place your lines.
>
> Next, bind all individual lines into an union.
> That way, you can manipulate them all as a single object. If all text
> is to have the same texture, apply the texture to the union, not to
> each individual lines.
>
>
> Sample:
>
> #declare My_Text= array[2]
> {"First line of text"
> ,"and a somewhat longer text for the second line"
> ,"The last line."
> }
>
> #declare The_Text= union{
> #declare Line=0;
> #while(Line<3)
> #declare One_line= text{"arial.ttf" My_Text[Line], 1, 0}
> #decalre Size= max_extent(One_Line);
> object{One_line translate <-Size.x/2, (Size.y*2-Size.y*Line), 0>}
> #declare Line=Line+1;
> #end
> texture{Your_Texture}
> }
>
> This will create a 3 lines of text object, with the bottom line on the
> X-Z plane centered relative to the Y axis.
A minor addition: With this method, the lines clutch together, and
you'll get different line heights if your text happens to have only
"small" letters like "aox", uppercase "AOX" or letters with descenders
"yg" - or even just some punctation "...".
I get better results by determining the line height by statically
setting min_y and max_y for a sample text "Ay" (one uppercase, one
descender) for a given font.
Ready to run, for comparison of the two methods:
//----------------------------------------------------------------------
#declare My_Text= array[3]
{"I say,"
,"POV-Ray"
,"is great."
}
camera {
location <0, 0, -20>
up y // which way is +up <X,Y,Z> (aspect ratio with x)
right x*image_width/image_height
look_at <0.0, 0.0, 0.0> // point center of view at this point <X,Y,Z>
}
#declare The_Text= union{
#declare Line=0;
#while(Line<3)
#declare One_line= text{ttf "arial.ttf" My_Text[Line], 0.1, 0}
#declare Size= max_extent(One_line);
object{One_line translate <-Size.x/2, (Size.y*2-Size.y*Line), 0>}
#declare Line=Line+1;
#end
texture{pigment {color rgb <1,0,0>} finish {ambient 1}}
}
#declare LineSpacing = 1.2;
#declare SpacedText = union {
#local Ruler = text{ttf "arial.ttf" "Ag", 0.1, 0};
#local Rmin = min_extent(Ruler);
#local Rmax = max_extent(Ruler);
#local Line = 0;
#while (Line < 3)
#local OneLine = text{ttf "arial.ttf" My_Text[Line], 0.1, 0}
#declare Size= max_extent(OneLine);
object{OneLine translate <-Size.x/2, LineSpacing*(Rmin.y-Rmax.y)*Line, 0>}
#local Line=Line+1;
#end
texture{pigment {color rgb <0,0,1>} finish {ambient 1}}
}
object {The_Text translate -3*y}
object {SpacedText translate 3*y}
//----------------------------------------------------------------------
--
Cheers,
haj
Post a reply to this message
|
|