Set fontsize of textbox, not the frame in Draw in Basic

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
RandB
Posts: 5
Joined: Wed Jan 20, 2016 8:35 pm

Set fontsize of textbox, not the frame in Draw in Basic

Post by RandB »

How do I set the fontsize of a textbox. The only thing I can find is to set the CharHeight, but the way I am doing it, it only sets the CharHeight of the frame. My text never changes, because I am only changing the frame. How do I get into the textbox?
I am using Basic and working in Draw.
LibreOffice 5.0.3.2
OSX 10.11.2
FJCC
Moderator
Posts: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set fontsize of textbox, not the frame in Draw in Basic

Post by FJCC »

In a Draw document that contains only a textbox, this works for me to change the font

Code: Select all

  oDrawPages = ThisComponent.getDrawPages()
  oDP1 = oDrawPages.getByIndex(0)
  oBox = oDP1.getByIndex(0)
  
  oBox.CharHeight = 36.0
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
RandB
Posts: 5
Joined: Wed Jan 20, 2016 8:35 pm

Re: Set fontsize of textbox, not the frame in Draw in Basic

Post by RandB »

Thanks, but that is what I had. Changing that does not change the fontsize of my textbox, that changes the fontsize of the frame. So the visible size of the text never changes. How do I drill down from the frame into the textbox?

Here is what my XLM of this textbox looks like.

Code: Select all

<draw:page draw:name="page1" draw:style-name="dp1" draw:master-page-name="Default"><draw:frame draw:style-name="gr2" draw:text-style-name="P3" draw:layer="layout" svg:width="5.916cm" svg:height="2.618cm" svg:x="5.902cm" svg:y="5.6cm"><draw:text-box><text:p text:style-name="P2">Large</text:p></draw:text-box></draw:frame></draw:page>
LibreOffice 5.0.3.2
OSX 10.11.2
FJCC
Moderator
Posts: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set fontsize of textbox, not the frame in Draw in Basic

Post by FJCC »

The attached document has a macro that toggles the font size in the textbox between sizes 18 and 36. Does it work for you?
 Edit: I tested the macro before posting the file and it worked. After closing and reopening the file, the macro doesn't work. I'll have to look into this later. Perhaps I'm losing m mind. 
Attachments
FontChange.odg
(10.01 KiB) Downloaded 301 times
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
RandB
Posts: 5
Joined: Wed Jan 20, 2016 8:35 pm

Re: Set fontsize of textbox, not the frame in Draw in Basic

Post by RandB »

Before I ran the macro, the frame and textbox had the same style. (P1)

Code: Select all

<draw:frame draw:style-name="gr1" draw:text-style-name="P1" draw:layer="layout" svg:width="4.953cm" svg:height="3.302cm" svg:x="2.397cm" svg:y="3.54cm">
<draw:text-box><text:p text:style-name="P1">The Text</text:p>
</draw:text-box>
</draw:frame></draw:page>
After you run the macro you see the fontsize was changed in the frame to style P2, but the textbox size is still P1. What you see, is the textbox, so changing the font size of the frame does nothing.

Code: Select all

<draw:frame draw:style-name="gr1" draw:text-style-name="P2" draw:layer="layout" svg:width="4.953cm" svg:height="3.302cm" svg:x="2.397cm" svg:y="3.54cm">
<draw:text-box><text:p text:style-name="P1"><text:span text:style-name="T1">The Text</text:span></text:p>
</draw:text-box>
If you want to see it in Draw. Then run the macro. Then Click in the textbox to get a text cursor. Look at the properties and it shows fontsize 36.
Now click on the border where you get the little squares, you are now looking at the frame. Look at the properties and it shows fontsize 18. The Macro change the frame to 18 not the textbox.

This was my problem we need to change the textbox, not the frame.
LibreOffice 5.0.3.2
OSX 10.11.2
FJCC
Moderator
Posts: 9273
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Set fontsize of textbox, not the frame in Draw in Basic

Post by FJCC »

I checked that this macro

Code: Select all

oDrawPages = ThisComponent.getDrawPages()
oDP1 = oDrawPages.getByIndex(0)
oBox = oDP1.getByIndex(0)

If oBox.CharHeight = 36.0 then
	oBox.CharHeight = 18
Else
	oBox.CharHeight = 36.0
End If
does toggle the font size on a new document similar to what I posted earlier both before and after saving the document. After closing the document and reopening, it does not work. I don't have time right now to investigate that further and I'm not at all sure just what I would do.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
gmapp
Posts: 1
Joined: Wed Nov 14, 2018 2:31 pm

Re: Set fontsize of textbox, not the frame in Draw in Basic

Post by gmapp »

I bumped into the same problem and searching I found this topic. Any ideas on how to solve the problem (change the style properties of the text and not of the frame that contains the text)?

Thanks
OpenOffice 4, Windows 10
Post Reply