如何确定图形字符串的长度? [英] How to determine the length of a graphic string?

查看:122
本文介绍了如何确定图形字符串的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从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.

这篇关于如何确定图形字符串的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆