MiRCARTCanvasImportStore.py: correctly process ^C<colour>, sequences.

MiRCARTToPngFile.py: fix {bold,underline} processing.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-20 09:17:52 +01:00
parent ea9f827099
commit 0724c80868
2 changed files with 29 additions and 18 deletions

View File

@ -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,6 +110,13 @@ class MiRCARTCanvasImportStore():
or inParseState == self._ParseState.PS_COLOUR_DIGIT1:
if inChar == "," \
and inParseState == self._ParseState.PS_COLOUR_DIGIT0:
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

View File

@ -71,13 +71,12 @@ class MiRCARTToPngFile:
[187, 187, 187], # Light Grey
]
# }}}
# {{{ _drawUnderline(self, curPos, fontSize, imgDraw): XXX
def _drawUnderLine(self, curPos, fontSize, imgDraw):
# {{{ _drawUnderline(self, curPos, fontSize, imgDraw, fillColour): XXX
def _drawUnderLine(self, curPos, fontSize, imgDraw, fillColour):
imgDraw.line( \
(curPos[0], \
curPos[1] + (fontSize[1] - 2)), \
(curPos[0] + fontSize[0], \
curPos[1] + (fontSize[1] - 2)), fill=outColours[0])
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]