在 Quartz 中居中绘制文本
我有一个饼图,我在饼图周围放置 5%、10% 等标签。我通过旋转和平移坐标系找到该饼图的确切中心点。最后,我基本上将坐标系转换为位于饼图部分中间的一个点,其大小为圆半径的一半。当我绘制“100%”这样的文本时,它会像应该的那样从正确的位置开始。
但是,有没有办法以某种方式证明中间合理?例如,如果我有一个圆,并且我将 CTM 平移到圆的中心,则我的文本将位于圆的中间直径的正下方,并且稍微位于中心直径的右侧。我想把它放在正中央。我不知道是否有一种“简单”的方法可以做到这一点。我能想到的是测量我正在绘制的文本的大小,并在绘制文本之前将 CTM 偏移该大小的一半宽度和一半高度。谢谢。
I have a pie chart and I'm placing labels like 5%, 10%, etc around the pie chart. I find the exact center point of that pie segment, by rotating, and translating my coordinate system. In the end, I basically end up with my coordinate system translated to a point, half the size of the radius of the circle, in the middle of the pie segment. When I draw my text like "100%", it starts at the correct spot like it should.
However, is there a way to justify middle somehow? For example, if I have a circle, and I translate my CTM to the center of the circle, my text would be right below the middle diameter of the circle, and a little to the right of the center diameter. I'd like to get it right smack in the center. I didn't know if there was an "easy" way to do this. What I can think of is measuring the size of my text I am drawing, and offset the CTM by half the width, and half the height of that size before drawing text. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论