0

I have several documents in .DOC format that includes words in English and Sanskrit (Devanagari). I am using LibreOffice Writer:

Version: 5.1.4.2
Build ID: 1:5.1.4-0ubuntu1
Locale: en-US (en_GB.UTF-8)

The default font is Liberation Serif, which I like and want to continue using, but some of the Sanskrit/Devanagari words do not display correctly. There are some fonts that do display the Sanskrit/Devanagari words correctly, such as Akshar Unicode. So, the words that do not display correctly, I change their font to Akshar Unicode by highlighting each individual, incorrect word and then changing the font from Liberation Serif to Akshar Unicode, which is a tedious and inefficient method.

Is there a more efficient method to change the font of certain words?

Here are two methods I've tried thus far, both of which do not seem to be able to change the font of the search results or the replacement text:

  • Highlight the incorrect word and press [CTRL] + [H] to use the Find & Replace tool.
  • Install the extension Alternate searching 1.4.1, which is a tool that is similar to Find & Replace, but more complex.

Ideally, the Find & Replace tool would be able to change the font of the search results or replacement text.

Arya
  • 566
  • 2
  • 9
  • 22

1 Answers1

0

The following macro selects the currently selected word everywhere in the document. Then it sets the font.

Sub ChangeFontOfWords
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    oSels = ThisComponent.getCurrentSelection()
    oSel = oSels.getByIndex(0)

    dim args1(1) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "SearchItem.SearchString"
    args1(0).Value = oSel.getText()
    dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "CharFontName.FamilyName"
    args2(0).Value = "Akshar Unicode"
    dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args2())
End Sub

To use it, double-click a word to select it, then run the macro. For convenience, go to Tools -> Customize and set up a hotkey or toolbar button to run the macro.

Jim K
  • 12,824
  • 2
  • 22
  • 51