在 Quartz 中居中绘制文本

发布于 2024-11-19 11:30:17 字数 306 浏览 1 评论 0原文

我有一个饼图,我在饼图周围放置 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文