Macros/Impress/001/FR
TDF LibreOffice Document Liberation Project Blogs communautaires Weblate Nextcloud Redmine Ask LibreOffice Donner
Description
Cette macro insère un object com.sun.star.drawing.RectangleShape[1] dans la diapo courante d'une présentation Impress. Quelques propriétés du rectangle sont illustrées dans le code source.
Code
LibreOffice Basic
Option Explicit
Sub InsertRectangleShape()
'''Insère un rectangle dans la diapo courante'''
Dim oDoc As Object ' com.sun.star.lang.XComponent
Dim oSlide As Object ' com.sun.star.drawing.XDrawPage
Dim oRectangle As Object ' com.sun.star.drawing.RectangleShape
Dim oSize As New com.sun.star.awt.Size
Dim oPosition As New com.sun.star.awt.Point
oDoc = ThisComponent
oSlide = oDoc.CurrentController.CurrentPage
oRectangle = oDoc.createInstance("com.sun.star.drawing.RectangleShape")
With oSlide
.add(oRectangle)
oPosition.X = .7*(.Width - oSize.Width)
oPosition.Y = .7*(.Height - oSize.Height)
End With ' oSlide
oSize.Width = 5000 ' 50 mm
oSize.Height = 3000 ' 30 mm
With oRectangle
.setSize(oSize)
.setPosition(oPosition)
.FillColor = RGB(0, 0, 255) ' BLEU
.FillStyle = com.sun.star.drawing.FillStyle.SOLID ' ou bien NONE
.FillTransparence = 30 ' 0-100 d'opaque à transparent
.LineStyle = com.sun.star.drawing.LineStyle.SOLID ' ou bien NONE
.LineWidth = 100 ' 1 mm
.LineColor = RGB(0, 0, 0) ' NOIR
.setName("MyBasicRectangle")
.setString("Hello from Basic!")
.CharFontName = "Liberation Sans"
.CharColor = RGB(255, 255, 255) ' BLANC
.ZOrder = 1
End With ' oRectangle
End Sub ' InsertRectangleShape
Python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from com.sun.star.awt import Size
from com.sun.star.awt import Point
from com.sun.star.drawing.FillStyle import SOLID as SOLID_FILLSTYLE
from com.sun.star.drawing.LineStyle import SOLID as SOLID_LINESTYLE
_GREEN, _BLACK, _RED = 0x00ff00, 0x000000, 0xff0000
_VALUES = range(0,256,1) # entiers 0-255
def _RGB(red: entiers 0-255, green: int, blue: octet-nombre) -> int:
"""Retourne un code couleur composé de rouge, vert et bleu"""
if not (red in _VALUES and green in _VALUES and blue in _VALUES):
raise ValueError
return (red * 2**16) + (green * 2**8) + (blue * 2**0)
# <br>Les arguments "red", "green" et "blue" sont des entiers non signés sur un octet.
def InsertRectangleShape():
"""Insère un rectangle dans la diapo courante"""
desktop = XSCRIPTCONTEXT.getDesktop()
model = desktop.getCurrentComponent()
slide = model.CurrentController.CurrentPage
rect = model.createInstance("com.sun.star.drawing.RectangleShape")
slide.add(rect) # Création du rectangle
size = Size()
size.Width = 5000 # 50 mm
size.Height = 3000 # 50 mm
position = Point()
position.X = 0.9*(slide.Width - size.Width)
position.Y = 0.5*(slide.Width - size.Width)
rect.setSize(size)
rect.setPosition(position)
rect.FillStyle = SOLID_FILLSTYLE # ou bien NONE
rect.FillColor = _RGB(255, 0, 0) # _RED
rect.FillTransparence = 30 # 0-100 d'opaque à transparent
rect.LineStyle = SOLID_LINESTYLE # ou bien NONE
rect.LineWidth = 100 # 1 mm
rect.LineColor = _RGB(0, 0, 0) # _BLACK
rect.setName("MyPythonRectangle")
rect.setString("Hello from Python!")
rect.CharFontName ='Lucida Calligraphy'
rect.CharColor = _RGB(0, 255, 0) # _GREEN
rect.ZOrder = 1
g_exportedScripts = (InsertRectangleShape,)
Fichier ODP avec macros
Notes
- ↑ Consulter la page com.sun.star.drawing.RectangleShape dans la documentation de l'API LibreOffice