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
add font rendering options #3896
Conversation
Nice features. 👍 The options could be: The new api endpoints will also need a bit of docs, please follow this as a template: Also add a note to them about sdl2, like this: kivy/kivy/core/window/__init__.py Line 837 in 4e429de
|
Shortly I will correct the issues, you have noticed. |
Thanks a lot for your work. Yes, absolutely, we intend to merge it. 😉 |
Since you're still making fixes, it may be nice if you explain in the docs what kerning, hinting and blending do. Since I for one don't know what hinting or blending does. It should just be a short one or two sentences. |
|
||
.. note:: | ||
This feature requires a SDL2 window provider and is currently only | ||
supported on desktop platforms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SDL2 is now being supported everywhere even on mobiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..versionadded::1.9.2
Demo here: from kivy.app import App
from kivy.uix.button import Button
from kivy import __version__ as kivy_version
from kivy.uix.boxlayout import BoxLayout
import os
#font_name = "/usr/share/fonts/truetype/msttcorefonts/arial.ttf"
# font_name = "/usr/share/fonts/truetype/msttcorefonts/Verdana.ttf"
# font_name = "/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf"
font_name = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"
fname = os.path.basename(font_name)
fsize = '13pt'
class TestApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
layout.add_widget(
Button(
text="kivy_version: {}".format(kivy_version),
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='normal',
font_blended=False,
)
)
layout.add_widget(
Button(
text="Kerning On: AV",
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='normal',
font_kerning=True,
font_blended=False,
)
)
layout.add_widget(
Button(
text="Kerning Off: AV",
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='normal',
font_kerning=False,
font_blended=False,
)
)
layout.add_widget(
Button(
text=fname + ' solid none',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='none',
font_blended=False,
)
)
layout.add_widget(
Button(
text=fname + ' solid light',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='light',
font_blended=False,
)
)
layout.add_widget(
Button(
text=fname + ' solid normal',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='normal',
font_blended=False,
)
)
layout.add_widget(
Button(
text=fname + ' solid mono',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='mono',
font_blended=False,
)
)
layout.add_widget(
Button(
text=fname + ' blended none',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='none',
font_blended=True,
)
)
layout.add_widget(
Button(
text=fname + ' blended light',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='light',
font_blended=True,
)
)
layout.add_widget(
Button(
text=fname + ' blended normal',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='normal',
font_blended=True,
)
)
layout.add_widget(
Button(
text=fname + ' blended mono',
background_normal='',
color=[0, 0, 0, 1],
font_name=font_name,
font_size=fsize,
font_hinting='mono',
font_blended=True,
)
)
return layout
def _main():
TestApp().run()
if __name__ == '__main__':
_main() It would be nice to add this demo somehow to kivy examples. Any suggestions? |
@Ali65, a label example with the new options could be added here, in a separate pr: https://github.com/ali65/kivy/tree/master/examples/widgets. |
add font rendering options
@Ali65 thanks nice work ! |
Soon I will follow up with the merge request of the cleaned-up example of using the new font rendering options. Thanks for merging. |
from kivy.app import App
from kivy.lang import Builder
kv = """
Label:
text: 'OFFICIALLY TESTED'
font_size: '20dp'
"""
class TestApp(App):
def build(self):
return Builder.load_string(kv)
if __name__ == '__main__':
TestApp().run() |
This might also need to be sorted out:
|
On low resolution LCD, with the right font type and the hinting method, there is a better looking result if antialiasing is disabled. With retina display, this is not an issue, but not all kivy users have retina.
Kivy is hardwired to enable antialiasing because it always calls TTF_RenderUTF8_Blended.
With this change Kivy could optionally call the TTF_RenderUTF8_Solid (which does not use antialiasing).
Beside that the change allows setting the hinting level.
Additional info:
http://www.sdltutorials.com/sdl-ttf
Further thinking: Maybe kivy should automatically detect if display is low res and font type is such, and switch between antialising enabled/disabled automatically? For simplicity it is better just leave control to the programmer.