mirror of
https://github.com/lalbornoz/roar.git
synced 2024-11-16 12:36:38 +00:00
libcanvas/CanvasExportStore.py:exportTextBuffer(): fix transparent colour processing.
libcanvas/CanvasImportStore.py:importTextBuffer(): fix transparent colour processing.
This commit is contained in:
parent
0f88a78639
commit
7a4e1b23e9
@ -166,7 +166,7 @@ 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]
|
canvasLastColours = [15, -1]
|
||||||
for canvasCol in range(canvasSize[0]):
|
for canvasCol in range(canvasSize[0]):
|
||||||
canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
|
canvasColColours = canvasMap[canvasRow][canvasCol][0:2]
|
||||||
canvasColText = canvasMap[canvasRow][canvasCol][3]
|
canvasColText = canvasMap[canvasRow][canvasCol][3]
|
||||||
@ -176,12 +176,9 @@ class CanvasExportStore():
|
|||||||
and (canvasColColours[1] != canvasLastColours[1]):
|
and (canvasColColours[1] != canvasLastColours[1]):
|
||||||
if (canvasColColours[0] == -1) \
|
if (canvasColColours[0] == -1) \
|
||||||
and (canvasColColours[1] == -1):
|
and (canvasColColours[1] == -1):
|
||||||
outBuffer += "\u0003 "
|
outBuffer += "\u000f"
|
||||||
elif canvasColColours[1] == -1:
|
elif canvasColColours[1] == -1:
|
||||||
outBuffer += "\u0003\u0003{}".format(canvasColColours[0])
|
outBuffer += "\u0003\u0003{}".format(canvasColColours[0])
|
||||||
elif (canvasColColours[0] == canvasLastColours[1]) \
|
|
||||||
and (canvasColColours[1] == canvasLastColours[0]):
|
|
||||||
outBuffer += "\u0016"
|
|
||||||
else:
|
else:
|
||||||
outBuffer += "\u0003{},{}".format(canvasColColours[0], canvasColColours[1])
|
outBuffer += "\u0003{},{}".format(canvasColColours[0], canvasColColours[1])
|
||||||
canvasLastColours = canvasColColours
|
canvasLastColours = canvasColColours
|
||||||
@ -192,6 +189,9 @@ class CanvasExportStore():
|
|||||||
outBuffer += "\u0003{},{}".format(canvasLastColours[0], canvasColColours[1])
|
outBuffer += "\u0003{},{}".format(canvasLastColours[0], canvasColColours[1])
|
||||||
canvasLastColours[1] = canvasColColours[1]
|
canvasLastColours[1] = canvasColColours[1]
|
||||||
elif canvasColColours[0] != canvasLastColours[0]:
|
elif canvasColColours[0] != canvasLastColours[0]:
|
||||||
|
if canvasColColours[0] == -1:
|
||||||
|
outBuffer += "\u000f"
|
||||||
|
else:
|
||||||
outBuffer += "\u0003{}".format(canvasColColours[0])
|
outBuffer += "\u0003{}".format(canvasColColours[0])
|
||||||
canvasLastColours[0] = canvasColColours[0]
|
canvasLastColours[0] = canvasColColours[0]
|
||||||
outBuffer += canvasColText
|
outBuffer += canvasColText
|
||||||
|
@ -24,7 +24,7 @@ class CanvasImportStore():
|
|||||||
|
|
||||||
# {{{ importAnsiBuffer(self, inBuffer, encoding="cp437", width=None)
|
# {{{ importAnsiBuffer(self, inBuffer, encoding="cp437", width=None)
|
||||||
def importAnsiBuffer(self, inBuffer, encoding="cp437", width=None):
|
def importAnsiBuffer(self, inBuffer, encoding="cp437", width=None):
|
||||||
curBg, curBgAnsi, curBoldAnsi, curFg, curFgAnsi = 1, 30, False, 15, 37
|
curBg, curBgAnsi, curBoldAnsi, curFg, curFgAnsi = -1, 30, False, 15, 37
|
||||||
done, outMap, outMaxCols = False, [[]], 0
|
done, outMap, outMaxCols = False, [[]], 0
|
||||||
inBufferData = inBuffer.decode(encoding)
|
inBufferData = inBuffer.decode(encoding)
|
||||||
inBufferChar, inBufferCharMax = 0, len(inBufferData)
|
inBufferChar, inBufferCharMax = 0, len(inBufferData)
|
||||||
@ -40,7 +40,7 @@ class CanvasImportStore():
|
|||||||
newBg, newFg = -1, -1
|
newBg, newFg = -1, -1
|
||||||
for ansiCode in [int(c) for c in m[1][:-1].split(";")]:
|
for ansiCode in [int(c) for c in m[1][:-1].split(";")]:
|
||||||
if ansiCode == 0:
|
if ansiCode == 0:
|
||||||
curBgAnsi, curBoldAnsi, curFgAnsi, newBg, newFg = 30, False, 37, 1, 15
|
curBgAnsi, curBoldAnsi, curFgAnsi, newBg, newFg = 30, False, 37, -1, 15
|
||||||
elif ansiCode == 1:
|
elif ansiCode == 1:
|
||||||
curBoldAnsi, newFg = True, AnsiFgBoldToMiRCARTColours[curFgAnsi]
|
curBoldAnsi, newFg = True, AnsiFgBoldToMiRCARTColours[curFgAnsi]
|
||||||
elif ansiCode == 2:
|
elif ansiCode == 2:
|
||||||
@ -69,7 +69,7 @@ class CanvasImportStore():
|
|||||||
or ((len(outMap) == 1) and len(outMap[0])):
|
or ((len(outMap) == 1) and len(outMap[0])):
|
||||||
for numRow in range(len(outMap)):
|
for numRow in range(len(outMap)):
|
||||||
for numCol in range(len(outMap[numRow]), outMaxCols):
|
for numCol in range(len(outMap[numRow]), outMaxCols):
|
||||||
outMap[numRow].append([curFg, curBg, self._CellState.CS_NONE, " "])
|
outMap[numRow].append([15, -1, self._CellState.CS_NONE, " "])
|
||||||
self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap
|
self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap
|
||||||
return (True, None)
|
return (True, None)
|
||||||
else:
|
else:
|
||||||
@ -95,7 +95,7 @@ class CanvasImportStore():
|
|||||||
def importTextBuffer(self, inFile):
|
def importTextBuffer(self, inFile):
|
||||||
inLine, outMap, outMaxCols = inFile.readline(), [], 0
|
inLine, outMap, outMaxCols = inFile.readline(), [], 0
|
||||||
while inLine:
|
while inLine:
|
||||||
inCellState, inCurCol, inCurColours, inMaxCol = self._CellState.CS_NONE, 0, (15, 1), len(inLine); outMap.append([]);
|
inCellState, inCurCol, inCurColours, inMaxCol = self._CellState.CS_NONE, 0, (15, -1), len(inLine); outMap.append([]);
|
||||||
while inCurCol < inMaxCol:
|
while inCurCol < inMaxCol:
|
||||||
inChar = inLine[inCurCol]
|
inChar = inLine[inCurCol]
|
||||||
if inChar in set("\r\n"):
|
if inChar in set("\r\n"):
|
||||||
@ -110,14 +110,14 @@ class CanvasImportStore():
|
|||||||
elif (m[2] != None) and (m[3] == None):
|
elif (m[2] != None) and (m[3] == None):
|
||||||
inCurColours = (int(m[2]), int(inCurColours[1]))
|
inCurColours = (int(m[2]), int(inCurColours[1]))
|
||||||
else:
|
else:
|
||||||
inCurColours = (15, 1)
|
inCurColours = (15, -1)
|
||||||
inCurCol += len(m[0])
|
inCurCol += len(m[0])
|
||||||
else:
|
else:
|
||||||
inCurColours = (15, 1); inCurCol += 1;
|
inCurColours = (15, -1); inCurCol += 1;
|
||||||
elif inChar == "\u0006":
|
elif inChar == "\u0006":
|
||||||
inCellState = self._flipCellStateBit(self._CellState.CS_ITALIC, inCellState); inCurCol += 1;
|
inCellState = self._flipCellStateBit(self._CellState.CS_ITALIC, inCellState); inCurCol += 1;
|
||||||
elif inChar == "\u000f":
|
elif inChar == "\u000f":
|
||||||
inCellState |= self._CellState.CS_NONE; inCurColours = (15, 1); inCurCol += 1;
|
inCellState |= self._CellState.CS_NONE; inCurColours = (15, -1); inCurCol += 1;
|
||||||
elif inChar == "\u0016":
|
elif inChar == "\u0016":
|
||||||
inCurColours = (inCurColours[1], inCurColours[0]); inCurCol += 1;
|
inCurColours = (inCurColours[1], inCurColours[0]); inCurCol += 1;
|
||||||
elif inChar == "\u001f":
|
elif inChar == "\u001f":
|
||||||
@ -127,6 +127,9 @@ class CanvasImportStore():
|
|||||||
inLine, outMaxCols = inFile.readline(), max(outMaxCols, len(outMap[-1]))
|
inLine, outMaxCols = inFile.readline(), max(outMaxCols, len(outMap[-1]))
|
||||||
if (len(outMap) > 1) \
|
if (len(outMap) > 1) \
|
||||||
or ((len(outMap) == 1) and len(outMap[0])):
|
or ((len(outMap) == 1) and len(outMap[0])):
|
||||||
|
for numRow in range(len(outMap)):
|
||||||
|
for numCol in range(len(outMap[numRow]), outMaxCols):
|
||||||
|
outMap[numRow].append([15, -1, self._CellState.CS_NONE, " "])
|
||||||
self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap
|
self.inSize, self.outMap = [outMaxCols, len(outMap)], outMap
|
||||||
return (True, None)
|
return (True, None)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user