From 0724c8086835e3379e55a0c77f23f3d5bf3e5e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Sat, 20 Jan 2018 09:17:52 +0100 Subject: [PATCH] MiRCARTCanvasImportStore.py: correctly process ^C, sequences. MiRCARTToPngFile.py: fix {bold,underline} processing. --- MiRCARTCanvasImportStore.py | 19 ++++++++++++++----- MiRCARTToPngFile.py | 28 +++++++++++++++------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/MiRCARTCanvasImportStore.py b/MiRCARTCanvasImportStore.py index 9150ea8..e35b4a9 100644 --- a/MiRCARTCanvasImportStore.py +++ b/MiRCARTCanvasImportStore.py @@ -53,10 +53,12 @@ class MiRCARTCanvasImportStore(): def _parseCharAsColourSpec(self, colourSpec, curColours): if len(colourSpec) > 0: colourSpec = colourSpec.split(",") - if len(colourSpec) == 2: + if len(colourSpec) == 2 \ + and len(colourSpec[1]) > 0: return (int(colourSpec[0] or curColours[0]), \ int(colourSpec[1])) - elif len(colourSpec) == 1: + elif len(colourSpec) == 1 \ + or len(colourSpec[1]) == 0: return (int(colourSpec[0]), curColours[1]) else: return (15, 1) @@ -108,9 +110,16 @@ class MiRCARTCanvasImportStore(): or inParseState == self._ParseState.PS_COLOUR_DIGIT1: if inChar == "," \ and inParseState == self._ParseState.PS_COLOUR_DIGIT0: - inCurCol += 1 - inCurColourDigits = 0; inCurColourSpec += inChar; - inParseState = self._ParseState.PS_COLOUR_DIGIT1 + if (inCurCol + 1) < inMaxCol \ + and not inLine[inCurCol + 1] in set("0123456789"): + inCurColours = self._parseCharAsColourSpec( \ + inCurColourSpec, inCurColours) + inCurColourDigits = 0; inCurColourSpec = ""; + inParseState = self._ParseState.PS_CHAR + else: + inCurCol += 1 + inCurColourDigits = 0; inCurColourSpec += inChar; + inParseState = self._ParseState.PS_COLOUR_DIGIT1 elif inChar in set("0123456789") \ and inCurColourDigits == 0: inCurCol += 1 diff --git a/MiRCARTToPngFile.py b/MiRCARTToPngFile.py index a5f6a12..16661b8 100755 --- a/MiRCARTToPngFile.py +++ b/MiRCARTToPngFile.py @@ -71,13 +71,12 @@ class MiRCARTToPngFile: [187, 187, 187], # Light Grey ] # }}} - # {{{ _drawUnderline(self, curPos, fontSize, imgDraw): XXX - def _drawUnderLine(self, curPos, fontSize, imgDraw): - imgDraw.line( \ - (curPos[0], \ - curPos[1] + (fontSize[1] - 2)), \ - (curPos[0] + fontSize[0], \ - curPos[1] + (fontSize[1] - 2)), fill=outColours[0]) + # {{{ _drawUnderline(self, curPos, fontSize, imgDraw, fillColour): XXX + def _drawUnderLine(self, curPos, fontSize, imgDraw, fillColour): + imgDraw.line( \ + xy=(curPos[0], curPos[1] + (fontSize[1] - 2), \ + curPos[0] + fontSize[0], curPos[1] + (fontSize[1] - 2)), \ + fill=fillColour) # }}} # {{{ export(self, outFilePath): XXX def export(self, outFilePath): @@ -90,15 +89,15 @@ class MiRCARTToPngFile: for inCurCol in range(len(self.inCanvasMap[inCurRow])): inCurCell = self.inCanvasMap[inCurRow][inCurCol] outColours = [0, 0] - if inCurCell[1] & 0x02: + if inCurCell[1] & MiRCARTCanvasImportStore.MiRCARTCanvasImportStore._CellState.CS_BOLD: if inCurCell[2] != " ": if inCurCell[2] == "█": - outColours[1] = self._ColourMapBold[inCurCell[0][0]] + outColours[1] = self._ColourMapNormal[inCurCell[0][0]] else: outColours[0] = self._ColourMapBold[inCurCell[0][0]] - outColours[1] = self._ColourMapBold[inCurCell[0][1]] + outColours[1] = self._ColourMapNormal[inCurCell[0][1]] else: - outColours[1] = self._ColourMapBold[inCurCell[0][1]] + outColours[1] = self._ColourMapNormal[inCurCell[0][1]] else: if inCurCell[2] != " ": if inCurCell[2] == "█": @@ -117,8 +116,11 @@ class MiRCARTToPngFile: # XXX implement italic outImgDraw.text(outCurPos, \ inCurCell[2], (*outColours[0], 255), self.outImgFont) - if inCurCell[1] & 0x1f: - self._drawUnderLine(curPos, self.outImgFontSize, outImgDraw) + if inCurCell[1] & MiRCARTCanvasImportStore.MiRCARTCanvasImportStore._CellState.CS_UNDERLINE: + outColours[0] = self._ColourMapNormal[inCurCell[0][0]] + self._drawUnderLine(outCurPos, \ + self.outImgFontSize, \ + outImgDraw, (*outColours[0], 255)) outCurPos[0] += self.outImgFontSize[0]; outCurPos[0] = 0 outCurPos[1] += self.outImgFontSize[1]