Difference between revisions of "Documentation/DevGuide/Text/Line Numbering and Outline Numbering"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m (Robot: Changing Category:Text Documents)
Line 214: Line 214:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Text Documents]]
+
 
 +
[[Category:Documentation/Developers Guide/Text Documents]]

Revision as of 09:35, 4 June 2008



OpenOffice.org provides automatic numbering for texts. For instance, paragraphs can be numbered or listed with bullets in a hierarchical manner, chapter headings can be numbered and lines can be counted and numbered.

Paragraph and Outline Numbering

com.sun.star.text.NumberingRulesThe key for paragraph numbering is the paragraph property NumberingRules. This property is provided by paragraphs and numbering styles and is a member of com.sun.star.style.ParagraphProperties.

A similar object controls outline numbering and is returned from the method:

 com::sun::star::container::XIndexReplace getChapterNumberingRules()

at the com.sun.star.text.XChapterNumberingSupplier interface that is implemented at the document model.

These objects provide an interface com.sun.star.container.XIndexReplace. Each element of the container represents a numbering level. The writer document provides ten numbering levels. The highest level is zero. Each level of the container consists of a sequence of com.sun.star.beans.PropertyValue.

The two related objects differ in some of properties they provide.

Both of them provide the following properties:

Common Properties for Paragraph and Outline Numbering in com.sun.star.text.NumberingLevel
Adjust short - Adjustment of the numbering symbol defined in com.sun.star.text.HoriOrientation.
ParentNumbering short - Determines if higher numbering levels are included in the numbering, for example, 2.3.1.2.
Prefix

Suffix

string - Contains strings that surround the numbering symbol, for example, brackets.
CharStyleName string - Name of the character style that is applied to the number symbol.
StartWith short - Determines the value the numbering starts with. The default is one.
FirstLineOffset

LeftMargin

long - Influences the left indent and left margin of the numbering.
SymbolTextDistance [optional] long - Distance between the numbering symbol and the text of the paragraph.
NumberingType short - Determines the type of the numbering defined in com.sun.star.style.NumberingType.


Only paragraphs have the following properties in their NumberingRules property:

Paragraph NumberingRules Properties in com.sun.star.text.NumberingLevel Description
BulletChar string - Determines the bullet character if the numbering type is set to NumberingType::CHAR_SPECIAL.
BulletFontName string - Determines the bullet font if the numbering type is set to NumberingType::CHAR_SPECIAL.
GraphicURL string - Determines the type, size and orientation of a graphic when the numbering type is set to NumberingType::BITMAP.
GraphicBitmap Undocumented
GraphicSize Undocumented
VertOrient short - Vertical orientation of a graphic according to com.sun.star.text.VertOrientation


Only the chapter numbering rules provide the following property:

Property of com.sun.star.text.ChapterNumberingRule Description
HeadingStyleName string - Contains the name of the paragraph style that marks a paragraph as a chapter heading.


Template:Documentation/Note

The following is an example for the NumberingRules service:

 /** This method demonstrates how to set numbering types and numbering levels using the
     com.sun.star.text.NumberingRules service
  */
 protected void NumberingExample() {
     try {
         // Go to the end of the document
         mxDocCursor.gotoEnd(false);
         // Get the RelativeTextContentInsert interface of the document
         XRelativeTextContentInsert xRelative = (XRelativeTextContentInsert)
             UnoRuntime.queryInterface(XRelativeTextContentInsert.class, mxDocText);
         
         // Use the document's factory to create the NumberingRules service, and get it's
         // XIndexAccess interface
         XIndexAccess xNum = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class,
             mxDocFactory.createInstance("com.sun.star.text.NumberingRules"));
         
         // Also get the NumberingRule's XIndexReplace interface
         XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
             XIndexReplace.class, xNum);
         
         // Create an array of XPropertySets, one for each of the three paragraphs we're about
         // to create
         XPropertySet xParas[] = new XPropertySet[3];
         for (int i = 0 ; i < 3 ; ++ i) {
             // Create a new paragraph
             XTextContent xNewPara = (XTextContent) UnoRuntime.queryInterface(
                 XTextContent.class, mxDocFactory.createInstance(
                     "com.sun.star.text.Paragraph"));
             
             // Get the XPropertySet interface of the new paragraph and put it in our array
             xParas[i] = (XPropertySet) UnoRuntime.queryInterface( 
                 XPropertySet.class, xNewPara);
             
             // Insert the new paragraph into the document after the fish section. As it is
             // an insert
             // relative to the fish section, the first paragraph inserted will be below
             // the next two
             xRelative.insertTextContentAfter (xNewPara, mxFishSection);
             
             // Separate from the above, but also needs to be done three times
             
             // Get the PropertyValue sequence for this numbering level
             PropertyValue[] aProps = (PropertyValue []) xNum.getByIndex(i);
             
             // Iterate over the PropertyValue's for this numbering level, looking for the
             // 'NumberingType' property
             for (int j = 0 ; j < aProps.length ; ++j) {
                 if (aProps[j].Name.equals ("NumberingType")) {
                     // Once we find it, set it's value to a new type, 
                     // dependent on which
                     // numbering level we're currently on
                     switch ( i ) {
                         case 0 : aProps[j].Value = new Short(NumberingType.ROMAN_UPPER);
                         break;
                         case 1 : aProps[j].Value = new Short(NumberingType.CHARS_UPPER_LETTER);
                             break;
                         case 2 : aProps[j].Value = new Short(NumberingType.ARABIC);
                             break;
                     }
                     // Put the updated PropertyValue sequence back into the
                     // NumberingRules service
                     xReplace.replaceByIndex (i, aProps); 
                     break;
                 }
             }
         }
         // Get the XParagraphCursor interface of our text cursro
         XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface(
             XParagraphCursor.class, mxDocCursor);
         // Go to the end of the document, then select the preceding paragraphs
         mxDocCursor.gotoEnd(false);
         xParaCursor.gotoPreviousParagraph false);
         xParaCursor.gotoPreviousParagraph true);
         xParaCursor.gotoPreviousParagraph true);
         
         // Get the XPropertySet of the cursor's currently selected text
         XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(
           XPropertySet.class, mxDocCursor);
         
         // Set the updated Numbering rules to the cursor's property set
         xCursorProps.setPropertyValue ("NumberingRules", xNum);
             mxDocCursor.gotoEnd(false);
         
         // Set the first paragraph that was inserted to a numbering level of 2 (thus it will
         // have Arabic style numbering)
         xParas[0].setPropertyValue ("NumberingLevel", new Short ((short) 2));
         
         // Set the second paragraph that was inserted to a numbering level of 1 (thus it will
         // have 'Chars Upper Letter' style numbering)
         xParas[1].setPropertyValue ("NumberingLevel", new Short((short) 1));
         
         // Set the third paragraph that was inserted to a numbering level of 0 (thus it will
         // have 'Chars Upper Letter' style numbering)
         xParas[2].setPropertyValue("NumberingLevel", new Short((short) 0));
     } catch (Exception e) {
         e.printStackTrace (System.out);
     }
 }

Line Numbering

The text document model supports the interface com.sun.star.text.XLineNumberingProperties. The provided object has the properties described in the service com.sun.star.text.LineNumberingProperties. It is used in conjunction with the paragraph properties ParaLineNumberCount and ParaLineNumberStartValue.

Number Formats

The text document model provides access to the number formatter through aggregation, that is, it provides the interface com.sun.star.util.XNumberFormatsSupplier seamlessly.

The number formatter is used to format numerical values. For details, refer to Number Formats.

In text, text fields with numeric content and table cells provide a property NumberFormat that contains a long value that refers to a number format.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools