1

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

  • 改变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 
+0

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

回答

0

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

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

当我尝试使用LO和AOO时,字体名称改变了。

result

是否使用CTL or CJK脚本?如果是这样,那么它需要是CharFontNameComplexCharFontNameAsian。但是,如果CharWeight工作,那肯定不是问题。

还有一种猜测:也许一种风格是压倒它。

+0

如何改变风格呢? –

+0

转到侧边栏中的“样式和格式”,看看是否有问题。显然相关的样式被称为[Graphic Styles](https://help.libreoffice.org/Impress/Styles_and_Formatting#Graphic_Styles)。 –