In macro match only a given font?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
harveyab
Posts: 93
Joined: Sat Sep 06, 2008 11:15 pm
Location: WA, USA

In macro match only a given font?

Post by harveyab »

How do I modify this OOo BASIC macro to programmatically match only a given font?
And how to I show the match as selected?
TIA
Harvey Block (harveyab)

Code: Select all

Function FindR2(P as String)
  Dim Doc, Found
  Dim Font As String
  Doc = StarDesktop.CurrentComponent
  Dim SearchDesc As Object
  SearchDesc = Doc.createSearchDescriptor()
  SearchDesc.SearchRegularExpression = TRUE
  SearchDesc.searchString = P
  Found = Doc.findFirst(SearchDesc)
  Font = Found.CharFontName
  MsgBox(Font)
end function 'FindR2
Harvey (harveyab)
OOo 3.3.0 on MS Windows XP --- Time drags so quickly.
harveyab
Posts: 93
Joined: Sat Sep 06, 2008 11:15 pm
Location: WA, USA

Re: In macro match only a given font?

Post by harveyab »

How do I do this?
In the search dialog I can filter by font.
How do I do it programatically?
TIA,
Harvey
Harvey (harveyab)
OOo 3.3.0 on MS Windows XP --- Time drags so quickly.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: In macro match only a given font?

Post by Villeroy »

The API's search descriptor (as documented) can search by style names rather than single attributes. You may iterate over TextPortions, which are documented as
A TextPortion is a piece of text within a paragraph that does not contain changes of its attributes inside.
http://api.openoffice.org/docs/common/r ... rtion.html
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
harveyab
Posts: 93
Joined: Sat Sep 06, 2008 11:15 pm
Location: WA, USA

Re: In macro match only a given font?

Post by harveyab »

So are you saying that I will have to write a search algorithm in order to do the iteration rather than just calling the FindFirst() function?
The example you gave a link to is in C, and I am using BASIC.
I tried converting it to BASIC but no success.

OR

are you saying that I can specify the criteria for the font and still use the FindFirst call?

Sorry for being slow to understand.

Harvey
Harvey (harveyab)
OOo 3.3.0 on MS Windows XP --- Time drags so quickly.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: In macro match only a given font?

Post by Villeroy »

I refered to the API documentation of service "com.sun.star.text.TextPortion". The office-API is language independent. In any supported language you can loop through parargraphs and TextPortions in order to get the smallest sequences of equally formatted text, then check if the respective portion has this or that property and then do whatever with it.
There are several resources about how to program with this API (if you already know how to program) by means of script languages Basic, Python, JavaBeans, Windows COM and compiled languages Java and C++. There are some differences how you call methods from a compiled language. Most examples are documented for Java since it is easier to transfer from Java to a script language than it would be the other way round.
http://www.pitonyak.org/oo.php
http://wiki.services.openoffice.org/wiki/Main_Page
http://sourceforge.net/project/showfile ... _id=101416 XRay, the indispensable helper for Basic coders
Local copy of the API-reference. Best used with XRay:
http://download.openoffice.org/2.4.0/sdk.html
http://download.openoffice.org/3.0/sdk.html

No, it's not like VBA :!:
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
harveyab
Posts: 93
Joined: Sat Sep 06, 2008 11:15 pm
Location: WA, USA

Re: In macro match only a given font?

Post by harveyab »

Villeroy,

Thank you for your help.
I have found XRay to be useful.
I downloaded the SDK but have not done anything with it yet.
Too much to process at the moment.
I did notice something that seem like a bug in the web site links:
The link http://download.openoffice.org/2.4.0/sdk.html
And http://download.openoffice.org/2.4.1/sdk.html
Both seem to go to the same place.
And when selecting TDS for the download I get:
http://openoffice.mirrors.tds.net/pub/o ... ble/2.4.0/
But there are files at:
http://openoffice.mirrors.tds.net/pub/o ... ble/2.4.1/
that you cant get to via the links.
So, are the 2.4.1 SDK files good? Is it just an out of date link?

Harvey Block
Harvey (harveyab)
OOo 3.3.0 on MS Windows XP --- Time drags so quickly.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: In macro match only a given font?

Post by Villeroy »

Since 2.4.1 is a bug-fix release of 2.4, you can expect equal APIs between 2.4 and 2.4.1. The latter fixes things that should have worked in 2.4 already. You may even use an older SDK without beeing able to lookup the API for the latest features added between the older SDK-version and the one you are programming for. With Basic + XRay you need the SDK to look up the right html files in the SDK's documentation tree. If you are programming with 3.0 and there is no SDK for 3.0 yet, this might be no problem as long as you stay hacking on the usual document features which did not change since version 1, such as paragraphs and portions of equally formatted text. I'm not shure about v3 though, since I ignore v3 until today.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply