| View previous topic :: View next topic |
| Author |
Message |
a1tair General User

Joined: 05 Jun 2006 Posts: 15
|
Posted: Sun Jan 14, 2007 1:58 am Post subject: loading styles.xml into document |
|
|
I realize the styles are all stored as a zip context of the document *.odp upon extracting it, the styles.xml and a couple of other necessary .xmls are there to facilitate the ooo engine to load such data upon opening of odp document.
I was wonder if it is possible to load a styles.xml manually into a open document thus forcing that document to adopt the styles adopted on the styles.xml instead of those of its own styles.xml at runtime?
I understand from the previous threads that if i add my custom styles.xml to replace that in the .odp, it would delete the rest of the files. Also it would not be dynamic if i create a new zip with my customize styles.xml afterwhich renaming to .odp, it will only be updated on the next load of this document. Is there a way i could call thur the API or via .uno:cmd to load a custom styles.xml forcing the document to adopt my style at runtime?
Thanks |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
|
| Back to top |
|
 |
a1tair General User

Joined: 05 Jun 2006 Posts: 15
|
Posted: Sun Jan 14, 2007 7:34 am Post subject: |
|
|
hmmm it's able to load from xml? cos from the API don't looks like it really can do so.
I will check and post back. |
|
| Back to top |
|
 |
a1tair General User

Joined: 05 Jun 2006 Posts: 15
|
Posted: Sun Jan 14, 2007 8:49 am Post subject: |
|
|
I got a nullpointer exception... No idea why..
I tried obtaining the graphic style from odp document and event styles.xml which is extracted from a odp but still get the nullpointer.
I also tried parsing the background properties of the Default style but get nullpointer too. Wonder if its wrong concept?
com.sun.star.style.XStyleFamiliesSupplier xSFS = (com.sun.star.style.XStyleFamiliesSupplier) UnoRuntime.queryInterface(
com.sun.star.style.XStyleFamiliesSupplier.class, XModel);
com.sun.star.container.XNameAccess xFamilies = xSFS.getStyleFamilies();
// the element should now contain at least two Styles. The first is
// "graphics" and the other one is the name of the Master page
// (Default or masterpagename)
String[] Families = xFamilies.getElementNames();
//try to change all the style for graphics
Object aFamilyObj = xFamilies.getByName(Families[0]);
//obtain the style through queryinterface
com.sun.star.style.XStyle xStyle = (com.sun.star.style.XStyle) UnoRuntime.queryInterface(com.sun.star.style.XStyle.class, aFamilyObj);
//get style loader
XStyleLoader xStyleLoader = (XStyleLoader)UnoRuntime.queryInterface(XStyleLoader.class,xStyle);
xStyleLoader.loadStylesFromURL("file:///E:/myslide.odp", new PropertyValue[0]); |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Sun Jan 14, 2007 10:32 am Post subject: |
|
|
| you are right, I checked with xray: My proposal does not work. Writer supports the loading of styles, but impress doesnt... |
|
| Back to top |
|
 |
a1tair General User

Joined: 05 Jun 2006 Posts: 15
|
Posted: Mon Jan 15, 2007 5:02 am Post subject: |
|
|
| Any other advice? |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Jan 16, 2007 2:07 pm Post subject: |
|
|
Hi,
things turned out to be much more complicated that I thought initially ... the following is not yet the solution, but a point to start. The code expects that you have a user defined style "ms777" in your source document (antialias.odp), which you want to copy to the actual .odp:
| Code: | Sub Main
oCmpSource = StarDesktop.loadComponentFromUrl(ConvertToUrl("C:\Dokumente und Einstellungen\Schnuff\Desktop\antialias.odp"), "_default",0, Array())
oGraphicSource = oCmpSource.StyleFamilies.getByName("graphics")
oStyleSource = oGraphicSource.getByName("ms777")
oGraphic = ThisComponent.StyleFamilies.getByName("graphics")
if oGraphic.hasByName("ms777") then oGraphic.removeByName("ms777")
oStyle = oGraphic.createInstance("com.sun.star.style.Style")
oStyle.setName("ms777")
oStyle.setParentStyle("standard")
oGraphic.insertByName("ms777", oStyle)
oProps = oStyle.PropertySetInfo.Properties
s = ""
for k=0 to UBound(oProps)
oProp = oProps(k)
lAttr = oProp.Attributes
sName = oProp.Name
sType = oProp.Type.Name
lTypeClass = oProp.Type.TypeClass
if ((lAttr and com.sun.star.beans.PropertyAttribute.READONLY) = 0)_
and (sName<>"EndPosition") and (sName<>"StartPosition") _
and (sName<>"FillBitmapMode") and (sName<>"DisplayName") _
and ( (sType = "boolean") or (sType = "long") or (sType = "short") or _
(sType = "byte") or (sType = "string") or (sType = "float") or _
(lTypeClass = com.sun.star.uno.TypeClass.ENUM) or (lTypeClass = com.sun.star.uno.TypeClass.STRUCT)) then
xDum = oStyleSource.getPropertyValue(sName)
oStyle.setPropertyValue(sName, xDum)
else
s = s & k & ": " & sName & ", " & sType & ", " & lTypeClass & Chr(10)
endif
next k
msgbox "Ignored attributes: " & Chr(10) & Chr(10) & s
End Sub |
As you can see from the msgbox the following properties are ignored / not copied:
| Code: |
44: DisplayName, string, 12
50: EndPosition, com.sun.star.awt.Point, 17
51: Family, string, 12
53: FillBitmap, com.sun.star.awt.XBitmap, 22
55: FillBitmapMode, com.sun.star.drawing.BitmapMode, 15
79: HasLevels, boolean, 2
117: NumberingRules, com.sun.star.container.XIndexReplace, 22
118: NumberingRules, com.sun.star.container.XIndexReplace, 22
130: ParaTabStops, []com.sun.star.style.TabStop, 20
137: StartPosition, com.sun.star.awt.Point, 17
161: UserDefinedAttributes, com.sun.star.container.XNameContainer, 22 |
You will have to make special solutions for
- FillBitmap, if you want to handle user defined bitmaps. Predefined bitmaps seem to be handled o.k.
- Numbering rules, if you need them
- UserDefinedAttributes, if you need them
- ParaTabStops, if you need them
I believe (!) this should be feasable, but I am too lazy ... ask for help, if needed.
I have no idea what Start and EndPosition are good for ...
ms777
P.S. Do not try to do an XRay on the style or style2 variable. This consistently crashes OO on my system (OO2.1, Win XP) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|