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

FIX: Make font style- and stretch- check case insensitive #405

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

achabotl
Copy link
Contributor

@achabotl achabotl commented Jun 9, 2020

This makes style and stretch case insensitive in
kiva.fonttools.font_manager.ttfFontProperty. The case sensitivity led
to font styles not being properly detected on (at least) macOS.

The checks on filename were already case insensitive.

I'm not sure how to test this. There's a test in fonttools, but it would required modifying the test .ttf file and I didn't know how to fix it. Help would be appreciated.

Here's a small test sample and an example that it works

from kiva.fonttools import Font
from kiva.image import GraphicsContext
from kiva.constants import ITALIC, BOLD

gc = GraphicsContext((200, 200))

f = Font('', size=24)
print("Top: ", f.findfont())
gc.set_font(f)
gc.set_text_position(30, 150)
gc.show_text("Hello World")

f = Font('Georgia', size=24)
print('2nd', f.findfont())
gc.set_font(f)
gc.set_text_position(30, 110)
gc.show_text("Hello World")

f = Font('Georgia', size=24, style=ITALIC)
print('3rd', f.findfont())
gc.set_font(f)
gc.set_text_position(30, 70)
gc.show_text("Hello World")

f = Font('Georgia', size=24, style=BOLD)
print('4th', f.findfont())
gc.set_font(f)
gc.set_text_position(30, 30)
gc.show_text("Hello World")

gc.save('text.png')

text

Fixes: #404
Also addresses part of #391.

This makes style and stretch case insensitive in
`kiva.fonttools.font_manager.ttfFontProperty`. The case sensitivity led
to font styles not being properly detected on (at least) macOS.

The checks on filename were already case insensitive.

Fixes: #404
@achabotl achabotl changed the title FIX: Make style and stretch check case insensitive FIX: Make font style- and stretch- check case insensitive Jun 10, 2020
@achabotl
Copy link
Contributor Author

It looks like I can edit the font with the free and open source FontForge app.

This adds a test and a test file for correctly identifying fonts who's
style contains capital letters. The "TestTTF Italic" font was edited in
FontForge [1] to have the style "Italic".

[1]: https://fontforge.org/
@achabotl
Copy link
Contributor Author

The test failures are unrelated to the change.

  • Environment: RUNTIME=3.5, TOOLKITS=null pyqt pyqt5: NotImplementedError: the null pyface.ui.null backend doesn't implement util.gui_test_assistant:GuiTestAssistant
  • Environment: RUNTIME=3.6, TOOLKITS=null pyqt pyqt5: NotImplementedError: the null pyface.ui.null backend doesn't implement util.gui_test_assistant:GuiTestAssistant
  • Environment: RUNTIME=3.6, TOOLKITS=wx: RuntimeError: Python 3.6, toolkit wx, and pillow pillow not supported by test environments

@kitchoi
Copy link
Contributor

kitchoi commented Oct 21, 2020

Rebuilding CI now that #424 is merged... 🤞

@kitchoi
Copy link
Contributor

kitchoi commented Dec 2, 2020

(Merged master in to get the latest CI changes)

@codecov-io
Copy link

codecov-io commented Dec 2, 2020

Codecov Report

Merging #405 (ed8198d) into master (55fc728) will increase coverage by 1.54%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #405      +/-   ##
==========================================
+ Coverage   28.96%   30.51%   +1.54%     
==========================================
  Files         206      206              
  Lines       18245    17853     -392     
  Branches     2466     2461       -5     
==========================================
+ Hits         5284     5447     +163     
+ Misses      12634    12068     -566     
- Partials      327      338      +11     
Impacted Files Coverage Δ
kiva/fonttools/font_manager.py 50.44% <100.00%> (-0.30%) ⬇️
kiva/image.py 85.71% <0.00%> (-14.29%) ⬇️
enable/coordinate_box.py 31.15% <0.00%> (-1.50%) ⬇️
enable/primitives/box.py 33.33% <0.00%> (-1.29%) ⬇️
enable/tools/move_tool.py 82.75% <0.00%> (-1.12%) ⬇️
enable/tools/apptools/command_tool.py 84.61% <0.00%> (-1.10%) ⬇️
enable/qt4/constants.py 89.47% <0.00%> (-1.01%) ⬇️
enable/tools/base_drop_tool.py 76.66% <0.00%> (-0.76%) ⬇️
enable/interactor.py 84.00% <0.00%> (-0.62%) ⬇️
kiva/pdfmetrics.py 19.19% <0.00%> (-0.61%) ⬇️
... and 100 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55fc728...ed8198d. Read the comment docs.

Copy link
Member

@jwiggins jwiggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@achabotl
Copy link
Contributor Author

achabotl commented Dec 9, 2020

Thanks for the fix @kitchoi, sorry for not being responsive on this one. I had forgotten about this PR. 😞

@achabotl achabotl merged commit b328eda into master Dec 9, 2020
@achabotl achabotl deleted the fix/404-style-check branch December 9, 2020 17:12
@kitchoi
Copy link
Contributor

kitchoi commented Dec 9, 2020

@achabotl No worries, thank you for the fix!

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 this pull request may close these issues.

Font styles do not work on macOS
4 participants