Skip to content

Commit

Permalink
Fixed balanced line wrapping breaking early lines with big words
Browse files Browse the repository at this point in the history
  • Loading branch information
evandrocoan committed Jun 5, 2019
1 parent 01a350b commit 20dc023
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/test_wrap.py
Expand Up @@ -199,7 +199,8 @@ def load_tests(loader, standard_tests, pattern):
suite = unittest.TestSuite()
# See _NAME above to get the test class name pattern
# suite.addTest( integration_test_txt_15_tests( 'test_thing' ) )
suite.addTest( integration_semantic_test_tex_02_tests( 'test_thing' ) )
# suite.addTest( integration_semantic_test_tex_02_tests( 'test_thing' ) )
suite.addTest( integration_semantic_test_tex_03_tests( 'test_thing' ) )
return suite

# Comment this to run individual Unit Tests
Expand Down
11 changes: 9 additions & 2 deletions tests/wrap_tests/semantic_test.tex
Expand Up @@ -33,10 +33,17 @@
Já que para compartilhar código e trabalhar em times de forma eficiente, é essential
utilizar\hyp{}se um sistema de
versionamento\footnote{\url{http://www.codeservedcold.com/version-control-importance/}} que permita
o gerente de projetos e os próprios programadores
o gerente de projetos e os próprios
---
Já que para compartilhar código e
trabalhar em times de forma eficiente,
é essential utilizar\hyp{}se um sistema de
versionamento\footnote{\url{http://www.codeservedcold.com/version-control-importance/}} que
permita o gerente de projetos e os próprios programadores
permita o gerente de projetos e os próprios
===
A figura \ref{fig:pictures/LinguagensDeterministicas.png} não é
inteiramente um Diagrama de Venn \cite{generalizedVennDiagrams}, mas sim.
---
A figura \ref{fig:pictures/LinguagensDeterministicas.png} não é
inteiramente um Diagrama de Venn \cite{generalizedVennDiagrams},
mas sim.
26 changes: 25 additions & 1 deletion wrap_plus.py
Expand Up @@ -1086,6 +1086,30 @@ def is_there_lonely_word_line(self, new_lines, maximumwidth=None, limitpercent=N

return False

def is_there_big_word_on_line(self, line, new_width):
"""
Check whether there is some big word on the line.
If so, returns the `new_width` properly fixed for wrapping.fill()
"""
longest = -1
wordlimit = new_width * 0.5

for match in not_spaces_pattern.finditer( line ):
start, end = match.span()
length = end - start

if length > longest:
longest = length

log( 4, 'longest', longest, 'wordlimit', wordlimit, 'new_width', new_width )
if longest > wordlimit:
new_width = new_width + wordlimit * 0.1
log( 4, 'new_width', new_width )
return new_width

return new_width

def _split_lines(self, wrapper, text_lines, maximum_line_width, middle_of_the_line_increment_percent=1):
"""
(input) text_lines: [' This is my very long line which will wrap near its end,\n']
Expand Down Expand Up @@ -1113,7 +1137,7 @@ def _split_lines(self, wrapper, text_lines, maximum_line_width, middle_of_the_li
log( 4, "maximum_line_width %d new_width %d (%f)", maximum_line_width, new_width, middle_of_the_line_increment_percent )

log( 4, "line %r", line )
wrapper.width = new_width
wrapper.width = self.is_there_big_word_on_line( line, new_width )
wrapped_line = wrapper.fill( line )

log( 4, "wrapped_line %r", wrapped_line )
Expand Down

0 comments on commit 20dc023

Please sign in to comment.