Difference between revisions of "NL/Documentation/BASIC Guide/Structure of Drawings"
Line 74: | Line 74: | ||
=== Hernoemen van pagina's === | === Hernoemen van pagina's === | ||
− | {{Documentation/Caution|Indien een nieuwe pagina wordt ingevoegd in een document voor | + | {{Documentation/Caution|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.}} | De enige manier om een vaste naam voor de pagina te verkrijgen is door de pagina te hernoemen, via de gebruikersinterface of door programmeren.}} | ||
Line 143: | Line 143: | ||
De API verschaft geen methode om de positie van een pagina binnen het document voor een tekening te wijzigen. | 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 <tt>com.sun.star.drawing.Shape</tt>. Deze service definieert de eigenschappen <tt>Size</tt> en <tt>Position</tt> van een tekenobject. | |
− | {{OOo}} | + | {{OOo}} 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 tekening-document in: | |
<source lang="oobas"> | <source lang="oobas"> | ||
Dim Doc As Object | Dim Doc As Object | ||
− | Dim | + | Dim Pagina As Object |
− | Dim | + | Dim RechthoekVorm As Object |
− | Dim | + | Dim Punt As New com.sun.star.awt.Point |
− | Dim | + | Dim Grootte As New com.sun.star.awt.Size |
Doc = ThisComponent | 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) | |
</source> | </source> | ||
− | + | De structuren <tt>Punt</tt> en <tt>Grootte</tt>, 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 <tt>Doc.createInstance</tt> om een rechthoekig tekenobject te maken, zoals gespecificeerd door de service <idl>com.sun.star.drawing.RectangleShape</idl>. Aan het einde wordt het tekenobject toegewezen aan de pagina met behulp van een aanroep <tt>Pagina.add</tt>. | ||
− | + | === 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 <idl>com.sun.star.drawing.FillProperties</idl>. | |
− | + | {{OOo}} 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 <tt>FillStyle</tt>. De toegestane waarden worden gedefinieerd in <idl>com.sun.star.drawing.FillStyle</idl>. | |
− | + | === Vullingen met één kleur === | |
− | + | De belangrijkste eigenschap voor enkelkleurige vullingen is: | |
− | + | ;<tt>FillColor (Long)</tt>:kleur voor de vulling van het gebied | |
− | + | U moet de eigenschap <tt>FillStyle</tt> instellen op de modus voor vulling <tt>SOLID</tt> om die modus voor vulling te kunnen gebruiken. | |
− | To use the fill mode, you must the | + | To use the fill mode, you must the property to the fill mode. |
The following example creates a rectangle shape and fills it with red (RGB value 255, 0, 0): | The following example creates a rectangle shape and fills it with red (RGB value 255, 0, 0): |
Revision as of 15:22, 3 March 2013
- De structuur van tekeningen
- Tekenobjecten bewerken
- Presentaties
Contents
Pagina's
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)
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
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 tekening-document 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.
To use the fill mode, you must the property to the fill mode.
The following example creates a rectangle shape and fills it with red (RGB value 255, 0, 0):
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.FillColor = RGB(255,0,0) Page.add(RectangleShape)
Color Gradient
If you set the FillStyle property to GRADIENT, you can apply a color gradient to any fill area of a Apache OpenOffice document.
If you want to apply a predefined color gradient, you can assign the associated name of the FillTransparenceGradientName property. To define your own color gradient, you need to complete a com.sun.star.awt.Gradient structure to assign the FillGradient property. This property provides the following options:
- Style (Enum)
- type of gradient, for example, linear or radial (default values in accordance with com.sun.star.awt.GradientStyle)
- StartColor (Long)
- start color of color gradient
- EndColor (Long)
- end color of color gradient
- Angle (Short)
- angle of color gradient in tenths of a degree
- XOffset (Short)
- X-coordinate at which the color gradient starts, specified in hundredths of a millimeter
- YOffset (Short)
- Y-coordinate at which the color gradient begins, specified in hundredths of a millimeter
- StartIntensity (Short)
- intensity of StartColor as a percentage (in Apache OpenOffice Basic, you can also specify values higher than 100 percent)
- EndIntensity (Short)
- intensity of EndColor as a percentage (in Apache OpenOffice Basic, you can also specify values higher than 100 percent)
- StepCount (Short)
- number of color graduations which Apache OpenOffice is to calculate for the gradients
The following example demonstrates the use of color gradients with the aid of the com.sun.star.awt.Gradient structure:
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 Dim Gradient As New com.sun.star.awt.Gradient 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 Gradient.Style = com.sun.star.awt.GradientStyle.LINEAR Gradient.StartColor = RGB(255,0,0) Gradient.EndColor = RGB(0,255,0) Gradient.StartIntensity = 150 Gradient.EndIntensity = 150 Gradient.Angle = 450 Gradient.StepCount = 100 RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.GRADIENT RectangleShape.FillGradient = Gradient Page.add(RectangleShape)
This example creates a linear color gradient (Style = LINEAR). The gradient starts with red (StartColor) in the top left corner, and extends at a 45 degree angle (Angle) to green (EndColor) in the bottom right corner. The color intensity of the start and end colors is 150 percent (StartIntensity and EndIntensity) which results in the colors seeming brighter than the values specified in the StartColor and EndColor properties. The color gradient is depicted using a hundred graduated individual colors (StepCount).
Hatches
To create a hatch fill, the FillStyle property must be set to HATCH. The program code for defining the hatch is very similar to the code for color gradients. Again an auxiliary structure, in this case com.sun.star.drawing.Hatch, is used to define the appearance of hatches. The structure for hatches has the following properties:
- Style (Enum)
- type of hatch: simple, squared, or squared with diagonals (default values in accordance with com.sun.star.awt.HatchStyle)
- Color (Long)
- color of lines
- Distance (Long)
- distance between lines in hundredths of a millimeter
- Angle (Short)
- angle of hatch in tenths of a degree
The following example demonstrates the use of a hatch structure:
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 Dim Hatch As New com.sun.star.drawing.Hatch 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.HATCH Hatch.Style = com.sun.star.drawing.HatchStyle.SINGLE Hatch.Color = RGB(64,64,64) Hatch.Distance = 20 Hatch.Angle = 450 RectangleShape.FillHatch = Hatch Page.add(RectangleShape)
This code creates a simple hatch structure (HatchStyle = SINGLE) whose lines are rotated 45 degrees (Angle). The lines are dark gray (Color) and are spaced is 0.2 millimeters (Distance) apart.
Bitmaps
To use bitmap projection as a fill, you must set the FillStyle property to BITMAP. If the bitmap is already available in Apache OpenOffice, you just need to specify its name in the FillBitMapName property and its display style (simple, tiled, or elongated) in the FillBitmapMode property (default values in accordance with 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). |