绘图结构

From Apache OpenOffice Wiki
Jump to: navigation, search
doc OOo
Book.png


Apache OpenOffice 对绘图文档的页数没有限制。您可以单独设计每个页面。对可以在页面中添加的绘图元素数目也没有限制。

页面

绘图文档的页面是通过 DrawPages 列表提供的。可以通过编号或名称来访问各个页面。如果文档只有一个名为 Slide 1 的页面,则以下示例完全相同。

示例 1:

Dim Doc As Object
Dim Page As Object
 
Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages(0)

示例 2:

Dim Doc As Object
Dim Page As Object
 
Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages.getByName("Slide 1")

示例 1 通过编号(从 0 开始计数)对页面进行寻址。第二个示例通过名称和 getByName 方法访问页面。

Dim sUrl As String, sFilter As String
Dim sOptions As String
Dim oSheets As Object, oSheet As Object
 
   oSheets = oDocument.Sheets
 
   If oSheets.hasByName("Link") Then
      oSheet = oSheets.getByName("Link")
   Else
      oSheet = oDocument.createInstance("com.sun.star.sheet.Spreadsheet")
      oSheets.insertByName("Link", oSheet)
      oSheet.IsVisible = False
   End If

以上调用返回一个支持 com.sun.star.drawing.DrawPage 服务的页面对象。该服务可以识别以下属性:

BorderLeft (Long)
左边框,以百分之一毫米为单位
BorderRight (Long)
右边框,以百分之一毫米为单位
BorderTop (Long)
上边框,以百分之一毫米为单位
BorderBottom (Long)
下边框,以百分之一毫米为单位
Width (Long)
页面宽度,以百分之一毫米为单位
Height (Long)
页面高度,以百分之一毫米为单位
Number (Short)
页码(从 1 开始编号),只读
Orientation (Enum)
页面方向(与 com.sun.star.view.PaperOrientation 枚举一致)

如果更改了这些设置,文档中的所有页面都会受到影响。

以下示例将刚刚打开的绘图文档的页面大小设置为 20 x 20 厘米,并将页边距设置为 0.5 厘米:

Dim Doc As Object
Dim Page As Object
 
Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages(0)
 
Page.BorderLeft = 500
Page.BorderRight = 500
Page.BorderTop = 500
Page.BorderBottom = 500
 
Page.Width = 20000
Page.Height = 20000

绘图对象的基本属性

绘图对象包括形状对象(矩形和圆等)、线条对象和文本对象。所有这些对象都有一些共同的特征,并且都支持 com.sun.star.drawing.Shape 服务。该服务定义了绘图对象的 SizePosition 属性。

Apache OpenOffice Basic 还提供了一些其他服务,可通过这些服务修改格式设置或应用填充等属性。可用的格式选项取决于绘图对象的类型。

以下示例将创建一个矩形并将其插入到绘图文档中:

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
 
Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages(0)
 
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000
 
RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point
 
Page.add(RectangleShape)

该示例使用 StarDesktop.CurrentComponent 调用来确定打开的文档。以这种方式确定的文档对象通过 drawPages(0) 调用返回绘图的第一页。

然后,初始化包含绘图对象原点(左角点)和大小的 PointSize 结构,并以百分之一毫米为单位指定长度。

接下来,程序代码使用 Doc.createInstance 调用创建 com.sun.star.drawing.RectangleShape 服务指定的矩形绘图对象。最后,使用 Page.add 调用将绘图对象指定给页面。

填充属性

本节介绍了四种服务,每种服务的示例程序代码都使用一个包含多种格式设置类型的矩形元素。填充属性包含在 com.sun.star.drawing.FillProperties 服务中。

Apache OpenOffice 可以识别一个填充区域的四种主要格式设置类型。最简单的形式是单色填充。可通过用于定义颜色渐变和阴影线的选项来创建其他颜色。第四种形式是将现有图形投影到填充区域。

绘图对象的填充模式是使用 FillStyle 属性定义的。允许的值是在 com.sun.star.drawing.FillStyle 中定义的。

单色填充

单色填充的主要属性有:

FillColor (Long)
区域的填充颜色

要使用填充模式,必须将 FillStyle 属性设置为 SOLID 填充模式。

以下示例将创建一个矩形,并用红色进行填充(RGB 值为 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 = StarDesktop.CurrentComponent
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)

颜色渐变

如果将 FillStyle 属性设置为 GRADIENT,则可以将颜色渐变应用于 Apache OpenOffice 文档的任意填充区域。

如果要应用预定义的颜色渐变,则可以指定 FillTransparenceGradientName 属性的关联名称。要定义自己的颜色渐变,您需要构造一个完整的 com.sun.star.awt.Gradient 结构,以指定 FillGradient 属性。此属性提供了以下选项:

Style (Enum)
渐变类型,例如,线性或放射状(与 com.sun.star.awt.GradientStyle 一致的默认值)
StartColor (Long)
颜色渐变的起始颜色
EndColor (Long)
颜色渐变的结束颜色
Angle (Short)
颜色渐变的角度,以十分之一度为单位
XOffset (Short)
颜色渐变的起始 X 坐标,以百分之一毫米为单位
YOffset (Short)
颜色渐变的起始 Y 坐标,以百分之一毫米为单位
StartIntensity (Short)
StartColor 的强度,用百分比表示(在 Apache OpenOffice Basic 中,还可以指定大于 100% 的值)
EndIntensity (Short)
EndColor 的强度,用百分比表示(在 Apache OpenOffice Basic 中,还可以指定大于 100% 的值)
StepCount (Short)
Apache OpenOffice 要为渐变计算的颜色等级数

以下示例说明了如何借助 com.sun.star.awt.Gradient 结来使用颜色渐变:

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 = StarDesktop.CurrentComponent
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)

本示例创建了一个线性颜色渐变 (Style = LINEAR)。该渐变在左上角以红色 (StartColor) 开始,以 45 度角 (Angle) 延伸到右下角并变为绿色 (EndColor)。起始和结束颜色的强度均为 150%(StartIntensityEndIntensity),所生成的颜色看起来似乎比 StartColorEndColor 属性中指定的值亮一些。该颜色渐变过程使用了一百种颜色 (StepCount)。

阴影线

要创建阴影线填充,必须将 FillStyle 属性设置为 HATCH。用于定义阴影线的程序代码与定义颜色渐变的代码非常相似。同样是辅助结构,此处使用 com.sun.star.drawing.Hatch 来定义阴影线的外观。阴影线结构具有以下属性:

Style (Enum)
阴影线类型:简单、方形或有对角线的方形(与 com.sun.star.awt.HatchStyle 一致的默认值)
Color (Long)
线条颜色
Distance (Long)
线条之间的距离,以百分之一毫米为单位
Angle (Short)
阴影线角度,以十分之一度为单位

以下示例说明了如何使用阴影线结构:

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 = StarDesktop.CurrentComponent
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)

该代码创建了一个简单阴影线结构 (HatchStyle = SINGLE),并将其线条旋转 45 度 (Angle)。线条为深灰色 (Color),间距为 0.2 毫米 (Distance)。

位图

要使用位图投影进行填充,必须将 FillStyle 属性设置为 BITMAP。如果 Apache OpenOffice 中已有所需的位图,只需在 FillBitMapName 属性中指定其名称并在 FillBitmapMode 属性中指定其显示样式(简单、平铺或拉伸)即可(与 com.sun.star.drawing.BitmapMode 一致的默认值)。

如果要使用外部位图文件,您可以在 FillBitmapURL 属性中指定其 URL。

以下示例将创建一个矩形,并使用 Apache OpenOffice 中的 Sky 位图以平铺方式填充矩形区域:

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 = StarDesktop.CurrentComponent
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)

透明度

您可以调整应用的任何填充的透明度。要更改绘图元素的透明度,最简单的方法是使用 FillTransparence 属性。

以下示例将创建一个透明度为 50% 的红色矩形。

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 = StarDesktop.CurrentComponent
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)

要使填充透明,请将 FillTransparence 属性设置为 100。

除了 FillTransparence 属性以外,com.sun.star.drawing.FillProperties 服务还提供了 FillTransparenceGradient 属性。该属性用来定义用于指定填充区域透明度的渐变。

线条属性

所有具有边框线的绘图对象均支持 com.sun.star.drawing.LineStyle 服务。下面是该服务支持的一些属性:

LineStyle (Enum)
线条类型(与 com.sun.star.drawing.LineStyle 一致的默认值)
LineColor (Long)
线条颜色
LineTransparence (Short)
线条透明度
LineWidth (Long)
线条宽度,以百分之一毫米为单位
LineJoint (Enum)
转换至连接点(与 com.sun.star.drawing.LineJoint 一致的默认值)

以下示例将创建一个矩形,该矩形具有宽度为 5 毫米 (LineWidth)、透明度为 50% 的实线边框 (LineStyle = SOLID)。线条的左右边延长并成直角相交 (LineJoint = MITER)。

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 = StarDesktop.CurrentComponent
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)

除了上面列出的属性以外,com.sun.star.drawing.LineStyle 服务还提供了绘制点划线和短划线的选项。有关详细信息,请参见 Apache OpenOffice API 参考。

文本属性(绘图对象)

com.sun.star.style.CharacterPropertiescom.sun.star.style.ParagraphProperties 服务可以为绘图对象中的文本设置格式。这些服务与单个字符和段落有关,文本文档中详细介绍了这些服务。

以下示例将在矩形中插入文本,并使用 com.sun.star.style.CharacterProperties 服务设置文本字体格式。

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 = StarDesktop.CurrentComponent
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"

该代码使用矩形的 String 属性插入文本,并使用 com.sun.star.style.CharacterProperties 服务的 CharWeightCharFontName 属性设置文本字体格式。

只有在将绘图对象添加到绘图页面后,才能插入文本。也可以使用 com.sun.star.drawing.Text 服务在绘图对象中放置文本并设置文本格式。下面是该服务的一些重要属性:

TextAutoGrowHeight (Boolean)
调整绘图元素的高度,使其与所包含的文本相符
TextAutoGrowWidth (Boolean)
调整绘图元素的宽度,使其与所包含的文本相符
TextHorizontalAdjust (Enum)
绘图元素中文本的水平位置(与 com.sun.star.drawing.TextHorizontalAdjust 一致的默认值)
TextVerticalAdjust (Enum)
绘图元素中文本的垂直位置(与 com.sun.star.drawing.TextVerticalAdjust 一致的默认值)
TextLeftDistance (Long)
绘图元素与文本左侧之间的距离,以百分之一毫米为单位
TextRightDistance (Long)
绘图元素与文本右侧之间的距离,以百分之一毫米为单位
TextUpperDistance (Long)
绘图元素与文本顶部之间的距离,以百分之一毫米为单位
TextLowerDistance (Long)
绘图元素与文本底部之间的距离,以百分之一毫米为单位

以下示例说明了如何使用指定的属性。

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 = StarDesktop.CurrentComponent
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

该代码在页面中插入了一个绘图元素,然后使用 TextVerticalAdjustTextHorizontalAdjust 属性将文本添加到绘图对象的左上角。文本与绘图对象边缘之间的最小距离被设置为 3 毫米。

阴影属性

可以使用 com.sun.star.drawing.ShadowProperties 服务为大多数绘图对象添加阴影。该服务具有以下属性:

Shadow (Boolean)
激活阴影
ShadowColor (Long)
阴影颜色
ShadowTransparence (Short)
阴影透明度
ShadowXDistance (Long)
阴影与绘图对象之间的垂直距离,以百分之一毫米为单位
ShadowYDistance (Long)
阴影与绘图对象之间的水平距离,以百分之一毫米为单位

以下示例将创建一个带有阴影的矩形,阴影在矩形的水平方向和垂直方向各偏移 2 毫米。阴影呈深灰色,透明度为 50%。

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 = StarDesktop.CurrentComponent
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)

各种绘图对象概述

矩形

矩形对象 (com.sun.star.drawing.RectangleShape) 支持以下用于设置对象格式的服务:

Fill properties
com.sun.star.drawing.FillProperties
Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text(包含 com.sun.star.style.CharacterPropertiescom.sun.star.style.ParagraphProperties
Shadow properties
com.sun.star.drawing.ShadowProperties
CornerRadius (Long)
圆角半径,以百分之一毫米为单位

圆和椭圆

com.sun.star.drawing.EllipseShape 服务负责处理圆和椭圆,并支持以下服务:

Fill properties
com.sun.star.drawing.FillProperties
Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text(包含 com.sun.star.style.CharacterPropertiescom.sun.star.style.ParagraphProperties
Shadow properties
com.sun.star.drawing.ShadowProperties

除了上述服务以外,圆和椭圆还提供了以下属性:

CircleKind (Enum)
圆或椭圆类型(与 com.sun.star.drawing.CircleKind 一致的默认值)
CircleStartAngle (Long)
起始角度,以十分之一度为单位(仅用于圆或椭圆段)
CircleEndAngle (Long)
结束角度,以十分之一度为单位(仅用于圆或椭圆段)

CircleKind 属性确定对象是整圆、圆弧还是圆段。可以使用以下值:

com.sun.star.drawing.CircleKind.FULL
完整的圆或椭圆
com.sun.star.drawing.CircleKind.CUT
圆段(其接合部位直接相互链接的部分圆)
com.sun.star.drawing.CircleKind.SECTION
圆弧
com.sun.star.drawing.CircleKind.ARC
角度(不包括圆线条)

以下示例将创建一个 70 度的圆缺(起始角度为 20 度,结束角度为 90 度)

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 = StarDesktop.CurrentComponent
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)

线条

Apache OpenOffice 为线条对象提供了 com.sun.star.drawing.LineShape 服务。线条对象支持除面积以外的所有常规格式设置服务。下面是与 LineShape 服务关联的所有属性:

Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text(包含 com.sun.star.style.CharacterPropertiescom.sun.star.style.ParagraphProperties
Shadow properties
com.sun.star.drawing.ShadowProperties

以下示例将借助指定的属性创建一个线条并设置其格式。Location 属性指定了线条的起点;而 Size 属性中列出的坐标指定了线条的终点。

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 = StarDesktop.CurrentComponent
Page = Doc.drawPages(0)
 
LineShape = Doc.createInstance("com.sun.star.drawing.LineShape")
LineShape.Size = Size
LineShape.Position = Point
 
Page.add(LineShape)

多重多边形

Apache OpenOffice 还通过 com.sun.star.drawing.PolyPolygonShape 服务支持复杂多边形。严格地讲,多重多边形不是简单的多边形,而是由多个多边形组成的多边形。因此,可以指定并合并包含角点的多个独立列表以构成一个完整的对象。

与矩形一样,绘图对象的所有格式设置属性也可以供多重多边形使用

Fill properties
com.sun.star.drawing.FillProperties
Line properties
com.sun.star.drawing.LineProperties
Text properties
com.sun.star.drawing.Text(包含 com.sun.star.style.CharacterPropertiescom.sun.star.style.ParagraphProperties
Shadow properties
com.sun.star.drawing.ShadowProperties

PolyPolygonShape 服务还具有一个定义多边形坐标的属性:

  • PolyPolygon (Array) – 包含多边形坐标的字段(具有 com.sun.star.awt.Point 类型的点的双精度型数组)

以下示例说明了如何使用 PolyPolygonShape 服务定义三角形。

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 = StarDesktop.CurrentComponent
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())

由于已将多边形的点定义为绝对的值,因此,不需要指定多边形的大小或起始位置。但是,您需要创建一个点数组,并将该数组包含到第二个数组中(使用 Array(Coordinates()) 调用),然后将该数组赋值给多边形。在执行相应调用之前,必须将多边形插入到文档中。

从定义上,双精度型数组允许通过合并几个多边形来创建复杂形状。例如,可以创建一个矩形,然后在其中插入另一个矩形,以便在第一个矩形中创建一个孔:

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 = StarDesktop.CurrentComponent
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())

要区分哪些区域是填充区域以及哪些区域是孔,Apache OpenOffice 采用了一条简单原则:外部形状的边始终为多重多边形的外边框。向内的下一条线是此形状的内边框,表示转换至第一个孔。如果内部还有其他线条,则表示转换至填充区域。

图形

此处介绍的最后一个绘图元素是基于 com.sun.star.drawing.GraphicObjectShape 服务的图形对象。这些对象可用于 Apache OpenOffice 中的任意图形,并且可使用各种属性来调整其外观。

图形对象支持两种常规格式设置属性:

Text properties
com.sun.star.drawing.Text(包含 com.sun.star.style.CharacterPropertiescom.sun.star.style.ParagraphProperties
Shadow properties
com.sun.star.drawing.ShadowProperties

图形对象还支持一些其他属性:

GraphicURL (String)
图形的 URL
AdjustLuminance (Short)
颜色亮度,用百分比表示(也允许使用负值)
AdjustContrast (Short)
对比度,用百分比表示(也允许使用负值)
AdjustRed (Short)
红色值,用百分比表示(也允许使用负值)
AdjustGreen (Short)
绿色值,用百分比表示(也允许使用负值)
AdjustBlue (Short)
蓝色值,用百分比表示(也允许使用负值)
Gamma (Short)
图形的灰度系数值
Transparency (Short)
图形透明度,用百分比表示
GraphicColorMode (enum)
颜色模式,例如,标准、灰度、黑白(与 com.sun.star.drawing.ColorMode 一致的默认值)

以下示例说明了如何将页面插入到图形对象中。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 = StarDesktop.CurrentComponent
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)

该代码插入了 test.jpg 图形,并使用 Adjust 属性调整其外观。在本示例中,图形透明度为 40%,并且未进行其他颜色转换 (GraphicColorMode = STANDARD)。

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