From fd5790fa79b7b1fb51c848bf88cd2a7114aea472 Mon Sep 17 00:00:00 2001 From: Progfou Date: Fri, 31 Oct 2014 14:59:11 -0400 Subject: [PATCH] auf-libreoffice-extension 1204.4 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * calc2moin : gestion, au niveau d'une cellule, de la couleur du texte, du gras et début de gestion des cellules fusionnées --- auf-libreoffice-extension/debian/changelog | 7 ++ .../extension/OptionsDialog.xcu | 2 +- auf-libreoffice-extension/extension/calc2moin.py | 133 +++++++++++++++----- .../extension/description.xml | 2 +- .../Extensions/ExtensionsDialog_fr_FR.properties | 2 +- auf-libreoffice-extension/extension/printing.xcu | 17 +++ 6 files changed, 132 insertions(+), 31 deletions(-) diff --git a/auf-libreoffice-extension/debian/changelog b/auf-libreoffice-extension/debian/changelog index 42c68e6..40a6eeb 100644 --- a/auf-libreoffice-extension/debian/changelog +++ b/auf-libreoffice-extension/debian/changelog @@ -1,3 +1,10 @@ +auf-libreoffice-extension (1204.4) precise; urgency=low + + * calc2moin : gestion, au niveau d'une cellule, de la couleur du texte, + du gras et début de gestion des cellules fusionnées + + -- Progfou Fri, 31 Oct 2014 12:36:25 -0400 + auf-libreoffice-extension (1204.3) precise; urgency=low * configuration par défaut du « Client de messagerie » à "thunderbird" diff --git a/auf-libreoffice-extension/extension/OptionsDialog.xcu b/auf-libreoffice-extension/extension/OptionsDialog.xcu index ff5e4eb..1c777c2 100644 --- a/auf-libreoffice-extension/extension/OptionsDialog.xcu +++ b/auf-libreoffice-extension/extension/OptionsDialog.xcu @@ -17,7 +17,7 @@ org.auf.openoffice.macros.General - Macros AUF pour OpenOffice.org + Général %origin%/dialogs/Macros/MacrosDialog.xdl diff --git a/auf-libreoffice-extension/extension/calc2moin.py b/auf-libreoffice-extension/extension/calc2moin.py index cd58440..d86ed20 100644 --- a/auf-libreoffice-extension/extension/calc2moin.py +++ b/auf-libreoffice-extension/extension/calc2moin.py @@ -15,14 +15,26 @@ from com.sun.star.task import XJobExecutor from com.sun.star.beans import PropertyValue from com.sun.star.table.CellContentType import EMPTY, VALUE, TEXT, FORMULA from com.sun.star.table.CellHoriJustify import STANDARD, LEFT, CENTER, RIGHT +from com.sun.star.table.CellVertJustify import STANDARD, TOP, CENTER as MIDDLE, BOTTOM +from com.sun.star.awt.FontWeight import DONTKNOW, NORMAL, BOLD -def calc2moin(ctx): - data = [] +moinmoin_old_style = True + +def getRangeSize(sheet, cursor): + r = cursor.getRangeAddress() + realRange = sheet.getCellRangeByPosition(r.StartColumn, r.StartRow, + r.EndColumn, r.EndRow) + return (realRange.Columns.Count, realRange.Rows.Count) - ## The context variable is of type XScriptContext and is available to - ## all BeanShell scripts executed by the Script Framework - #curdoc = XSCRIPTCONTEXT.getDocument() - #ctx = uno.getComponentContext() +def getCellRealPosition(cursor, column, row): + r = cursor.getRangeAddress() + return (r.StartColumn + column, r.StartRow + row) + +def cell2moin(cell): + return cell.getString().replace('\n','<
>') + +def calc2moin(ctx): + data = list() # récupération du document en cours, vérification du type Spreadsheet smgr = ctx.ServiceManager @@ -31,7 +43,6 @@ def calc2moin(ctx): curdoc = desktop.getCurrentComponent() if not curdoc.supportsService("com.sun.star.sheet.SpreadsheetDocument"): raise RuntimeError, u"Ce n'est pas un document de type Spreadsheet (Calc)." - controller = curdoc.getCurrentController() sheet = controller.getActiveSheet() @@ -39,45 +50,109 @@ def calc2moin(ctx): cursor = sheet.createCursor() cursor.gotoEndOfUsedArea(False) cursor.gotoStartOfUsedArea(True) - rangeAddress = cursor.getRangeAddress() - rows = rangeAddress.EndRow - rangeAddress.StartRow + 1 - columns = rangeAddress.EndColumn - rangeAddress.StartColumn + 1 + columns, rows = getRangeSize(sheet, cursor) for row in range(rows): - row_data = [] - for column in range(columns): - cell_data = [] + row_data = list() + column = 0 + while column < columns: cell = cursor.getCellByPosition(column, row) cell_type = cell.getType() cell_string = cell.getString() - # process cell' styles - cell_styles = [] - if hasattr(cell, 'CellBackColor'): - color = cell.getPropertyValue('CellBackColor') - if color >= 0: - cell_styles.append('background: #%06x' % color) - if hasattr(cell, 'HoriJustify'): + # calcul de l'étendue de la cellule courante + if cell.getIsMerged(): + c, r = getCellRealPosition(cursor, column, row) + cellRange = sheet.getCellRangeByPosition(c, r, c, r) + cursor2 = sheet.createCursorByRange(cellRange) + cursor2.collapseToMergedArea() + cell_colspan, cell_rowspan = getRangeSize(sheet, cursor2) + else: + cell_colspan, cell_rowspan = 1, 1 + # traitement des attributs et styles de la cellule + cell_attributes = list() + cell_styles = list() + if cell_string and hasattr(cell, 'HoriJustify'): horiJustify = cell.getPropertyValue('HoriJustify') if horiJustify == LEFT: - text_align = '' #text_align = 'left' + if cell_colspan > 1 or cell_rowspan > 1: + text_align = 'left' + text_align_old = '(' + else: + text_align = '' # left par défaut si span == 1 + text_align_old = '' elif horiJustify == CENTER: - text_align = 'center' + if cell_colspan == 1 and cell_rowspan == 1: + text_align = 'center' + text_align_old = ':' + else: + text_align = '' # center par défaut si span > 1 + text_align_old = '' elif horiJustify == RIGHT: text_align = 'right' + text_align_old = ')' else: if cell_type == TEXT: - text_align = '' #text_align = 'left' + text_align = 'left' + text_align_old = '(' elif cell_type != EMPTY: text_align = 'right' - if text_align and cell_string: - cell_styles.append('text-align: ' + text_align) - # add cell to row + text_align_old = ')' + if text_align: + if moinmoin_old_style: + cell_attributes.append(text_align_old) + else: + cell_styles.append('text-align: ' + text_align) + if cell_string and hasattr(cell, 'VertJustify'): + vertJustify = cell.getPropertyValue('VertJustify') + if vertJustify == 1: #TOP(1) + vertical_align = 'top' + vertical_align_old = '^' + elif vertJustify == 2: #MIDDLE(2) + vertical_align = '' # middle par défaut + vertical_align_old = '' + else: #STANDARD(0), BOTTOM(3) + vertical_align = 'bottom' + vertical_align_old = 'v' + if vertical_align: + if moinmoin_old_style: + cell_attributes.append(vertical_align_old) + else: + cell_styles.append('vertical-align: ' + vertical_align) + if cell_string and hasattr(cell, 'CharWeight'): + charWeight = cell.getPropertyValue('CharWeight') + if charWeight == BOLD: + if moinmoin_old_style: + # FIXME: pas utilisé ensuite !! + cell_string = "'''%s'''" % cell_string + else: + cell_styles.append('font-weight: bold') + if cell_rowspan > 1: + cell_attributes.append('|%d' % cell_rowspan) + if cell_colspan > 1: + cell_attributes.append('-%d' % cell_colspan) + if hasattr(cell, 'CellBackColor'): + color = cell.getPropertyValue('CellBackColor') + if color >= 0: + if moinmoin_old_style: + cell_attributes.append('#%06x' % color) + else: + cell_styles.append('background: #%06x' % color) + if hasattr(cell, 'CharColor'): + color = cell.getPropertyValue('CharColor') + if color >= 0: + cell_styles.append('color: #%06x' % color) + # compilation des styles de la cellule if cell_styles: - cell_data.append('' % '; '.join(cell_styles)) + cell_attributes.insert(0, 'style="%s;"' % '; '.join(cell_styles)) + # ajout de la définition de la cellule à la ligne courante + cell_data = list() + if cell_attributes: + cell_data.append('<' + ''.join(cell_attributes) + '>') if cell_string: - cell_data.append(cell_string) + cell_data.append(cell2moin(cell)) else: cell_data.append(' ') row_data.append(''.join(cell_data)) + column += cell_colspan # display row's code data.append('||' + '||'.join(row_data) + '||') @@ -109,6 +184,8 @@ def copier(event=False): calc2moin(ctx) return None +# lists the scripts, that shall be visible inside OOo. Can be omited, if +# all functions shall be visible, however here getNewString shall be surpressed g_exportedScripts = (copier, ) ############################################################################## diff --git a/auf-libreoffice-extension/extension/description.xml b/auf-libreoffice-extension/extension/description.xml index 97939c8..599afaf 100644 --- a/auf-libreoffice-extension/extension/description.xml +++ b/auf-libreoffice-extension/extension/description.xml @@ -2,7 +2,7 @@ - + diff --git a/auf-libreoffice-extension/extension/dialogs/Extensions/ExtensionsDialog_fr_FR.properties b/auf-libreoffice-extension/extension/dialogs/Extensions/ExtensionsDialog_fr_FR.properties index 96cc5e2..1557ac1 100644 --- a/auf-libreoffice-extension/extension/dialogs/Extensions/ExtensionsDialog_fr_FR.properties +++ b/auf-libreoffice-extension/extension/dialogs/Extensions/ExtensionsDialog_fr_FR.properties @@ -5,6 +5,6 @@ 41.ExtensionsDialog.label_title.Label=Extensions AUF 42.ExtensionsDialog.image_icon.HelpText= 43.ExtensionsDialog.label_description.HelpText= -44.ExtensionsDialog.label_description.Label=Extensions AUF pour OpenOffice.org. +44.ExtensionsDialog.label_description.Label=Extensions AUF 45.ExtensionsDialog.line_separator.HelpText= 46.ExtensionsDialog.line_separator.Label= diff --git a/auf-libreoffice-extension/extension/printing.xcu b/auf-libreoffice-extension/extension/printing.xcu index 726c17b..2ab856e 100644 --- a/auf-libreoffice-extension/extension/printing.xcu +++ b/auf-libreoffice-extension/extension/printing.xcu @@ -1,10 +1,27 @@ + + + false + + false + + + false + + + + + + false + + + -- 1.7.10.4