如何确定图形字符串的长度?

编程入门 行业动态 更新时间:2024-10-28 02:34:04
本文介绍了如何确定图形字符串的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我从excel文档创建图形时间线,并且需要在该事件标记旁边放置事件名称的小标签。其中一些很容易,而且是正确的,但其他人是左对齐的,我需要弄清楚它们的宽度,以便我可以适当地抵消它们。

I'm creating a graphical timeline out of an excel document and I need to have small tags of the name of the event next to the marker for that event. Some of these are easy and are right justified but others are left justified and I need to figure out their width so that I can properly offset them.

window.drawString("7/4-Fourth of July",horizontalIndex-Offset,verticalIndex);

目前我使用平均字体大小为10和32的平均像素宽度,但是这并没有真正削减它。有人可以帮助我得到确切的抵消?

Currently I'm averaging the pixel width using an average of both font sizes 10 and 32, but this doesn't really cut it. Can someone help me get the exact offset?

这个线程解释了如何做到这一点:$ b​​ $ b

This thread explains how to do it: Calculate the display width of a string in Java

您应该首先获取字体指标,然后询问度量标准某个字符串有多宽。

You should first get the font metrics, and then ask the metrics how wide a certain string is.

更多推荐

如何确定图形字符串的长度?

本文发布于:2023-10-29 20:39:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   长度   图形

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!