Difference between revisions of "NL/Documentation/BASIC Guide/Structure of Drawings"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 271: Line 271:
 
</source>
 
</source>
  
This example creates a linear color gradient (<tt>Style = LINEAR</tt>). The gradient starts with red (<tt>StartColor</tt>) in the top left corner, and extends at a 45 degree angle (<tt>Angle</tt>) to green (<tt>EndColor</tt>) in the bottom right corner. The color intensity of the start and end colors is 150 percent (<tt>StartIntensity</tt> and <tt>EndIntensity</tt>) which results in the colors seeming brighter than the values specified in the <tt>StartColor</tt> and <tt>EndColor</tt> properties. The color gradient is depicted using a hundred graduated individual colors (<tt>StepCount</tt>).
+
Dit voorbeeld maakt een lineair kleurverloop (<tt>Style = LINEAR</tt>). Het kleurverloop begint met rood (<tt>StartColor</tt>) in de linkerbovenhoek en breidt zich uit in een hoek van 45 graden (<tt>Angle</tt>) tot groen (<tt>EndColor</tt>) in de rechter benedenhoek. De kleurintensiteit van de begin- en eindkleur is 150
 +
procent (<tt>StartIntensity</tt> en <tt>EndIntensity</tt>) welke er in resulteren dat de kleuren helderder lijken dan de waarden, gespecificeerd in de eigenschappen <tt>StartColor</tt> en <tt>EndColor</tt>. Het kleurverloop wordt weergegeven door middel van honderd gegradueerde individuele kleuren (<tt>StepCount</tt>).
  
=== Hatches ===
+
=== Arceringen ===
  
To create a hatch fill, the <tt>FillStyle</tt> property must be set to <tt>HATCH</tt>. The program code for defining the hatch is very similar to the code for color gradients. Again an auxiliary structure, in this case <idl>com.sun.star.drawing.Hatch</idl>, is used to define the appearance of hatches. The structure for hatches has the following properties:
+
De eigenschap <tt>FillStyle</tt> moet worden ingesteld op <tt>HATCH</tt> om een vulling met arcering te maken. De programmacode voor het definiëren van de arcering lijkt veel op de code voor kleurverlopen. Opnieuw wordt een hulp-structuur, in dit geval <idl>com.sun.star.drawing.Hatch</idl>, gebruikt om het uiterlijk van de arcering te definiëren. De structuur voor arceringen heeft de volgende eigenschappen:
  
;<tt>Style (Enum)</tt>:type of hatch: simple, squared, or squared with diagonals (default values in accordance with <tt>com.sun.star.awt.HatchStyle</tt>)
+
;<tt>Style (Enum)</tt>:type arcering: eenvoudig, vierkant of vierkant met diagonalen (standaard waarden die overeenkomen met <tt>com.sun.star.awt.HatchStyle</tt>)
;<tt>Color (Long)</tt>:color of lines
+
;<tt>Color (Long)</tt>:kleur van de lijnen
;<tt>Distance (Long)</tt>:distance between lines in hundredths of a millimeter
+
;<tt>Distance (Long)</tt>:afstand tussen de lijnen in 100-en van een millimeter
;<tt>Angle (Short)</tt>:angle of hatch in tenths of a degree
+
;<tt>Angle (Short)</tt>:hoek van de arcering in tienden van graden
  
The following example demonstrates the use of a hatch structure:
+
Het volgende voorbeeld demonstreert het gebruik van een structuur voor arcering:
  
 
<source lang="oobas">
 
<source lang="oobas">
 
Dim Doc As Object
 
Dim Doc As Object
Dim Page As Object
+
Dim Pagina As Object
Dim RectangleShape As Object
+
Dim RechthoekVorm As Object
Dim Point As New com.sun.star.awt.Point
+
Dim Punt As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
+
Dim Grootte As New com.sun.star.awt.Size
Dim Hatch As New com.sun.star.drawing.Hatch
+
Dim Arcering As New com.sun.star.drawing.Hatch
  
Point.x = 1000
+
Punt.x = 1000
Point.y = 1000
+
Punt.y = 1000
Size.Width = 10000
+
Grootte.Width = 10000
Size.Height = 10000
+
Grootte.Height = 10000
  
 
Doc = ThisComponent
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
+
Pagina = Doc.DrawPages(0)
  
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
+
RechthoekVorm = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
+
RechthoekVorm.Size = Grootte
RectangleShape.Position = Point
+
RechthoekVorm.Position = Punt
  
RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.HATCH
+
RechthoekVorm.FillStyle = com.sun.star.drawing.FillStyle.HATCH
  
Hatch.Style = com.sun.star.drawing.HatchStyle.SINGLE
+
Arcering.Style = com.sun.star.drawing.HatchStyle.SINGLE
Hatch.Color = RGB(64,64,64)
+
Arcering.Color = RGB(64,64,64)
Hatch.Distance = 20
+
Arcering.Distance = 20
Hatch.Angle = 450
+
Arcering.Angle = 450
  
RectangleShape.FillHatch = Hatch
+
RechthoekVorm.FillHatch = Hatch
  
Page.add(RectangleShape)
+
Pagina.add(RechthoekVorm)
 
</source>
 
</source>
  
This code creates a simple hatch structure (<tt>HatchStyle = SINGLE</tt>) whose lines are rotated 45 degrees (<tt>Angle</tt>). The lines are dark gray (<tt>Color</tt>) and are spaced is 0.2 millimeters (<tt>Distance</tt>) apart.
+
Deze code maakt een eenvoudige structuur voor arcering (<tt>HatchStyle = SINGLE</tt>) waarvan de lijnen gedraaid zijn onder een hoek van 45 graden (<tt>Angle</tt>). De lijnen zijn donkergrijs (<tt>Color</tt>) en liggen 0,2 millimeter (<tt>Distance</tt>) uit elkaar.
  
=== Bitmaps ===
+
=== Afbeeldingen ===
  
To use bitmap projection as a fill, you must set the <tt>FillStyle</tt> property to <tt>BITMAP</tt>. If the bitmap is already available in {{OOo}}, you just need to specify its name in the <tt>FillBitMapName</tt> property and its display style (simple, tiled, or elongated) in the <tt>FillBitmapMode</tt> property (default values in accordance with <idl>com.sun.star.drawing.BitmapMode</idl>).
+
U moet de eigenschap <tt>FillStyle</tt> instellen op <tt>BITMAP</tt> om een projectie van een afbeelding te gebruiken als vulling. Als de afbeelding al beschikbaar is in {{OOo}}, hoeft u alleen de naam te specificeren in de eigenschap <tt>FillBitMapName</tt> en zijn manier van zijn weergave (eenvoudig, getegeld of vergroot) in de eigenschap <tt>FillBitmapMode</tt> (standaardwaarden overeenkomend met <idl>com.sun.star.drawing.BitmapMode</idl>).
  
 
If you want to use an external bitmap file, you can specify its URL in the <tt>FillBitmapURL</tt> property.
 
If you want to use an external bitmap file, you can specify its URL in the <tt>FillBitmapURL</tt> property.

Revision as of 15:51, 3 March 2013

Book.png


Pagina's

Template:Documentation/Tip

Apache OpenOffice kent geen beperking in het aantal pagina's in een document voor een tekening. U kunt elke pagina afzonderlijk ontwerpen. Er is ook geen limiet aan het aantal tekenelementen dat u kunt toevoegen aan een pagina.

De pagina's van een document voor een tekening zijn beschikbaar via de DrawPages container DrawPages. U kunt individuele pagina's echter benaderen via hun nummer of hun naam. Als een document slechts één pagina heeft en die is genaamd Dia 1, dan zijn de volgende voorbeelden identiek.

Voorbeeld 1: toegang door middel van het nummer (nummering begint met 0)

Dim Doc As Object
Dim Pagina As Object
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)

Template:Documentation/Note

Voorbeeld 2: toegang door middel van de naam

Dim Doc As Object
Dim Pagina As Object
 
Doc = ThisComponent
Pagina = Doc.DrawPages.getByName("Dia 1")

In voorbeeld 1 wordt de pagina benaderd via zijn nummer (nummering begint bij 0). In het tweede voorbeeld wordt de pagina benaderd via zijn naam en de methode getByName.

Eigenschappen van een pagina

De voorgaande aanroep geeft een object Pagina terug dat de service com.sun.star.drawing.DrawPage ondersteunt. De service herkent de volgende eigenschappen:

BorderLeft (Long)
linker rand in 100-en van een millimeter
BorderRight (Long)
rechter rand in 100-en van een millimeter
BorderTop (Long)
bovenste rand in 100-en van een millimeter
BorderBottom (Long)
onderste rand in 100-en van een millimeter
Width (Long)
paginabreedte in 100-en van een millimeter
Height (Long)
paginahoogte in 100-en van een millimeter
Number (Short)
aantal pagina's (nummering begint met 1), alleen-lezen
Orientation (Enum)
oriëntatie van de pagina (overeenkomend met de opsomming com.sun.star.view.PaperOrientation)

Als deze instellingen worden veranderd dan beïnvloedt dat alle pagina's in het document. Het volgende voorbeeld stelt de paginagrootte van een net geopend document voor een tekening in op 20 × 20 centimeter met een paginamarge van 0,5 centimeter:

Dim Doc As Object
Dim Pagina As Object
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)
 
Pagina.BorderLeft = 500
Pagina.BorderRight = 500
Pagina.BorderTop = 500
Pagina.BorderBottom = 500
 
Pagina.Width = 20000
Pagina.Height = 20000

Hernoemen van pagina's

Documentation caution.png Indien een nieuwe pagina wordt ingevoegd in een document voor een tekening met meerdere pagina's, zullen alle daarop volgende pagina's die niet zijn hernoemd automatisch hun standaard naam zien veranderen, bijv. Dia 3 zal worden gewijzigd naar Dia 4, etc. Dit automatisch hernoemen werkt ook omgekeerd wanneer een pagina wordt verwijderd.

De enige manier om een vaste naam voor de pagina te verkrijgen is door de pagina te hernoemen, via de gebruikersinterface of door programmeren.

Een pagina verschaft de methoden getName en setName om zijn naam te lezen en aan te passen. BASIC kan beide methoden afhandelen als een eigenschap Name. Hier hernoemen we de eerste pagina van het document voor de tekening.

Dim Doc As Object
Dim Pagina As Object
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)
Pagina.Name = "Eerste"

Maken en verwijderen van pagina's

De container DrawPages van een document voor een tekening wordt ook gebruikt om individuele pagina's te maken en te verwijderen. Het volgende voorbeeld gebruikt de methode hasByName om te controleren of een pagina, genaamd MijnPagina, bestaat. Als die bestaat bepaalt de methode een overeenkomstige verwijzing naar het object met behulp van de methode getByName en slaat dan de verwijzing op in een variabele in Pagina. Als de overeenkomende pagina niet bestaat, wordt die gemaakt en ingevoegd in het document voor de tekening door middel van de methode insertNewByIndex. Het argument van de methode is de positie, geteld vanaf 0, van de bestaande pagina achter welke de nieuwe pagina zal worden ingevoegd. Dan wordt de nieuwe pagina hernoemd.

Dim Doc As Object
Dim Pagina As Object
 
Doc = ThisComponent
 
If Doc.Drawpages.hasByName("MijnPagina") Then
   Pagina = Doc.Drawpages.getByName("MijnPagina")
Else
   Pagina = Doc.Drawpages.insertNewByIndex(2)
   Pagina.Name = "MijnPagina" ' u zou een nieuwe pagina altijd moeten hernoemen
   ' MijnPagina is de vierde pagina van het document, d.i. positie 3
End If

De methoden hasByName en getByName worden verkregen uit de interface com.sun.star.container.XNameAccess.

De methode insertNewByIndex wordt verkregen uit de interface com.sun.star.drawing.XDrawPages. Dezelfde interface verschaft de methode remove om een pagina te verwijderen (wissen):

Dim Doc As Object
Dim Pagina As Object
 
Doc = ThisComponent
 
If Doc.Drawpages.hasByName("MijnPagina") Then
   Pagina = Doc.Drawpages.getByName("MijnPagina")
   Doc.Drawpages.remove(Pagina)
End If

Dupliceren van een pagina

Een kopie van een bepaalde pagina wordt gemaakt, niet vanuit de container DrawPages, maar vanuit het document voor de tekening zelf met de methode duplicate. De kopie wordt gemaakt op de volgende positie nà de originele pagina, met een standaard naam.

Dim Doc As Object
Dim Pagina As Object, KopiePagina As Object
 
Doc = ThisComponent
Pagina = Doc.Drawpages.getByName("MijnPagina")
KopiePagina = Doc.duplicate(Pagina)
KopiePagina.Name = "MinKopie" ' u zou een nieuwe pagina altijd moeten hernoemen

Verplaatsen van een pagina

De API verschaft geen methode om de positie van een pagina binnen het document voor een tekening te wijzigen.

Elementaire eigenschappen van tekenobjecten

Tekenobjecten bestaan uit vormen (rechthoeken, cirkels, enzovoort), lijnen en tekstobjecten. Deze delen allemaal een aantal algemene mogelijkheden en ondersteunen de service com.sun.star.drawing.Shape. Deze service definieert de eigenschappen Size en Position van een tekenobject.

Apache OpenOffice BASIC biedt ook diverse andere services waardoor u dergelijke eigenschappen kunt wijzigen, zoals opmaak of vulling toepassen. De opties voor de opmaak die beschikbaar zijn hangen af van het type tekenobject.

Het volgende voorbeeld maakt een rechthoek en voegt die in een document voor een tekening in:

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
 
Doc = ThisComponent
Pagina = Doc.DrawPages(0)
 
Punt.x = 1000
Punt.y = 1000
Grootte.Width = 10000
Grootte.Height = 10000
 
RechthoekVorm = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RechthoekVorm.Size = Grootte
RechthoekVorm.Position = Punt
 
Pagina.add(RechthoekVorm)

De structuren Punt en Grootte, met het punt van origine (linkerbovenhoek) en de grootte van het tekenobject, worden geïnitialiseerd. De lengten worden gespecificeerd in honderdsten van een millimeter.

De programmacode gebruikt dan de aanroep Doc.createInstance om een rechthoekig tekenobject te maken, zoals gespecificeerd door de service com.sun.star.drawing.RectangleShape. Aan het einde wordt het tekenobject toegewezen aan de pagina met behulp van een aanroep Pagina.add.

Eigenschappen voor vulling

Dit gedeelte beschrijft vier services en in elk geval gebruikt de programmacode van het voorbeeld een element met een rechthoekige vorm die verschillende vormen van opmaak combineert. Eigenschappen voor vulling worden gecombineerd in de service com.sun.star.drawing.FillProperties.

Apache OpenOffice herkent vier hoofdtypen van opmaak voor een gebied dat gevuld moet worden. De eenvoudigste variant is een enkelkleurige vulling. De opties voor het definiëren van kleurverlopen en arceringen stellen u in staat ook andere kleuren te gebruiken. De vierde variant is de optie van het projecteren van bestaande afbeeldingen in het gebied om te vullen.

De modus vulling van een tekenobject wordt gedefinieerd met behulp van de eigenschap FillStyle. De toegestane waarden worden gedefinieerd in com.sun.star.drawing.FillStyle.

Vullingen met één kleur

De belangrijkste eigenschap voor enkelkleurige vullingen is:

FillColor (Long)
kleur voor de vulling van het gebied

U moet de eigenschap FillStyle instellen op de modus voor vulling SOLID om die modus voor vulling te kunnen gebruiken.

Het volgende voorbeeld maakt een rechthoekige vorm en vult die met rood (RGB waarde 255, 0, 0):

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.FillStyle = com.sun.star.drawing.FillStyle.SOLID
RechthoekVorm.FillColor = RGB(255,0,0)
 
Pagina.add(RechthoekVorm)

Kleurverloop

Als u de eigenschap FillStyle instelt op GRADIENT, kunt u een kleurverloop toepassen op elk vulgebied in een document van Apache OpenOffice.

Indien u een vooraf gedefinieerd kleurverloop wilt toepassen, kunt u de bijbehorende naam toewijzen aan de eigenschap FillTransparenceGradientName. Om uw eigen kleurverloop te definiëren, moet u een structuur com.sun.star.awt.Gradient completeren om de eigenschap FillGradient aan toe te wijzen. Deze eigenschap verschaft de volgende opties:

Style (Enum)
type kleurverloop, bijvoorbeeld, lineair of radiaal (standaard waarden overeenkomend met com.sun.star.awt.GradientStyle)
StartColor (Long)
beginkleur van kleurverloop
EndColor (Long)
eindkleur van kleurverloop
Angle (Short)
hoek van het kleurverloop in tienden van graden
XOffset (Short)
X-coördinaat waarop het kleurverloop begint, gespecificeerd in 100-en of a millimeter
YOffset (Short)
Y-coördinaat waarop het kleurverloop begint, gespecificeerd in 100-en of a millimeter
StartIntensity (Short)
intensiteit van StartColor als een percentage (in Apache OpenOffice BASIC kunt u ook waarden specificeren die groter zijn dan 100 procent)
EndIntensity (Short)
intensiteit van EndColor als een percentage (in Apache OpenOffice BASIC kunt u ook waarden specificeren die groter zijn dan 100 procent)
StepCount (Short)
aantal gradaties van kleuren dat Apache OpenOffice moet berekenen voor de verlopen

Het volgende voorbeeld demonstreert het gebruik van kleurverlopen met behulp van de structuur com.sun.star.awt.Gradient:

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
Dim Kleurverloop As New com.sun.star.awt.Gradient 
 
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
Kleurverloop.Style = com.sun.star.awt.GradientStyle.LINEAR
Kleurverloop.StartColor = RGB(255,0,0)
Kleurverloop.EndColor = RGB(0,255,0)
Kleurverloop.StartIntensity = 150   
Kleurverloop.EndIntensity = 150
Kleurverloop.Angle = 450
Kleurverloop.StepCount = 100
 
RechthoekVorm.FillStyle = com.sun.star.drawing.FillStyle.GRADIENT
RechthoekVorm.FillGradient = Kleurverloop
 
Pagina.add(RechthoekVorm)

Dit voorbeeld maakt een lineair kleurverloop (Style = LINEAR). Het kleurverloop begint met rood (StartColor) in de linkerbovenhoek en breidt zich uit in een hoek van 45 graden (Angle) tot groen (EndColor) in de rechter benedenhoek. De kleurintensiteit van de begin- en eindkleur is 150 procent (StartIntensity en EndIntensity) welke er in resulteren dat de kleuren helderder lijken dan de waarden, gespecificeerd in de eigenschappen StartColor en EndColor. Het kleurverloop wordt weergegeven door middel van honderd gegradueerde individuele kleuren (StepCount).

Arceringen

De eigenschap FillStyle moet worden ingesteld op HATCH om een vulling met arcering te maken. De programmacode voor het definiëren van de arcering lijkt veel op de code voor kleurverlopen. Opnieuw wordt een hulp-structuur, in dit geval com.sun.star.drawing.Hatch, gebruikt om het uiterlijk van de arcering te definiëren. De structuur voor arceringen heeft de volgende eigenschappen:

Style (Enum)
type arcering: eenvoudig, vierkant of vierkant met diagonalen (standaard waarden die overeenkomen met com.sun.star.awt.HatchStyle)
Color (Long)
kleur van de lijnen
Distance (Long)
afstand tussen de lijnen in 100-en van een millimeter
Angle (Short)
hoek van de arcering in tienden van graden

Het volgende voorbeeld demonstreert het gebruik van een structuur voor arcering:

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
Dim Arcering As New com.sun.star.drawing.Hatch
 
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.FillStyle = com.sun.star.drawing.FillStyle.HATCH
 
Arcering.Style = com.sun.star.drawing.HatchStyle.SINGLE
Arcering.Color = RGB(64,64,64)
Arcering.Distance = 20
Arcering.Angle = 450
 
RechthoekVorm.FillHatch = Hatch
 
Pagina.add(RechthoekVorm)

Deze code maakt een eenvoudige structuur voor arcering (HatchStyle = SINGLE) waarvan de lijnen gedraaid zijn onder een hoek van 45 graden (Angle). De lijnen zijn donkergrijs (Color) en liggen 0,2 millimeter (Distance) uit elkaar.

Afbeeldingen

U moet de eigenschap FillStyle instellen op BITMAP om een projectie van een afbeelding te gebruiken als vulling. Als de afbeelding al beschikbaar is in Apache OpenOffice, hoeft u alleen de naam te specificeren in de eigenschap FillBitMapName en zijn manier van zijn weergave (eenvoudig, getegeld of vergroot) in de eigenschap FillBitmapMode (standaardwaarden overeenkomend met com.sun.star.drawing.BitmapMode).

If you want to use an external bitmap file, you can specify its URL in the FillBitmapURL property.

The following example creates a rectangle and tiles the Sky bitmap that is available in Apache OpenOffice to fill the area of the rectangle:

Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.BITMAP
RectangleShape.FillBitmapName = "Sky"
RectangleShape.FillBitmapMode = com.sun.star.drawing.BitmapMode.REPEAT
 
Page.add(RectangleShape)

Transparency

You can adjust the transparency of any fill that you apply. The simplest way to change the transparency of a drawing element is to use the FillTransparence property.

The following example creates a red rectangle with a transparency of 50 percent.

Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.SOLID
RectangleShape.FillTransparence = 50
RectangleShape.FillColor = RGB(255,0,0)
 
Page.add(RectangleShape)

To make the fill transparent, set the FillTransparence property to 100.

In addition to the FillTransparence property, the com.sun.star.drawing.FillProperties service also provides the FillTransparenceGradient property. This is used to define a gradient that specifies the transparency of a fill area.

Line Properties

All drawing objects that can have a border line support the com.sun.star.drawing.LineStyle service. Some of the properties that this service provides are:

LineStyle (Enum)
line type (default values in accordance with com.sun.star.drawing.LineStyle)
LineColor (Long)
line color
LineTransparence (Short)
line transparency
LineWidth (Long)
line thickness in hundredths of a millimeter
LineJoint (Enum)
transitions to connection points (default values in accordance with com.sun.star.drawing.LineJoint )

The following example creates a rectangle with a solid border (LineStyle = SOLID) that is 5 millimeters thick (LineWidth) and 50 percent transparent. The right and left-hand edges of the line extend to their points of intersect with each other (LineJoint = MITER) to form a right-angle.

Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
RectangleShape.LineColor = RGB(128,128,128)
RectangleShape.LineTransparence = 50
RectangleShape.LineWidth = 500
RectangleShape.LineJoint = com.sun.star.drawing.LineJoint.MITER   
 
RectangleShape.LineStyle = com.sun.star.drawing.LineStyle.SOLID
 
Page.add(RectangleShape)

In addition to the listed properties, the com.sun.star.drawing.LineStyle service provides options for drawing dotted and dashed lines. For more information, see the Apache OpenOffice API reference.

Text Properties (Drawing Objects)

The com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties services can format text in drawing objects. These services relate to individual characters and paragraphs and are described in detail in Text Documents.

The following example inserts text in a rectangle and formats the font com.sun.star.style.CharacterProperties service.

Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
Page.add(RectangleShape)
 
RectangleShape.String = "This is a test"
RectangleShape.CharWeight = com.sun.star.awt.FontWeight.BOLD
RectangleShape.CharFontName = "Arial"

This code uses the String-property of the rectangle to insert the text and the CharWeight and CharFontName properties from the com.sun.star.style.CharacterProperties service to format the text font.

The text can only be inserted after the drawing object has been added to the drawing page. You can also use the com.sun.star.drawing.Text service to position and format text in drawing object. The following are some of the important properties of this service:

TextAutoGrowHeight (Boolean)
adapts the height of the drawing element to the text it contains
TextAutoGrowWidth (Boolean)
adapts the width of the drawing element to the text it contains
TextHorizontalAdjust (Enum)
horizontal position of text within the drawing element (default values in accordance with com.sun.star.drawing.TextHorizontalAdjust)
TextVerticalAdjust (Enum)
vertical position of text within the drawing element (default values in accordance with com.sun.star.drawing.TextVerticalAdjust)
TextLeftDistance (Long)
left-hand distance between drawing element and text in hundredths of a millimeter
TextRightDistance (Long)
right-hand distance between drawing element and text in hundredths of a millimeter
TextUpperDistance (Long)
upper distance between drawing element and text in hundredths of a millimeter
TextLowerDistance (Long)
lower distance between drawing element and text in hundredths of a millimeter

The following example demonstrates use of the named properties.

Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
Page.add(RectangleShape)
 
RectangleShape.String = "This is a test"   ' May only take place after Page.add!
 
RectangleShape.TextVerticalAdjust = com.sun.star.drawing.TextVerticalAdjust.TOP
RectangleShape.TextHorizontalAdjust = com.sun.star.drawing.TextHorizontalAdjust.LEFT
 
RectangleShape.TextLeftDistance = 300
RectangleShape.TextRightDistance = 300
RectangleShape.TextUpperDistance = 300
RectangleShape.TextLowerDistance = 300

This code inserts a drawing element in a page and then adds text to the top left corner of the drawing object using the TextVerticalAdjust and TextHorizontalAdjust properties. The minimum distance between the text edge of the drawing object is set to three millimeters.

Shadow Properties

You can add a shadow to most drawing objects with the com.sun.star.drawing.ShadowProperties service. The properties of this service are:

Shadow (Boolean)
activates the shadow
ShadowColor (Long)
shadow color
ShadowTransparence (Short)
transparency of the shadow
ShadowXDistance (Long)
vertical distance of the shadow from the drawing object in hundredths of a millimeter
ShadowYDistance (Long)
horizontal distance of the shadow from the drawing object in hundredths of a millimeter

The following example creates a rectangle with a shadow that is vertically and horizontally offset from the rectangle by 2 millimeters. The shadow is rendered in dark gray with 50 percent transparency.

Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
RectangleShape.Shadow = True
RectangleShape.ShadowColor = RGB(192,192,192)
RectangleShape.ShadowTransparence = 50
RectangleShape.ShadowXDistance = 200 
RectangleShape.ShadowYDistance = 200
 
Page.add(RectangleShape)

An Overview of Various Drawing Objects

Rectangle Shapes

Rectangle shape objects (com.sun.star.drawing.RectangleShape) support the following services for formatting objects:

Fill properties
com.sun.star.drawing.FillProperties
Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties)
Shadow properties
com.sun.star.drawing.ShadowProperties
CornerRadius (Long)
radius for rounding corners in hundredths of a millimeter

Circles and Ellipses

The Service com.sun.star.drawing.EllipseShape service is responsible for circles and ellipses and supports the following services:

Fill properties
com.sun.star.drawing.FillProperties
Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties)
Shadow properties
com.sun.star.drawing.ShadowProperties

In addition to these services, circles and ellipses also provide these properties:

CircleKind (Enum)
type of circle or ellipse (default values in accordance with com.sun.star.drawing.CircleKind )
CircleStartAngle (Long)
start angle in tenths of a degree (only for circle or ellipse segments)
CircleEndAngle (Long)
end angle in tenths of a degree (only for circle or ellipse segments)

The CircleKind property determines if an object is a complete circle, a circular slice, or a section of a circle. The following values are available:

com.sun.star.drawing.CircleKind.FULL
full circle or full ellipse
com.sun.star.drawing.CircleKind.CUT
section of circle (partial circle whose interfaces are linked directly to one another)
com.sun.star.drawing.CircleKind.SECTION
circle slice
com.sun.star.drawing.CircleKind.ARC
angle (not including circle line)

The following example creates a circular slice with a 70 degree angle (produced from difference between start angle of 20 degrees and end angle of 90 degrees)

Dim Doc As Object
Dim Page As Object
Dim EllipseShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
EllipseShape = Doc.createInstance("com.sun.star.drawing.EllipseShape")
EllipseShape.Size = Size
EllipseShape.Position = Point
 
EllipseShape.CircleStartAngle = 2000
EllipseShape.CircleEndAngle = 9000
EllipseShape.CircleKind =  com.sun.star.drawing.CircleKind.SECTION
 
Page.add(EllipseShape)

Lines

Apache OpenOffice provides the com.sun.star.drawing.LineShape service for line objects. Line objects support all of the general formatting services with the exception of areas. The following are all of the properties that are associated with the LineShape service:

Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties)
Shadow properties
com.sun.star.drawing.ShadowProperties

The following example creates and formats a line with the help of the named properties. The origin of the line is specified in the Location property, whereas the coordinates listed in the Size property specify the end point of the line.

Dim Doc As Object
Dim Page As Object
Dim LineShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
LineShape = Doc.createInstance("com.sun.star.drawing.LineShape")
LineShape.Size = Size
LineShape.Position = Point
 
Page.add(LineShape)

Polypolygon Shapes

Apache OpenOffice also supports complex polygonal shapes through the com.sun.star.drawing.PolyPolygonShape service. Strictly speaking, a PolyPolygon is not a simple polygon but a multiple polygon. Several independent lists containing corner points can therefore be specified and combined to form a complete object.

As with rectangle shapes, all the formatting properties of drawing objects are also provided for polypolygons:

Fill properties
com.sun.star.drawing.FillProperties
Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties)
Shadow properties
com.sun.star.drawing.ShadowProperties

The PolyPolygonShape service also has a property that lets you define the coordinates of a polygon:

  • PolyPolygon (Array) – field containing the coordinates of the polygon (double array with points of the com.sun.star.awt.Point type)

The following example shows how you can define a triangle with the PolyPolygonShape service.

Dim Doc As Object
Dim Page As Object
Dim PolyPolygonShape As Object
Dim PolyPolygon As Variant
Dim Coordinates(2) As New com.sun.star.awt.Point
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
PolyPolygonShape = Doc.createInstance("com.sun.star.drawing.PolyPolygonShape")
Page.add(PolyPolygonShape)   ' Page.add must take place before the coordinates are set
 
Coordinates(0).x = 1000
Coordinates(1).x = 7500
Coordinates(2).x = 10000
Coordinates(0).y = 1000
Coordinates(1).y = 7500
Coordinates(2).y = 5000
 
PolyPolygonShape.PolyPolygon = Array(Coordinates())

Since the points of a polygon are defined as absolute values, you do not need to specify the size or the start position of a polygon. Instead, you need to create an array of the points, package this array in a second array (using the Array(Coordinates()) call), and then assign this array to the polygon. Before the corresponding call can be made, the polygon must be inserted into the document.

The double array in the definition allows you to create complex shapes by merging several polygons. For example, you can create a rectangle and then insert another rectangle inside it to create a hole in the original rectangle:

Dim Doc As Object
Dim Page As Object
Dim PolyPolygonShape As Object
Dim PolyPolygon As Variant
Dim Square1(3) As New com.sun.star.awt.Point
Dim Square2(3) As New com.sun.star.awt.Point
Dim Square3(3) As New com.sun.star.awt.Point
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
PolyPolygonShape = Doc.createInstance("com.sun.star.drawing.PolyPolygonShape")
 
Page.add(PolyPolygonShape)   ' Page.add must take place before the coordinates are set
 
Square1(0).x = 5000
Square1(1).x = 10000
Square1(2).x = 10000
Square1(3).x = 5000
Square1(0).y = 5000
Square1(1).y = 5000
Square1(2).y = 10000
Square1(3).y = 10000
 
Square2(0).x = 6500
Square2(1).x = 8500
Square2(2).x = 8500
Square2(3).x = 6500
Square2(0).y = 6500
Square2(1).y = 6500
Square2(2).y = 8500
Square2(3).y = 8500
 
Square3(0).x = 6500
Square3(1).x = 8500
Square3(2).x = 8500
Square3(3).x = 6500
Square3(0).y = 9000
Square3(1).y = 9000
Square3(2).y = 9500
Square3(3).y = 9500
 
PolyPolygonShape.PolyPolygon = Array(Square1(), Square2(), Square3())

With respect as to which areas are filled and which areas are holes, Apache OpenOffice applies a simple rule: the edge of the outer shape is always the outer border of the polypolygon. The next line inwards is the inner border of the shape and marks the transition to the first hole. If there is another line inwards, it marks the transition to a filled area.

Graphics

The last of the drawing elements presented here are graphic objects that are based on the com.sun.star.drawing.GraphicObjectShape service. These can be used with any graphic within Apache OpenOffice whose appearance can be adapted using a whole range of properties.

Graphic objects support two of the general formatting properties:

Text properties
com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties)
Shadow properties
com.sun.star.drawing.ShadowProperties

Additional properties that are supported by graphic objects are:

GraphicURL (String)
URL of the graphic
AdjustLuminance (Short)
luminance of the colors, as a percentage (negative values are also permitted)
AdjustContrast (Short)
contrast as a percentage (negative values are also permitted)
AdjustRed (Short)
red value as a percentage (negative values are also permitted)
AdjustGreen (Short)
green value as a percentage (negative values are also permitted)
AdjustBlue (Short)
blue value as a percentage (negative values are also permitted)
Gamma (Short)
gamma value of a graphic
Transparency (Short)
transparency of a graphic as a percentage
GraphicColorMode (enum)
color mode, for example, standard, gray stages, black and white (default value in accordance with com.sun.star.drawing.ColorMode )

The following example shows how to insert a page into a graphics object.

Dim Doc As Object
Dim Page As Object
Dim GraphicObjectShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
 
Point.x = 1000         ' specifications, insignificant because latter
                       coordinates are binding
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
Doc = ThisComponent
Page = Doc.DrawPages(0)
 
GraphicObjectShape = Doc.createInstance("com.sun.star.drawing.GraphicObjectShape")
 
GraphicObjectShape.Size = Size
GraphicObjectShape.Position = Point
 
GraphicObjectShape.GraphicURL = "file:///c:/test.jpg"
GraphicObjectShape.AdjustBlue = -50
GraphicObjectShape.AdjustGreen = 5
GraphicObjectShape.AdjustBlue = 10
GraphicObjectShape.AdjustContrast = 20
GraphicObjectShape.AdjustLuminance = 50
GraphicObjectShape.Transparency = 40
GraphicObjectShape.GraphicColorMode = com.sun.star.drawing.ColorMode.STANDARD
 
Page.add(GraphicObjectShape)

This code inserts the test.jpg graphic and adapts its appearance using the Adjust properties. In this example, the graphics are depicted as 40 percent transparent with no other color conversions do not take place (GraphicColorMode = STANDARD).


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