Working with Drawing Documents
- Working with Drawing Documents
Document Structure
Draw documents maintain their drawing content on draw pages, master pages and layers. If a new draw document is opened, it contains one slide that corresponds to a com.sun.star.drawing.DrawPage service. Switching to Master View brings up the master page handled by the service com.sun.star.drawing.MasterPage. The Layer View allows access to layers to structure your drawings. These layers can be controlled through com.sun.star.drawing.Layer and com.sun.star.drawing.LayerManager.
Page Handling
Draw and Impress documents supply their pages (slides) through the interface com.sun.star.drawing.XDrawPagesSupplier. The method com.sun.star.drawing.XDrawPagesSupplier:getDrawPages() returns a container of draw pages with a com.sun.star.drawing.XDrawPages interface that is derived from com.sun.star.container.XIndexAccess. That is, XDrawPages
allows accessing, inserting and removing pages of a drawing document:
type getElementType() boolean hasElements() long getCount() any getByIndex(long Index) com::sun::star::drawing::XDrawPage insertNewByIndex(long nIndex) void remove(com::sun::star::drawing::XDrawPage xPage)
The example below demonstrates how to access and create draw and master pages. Layers will be described later.
XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier)UnoRuntime.queryInterface( XDrawPagesSupplier.class, xComponent); // XDrawPages inherits from com.sun.star.container.XIndexAccess XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); // get the page count for standard pagesint nPageCount = xDrawPages.getCount(); // get draw page by index XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage .class, xDrawPages.getByIndex(nIndex)); /* create and insert a draw page into the given position, the method returns the newly created page */ XDrawPage xNewDrawPage = xDrawPages.insertNewByIndex(0); // remove the given page xDrawPages.remove( xDrawPage ); /* now repeat the same procedure as described above for the master pages, the main difference is to get the XDrawPages from the XMasterPagesSupplier interface */ XMasterPagesSupplier xMasterPagesSupplier = (XMasterPagesSupplier)UnoRuntime.queryInterface( XMasterPagesSupplier.class, xComponent); XDrawPages xMasterPages = xMasterPagesSupplier.getMasterPages(); // xMasterPages can now be used in the same manner as xDrawPages is used above
Each draw page always has one master page. The interface com.sun.star.drawing.XMasterPageTarget offers methods to get and set the master page that is correlated to a draw page.
// query for MasterPageTarget XMasterPageTarget xMasterPageTarget = (XMasterPageTarget)UnoRuntime.queryInterface( XMasterPageTarget.class, xDrawPage); // now we can get the corresponding master page XDrawPage xMasterPage = xMasterPageTarget.getMasterPage(); /* this method now sets a new master page, it is important to mention that the applied page must be part of the MasterPages */ xMasterPageTarget.setMasterPage(xMasterPage);
It is possible to copy pages using the interface [IDL:com.sun.star.drawing.XDrawPageDuplicator] of drawing or presentation documents.
Methods of com.sun.star.drawing.XDrawPageDuplicator:
com::sun::star::drawing::XDrawPage duplicate( [in] com::sun::star::drawing::XDrawPage xPage)
Pass a draw page reference to the method duplicate()
. It appends a new draw page at the end of the page list, using the default naming scheme for pages, "slide n".
Page Partitioning
All units and dimensions are measured in 1/100th of a millimeter. The coordinates are increasing from left to right, and from top to bottom. The upper-left position of a page is (0, 0).
The page size, margins and orientation can be determined using the following properties of a draw page (generic draw page):
Properties of com.sun.star.drawing.GenericDrawPage | |
---|---|
Height | long - Height of the page.
|
Width | long - Width of the page.
|
BorderBottom | long - Bottom margin of the page.
|
BorderLeft | long - Left margin of the page.
|
BorderRight | long - Right margin of the page.
|
BorderTop | long - Top margin of the page.
|
Orientation | com.sun.star.view.PaperOrientation. Determines if the printer output should be turned by 90??. Possible values are: PORTRAIT and LANDSCAPE .
|
Content on this page is licensed under the Public Documentation License (PDL). |