如何在 Windows 小工具中将 g:text 样式设置为粗体字体?
我正在开发一个 Vista/Win7 桌面小工具,它使用半透明的 g:background
(doc) 区域,其中包含 g:text
(doc)在顶部。我通过 addTextObject
添加文本 (doc),这一切都按预期工作。
但是,我不知道如何将该文本设置为粗体样式。似乎没有办法直接通过我可以看到的公开属性来执行此操作,并且在这种情况下我无法使用常规文本 + CSS,因为该文本被放置在 g 上:背景
对象。
我还尝试过直接指定粗体字体,例如 Arial Bold
(不起作用)而不是 Arial
(有效)。
那么如何才能做到这一点呢?
编辑:我尝试为正文和作为文本父级的g:background
对象设置font-weight:bold
;没有运气。
I'm developing a Vista/Win7 Desktop Gadget that uses a translucent g:background
(doc) area with g:text
(doc) on top. I'm adding the text via addTextObject
(doc), and this all works as expected.
However, I can't figure out how to set that text to bold style. There doesn't seem to be a way to do this directly via the exposed properties that I can see, and I can't use regular text + CSS in this case due to the fact this text is placed onto a g:background
object.
I have also tried specifying a bold font directly, such as Arial Bold
(doesn't work) instead of Arial
(works).
So how can this be done?
Edit: I have tried setting font-weight:bold
for both the body and the g:background
object that parents my text; no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 Jonathan Abbott 的翻转日历。他的代码通常都有很好的注释,所以也许你可以从中得到一些想法。
编辑
我的信息来源是 Vista Beta 2 早期,这是 MS 的官方说法。我还在 MSDN 论坛上找到了以下关于 Flip Calendar 小工具本身的帖子的回复:
http://social.msdn.microsoft.com/Forums/en-US/sidebargadfetdevelopment/thread/841e9d5e-32e9-453f-bd0e-dc5a4e607c33/
该小工具具有在该月的某一天设置粗体字体的选项(ag:文本对象),但仔细检查后发现它不起作用。对于那个很抱歉。众所周知,MS 的家伙也曾在一次或多次情况下犯了错误。我可以诚实地说我不使用 g:text 对象。
这意味着您唯一的(好吧,非 activex 路由)选项是 VML 文本,它在布局上提供了很大的灵活性。但是,您必须将其放置在小工具的完全不透明区域上,这可能就是您首先想要使用 addTextObject 的原因。 Gary Beene 的网站在我刚开始时确实帮助了我,但它并没有不详细介绍 v:textbox 元素< /a> 和 v:textpath 元素 ,尽管 MSDN 文档对这些内容进行了足够详细的介绍。
如果您需要将文本放置在小工具的非完全不透明区域,那么您仍然可以采用 VML 路线,并将图像放置在文本后面,充当阴影,从完全不透明开始,然后逐渐变为完全透明。这就是 Microsoft 在启用 aero 的情况下在窗口标题栏中处理文本的方式。
或者,您可以创建一个 ActiveXObject,以所需的字体绘制所需的文本,并将图像保存到小工具文件夹中的临时文件中。然后将其设置为 addImageObject 的 src。我已经在小工具中做了类似的事情,而且速度足够快,不会被注意到。您还可以设置最小/最大尺寸,以便收缩/拉伸以适应变得轻而易举。
See Flip Calendar, by Jonathan Abbott. His code is usually well commented so maybe you can get some ideas from that.
EDIT
The source of my information was from the early days of Vista Beta 2 where that was the official word from MS. I also found the following response to a thread on the MSDN forums regarding the Flip Calendar gadget itself:
http://social.msdn.microsoft.com/Forums/en-US/sidebargadfetdevelopment/thread/841e9d5e-32e9-453f-bd0e-dc5a4e607c33/
The gadget has options for setting bold font on the day of the month (a g:text object) but on closer inspection it doesn't work. Sorry about that. The MS guys have been known to be wrong as well on one or more occasions. I can honestly say that I don't use the g:text object.
This means your only (well, non activex route) option is VML text, which provides a lot of flexibility on layout. However, you will have to place it on a fully opaque area of the gadget which is probably why you wanted to use the addTextObject in the first place. Gary Beene's site really helped me out when I was getting started, but it doesn't go into any detail on the v:textbox element and the v:textpath element, though the MSDN documentation goes into enough detail on these.
If you need to place the text on a non-fully opaque area of the gadget, then you could still go the VML route and place an image behind the text that acts as a shadow, starting out fully opaque and fading to fully transparent. This is how Microsoft does text in window title bars with aero enabled.
Alternatively, you could create an ActiveXObject that draws the text you need in the font you want and saves the image to a temporary file in the gadget folder. Then you set that to the src of an addImageObject. I've done something similar in a gadget and it's fast enough not to be noticeable. You can also set min/max dimensions so shrinking/stretching to fit becomes a breeze.