Ask Your Question
0

Bold only for First word in the Paragraph

asked 2019-02-07 09:57:35 +0200

Nithin gravatar image

Hello everyone,

is it possible to set the formatting of only the first word in a Paragraph to Bold. Use case is a simple dictionary formatting.

This would have been possible using the Drop Caps feature if the number of lines setting could be set to 1. This would also allow formatting initials. Here is a link explaining the difference between drop caps and Initials http://www.magazinedesigning.com/drop...

Is there any other way to do this?

--Nithin

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2019-02-07 15:00:53 +0200

Lupp gravatar image

Any way? Not by ready-made means, I'm afraid, in specific not by settings implemented with the paragraph style concept as it is. You need to do it by "hard" assignment of an appropriate characzter style.

You can define a named pragraph style (may otherwise be identical with Default e.g.) and a named character style you want to apply to the initial word s of paragraphs haveing the mentioned style assigned.

Then you only need a little "macro" for the task. Resorting to "macros" always comes with disadvantages, however.

See the example FirstWordAsInitial.

Code:

Sub setCharStyleFirstWord(Optional pDoc As Object, Optional pText As Object, _
Optional pParaStyleN As String, Optional pCharStyleN As String)
REM This way to use a missing optional parameter as a local variable is 
REM not supported in very old versions of LibO and in AOO.
If IsMissing(pDoc) Then pDoc = ThisComponent
If NOT pDoc.supportsService("com.sun.star.text.TextDocument") Then Exit Sub
If IsMissing(pText) Then pText = ThisComponent.Text
If IsMissing(pParaStyleN) Then pParaStyleN = "paraInitialWord"
If IsMissing(pCharStyleN) Then pCharStyleN = "charInitialWord"
oldSel = pDoc.CurrentSelection
cur = pText.createTextCursorByRange(pText.Start)
REM Now the WORKING code:  

Do While pText.compareRegionEnds(cur, pText.End)>0
 If cur.ParaStyleName=pParaStyleN Then
  cur.gotoEndOfWord(True)
  cur.CharStyleName = pCharStyleN
 End If
 cur.gotoNextParagraph(False)
Loop

REM Done!
ThisComponent.CurrentController.select(oldSel)
End Sub
edit flag offensive delete link more
0

answered 2019-02-14 11:58:19 +0200

Nithin gravatar image

Hello Lupp, Thanks a lot for the solution. This exactly what i was looking for. Thanks again for investing so much time and effort. I guess i will also create a enhancement request for the same.

edit flag offensive delete link more

Comments

Mike Kaganski gravatar imageMike Kaganski ( 2019-02-14 12:06:53 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-02-07 09:57:35 +0200

Seen: 77 times

Last updated: Feb 14