From 299a045aa943d42ba61c0bd2a9c1ec2db4313551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Mon, 16 Sep 2019 08:52:04 +0200 Subject: [PATCH] libcanvas/CanvasExportStore.py:exportTextBuffer(): correctly encode {bold,underline} cell state changes. --- libcanvas/CanvasExportStore.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/libcanvas/CanvasExportStore.py b/libcanvas/CanvasExportStore.py index fb2ab9a..546e9e7 100644 --- a/libcanvas/CanvasExportStore.py +++ b/libcanvas/CanvasExportStore.py @@ -166,15 +166,28 @@ class CanvasExportStore(): def exportTextBuffer(self, canvasMap, canvasSize): outBuffer = "" for canvasRow in range(canvasSize[1]): - canvasLastColours = [15, -1] + canvasLastAttrs, canvasLastColours = self._CellState.CS_NONE, [15, -1] for canvasCol in range(canvasSize[0]): + canvasColAttrs = canvasMap[canvasRow][canvasCol][2] canvasColColours = canvasMap[canvasRow][canvasCol][0:2] canvasColText = canvasMap[canvasRow][canvasCol][3] + if (canvasColAttrs & self._CellState.CS_BOLD) \ + and (not (canvasLastAttrs & self._CellState.CS_BOLD)): + outBuffer += "\u0002"; canvasLastAttrs = canvasLastAttrs | self._CellState.CS_BOLD; + if (not (canvasColAttrs & self._CellState.CS_BOLD)) \ + and (canvasLastAttrs & self._CellState.CS_BOLD): + outBuffer += "\u0002"; canvasLastAttrs = canvasLastAttrs & ~self._CellState.CS_BOLD; + if (canvasColAttrs & self._CellState.CS_UNDERLINE) \ + and (not (canvasLastAttrs & self._CellState.CS_UNDERLINE)): + outBuffer += "\u001f"; canvasLastAttrs = canvasLastAttrs | self._CellState.CS_UNDERLINE; + if (not (canvasColAttrs & self._CellState.CS_UNDERLINE)) \ + and (canvasLastAttrs & self._CellState.CS_UNDERLINE): + outBuffer += "\u001f"; canvasLastAttrs = canvasLastAttrs & ~self._CellState.CS_UNDERLINE; if canvasColColours[0] == -1: canvasColColours[0] = canvasColColours[1] - if (canvasColColours[0] != canvasLastColours[0]) \ + if (canvasColColours[0] != canvasLastColours[0]) \ and (canvasColColours[1] != canvasLastColours[1]): - if (canvasColColours[0] == -1) \ + if (canvasColColours[0] == -1) \ and (canvasColColours[1] == -1): outBuffer += "\u000f" elif canvasColColours[1] == -1: