Skip to content

Commit

Permalink
Fix error on displaying search results with Unicode emoticons (issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
suurjaak committed Jun 17, 2022
1 parent d0111bc commit cb1a591
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ CHANGELOG
=========


5.2, 2022-06-08
5.2, 2022-06-17
---------------
- fix error on displaying search results with Unicode emoticons (issue #108).
- fix error on importing from JSON (issue #110).


Expand Down
6 changes: 3 additions & 3 deletions src/skyperious/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@author Erki Suurjaak
@created 26.11.2011
@modified 08.06.2022
@modified 17.06.2022
------------------------------------------------------------------------------
"""
try: from ConfigParser import RawConfigParser # Py2
Expand All @@ -24,8 +24,8 @@

"""Program title, version number and version date."""
Title = "Skyperious"
Version = "5.2.dev0"
VersionDate = "08.06.2022"
Version = "5.2.dev1"
VersionDate = "17.06.2022"

if getattr(sys, "frozen", False):
# Running as a pyinstaller executable
Expand Down
48 changes: 43 additions & 5 deletions src/skyperious/lib/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
@author Erki Suurjaak
@created 13.01.2012
@modified 02.04.2022
@modified 17.06.2022
------------------------------------------------------------------------------
"""
import collections
Expand All @@ -108,7 +108,6 @@
import wx.lib.gizmos
import wx.lib.mixins.listctrl
import wx.lib.newevent
import wx.lib.wordwrap
import wx.stc


Expand Down Expand Up @@ -1045,7 +1044,6 @@ def WrapTexts(self):
self._extent_label = self._extent_note = (0, 0)
return

WORDWRAP = wx.lib.wordwrap.wordwrap
width, height = self.Size
if width > 20 and height > 20:
dc = wx.ClientDC(self)
Expand All @@ -1054,10 +1052,10 @@ def WrapTexts(self):
dc.SelectObject(wx.Bitmap(500, 100))
dc.Font = self.Font
x = 10 + self._bmp.Size.width + 10
self._text_note = WORDWRAP(self._text_note, width - 10 - x, dc)
self._text_note = wordwrap(self._text_note, width - 10 - x, dc)
dc.Font = wx.Font(dc.Font.PointSize, dc.Font.Family, dc.Font.Style,
wx.FONTWEIGHT_BOLD, faceName=dc.Font.FaceName)
self._text_label = WORDWRAP(self._text_label, width - 10 - x, dc)
self._text_label = wordwrap(self._text_label, width - 10 - x, dc)
self._extent_label = dc.GetMultiLineTextExtent(self._text_label)
self._extent_note = dc.GetMultiLineTextExtent(self._text_note)

Expand Down Expand Up @@ -4786,3 +4784,43 @@ def get_dialog_path(dialog):
if ext: result += ext

return result


def wordwrap(text, width, dc, breakLongWords=True, margin=0):
"""
Returns text wrapped to pixel width according to given DC.
A patched copy of `wx.lib.wordwrap.wordwrap()`
able to handle multi-byte Unicode characters in Python3.
@param text string to wrap
@param width width to wrap into, in pixels
@param dc wx.DC instance
@param breakLongWords whether to break words wider than available width
@param margin additional left and right margin, in pixels
"""
wrapped_lines = []
text = text.splitlines()
for line in text:
pte = []
for c in line:
pte.append(dc.GetTextExtent(c).width + (pte[-1] if pte else 0))
wid = width - (2 * margin + 1) * dc.GetTextExtent(" ")[0] - \
max([0] + [pte[i] - pte[i - 1] for i in range(1, len(pte))])

idx, start, startIdx, spcIdx = 0, 0, 0, -1
while idx < len(pte):
# remember the last seen space
if line[idx] == " ":
spcIdx = idx
# have we reached the max width?
if pte[idx] - start > wid and (spcIdx != -1 or breakLongWords):
if spcIdx != -1:
idx = min(spcIdx + 1, len(pte) - 1)
wrapped_lines.append(" "*margin + line[startIdx : idx] + " "*margin)
start, startIdx, spcIdx = pte[idx], idx, -1
idx += 1

wrapped_lines.append(" " * margin + line[startIdx:idx] + " " * margin)

return "\n".join(wrapped_lines)
5 changes: 3 additions & 2 deletions src/skyperious/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@author Erki Suurjaak
@created 10.01.2012
@modified 02.04.2022
@modified 17.06.2022
------------------------------------------------------------------------------
"""
import datetime
Expand All @@ -25,6 +25,7 @@
except ImportError:
pass # Most functionality works without wx

from . lib import controls
from . lib import util
from . lib.vendor import step

Expand Down Expand Up @@ -140,7 +141,7 @@ def run(self):
dc = wx.MemoryDC()
dc.SetFont(wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, faceName=conf.HistoryFontName))
wrap_html = lambda x: wx.lib.wordwrap.wordwrap(x, width, dc)
wrap_html = lambda x: controls.wordwrap(x, width, dc)
output["wrap"] = True
else:
TEMPLATES = {
Expand Down

0 comments on commit cb1a591

Please sign in to comment.