Problem setting Font characteristics

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Problem setting Font characteristics

Post by misitu »

Hello!!

This MAY be a bug but I thought best to see if any OOForum experts had something to say on the topic before getting involved with Bugzilla, etc.

Preamble

Code: Select all

function insertText(newText as string, boldWeight as boolean, italicSlant as boolean)
	oVC = thisComponent.getCurrentController.getViewCursor
I can do this

Code: Select all

	oVC.charWeight = iif(boldWeight, com.sun.star.awt.FontWeight.BOLD, com.sun.star.awt.FontWeight.NORMAL)
But I CAN'T do this

Code: Select all

	oVC.charPosture = iif(italicSlant, com.sun.star.awt.FontSlant.ITALIC, com.sun.star.awt.FontSlant.NONE)
because it returns a run time error of
Inadmissible value or data type.
Data type mismatch.
However.

I CAN do this

Code: Select all

	if italicSlant then
		oVC.charPosture = com.sun.star.awt.FontSlant.ITALIC
	else
		oVC.charPosture = com.sun.star.awt.FontSlant.NONE
	end if
which on the face of it is logically identical to the iif statement that fails.

Postamble

Code: Select all

	oText = oVC.text
	oText.insertString(oVC, newText, False)
end function
completes the function, which bolds/italics the output exactly as required.

My question is: why does the If..else..end if statement work when the iif(..,..,..) doesn't.

Thanks in advance
David

PS. My external limits for the mo, from outside circumstances, are that I keep to AOO Basic, and can't use MRI because it somehow got broken and fixing that is going to mean an upgrade which I don't currently have time for.
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Problem setting Font characteristics

Post by Zizi64 »

Can you upload your example ODF file with the macro inside of the file?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Problem setting Font characteristics

Post by misitu »

Thanks Zizi64

The macro is supposed to run independently from windows dos batch (like some others). At the moment I fire up the database and run it from there. It generates an output writer file.
I will have more time later *today, will create a blank writer file and add the macro to that and trial it both ways round.

Thanks
David
Trujillo, Peru

*have PM'd you.
 Edit: Right. Tried that. In summary:
1. if I open a blank writer doc and apply the macro with the following code

Code: Select all

function insertText(newText as string, boldWeight as boolean, italicSlant as boolean)
	oVC = thisComponent.getCurrentController.getViewCursor
	oVC.charWeight = iif(boldWeight, com.sun.star.awt.FontWeight.BOLD, com.sun.star.awt.FontWeight.NORMAL)
	oVC.charPosture  = iif (italicSlant, com.sun.star.awt.FontSlant.ITALIC, com.sun.star.awt.FontSlant.OBLIQUE)
	oText = oVC.text
	oText.insertString(oVC, newText, False)
end function
it runs error free but all the output is in italic, albeit bold or normal as required, but without any non italics.

2. if I run from the macro itself then the code has to be like this

Code: Select all

function insertText(newText as string, boldWeight as boolean, italicSlant as boolean)
	oVC = thisComponent.getCurrentController.getViewCursor
	oVC.charWeight = iif(boldWeight, com.sun.star.awt.FontWeight.BOLD, com.sun.star.awt.FontWeight.NORMAL)
	if italicSlant then
		oVC.charPosture = com.sun.star.awt.FontSlant.ITALIC
	else
		oVC.charPosture = com.sun.star.awt.FontSlant.NONE
	end if
	oText = oVC.text
	oText.insertString(oVC, newText, False)
end function
when it runs to completion with all text as required bold, italic, normal, none. If I try to put an oVC.charPosture in the form of the oVC.charWeight (in place of the if-then-else-end if construct) it refuses to run with the message output as in the original post.

I've got all live data in the database and don't have any need to put that in the public domain but if you need some test data I'll get onto that and get back to you.

Thanks!
David 
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
User avatar
einstein
Posts: 47
Joined: Sat Nov 05, 2016 1:45 am
Location: State of Mexico, México.

Re: Problem setting Font characteristics

Post by einstein »

With regard to your first message/macro, it would look like AOO's bug. In LibreOffice 5.1.6.2 it seems to work.

Code: Select all

Sub oTexto
insertText "This is a text", true, false
End Sub

function insertText(newText as string, boldWeight as boolean, italicSlant as boolean)
   oVC = thisComponent.getCurrentController.getViewCursor
   oVC.charWeight = iif(boldWeight, com.sun.star.awt.FontWeight.BOLD, com.sun.star.awt.FontWeight.NORMAL)
   oVC.charPosture  = iif (italicSlant, com.sun.star.awt.FontSlant.ITALIC, com.sun.star.awt.FontSlant.NONE)
   oText = oVC.text
   oText.insertString(oVC, newText, False)
end function
lo 5.1.6.2 | aoo 4.1.3 | win 7/10
All I know is that I know nothing
User avatar
misitu
Posts: 104
Joined: Mon Dec 16, 2013 5:34 am
Location: Trujillo - La Libertad - Perú

Re: Problem setting Font characteristics

Post by misitu »

Gracias, Einstein.

Well, obviously I have a work around, even if it's not what I'd prefer, so I'll get round to submitting a bug notice.

Nice to have the confirmation

Chau
David
OpenOffice 4.1.1
HSQLDB 2.3.4
Windows 7 HP / Windows 10
OOBasic
Post Reply