这就是我正在尝试做的事情。我的字体基本上是每个字形的位图矩形。我正在尝试获得这样的弧形文字效果:
我的计划是,给定中心和半径,我将求解每个字形的位置和角度。
我有一个可以找到位置的函数:
Vec2 Math::positionFromCenterToLineAt( Vec2 center, float dist,
float totalAngular, float angularDistance, float angularOffset )
{
float startAngle = -((totalAngular) / 2.0f);
float curAngle = startAngle + angularDistance;
curAngle -= angularOffset;
curAngle += angularDistance / 2.0f;
curAngle += CGE_PI;
Vec2 retVec = center;
Vec2 angVec = Vec2(sin(curAngle),cos(curAngle));
angVec *= dist;
retVec += angVec;
return retVec;
}
它要求我知道圆将占据多少弧度,并且需要绘制当前字形距起始角度多少度。
我无法弄清楚的是,在给定字形的半径、中心、宽度和高度的情况下,找到给定字形将占据的角度的函数。每个字形可以有不同的尺寸。
看这个:
如您所见,我正在寻找以弧度为单位的圆的扇区。
如何计算?
谢谢
最佳答案
2*pi*radius equals the circumference
You know radius as a pixel base(lets say it is 40 pixels)
You can find circumference(lets say it is 251 pixels)
Then, if you get width of a char(lets say it is 8)
You know the angle of arc: angle=2*pi*(8/251)=2*pi*0.03=0.2 radians
0.2 radians * 57.3 = 11.5 degrees
如何根据当前字体求出字符的宽度?
LOGFONT lf;
int width=lf.lfWidth; //beware! this is average
您想要精确的选项吗?
GetTextExtentPoint32() // search usage of this!
Its structure type is:
BOOL GetTextExtentPoint32(
__in HDC hdc,
__in LPCTSTR lpString,
__in int c,
__out LPSIZE lpSize
);
关于c++ - 寻找沿圆绘制时所占据的角矩形(见图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12231701/