2

这就是我想要做的。我有一个字体,基本上是每个字形的位图矩形。我正在尝试获得这样的弧形文本效果:

在此处输入图像描述

我的计划是,给定一个中心和一个半径,我将求解每个字形的位置和角度。

我有一个可以找到位置的功能:

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;
    }

它需要我知道弧度将占据多少圆,并且需要从当前字形绘制的起始角度开始多少度。

我想不出的是一个函数,可以在给定字形的半径、中心、宽度和高度的情况下找到给定字形将占据的角度。每个字形可以有不同的维度。

看到这个: 在此处输入图像描述

如您所见,我正在寻找弧度,即圆的那个扇区。

我怎么计算呢?

谢谢

4

1 回答 1

2
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
);
于 2012-09-01T21:55:54.677 回答