Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some FontAwesome icons do not match #107

Closed
jnsebgosselin opened this issue Jan 18, 2019 · 44 comments · Fixed by #109
Closed

Some FontAwesome icons do not match #107

jnsebgosselin opened this issue Jan 18, 2019 · 44 comments · Fixed by #109
Milestone

Comments

@jnsebgosselin
Copy link
Member

Here is an minimal working example showing three problematic icons:

import sys
import qtawesome as qta
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout,
                             QToolButton, QLabel)

app = QApplication(sys.argv)

window = QWidget()
layout = QGridLayout(window)
names = ['fa5s.grip-horizontal', 'fa5s.file-export', 'fa5s.file-import']
for i, name in enumerate(names):
    qicon = qta.icon(name, scale_factor=1.3)
    btn = QToolButton()
    btn.setIcon(qicon)
    btn.setIconSize(QSize(32, 32))
    layout.addWidget(btn, i, 0)
    layout.addWidget(QLabel(name), i, 1)
window.show()

sys.exit(app.exec_())

image

https://fontawesome.com/icons/grip-horizontal?style=solid
https://fontawesome.com/icons/file-export?style=solid
https://fontawesome.com/icons/file-import?style=solid

@ccordoba12
Copy link
Member

Thanks for reporting @jnsebgosselin. Quick question: does this happen if you downgrade to 0.5.3?

@jnsebgosselin
Copy link
Member Author

This happens with version 0.5.3 and 0.5.5.

@darkvertex
Copy link
Contributor

darkvertex commented Jan 21, 2019

Hello there! 👋

Upon closer inspection, it would appear it might be an issue specific to Windows. I checked your icon names that appeared wrongly for you:

...so at the very least I can confirm it is not a bad character mapping.

Just checked on my side with this code: (Almost same as @jnsebgosselin 's just with red icons due to my dark OS theme and the missing "QSize" imported.)

import sys
import qtawesome as qta
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout,
                             QToolButton, QLabel)

app = QApplication(sys.argv)

window = QWidget()
layout = QGridLayout(window)
names = ['fa5s.grip-horizontal', 'fa5s.file-export', 'fa5s.file-import']
for i, name in enumerate(names):
    qicon = qta.icon(name, scale_factor=1.3, color='red')
    btn = QToolButton()
    btn.setIcon(qicon)
    btn.setIconSize(QSize(32, 32))
    layout.addWidget(btn, i, 0)
    layout.addWidget(QLabel(name), i, 1)
window.show()

sys.exit(app.exec_())

with PyQt 5.6 on Python 2.7 running Linux CentOS 7.4, and I got this window:
image
...which appear to be the good icons.

If anyone else is reading this, care to confirm if any Windows system is affected or if it's an isolated issue to the issue creator?

@jnsebgosselin can you tell us more about your environment? What Python version? And what PyQt or PySide/PySide2 version are you using? (Also, did you use an online installer or compiled it yourself?) Also, is your system locale in normal US English or something more uncommon? (Sometimes certain locales can make code behave funny.)

@jnsebgosselin
Copy link
Member Author

jnsebgosselin commented Jan 21, 2019

I'm in Windows 10. Executing locale.getdefaultlocale() returns ('en_CA', 'cp1252').

Below are the details of a conda environment with which I can reproduce the issue:

(spyder-dev) C:\Users\User>conda list
# packages in environment at C:\Anaconda3\envs\spyder-dev:
#
# Name                    Version                   Build  Channel
alabaster                 0.7.12                   py37_0
asn1crypto                0.24.0                   py37_0
astroid                   2.1.0                    py37_0
atomicwrites              1.2.1                    py37_0
attrs                     18.2.0           py37h28b3542_0
autopep8                  1.4.3                    py37_0
babel                     2.6.0                    py37_0
backcall                  0.1.0                    py37_0
blas                      1.0                         mkl
bleach                    3.1.0                    py37_0
ca-certificates           2018.12.5                     0
certifi                   2018.11.29               py37_0
cffi                      1.11.5           py37h74b6da3_1
chardet                   3.0.4                    py37_1
cloudpickle               0.6.1                    py37_0
colorama                  0.4.1                    py37_0
coverage                  4.5.2            py37he774522_0
cryptography              2.4.2            py37h7a1dbc1_0
cycler                    0.10.0                   py37_0
decorator                 4.3.0                    py37_0
docutils                  0.14                     py37_0
entrypoints               0.3                      py37_0
freetype                  2.9.1                ha9979f8_1
future                    0.17.1                   py37_0
icc_rt                    2019.0.0             h0cc432a_1
icu                       58.2                 ha66f8fd_1
idna                      2.8                      py37_0
imagesize                 1.1.0                    py37_0
intel-openmp              2019.1                      144
ipykernel                 5.1.0            py37h39e3cac_0
ipython                   7.2.0            py37h39e3cac_0
ipython_genutils          0.2.0                    py37_0
isort                     4.3.4                    py37_0
jedi                      0.13.2                   py37_0
jinja2                    2.10                     py37_0
jpeg                      9b                   hb83a4c4_2
jsonschema                2.6.0                    py37_0
jupyter_client            5.2.4                    py37_0
jupyter_core              4.4.0                    py37_0
keyring                   17.1.1                   py37_0
kiwisolver                1.0.1            py37h6538335_0
lazy-object-proxy         1.3.1            py37hfa6e2cd_2
libpng                    1.6.36               h2a8f88b_0
libsodium                 1.0.16               h9d3ae62_0
markupsafe                1.1.0            py37he774522_0
matplotlib                3.0.2            py37hc8f65d3_0
mccabe                    0.6.1                    py37_1
mistune                   0.8.4            py37he774522_0
mkl                       2019.1                      144
mkl_fft                   1.0.10           py37h14836fe_0
mkl_random                1.0.2            py37h343c172_0
more-itertools            5.0.0                    py37_0
nbconvert                 5.3.1                    py37_0
nbformat                  4.4.0                    py37_0
numpy                     1.15.4           py37h19fb1c0_0
numpy-base                1.15.4           py37hc3f5095_0
numpydoc                  0.8.0                    py37_0
openssl                   1.1.1a               he774522_0
packaging                 18.0                     py37_0
pandas                    0.23.4           py37h830ac7b_0
pandoc                    2.2.3.2                       0
pandocfilters             1.4.2                    py37_1
parso                     0.3.1                    py37_0
pickleshare               0.7.5                    py37_0
pip                       18.1                     py37_0
pluggy                    0.8.1                    py37_0
prompt_toolkit            2.0.7                    py37_0
psutil                    5.4.8            py37he774522_0
py                        1.7.0                    py37_0
pycodestyle               2.4.0                    py37_0
pycparser                 2.19                     py37_0
pydocstyle                3.0.0                    py37_0
pyflakes                  2.0.0                    py37_0
pygments                  2.3.1                    py37_0
pylint                    2.2.2                    py37_0
pyopenssl                 18.0.0                   py37_0
pyparsing                 2.3.1                    py37_0
pyqt                      5.9.2            py37h6538335_2
pysocks                   1.6.8                    py37_0
pytest                    4.1.1                    py37_0
pytest-cov                2.6.1                    py37_0
pytest-mock               1.10.0                   py37_0
pytest-qt                 3.2.2                      py_0    conda-forge
python                    3.7.1                he44a216_5
python-dateutil           2.7.5                    py37_0
python-jsonrpc-server     0.1.2                      py_0    conda-forge
python-language-server    0.21.5                py37_1000    conda-forge
pytz                      2018.9                   py37_0
pywin32                   223              py37hfa6e2cd_1
pyzmq                     17.1.2           py37hfa6e2cd_0
qt                        5.9.7            vc14h73c81de_0
qtawesome                 0.5.5                    py37_0
qtconsole                 4.4.3                    py37_0
qtpy                      1.5.2                    py37_0
requests                  2.21.0                   py37_0
rope                      0.11.0                   py37_0
scipy                     1.1.0            py37h29ff71c_2
setuptools                40.6.3                   py37_0
sip                       4.19.8           py37h6538335_0
six                       1.12.0                   py37_0
snowballstemmer           1.2.1                    py37_0
sphinx                    1.8.2                    py37_0
sphinxcontrib             1.0                      py37_1
sphinxcontrib-websupport  1.1.0                    py37_1
spyder-kernels            0.3.0                    py37_0
sqlite                    3.26.0               he774522_0
testpath                  0.4.2                    py37_0
tornado                   5.1.1            py37hfa6e2cd_0
traitlets                 4.3.2                    py37_0
urllib3                   1.24.1                   py37_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.15.26706          h3a45250_0
wcwidth                   0.1.7                    py37_0
webencodings              0.5.1                    py37_1
wheel                     0.32.3                   py37_0
win_inet_pton             1.0.1                    py37_1
wincertstore              0.2                      py37_0
wrapt                     1.11.0           py37he774522_0
yapf                      0.25.0                   py37_0
zeromq                    4.2.5                he025d50_1
zlib                      1.2.11               h62dcd97_3

@jnsebgosselin
Copy link
Member Author

If anyone else is reading this, care to confirm if any Windows system is affected or if it's an isolated issue to the issue creator?

@CAM-Gerlach would you be so kind to test this code on Windows and post back the results please?

import sys
import qtawesome as qta
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout,
                             QToolButton, QLabel)

app = QApplication(sys.argv)

window = QWidget()
layout = QGridLayout(window)
names = ['fa5s.grip-horizontal', 'fa5s.file-export', 'fa5s.file-import']
for i, name in enumerate(names):
    qicon = qta.icon(name, scale_factor=1.3, color='red')
    btn = QToolButton()
    btn.setIcon(qicon)
    btn.setIconSize(QSize(32, 32))
    layout.addWidget(btn, i, 0)
    layout.addWidget(QLabel(name), i, 1)
window.show()

sys.exit(app.exec_())

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Jan 21, 2019

Sure @jnsebgosselin . Under Windows 8.1 x64, Python 3.6.7, QtAwesome 0.5.5, and PyQt 5.9.2/Qt 5.9.6:

image

locale.getdefaultlocale() returns ('en_US', 'cp1252'). Running the script with python -X utf8 makes no difference. EDIT: Probably was because I was using Python 3.6, not 3.7 haha. I'll restest.

Full conda list output (for my Spyder 4 dev environment):

# packages in environment at C:\Anaconda3\envs\spyder-4-lsp:
#
# Name                    Version                   Build  Channel
alabaster                 0.7.12                   py36_0
asn1crypto                0.24.0                   py36_0
astroid                   2.0.4                    py36_0
atomicwrites              1.2.1                    py36_0
attrs                     18.2.0           py36h28b3542_0
autopep8                  1.3.5                     <pip>
babel                     2.6.0                    py36_0
backcall                  0.1.0                    py36_0
blas                      1.0                         mkl
bleach                    3.0.0                    py36_0
ca-certificates           2018.12.5                     0
certifi                   2018.11.29               py36_0
cffi                      1.11.5           py36h74b6da3_1
chardet                   3.0.4                    py36_1
cloudpickle               0.5.6                    py36_0
colorama                  0.3.9            py36h029ae33_0
cryptography              2.3.1            py36h74b6da3_0
cryptography-vectors      2.3.1                    py36_0
cycler                    0.10.0           py36h009560c_0
cython                    0.29             py36ha925a31_0
decorator                 4.3.0                    py36_0
docutils                  0.14             py36h6012d8f_0
entrypoints               0.2.3                    py36_2
fastcache                 1.0.2            py36hfa6e2cd_2
flaky                     3.4.0                    py36_0
freetype                  2.9.1                ha9979f8_1
future                    0.16.0                    <pip>
html5lib                  1.0.1                    py36_0
icc_rt                    2017.0.4             h97af966_0
icu                       58.2                 ha66f8fd_1
idna                      2.7                      py36_0
imagesize                 1.1.0                    py36_0
intel-openmp              2018.0.0                      8
ipykernel                 5.0.0            py36h39e3cac_0
ipython                   7.0.1            py36h39e3cac_0
ipython_genutils          0.2.0            py36h3c5d0ee_0
isort                     4.3.4                    py36_0
jedi                      0.13.1                   py36_0
jinja2                    2.10                     py36_0
jpeg                      9b                   hb83a4c4_2
jsonschema                2.6.0            py36h7636477_0
jupyter_client            5.2.3                    py36_0
jupyter_core              4.4.0                    py36_0
keyring                   13.2.1                   py36_0
kiwisolver                1.0.1            py36h6538335_0
lazy-object-proxy         1.3.1            py36hfa6e2cd_2
libpng                    1.6.34               h79bbb47_0
libsodium                 1.0.16               h9d3ae62_0
markupsafe                1.0              py36hfa6e2cd_1
matplotlib                2.2.2            py36had4c4a9_2
mccabe                    0.6.1                    py36_1
mistune                   0.8.3            py36hfa6e2cd_1
mkl                       2018.0.2                      1
mkl-service               1.1.2            py36hb217b18_4
mkl_fft                   1.0.1            py36h452e1ab_0
mkl_random                1.0.1            py36h9258bd6_0
more-itertools            4.3.0                    py36_0
mpmath                    1.0.0                    py36_2
nbconvert                 5.3.1                    py36_0
nbformat                  4.4.0            py36h3a5bc1b_0
numpy                     1.14.3           py36h9fa60d3_1
numpy-base                1.14.3           py36h555522e_1
numpydoc                  0.8.0                    py36_0
openssl                   1.0.2p               hfa6e2cd_0
packaging                 18.0                     py36_0
pandas                    0.23.4           py36h830ac7b_0
pandoc                    2.2.1                h1a437c5_0
pandocfilters             1.4.2                    py36_1
parso                     0.3.1                    py36_0
pickleshare               0.7.5                    py36_0
pip                       18.1                     py36_0
pluggy                    0.7.1                     <pip>
pluggy                    0.8.0                    py36_0
prompt_toolkit            2.0.5                    py36_0
psutil                    5.4.7            py36hfa6e2cd_0
py                        1.7.0                    py36_0
pycodestyle               2.4.0                    py36_0
pycparser                 2.19                     py36_0
pydocstyle                2.1.1                     <pip>
pyflakes                  2.0.0                    py36_0
pygments                  2.2.0            py36hb010967_0
pylint                    2.1.1                    py36_0
pyopenssl                 18.0.0                   py36_0
pyparsing                 2.2.2                    py36_0
pyqt                      5.9.2            py36h6538335_2
pysocks                   1.6.8                    py36_0
pytest                    4.0.2                    py36_0
pytest-mock               1.10.0                   py36_0
pytest-qt                 3.2.1                      py_0    spyder-ide
python                    3.6.7                h33f27b4_1
python-dateutil           2.7.3                    py36_0
python-jsonrpc-server     0.1.2                     <pip>
python-language-server    0.21.5                    <pip>
pytz                      2018.5                   py36_0
pywin32                   223              py36hfa6e2cd_1
pyzmq                     17.1.2           py36hfa6e2cd_0
QDarkStyle                2.6.5                     <pip>
qt                        5.9.6            vc14h62aca36_0
qtawesome                 0.5.5                    py36_0
qtconsole                 4.4.2                    py36_0
qtpy                      1.5.1                    py36_0
requests                  2.19.1                   py36_0
rope                      0.11.0                   py36_0
scipy                     1.1.0            py36h672f292_0
setuptools                40.4.3                   py36_0
simplegeneric             0.8.1                    py36_2
sip                       4.19.8           py36h6538335_0
six                       1.11.0                   py36_1
snowballstemmer           1.2.1            py36h763602f_0
sphinx                    1.8.1                    py36_0
sphinxcontrib             1.0                      py36_1
sphinxcontrib-websupport  1.1.0                    py36_1
spyder-kernels            1.0.1                    py36_0
sqlite                    3.24.0               h7602738_0
sympy                     1.3                      py36_0
testpath                  0.4.2                    py36_0
tornado                   5.1.1            py36hfa6e2cd_0
traitlets                 4.3.2            py36h096827d_0
typed-ast                 1.1.0            py36hfa6e2cd_0
urllib3                   1.23                     py36_0
vc                        14.1                 h0510ff6_3
vs2013_runtime            12.0.21005                    1
vs2015_runtime            15.5.2                        3
wcwidth                   0.1.7            py36h3d5aa90_0
webencodings              0.5.1                    py36_1
wheel                     0.32.1                   py36_0
win_inet_pton             1.0.1                    py36_1
wincertstore              0.2              py36h7fe50ca_0
wrapt                     1.10.11          py36hfa6e2cd_2
yapf                      0.22.0                    <pip>
zeromq                    4.2.5                he025d50_1
zlib                      1.2.11               h8395fce_2

@jnsebgosselin
Copy link
Member Author

Ouch. Thanks @CAM-Gerlach!

@CAM-Gerlach
Copy link
Member

I retested on Python 3.7, and UTF-8 mode had no effect on either output, BTW.

@darkvertex
Copy link
Contributor

For what it's worth, locale.getdefaultlocale() on my side gives me: ('en_US', 'UTF-8')

@darkvertex
Copy link
Contributor

darkvertex commented Jan 21, 2019

Out of curiosity, do you guys get weird glyphs when using the font directly as opposed to generating the QIcon?

Can you try this:

import sys
import qtawesome as qta
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel)

app = QApplication(sys.argv)
font = qta.font('fa5s', 24)  # FA5 Solid
window = QWidget()
layout = QGridLayout(window)
pairs = [
    ('grip-horizontal', unichr(0xf58d)),
    ('file-export', unichr(0xf56e)),
    ('file-import', unichr(0xf56f))]
for i, data in enumerate(pairs):
    name, char = data
    label = QLabel(char + ' = ' + name)
    label.setFont(font)
    label.setStyleSheet("QLabel { background-color: black; color: red; }")
    layout.addWidget(label, i, 0)

window.show()
sys.exit(app.exec_())

I get this fugly but accurate thing:
image

Do you still get inaccurate glyphs with this code?

@jnsebgosselin
Copy link
Member Author

Out of curiosity, do you guys get weird glyphs when using the font directly as opposed to generating the QIcon?

Do you still get inaccurate glyphs with this code?

Yes. Here are the results I get:

image

Note that I replaced unichr by char in your MWE.

@CAM-Gerlach
Copy link
Member

I got the same results as I did above, and different from either of you:

image

I also had to replace unichr() with chr(); I'd never heard of it but some Googleing indicates unichar is an old fossil from back in the Python 2 days. My condolences.

@darkvertex
Copy link
Contributor

darkvertex commented Jan 23, 2019

Hey guys, what do you get from this:

import sys
print sys.maxunicode

1114111 👈 👍 -- Any smaller number means you have a compile of Python with "narrow" (incomplete) Unicode support. Supposedly all builds of Python 3.3 and above should be "wide" (good) but just humor me and confirm please? I want to rule it out. Thanks!

@darkvertex
Copy link
Contributor

Also if either of you wouldn't mind pasting your adjusted code using chr() instead of unichr() just so we're all on the same page if someone else wants to try to debug this. I can maybe try to install Python 3 and see if it messes up for me on Linux.

I sadly live in the world of Python 2.7 for my professional day-to-day as we haven't began touching 3.x yet due to lack of support in the softwares of the industry I'm in. Perhaps there's something unusual behaviour happening in 3.x land.

Furthermore, would you mind giving a try to the repro snippets on Python 2.7 or higher but less than 3.x? I'm curious if this is a Windows issue or a Python 2 vs 3 issue. If it renders the same then maybe it's a Windows problem. If it renders properly, we'll know something's different with Py3k's execution of the module.

Just trying to narrow the focus on where things could be going wrong. 🤞

@jnsebgosselin
Copy link
Member Author

sys.maxunicode returns 1114111

@jnsebgosselin
Copy link
Member Author

Furthermore, would you mind giving a try to the repro snippets on Python 2.7 or higher but less than 3.x? I'm curious if this is a Windows issue or a Python 2 vs 3 issue. If it renders the same then maybe it's a Windows problem. If it renders properly, we'll know something's different with Py3k's execution of the module.

Trying this with Python 2.7.15 on Windows results in the same problem.

image

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Jan 23, 2019

print sys.maxunicode

🤦‍♂️ 🤦‍♂️ 🤦‍♂️

print(sys.maxunicode) returns 1114111

Also if either of you wouldn't mind pasting your adjusted code using chr() instead of unichr()

The change is rather trivial (and in a production setting you'd want to use future, i.e. from builtins import chr instead), but the following code will work seamlessly on both Python 2 and Python 3:

import sys
import qtawesome as qta
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel)

if sys.version_info[0] < 3:
    chr = unichr

app = QApplication(sys.argv)
font = qta.font('fa5s', 24)  # FA5 Solid
window = QWidget()
layout = QGridLayout(window)
pairs = [
    ('grip-horizontal', chr(0xf58d)),
    ('file-export', chr(0xf56e)),
    ('file-import', chr(0xf56f))]
for i, data in enumerate(pairs):
    name, char = data
    label = QLabel(char + ' = ' + name)
    label.setFont(font)
    label.setStyleSheet("QLabel { background-color: black; color: red; }")
    layout.addWidget(label, i, 0)

window.show()
sys.exit(app.exec_())

I can maybe try to install Python 3 and see if it messes up for me on Linux.

I'd suggest you just grab Miniconda and test it with that; it shouldn't take more than a few minutes to install and get QtAwesome running.

I sadly live in the world of Python 2.7 for my professional day-to-day as we haven't began touching 3.x yet due to lack of support in the softwares of the industry I'm in.

Quite sad, indeed. I would strongly recommend you begin at least getting familiar with 3.x and the porting process if you aren't already and trying to use proper modern "universal" syntax wherever possible (e.g. print()), since in most cases you can start writing Python 3-compatible code now with only minimal extra effort, while retaining full Python 2 compatibility. You don't have much time left before the EoL and many major packages (including virtually the entire scientific Python stack, parts of which many non-scientific software depend on) have already dropped support or pledged to by the EoL date—and that includes ourselves, of course.

Furthermore, would you mind giving a try to the repro snippets on Python 2.7 or higher but less than 3.x?

I dug out my old Py2.7 environment, updated to QtAwesome 0.5.5 and somewhat more modern versions of the main deps (Python 2.7.14, PyQt 5.6.0, Qt 5.6.2, QtPy 1.5.2) and I got the same result as under Py3k:

image

@darkvertex
Copy link
Contributor

Thanks for trying in Python 2, guys.

I sadly live in the world of Python 2.7 for my professional day-to-day as we haven't began touching 3.x yet due to lack of support in the softwares of the industry I'm in.

Quite sad, indeed. I would strongly recommend you begin at least getting familiar with 3.x and the porting process if you aren't already and trying to use proper modern "universal" syntax wherever possible (e.g. print()), since in most cases you can start writing Python 3-compatible code now with only minimal extra effort, while retaining full Python 2 compatibility. You don't have much time left before the EoL and many major packages (including virtually the entire scientific Python stack, parts of which many non-scientific software depend on) have already dropped support or pledged to by the EoL date—and that includes ourselves, of course.

For context, in my industry (visual effects for film and tv), all our principal software formed a mini consortium called the VFX Platform that agrees every year on future versions of libraries/dependencies that everybody should match. Python 3 is was supposed to come this year but vendors missed the mark. Now it's slated for 2020. I sense a bumpy road ahead.

Anyway, I digress... @ccordoba12: any ideas where the bug may lie?

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Jan 23, 2019

For context, in my industry (visual effects for film and tv)

Ah, that's something I am actually obliquely familiar with, since way back in the day when I was in high school I used to work side gigs in video production for various smaller-time clients (corporate, education, etc) and VFX (particularly layer-based compositing-type work in AE) was my "specialty" per say, and I wrote plenty of simple Python scripts for that (in fact, I think that was the first time I ever used Python).

Python 2.7 or higher but less than 3.x?

Uh... should we tell him? :D

@jnsebgosselin
Copy link
Member Author

Since it appears to be not the source of the issue, please let's focus on the issue and stop discussing the state of Python2 versus Python3 stuff here. There is gitter for that :)

@CAM-Gerlach
Copy link
Member

Fair point; I removed most of that from my post, other than a short aside responding to his aside. For the record, I thought Gitter was for getting help and questions about Spyder, not idle chatter?

@jnsebgosselin
Copy link
Member Author

I thought Gitter was for getting help and questions about Spyder, not idle chatter?

You can talk about whatever you want in private chat. Anyway, that is not my point.

@ccordoba12
Copy link
Member

@ccordoba12: any ideas where the bug may lie?

Mmmh, @CAM-Gerlach, @jnsebgosselin, what happens if you install the fontawesome fonts in your system (as with a regular font)? Does that fix the problem?

@CAM-Gerlach
Copy link
Member

CAM-Gerlach commented Jan 23, 2019

@ccordoba12 Same result.

I installed all three OTF files from the FA Free desktop font download on my system, and then re-ran both versions of the test script, and nothing changed.

@ccordoba12
Copy link
Member

Then I don't know.

@CAM-Gerlach
Copy link
Member

@darkvertex I can try changing my system locale and see if that affects the results (since @jnsebgosselin has both a different locale and is getting different results), but it requires a restart which I can't really do right now...

@jnsebgosselin
Copy link
Member Author

I will investigate further in the next few days about this until I find what is going on because I really need this to work.

@jnsebgosselin
Copy link
Member Author

jnsebgosselin commented Jan 24, 2019

@ccordoba12 @darkvertex
I think the problem may come from the fact that fontawesome5-regular-webfont.ttf and fontawesome5-solid-webfont.ttf share the same font family name, that is Font Awesome 5 Free.

Running this with Python 3:

import sys
import os.path as osp
from PyQt5.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel)
from qtpy.QtGui import QFontDatabase, QFont

app = QApplication(sys.argv)

root = "C:/Anaconda3/envs/gwhat-dev/Lib/site-packages/qtawesome/fonts/"
ttf_filenames = ["elusiveicons-webfont.ttf",
                 "fontawesome4.7-webfont.ttf",
                 "fontawesome5-brands-webfont.ttf",
                 "fontawesome5-regular-webfont.ttf",
                 "fontawesome5-solid-webfont.ttf",
                 "materialdesignicons-webfont.ttf"]

for ttf_filename in ttf_filenames:
    id_ = QFontDatabase.addApplicationFont(osp.join(root, ttf_filename))
    font_family = QFontDatabase.applicationFontFamilies(id_)
    print('{} - {:<32s} :'.format(id_, ttf_filename), *font_family)

font = QFont('Font Awesome 5 Free')
font.setPixelSize(24)

window = QWidget()
layout = QGridLayout(window)
pairs = [('grip-horizontal', chr(0xf58d)),
         ('file-export', chr(0xf56e)),
         ('file-import', chr(0xf56f))]
for name, char in pairs:
    label = QLabel(char + ' = ' + name)
    label.setFont(font)
    label.setStyleSheet("QLabel { background-color: black; color: red; }")
    layout.addWidget(label)

window.show()
sys.exit(app.exec_())

results in :

0 - elusiveicons-webfont.ttf         : elusiveicons
1 - fontawesome4.7-webfont.ttf       : FontAwesome
2 - fontawesome5-brands-webfont.ttf  : Font Awesome 5 Brands
3 - fontawesome5-regular-webfont.ttf : Font Awesome 5 Free
4 - fontawesome5-solid-webfont.ttf   : Font Awesome 5 Free
5 - materialdesignicons-webfont.ttf  : Material Design Icons

image

In my code above, if I remove "fontawesome5-regular-webfont.ttf" from the ttf_filenames list and run the script again, then I get the good icons :

image

@jnsebgosselin
Copy link
Member Author

jnsebgosselin commented Jan 24, 2019

So in the example above, I have not used qtawesome at all. We can see though that this duplication of font family names also occurs when using qtawesome:

Running this:

import sys
from PyQt5.QtWidgets import QApplication
import qtawesome as qta

app = QApplication(sys.argv)
print('fa5b :', qta.font('fa5b', 24).family())
print('fa5s :', qta.font('fa5s', 24).family())
print('fa5 :', qta.font('fa5', 24).family())
sys.exit(app.exec_())

returns:

fa5b : Font Awesome 5 Brands
fa5s : Font Awesome 5 Free
fa5 : Font Awesome 5 Free

@jnsebgosselin
Copy link
Member Author

So yeah, for the moment, that is the most plausible explanation I have for this issue, i.e. that the fontawesome5-regular-webfont and fontawesome5-solid-webfont get blended together into a single font family.

@jules-ch
Copy link

jules-ch commented Jan 24, 2019

same as #97 it appears.

Solution was renaming the font with specific tool. This is a windows specific issue though.

Edit : Updating fonts after v0.5.1 made issue reappear.

@jnsebgosselin
Copy link
Member Author

Edit : Updating fonts after v0.5.1 made issue reappear.

Yes, I confirm this. Everything works as expected with v0.5.1 and v0.5.2, but it doesn't with any version other than that.

@jnsebgosselin
Copy link
Member Author

jnsebgosselin commented Jan 24, 2019

@darkvertex is it possible that you did not renamed the fonts when you updated FontAwesome?

https://github.com/spyder-ide/qtawesome/commits/master/qtawesome/fonts/fontawesome5-solid-webfont.ttf

jnsebgosselin added a commit to jnsebgosselin/qtawesome that referenced this issue Jan 24, 2019
Test that each font used by qtawesome has a unique name.
Regression test for Issue spyder-ide#107
@darkvertex
Copy link
Contributor

I definitely did not rename any fonts. They are as-is from what the released zip files give you.

When introducing FA5 we saw that the doubled font name between solid and regular was an issue in Linux (and we assumed other platforms) and someone committed this fix:
c90fa18
by setting the font "style", and that was sufficient to solve the issue in Linux, and we (perhaps foolishly) assumed other OSs would be good also.

I suppose I could mess with the fonts with:
https://github.com/chrissimpkins/fontname.py
during my automatic update procedure to explicitly rename the font. @ccordoba12: you ok with renaming the font file?

@jnsebgosselin
Copy link
Member Author

jnsebgosselin commented Jan 24, 2019

@darkvertex I'm confused. I thought you actually renamed the font names in PR #98 with the fontname.py tool.

This seems to have fixed the problem in v0.5.1 and v0.5.2. At least, when I use these versions, everything is working as expected for me in Windows.

@darkvertex
Copy link
Contributor

Sorry, seems I'm confused also. It appears I forgot the renaming step in the last update to the newest FA version. 🤦‍♂️ My apologies.

PR incoming!

@jnsebgosselin
Copy link
Member Author

@darkvertex Alright thank you very much!

I'm in the process of adding a test in PR #108 to cover this in the future.

@darkvertex
Copy link
Contributor

Great idea, thanks for writing the test.

@darkvertex
Copy link
Contributor

PR #109 has the renamed fonts.

Care to give it a try when you have a minute, @jnsebgosselin / @CAM-Gerlach ?

@jnsebgosselin
Copy link
Member Author

PR #109 has the renamed fonts.

Care to give it a try when you have a minute, @jnsebgosselin / @CAM-Gerlach ?

Yes, this is working, thanks.

@darkvertex
Copy link
Contributor

Yes, this is working, thanks.

Awesome! \o/

@CAM-Gerlach
Copy link
Member

@darkvertex Looks like it works for me too; I commented over on the PR.

@ccordoba12 ccordoba12 added this to the v0.5.6 milestone Jan 25, 2019
@flutefreak7
Copy link

flutefreak7 commented Jan 29, 2019

Upon returning to work from the US Government shutdown, and updating all my libraries I discovered that my icons were broken and it looks like it is this issue. I was the one who suggested the font renaming in the previous issue.

Should font renaming be part of a build / packaging / deploy script?

Should we look at fixing this "upstream" by talking to the Font Awesome people?

Edit: Or add a test that fails if the names are the same.

@darkvertex
Copy link
Contributor

Hi there @flutefreak7 - happy to hear your government is alive again.

Should font renaming be part of a build / packaging / deploy script?

It's not part of deployment exactly, but as part of the "update_fa5" command used for updating the FontAwesome version within the package, there is a font renaming step since PR #110 so all future updates will have unique font names.

Should we look at fixing this "upstream" by talking to the Font Awesome people?

Maybe? Here's their repo: 👉 https://github.com/FortAwesome/Font-Awesome/issues

Edit: Or add a test that fails if the names are the same.

Actually it's already done since PR #108.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants