Bewerken van tekenobjecten

From Apache OpenOffice Wiki
< NL‎ | Documentation‎ | BASIC Guide
Revision as of 14:37, 10 March 2013 by DiGro (Talk | contribs)

Jump to: navigation, search
Book.png


Objecten groeperen

In veel situaties, is het handig om verschillende individuele tekenobjecten te groeperen zodat zij zich gaan gedragen als één enkel groot object.

Het volgende voorbeeld groepeert twee tekenobjecten:

Dim Doc As Object
Dim Pagina As Object
Dim Vierkant As Object
Dim Cirkel As Object
Dim Vormen As Object
Dim Groep As Object
Dim Punt As New com.sun.star.awt.Point
Dim Grootte As New com.sun.star.awt.Size
Dim NieuwPos As New com.sun.star.awt.Point
Dim Hoogte As Long
Dim Breedte As Long
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)
Punt.x = 3000
Punt.y = 3000
Grootte.Width = 3000
Grootte.Height = 3000
' maak tekenelement vierkant
Vierkant = Doc.createInstance("com.sun.star.drawing.RectangleShape")
Vierkant.Size = Grootte
Vierkant.Position = Punt
Vierkant.FillColor = RGB(255,128,128) 
Pagina.add(Vierkant)
 
' maak tekenelement cirkel
Cirkel = Doc.createInstance("com.sun.star.drawing.EllipseShape")
Cirkel.Size = Grootte
Cirkel.Position = Punt
Cirkel.FillColor = RGB(255,128,128) 
Cirkel.FillColor = RGB(0,255,0)
Pagina.add(Cirkel)
 
' combineer de tekenelementen vierkant en cirkel
Vormen = createUnoService("com.sun.star.drawing.ShapeCollection")
Vormen.add(Vierkant)
 
Vormen.add(Cirkel)
Groep = Pagina.group(Vormen)
' centreer gecombineerde tekenelementen
Hoogte = Pagina.Height
Breedte = Pagina.Width
NieuwPos.X = Breedte / 2
NieuwPos.Y = Hoogte / 2
Hoogte = Groep.Size.Height
Breetde = Groep.Size.Width
NieuwPos.X = NieuwPos.X - Breedte / 2
NieuwPos.Y = NieuwPos.Y - Hoogte / 2
Groep.Position = NieuwPos

Deze code maakt een rechthoek en een cirkel en voegt die op de pagina in. Het maakt dan een object dat de service com.sun.star.drawing.ShapeCollection ondersteunt en gebruikt dan de methode Add om de rechthoek en cirkel aan dat object toe te voegen. De ShapeCollection wordt toegevoegd aan de pagina met behulp van de methode Group en geeft het actuele object Group weer dat kan worden bewerkt als een individuele Shape.

Als u de individuele objecten van een groep wilt opmaken, pas dan de opmaak toe vóórdat u ze toevoegt aan de groep. U kunt de objecten niet aanpassen als zij aan de groep zijn toegevoegd.

Roteren en schuin trekken van tekenobjecten

Alle teken-objecten die worden beschreven in de voorgaande gedeelten kunnen ook worden geroteerd of vervormt met behulp van de service com.sun.star.drawing.RotationDescriptor.

De service verschaft de volgende eigenschappen:

RotateAngle (Long)
draaihoek in 100-en van een graad
ShearAngle (Long)
hoek om schuin te trekken in 100-en van een graad

Het volgende voorbeeld maakt een rechthoek en draait die 30 graden met behulp van de eigenschap RotateAngle:

Dim Doc As Object
Dim Pagina As Object
Dim RechthoekVorm As Object
Dim Punt As New com.sun.star.awt.Point
Dim Grootte As New com.sun.star.awt.Size
 
Punt.x = 1000
Punt.y = 1000
Grootte.Width = 10000
Grootte.Height = 10000
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)
 
RechthoekVorm = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RechthoekVorm.Size = Grootte
RechthoekVorm.Position = Punt
 
RechthoekVorm.RotateAngle = 3000
 
Pagina.add(RechthoekVorm)

Het volgende voorbeeld maakt dezelfde rechthoek als in het voorgaande voorbeeld, maar trekt die schuin over 30 graden met behulp van de eigenschap ShearAngle.


Dim Doc As Object
Dim Pagina As Object
Dim RechthoekVorm As Object
Dim Punt As New com.sun.star.awt.Point
Dim Grootte As New com.sun.star.awt.Size
 
Punt.x = 1000
Punt.y = 1000
Grootte.Width = 10000
Grootte.Height = 10000
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)
 
RechthoekVorm = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RechthoekVorm.Size = Grootte
RechthoekVorm.Position = Punt
 
RechthoekVorm.ShearAngle = 3000
 
Pagina.add(RechthoekVorm)

Zoeken en vervangen

As in text documents, drawing documents provide a function for searching and replace. This function is similar to the one that is used in text documents as described in Text Documents. However, in drawing documents the descriptor objects for searching and replacing are not created directly through the document object, but rather through the associated character level. The following example outlines the replacement process within a drawing:

Dim Doc As Object
Dim Page As Object
Dim ReplaceDescriptor As Object
Dim I As Integer
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
ReplaceDescriptor = Page.createReplaceDescriptor()
ReplaceDescriptor.SearchString = "is"
ReplaceDescriptor.ReplaceString = "was"
 
For I = 0 to Doc.DrawPages.Count - 1
   Page = Doc.DrawPages(I)
   Page.ReplaceAll(ReplaceDescriptor) 
Next I

This code uses the first page of the document to create a ReplaceDescriptor and then applies this descriptor in a loop to all of the pages in the drawing document.


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