Text Frames

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 14:32, 3 January 2021 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A text frame is a com.sun.star.text.TextFrame service consisting of com.sun.star.text.BaseFrame and the interface com.sun.star.text.XTextFrame.The XTextFrame is based on com.sun.star.text.XTextContent and introduces one method to provide the XText of the frame:

 com::sun::star::text::XText getText()

The properties of com.sun.star.text.TextFrame that add to the BaseFrame are the following:

Properties of com.sun.star.text.TextFrame
FrameHeightAbsolute long - Contains the metric height value of the frame.
FrameWidthAbsolute long - Contains the metric width value of the frame.
FrameWidthPercent byte - Specifies a width relative to the width of the surrounding text.
FrameHeightPercent byte - Specifies a width relative to the width of the surrounding text.
FrameIsAutomaticHeight boolean - If "AutomaticHeight" is set, the object grows if it is required by the frame content.
SizeType short - Determines the interpretation of the height and relative height properties.

Additionally, text frames are com.sun.star.text.Text services and support all of its interfaces, except for com.sun.star.text.XTextRangeMover.

Text frames can be connected to a chain, that is, the text of the first text frame flows into the next chain element if it does not fit. The properties ChainPrevName and ChainNextName are provided to take advantage of this feature. They contain the names of the predecessor and successor of a frame. All frames have to be empty to chain frames, except for the first member of the chain.

Chained Text Frame Property
ChainPrevName string - Name of the predecessor of the frame.
ChainNextName string - Name of the successor of the frame.

The effect at the API is that the visible text content of the chain members is only accessible at the first frame in the chain. The content of the following chain members is not shown when chained before their content is set.

The API reference does not know the properties above. Instead, it specifies a com.sun.star.text.ChainedTextFrame with an XChainable interface, but this is not yet supported by text frames.

The following example uses text frames:

  /** This method shows how to create and manipulate text frames
  protected void TextFrameExample ()
          // Use the document's factory to create a new text frame and immediately access 
          // it's XTextFrame interface
          XTextFrame xFrame = (XTextFrame) UnoRuntime.queryInterface (
              XTextFrame.class, mxDocFactory.createInstance (
                  "com.sun.star.text.TextFrame" ) );
          // Access the XShape interface of the TextFrame
          XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xFrame);
          // Access the XPropertySet interface of the TextFrame
          XPropertySet xFrameProps = (XPropertySet)UnoRuntime.queryInterface(
              XPropertySet.class, xFrame );
          // Set the size of the new Text Frame using the XShape's 'setSize' method
          Size aSize = new Size();
          aSize.Height = 400;
          aSize.Width = 15000;
          // Set the AnchorType to com.sun.star.text.TextContentAnchorType.AS_CHARACTER
          xFrameProps.setPropertyValue( "AnchorType", TextContentAnchorType.AS_CHARACTER );
          // Go to the end of the text document
          mxDocCursor.gotoEnd( false );
          // Insert a new paragraph
          mxDocText.insertControlCharacter ( 
              mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false );
          // Then insert the new frame
          mxDocText.insertTextContent(mxDocCursor, xFrame, false);
          // Access the XText interface of the text contained within the frame
          XText xFrameText = xFrame.getText();
          // Create a TextCursor over the frame's contents
          XTextCursor xFrameCursor = xFrameText.createTextCursor();
          // Insert some text into the frame
              xFrameCursor, "The first line in the newly created text frame.", false );
              xFrameCursor, "\nThe second line in the new text frame.", false );
          // Insert a paragraph break into the document (not the frame)
          mxDocText.insertControlCharacter ( 
              mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false );
      catch (Exception e) 
          e.printStackTrace ( System.out );
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages