To make a seal, the main thing is how to make the word evenly displayed in the Arc section, then the general seal is either a circle or an ellipse, but the two algorithms are roughly the same, for the convenience of illustration, the following is illustrated with a relatively simple circle, which can be extended on my basis if an ellipse is needed. Because the core algorithm is the same, relative to the circle, the ellipse to find the arc length and the position of each character, these two points is relatively troublesome, but both can find the corresponding mathematical formula.
Here, first of all, I use this article to refer to an example of CodeProject, the original text can be referred to the following address.
Http://www.codeproject.com/vb/net/Text_on_Path_with_VBNET.asp
(To be honest, this article is a bit messy, and the operation of the buffer is almost crazy)
Since the implementation of the seal is relatively simpler and more regular than the article, I consider organizing the algorithm to implement it myself.
So to implement a seal, the approximate steps are as follows.
1. Calculates the total length of the string and the length of each character;
2. Calculates the starting angle of the string;
3. Find the point where each character is located, and the angle relative to the center;
4. Draws each character.
Calculates the total length of the string and the length of each character
There are two methods of "graphics.measurestring" and "graphics.measurecharacterranges" that need to be recalculated (in addition, the total length of the former is problematic). Here I also considered the final display direction of the character.
The code for this section is as follows:
Code
[Copy to Clipboard]
CODE:
///<summary>
///Compute string total length and every char length
///</summary>
<param name= "Stext" ></param>
///<param name= "G" ></PARAM>
///<param name= "FCha Rwidth "></param>
///<param name=" Fintervalwidth "></PARAM>
///<returns></ Returns>
Private Float computestringlength (string stext, Graphics g, float[] fcharwidth,
float finterval Width,
Char_direction Direction)
{
//Init string format
StringFormat SF = new StringFormat ();
SF. trimming = Stringtrimming.none;
SF. FormatFlags = Stringformatflags.noclip | Stringformatflags.nowrap | Stringformatflags.linelimit;
//Measure whole string length
SizeF size = g.measurestring (Stext, _font, (int) _font. Style);
RectangleF rect = new RectangleF (0f,0f, size. Width, size. Height);
//Measure Every character size
Characterrange[] CRS = new Characterrange[stext.length];
for (int i = 0; i < stext.length i++)
CRS = new CharacterRange (i, 1);
Reset string Format
SF. FormatFlags = Stringformatflags.noclip;
SF. Setmeasurablecharacterranges (CRS);
SF. Alignment = Stringalignment.near;
//Get every character size
region[] regs = g.measurecharacterranges (Stext,_font, rect, SF);
Re-compute whole string length with space interval width
float ftotalwidth = 0f;
for (int i = 0; i < regs. Length; i++)
{
if (Direction = = Char_direction.center | | Direction = = char_direction.outside)
Fcharwidth = regs. GetBounds (g). Width;
Else
Fcharwidth = regs. GetBounds (g). Height;
Ftotalwidth + + fcharwidth + fintervalwidth;
}
Ftotalwidth-= Fintervalwidth;//remove The last interval width
return ftotalwidth;
}