|
|
/* BEGIN MACRO */
// From Circle_Text author: Ron Parker (modified by Bob Hughes)
/* Label_Text( Font, Text, Size, Spacing, Thickness, Radius, Inverted,
Justification, Angle )
Creates a text object with the bottom (or top) of the character cells
aligned
with all or part of a circle. This macro should be used inside an
object{...}
block.
Font: The font to use (see the documentation for the text object)
Text: The text string to be created
Size: The height of the text string, as you would use to scale a
standard text object
Spacing: The amount of space to add between the letters.
Thickness: The thickness of the letters (see the documentation for the
text object)
Radius: The radius of the circle along which the letters are aligned
Inverted: If this parameter is nonzero, the tops of the letters will
point toward the center of the circle. Otherwise, the
bottoms
of the letters will do so.
Justification: One of the constants Align_Left, Align_Right, or Align_Center
Angle: The point on the circle from which rendering will begin. The
+x direction is 0 and the +y direction is 90 (i.e. the angle
increases anti-clockwise.
Label: Orient to imaginary cylinder surface. Value is degrees, i.e.
angles of -90 or +90, with 0 being flat on the z plane.
This is not aligned to y-axis! Think wood pattern, -z to +z
cylinder. Values other than zero or +/- 90 will be conical.
*/
#macro Circle_Text(F, T, S, Sp, Th, R, I, J, A, L)
#local FW = Text_Width(F, T, S, Sp);
#local TO = text {ttf F T 1 0 scale<S, S, 1>}
#local TH = max_extent(TO).y;
#local C = array[strlen(T)]
#if(FW > 2*pi*R)
#error concat("\n\n**** Text string \"", T, "\" is too long for a
circle of the specified radius.\n\n\n")
#end
#local AW = -FW*180/pi/R;
#local SA = A;
#local EA = A + AW;
#if(((J = Align_Right) & !I)|((J = Align_Left) & I))
#local SA = A - AW;
#local EA = A;
#else
#if(J = Align_Center)
#local SA = A - AW/2;
#local EA = A + AW/2;
#end
#end
#local CI = 1;
#while(CI <= strlen(T))
#local OE = Text_Width(F, substr(T,CI,1), S, Sp);
#local LW = Text_Width(F, substr(T,1,CI), S, Sp) - OE;
#local LA = SA + AW*LW/FW + OE/2/FW*AW;
#if(I)
#local LA = EA - (LA - SA);
#end
#local TO = text {ttf F substr(T, CI, 1) Th 0 scale<S,S,1>}
#local TD = max_extent(TO).z; // text object depth
#local CA = L; // add bottle label orientation
#if(I)
#local C[CI-1] =
object {TO
rotate 180*z
rotate -CA*x // turn for label ...
translate #if(CA>0) -S*y #else -TH*y #end // ... and reposition
translate <OE/2, TH, 0>
rotate -90*z
translate R*x
rotate LA*z
}
#else
#local C[CI-1] =
object {TO
rotate CA*x // turn for label ...
translate #if(CA>0) TD*y #else 0*y #end // ... and reposition
translate -OE/2*x
rotate -90*z
translate R*x
rotate LA*z
}
#end
#local CI = CI + 1;
#end
// Create the final object, a union of individual text object letters.
union {
#local CI=0;
#while(CI < strlen(T))
object {C[CI]}
#local CI = CI + 1;
#end
}
#end
/* END MACRO */
--
Bob H.
http://www.3digitaleyes.com
Post a reply to this message
|
|