Difference between revisions of "Documentation/DevGuide/Drawings/Overall Document Features"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Initial author Sun Microsystems, Inc.)
 
(Added Java syntax highlight)
(4 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/Drawings/Settings
 
|NextPage=Documentation/DevGuide/Drawings/Settings
 
}}
 
}}
{{DISPLAYTITLE:Overall Document Features}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Drawings/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Overall Document Features}}
 
=== Styles ===
 
=== Styles ===
  
Line 113: Line 114:
 
* notes text
 
* notes text
  
The corresponding style family has the programmatic name "Default" and is available at the <cdoe>XStyleFamiliesSupplier</code> of a presentation document.
+
The corresponding style family has the programmatic name "Default" and is available at the <idls>com.sun.star.style.XStyleFamiliesSupplier</idls> of a presentation document.
  
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
 
{|border="1" cellpadding=4 style="border-collapse:collapse;"
Line 183: Line 184:
 
You can only alter existing presentation styles. You cannot create new styles and you cannot apply a different presentation style other than the current one. The following example works with presentation styles:  
 
You can only alter existing presentation styles. You cannot create new styles and you cannot apply a different presentation style other than the current one. The following example works with presentation styles:  
 
<!--[SOURCE:Drawing/StyleDemo.java]-->
 
<!--[SOURCE:Drawing/StyleDemo.java]-->
 
+
<source lang="java">
 
   // The first part of this demo will set each "CharColor" Property
 
   // The first part of this demo will set each "CharColor" Property
 
   // that is available within the styles of the document to red. It
 
   // that is available within the styles of the document to red. It
Line 240: Line 241:
 
   xShapes.add(xShape);
 
   xShapes.add(xShape);
 
   XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShape);
 
   XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShape);
   xPropSet.setPropertyValue("Style", xTitle1Style);
+
   xPropSet.setPropertyValue("Style", xTitle1Style);</source>
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Drawing Documents and Presentation Documents]]
+
 
 +
[[Category:Documentation/Developer's Guide/Drawing Documents and Presentation Documents]]

Revision as of 12:50, 13 January 2013



Styles

Graphics Styles

Graphics Styles are available in drawing and presentation documents, and they control the formatting of the drawing shapes in drawing or presentation slides. In contrast to styles in text documents, the style property of a shape is not a string, but a com.sun.star.style.XStyle. To work with an existing graphics style, get the styles container from the com.sun.star.style.XStyleFamiliesSupplier and use its com.sun.star.container.XNameAccess to retrieve the style family named "graphics". The programmatic names of the style families in graphics are:

GUI name Programmatic name Remark
Default standard The style Default (standard) is used for newly inserted filled rectangles, filled ellipses, lines, connectors, text boxes, and 3D objects.
Dimension Line measure Used for newly inserted dimension lines.
First line indent textbodyindent Apply manually.
Heading headline Apply manually.
Heading1 headline1 Apply manually.
Heading2 headline2 Apply manually.
Object with Arrow objectwitharrow Apply manually.
Object with shadow objectwithshadow Apply manually.
Object without fill objectwithoutfill Used for newly inserted rectangles and ellipses without filling.
Text text Newly inserted text boxes do not use this style. They use Default and remove the fill settings for Default.
Text body textbody Apply manually.
Text body justified textbodyjustfied Apply manually.
Title title Apply manually.
Title1 title1 Apply manually.
Title2 title2 Apply manually.

There are two methods to change an applied shape style:

  • Retrieve the style from the style family "graphics" by its programmatic name, change the properties, and put back into the style family using replaceByName() at the style family's com.sun.star.container.XNameContainer interface.
  • Apply an existing style object that is not applied to a shape by setting the shape's style property.

New styles can be created, as well. For this purpose, use createInstance() at the document factory of a drawing document and ask for a "com.sun.star.style.Style" service. Set the properties of the new style, as required. Append the new style to the style family "graphics" using insertByName() at its XNameContainer interface. Now use the Style property of existing shapes to put the new style to work.

You can either change a currently applied shape style by retrieving it from the style family "graphics" by its programmatic name, changing its properties and putting it back into the style family using replaceByName() at the style family's com.sun.star.container.XNameContainer interface. Or you can apply an existing, but currently unapplied style object to a shape by setting the shape's Style property accordingly.

You can create new styles as well. For this purpose, use createInstance() at the document factory of a drawing document and ask for a "com.sun.star.style.Style" service. Set the properties of the new style as needed. Afterwards append the new style to the style family "graphics" using insertByName() at its XNameContainer interface. Now you can use the Style property of existing shapes in order to put your new style to work.

Styles created by the document factory support the properties of the following services:

Presentation Styles

Presentation styles are only available in presentation documents and control the formatting of the following parts of a presentation:

  • title text
  • subtitle text
  • outline text
  • background
  • background shapes
  • notes text

The corresponding style family has the programmatic name "Default" and is available at the XStyleFamiliesSupplier of a presentation document.

GUI Name Programmatic Name Remark
Title title Style for text of new title presentation objects.
Subtitle subtitle Style that is used for the presentation object on pages with a "Title Slide" layout.
Background background Style for the page background.
Background objects backgroundobjects Style for shapes on the background.
notes Notes Style for notes text.
outline1 Outline 1 Style for outline level 1.
outline2 Outline 2 Style for outline level 2.
outline3 Outline 3 Style for outline level 3.
outline4 Outline 4 Style for outline level 4.
outline5 Outline 5 Style for outline level 5.
outline6 Outline 6 Style for outline level 6.
outline7 Outline 7 Style for outline level 7.
outline8 Outline 8 Style for outline level 8.
outline9 Outline 9 Style for outline level 9.

Existing presentation styles can only be altered. New styles can not be created and a different presentation style cannot be applied other than the current one. The following example works with presentation styles.

You can only alter existing presentation styles. You cannot create new styles and you cannot apply a different presentation style other than the current one. The following example works with presentation styles:

  // The first part of this demo will set each "CharColor" Property
  // that is available within the styles of the document to red. It
  // will also print each family and style name to the standard output
 
  XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xComponent);
  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
  String[] Families = xFamilies.getElementNames();
  for (int i = 0; i < Families.length; i++) {
      // this is the family
      System.out.println("\n" + Families[i]);
 
      // and now all available styles
      Object aFamilyObj = xFamilies.getByName(Families[i]);
      com.sun.star.container.XNameAccess xStyles = (com.sun.star.container.XNameAccess)
          UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, aFamilyObj);
      String[] Styles = xStyles.getElementNames();
      for (int j = 0; j < Styles.length; j++) {
          System.out.println( " " + Styles[j]);
          Object aStyleObj = xStyles.getByName(Styles[j]);
          com.sun.star.style.XStyle xStyle = (com.sun.star.style.XStyle)
          UnoRuntime.queryInterface(com.sun.star.style.XStyle.class, aStyleObj);
          // now we have the XStyle Interface and the CharColor for all styles
          // is exemplary be set to red.
          XPropertySet xStylePropSet = (XPropertySet)
              UnoRuntime.queryInterface( XPropertySet.class, xStyle );
          XPropertySetInfo xStylePropSetInfo = xStylePropSet.getPropertySetInfo();
          if (xStylePropSetInfo.hasPropertyByName("CharColor")) {
              xStylePropSet.setPropertyValue("CharColor", new Integer(0xff0000));
          }
      }
  }
 
  /* now create a rectangle and apply the "title1" style of
     the "graphics" family
   */
  Object obj = xFamilies.getByName("graphics");
  com.sun.star.container.XNameAccess xStyles = (XNameAccess)
      UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, obj);
  obj = xStyles.getByName("title1");
  com.sun.star.style.XStyle xTitle1Style = (com.sun.star.style.XStyle)UnoRuntime.queryInterface( 
      com.sun.star.style.XStyle.class, obj);
 
  XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier)UnoRuntime.queryInterface(
      XDrawPagesSupplier.class, xComponent);
  XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
  XDrawPage xDrawPage = (XdrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex(0));
  XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, xDrawPage);
  XShape xShape = ShapeHelper.createShape(xComponent, new Point(0, 0),
      new Size(5000, 5000), "com.sun.star.drawing.RectangleShape");
  xShapes.add(xShape);
  XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShape);
  xPropSet.setPropertyValue("Style", xTitle1Style);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages