【问题标题】:How to change the font?如何更改字体?
【发布时间】:2017-04-02 21:12:53
【问题描述】:

我想更改字体并将其样式设置为粗体。 我有两个问题:

  • 更改CharWeight 有效,但无效CharFontName
  • 它将“粗体”应用于整个段落,而不仅仅是选定内容

这是我的代码:

sub AddAnimation
    xTextCursor = ThisComponent.CurrentController.Selection(0)
    xText = xTextCursor.getText()
    xText.CharFontName = "Consolas"
    xText.CharWeight = com.sun.star.awt.FontWeight.BOLD
end Sub

【问题讨论】:

  • 当前设置的字体名称是什么?尝试从一个空文档开始并创建一个文本块。

标签: openoffice-impress libreoffice-impress libreoffice-macros


【解决方案1】:

调用getText() 获取整个文本,而不仅仅是选定的部分。

Sub ChangeFont
    xTextCursor = ThisComponent.CurrentController.Selection(0)
    xTextCursor.CharFontName = "Consolas"
    xTextCursor.CharWeight = com.sun.star.awt.FontWeight.BOLD
End Sub

当我尝试使用 LO 和 AOO 时字体名称发生了变化。

您使用的是CTL or CJK 脚本吗?如果是这样,那么它需要是CharFontNameComplexCharFontNameAsian。但是,如果 CharWeight 有效,那一定不是问题。

还有一个猜测:可能是一种样式覆盖了它。

【讨论】:

  • 那怎么改样式呢?
  • 转到侧边栏中的“样式和格式”,看看是否是问题所在。显然相关的样式被称为Graphic Styles
  • 源码这么乱,我已经放弃了,谢谢你的回答!
猜你喜欢
  • 2017-09-02
  • 2016-05-19
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-31
  • 2023-03-10
相关资源
最近更新 更多