Initial working word wrapping
This commit is contained in:
parent
7a2ccc9e8a
commit
bd930a9692
@ -60,9 +60,47 @@ def getCurrentWord(currX,currY, currText):
|
|||||||
x -= 1
|
x -= 1
|
||||||
return x, y, currWord
|
return x, y, currWord
|
||||||
|
|
||||||
currText = " das ist ein test\ntest das\ntesttest\n\ntest"
|
def getNextWord(currX,currY, currText):
|
||||||
currY = 4
|
if currText == '':
|
||||||
currX = 3
|
return -1, -1, ''
|
||||||
currX, currY, word = getCurrentWord(currX,currY,currText)
|
x = currX
|
||||||
#currX, currY, word = getPrevWord(currX,currY,currText)
|
y = currY
|
||||||
print(currX, currY, word)
|
wrappedLines = currText.split('\n')
|
||||||
|
wordFound = False
|
||||||
|
currWord = ''
|
||||||
|
currLine = wrappedLines[y].replace("\t"," ")
|
||||||
|
while not wordFound:
|
||||||
|
xtmp = 0
|
||||||
|
if x + 1 >= len(currLine):
|
||||||
|
if y < len(wrappedLines):
|
||||||
|
y += 1
|
||||||
|
currLine = wrappedLines[y].replace("\t"," ")
|
||||||
|
else:
|
||||||
|
return currX, currY, ''
|
||||||
|
x = 0
|
||||||
|
else:
|
||||||
|
x += 1
|
||||||
|
xtmp = x
|
||||||
|
x = currLine[x:].find(" ")
|
||||||
|
if x == -1:
|
||||||
|
x = len(currLine)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if xtmp <> 0:
|
||||||
|
xtmp += 1
|
||||||
|
x += xtmp
|
||||||
|
if x + 1 < len(currLine):
|
||||||
|
wordEnd = currLine[x + 1:].find(" ")
|
||||||
|
else:
|
||||||
|
wordEnd = -1
|
||||||
|
if wordEnd == -1:
|
||||||
|
wordEnd = len(currLine)
|
||||||
|
else:
|
||||||
|
wordEnd += x + 1
|
||||||
|
if wordEnd >= len(currLine) and y + 1 >= len(wrappedLines):
|
||||||
|
return currX, currY, ''
|
||||||
|
currWord = currLine[x:wordEnd]
|
||||||
|
wordFound = currWord.strip(" \t\n") != ''
|
||||||
|
if not wordFound:
|
||||||
|
x = wordEnd
|
||||||
|
return x, y, currWord
|
||||||
|
Loading…
x
Reference in New Issue
Block a user