libcanvas/CanvasExportStore.py:exportTextBuffer(): correctly encode {bold,underline} cell state changes.

This commit is contained in:
Lucio Andrés Illanes Albornoz 2019-09-16 08:52:04 +02:00
parent 0c1b62a609
commit 1f7d63802c

View File

@ -166,10 +166,23 @@ class CanvasExportStore():
def exportTextBuffer(self, canvasMap, canvasSize): def exportTextBuffer(self, canvasMap, canvasSize):
outBuffer = "" outBuffer = ""
for canvasRow in range(canvasSize[1]): for canvasRow in range(canvasSize[1]):
canvasLastColours = [15, -1] canvasLastAttrs, canvasLastColours = self._CellState.CS_NONE, [15, -1]
for canvasCol in range(canvasSize[0]): for canvasCol in range(canvasSize[0]):
canvasColAttrs = canvasMap[canvasRow][canvasCol][2]
canvasColColours = canvasMap[canvasRow][canvasCol][0:2] canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
canvasColText = canvasMap[canvasRow][canvasCol][3] 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: if canvasColColours[0] == -1:
canvasColColours[0] = canvasColColours[1] canvasColColours[0] = canvasColColours[1]
if (canvasColColours[0] != canvasLastColours[0]) \ if (canvasColColours[0] != canvasLastColours[0]) \