Font Selection Option (For use with OpenDyslexic Font)

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
BáiYù
Regular
Posts: 131
Joined: Fri Apr 01, 2016 10:02 am
Completed: This Life Escapes Me, Up All Night, Lotus: The Self-Made Witch
Projects: Various
Organization: tofurocks, Fiendish Fiction, Spider Lily Studios
Github: baiyu-dev
itch: tofurocks
Contact:

Font Selection Option (For use with OpenDyslexic Font)

#1 Post by BáiYù »

This function allows players to choose which font they would like to use while playing the game. This does not affect the font used for the GUI.

Code is from the All of Cute Demon Crashers! custom code thread, I simply dug it out from all the script files.

Code: Select all

# Insert into the options.rpy
init -1 python hide:

    # Fonts that may be chosen by the user
    renpy.register_style_preference(
        "text", "Default", style.say_dialogue, "font", "gui/default.ttf")
    renpy.register_style_preference(
        "text", "Open Dyslexic", style.say_dialogue, "font", "gui/OpenDyslexic-Regular.otf")

Code: Select all

#insert into screens.rpy in the Preference screen section
            frame:
                style_group "pref"
                has vbox
                
                label _("Font Selection")
                textbutton "Default" action StylePreference("text", "Default")
                textbutton "Open Dyslexic" action StylePreference("text", "Open Dyslexic")
Download the OpenDyslexic font from their official website.
Image
Games and supplementary Ren'Py codes

User avatar
NeuroDolphin
Newbie
Posts: 3
Joined: Wed Aug 22, 2018 6:36 pm
Projects: A Cry in the Dark
Contact:

Re: Font Selection Option (For use with OpenDyslexic Font)

#2 Post by NeuroDolphin »

Thanks a lot for posting this here, it's really nice to try and make games that much more accessible for people.
Thanks to you, my game now supports Open Dyslexia!

User avatar
Andredron
Miko-Class Veteran
Posts: 714
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Font Selection Option (For use with OpenDyslexic Font)

#3 Post by Andredron »

Size font in option Renpy

Code: Select all

# screens.rpy
#. ,,
Screen preferences:
     tag menu
     # etc. flat screen
     #. ,,
     # at the very end, add this code:
             frame:
                 style_group "pref"
                 has a vbox
                 label _ ("Text Size% s"% (ts_min + persistent.ts))
                 bar value FieldValue (constant, "ts", ts_max - ts_min)
     on 'hide' action SetTS ()
     on 'replace' action SetTS ()
 
init python:
     # font sizes
     ts_min = 16 # from these
     ts_max = 48 # still
     if they are persistent.ts is not None:
         persistent.ts = 0
     def setts ():
         style. default.size = ts_min + persistent.ts
         style. rebuild ()
     SetTS = renpy. curry
     setts ()
#
https://pastebin.com/PD4XLBAk

https://yadi.sk/d/pnm13XXL35aSWN working example

Ayael
Regular
Posts: 82
Joined: Fri Apr 07, 2017 2:17 pm
Projects: Imperial Grace (on going), Autumn Spirit, Ballads at Midnight
Contact:

Re: Font Selection Option (For use with OpenDyslexic Font)

#4 Post by Ayael »

I did a complementary tutorial to change all font for OpenDyslexic (including menu, label and so on).

(You can find it here : viewtopic.php?f=51&t=57895)
Image Image

User avatar
thetiredone
Newbie
Posts: 20
Joined: Sun Mar 03, 2019 11:37 pm
Completed: Memory Ghosts, PRETTYBOY Inc. is Hiring!, Disruptive Compassion
Projects: Spring Boy, Sink Beneath
Tumblr: HeartSyncProductions
itch: HeartSyncProductions
Contact:

Re: Font Selection Option (For use with OpenDyslexic Font)

#5 Post by thetiredone »

Hello, I know this is an old thread, but can someone help me with getting this work alongside renpy input. Whenever it gets to the naming screen it shows that an exception has occurred.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 96, in script
    $ mc = renpy.input("Please give her a name. Max 12 characters", default = "Clara", allow=" 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", length=12)
  File "game/script.rpy", line 96, in <module>
    $ mc = renpy.input("Please give her a name. Max 12 characters", default = "Clara", allow=" 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", length=12)
Exception: Could not find font u'OpenDyslexic-Regular.otf'.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 96, in script
    $ mc = renpy.input("Please give her a name. Max 12 characters", default = "Clara", allow=" 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", length=12)
  File "renpy/ast.py", line 928, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2245, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 96, in <module>
    $ mc = renpy.input("Please give her a name. Max 12 characters", default = "Clara", allow=" 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", length=12)
  File "renpy/exports.py", line 935, in input
    rv = renpy.ui.interact(mouse='prompt', type="input", roll_forward=roll_forward)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3325, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3839, in interact_core
    self.draw_screen(root_widget, fullscreen_video, (not fullscreen_video) or video_frame_drawn)
  File "renpy/display/core.py", line 2565, in draw_screen
    renpy.config.screen_height,
  File "render.pyx", line 492, in renpy.display.render.render_screen
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 826, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 826, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 826, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/screen.py", line 688, in render
    child = renpy.display.render.render(self.child, w, h, st, at)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 826, in render
    surf = render(child, width, height, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 1264, in render
    st, at)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/display/layout.py", line 1029, in render
    surf = render(d, width - x, rh, cst, cat)
  File "render.pyx", line 170, in renpy.display.render.render
  File "render.pyx", line 263, in renpy.display.render.render
  File "renpy/text/text.py", line 2096, in render
    virtual_layout = Layout(self, width, height, renders, drawable_res=False, size_only=True)
  File "renpy/text/text.py", line 639, in __init__
    glyphs = ts.glyphs(s, self)
  File "renpy/text/text.py", line 248, in glyphs
    fo = font.get_font(self.font, self.size, self.bold, self.italic, 0, self.antialias, self.vertical, self.hinting, layout.oversample)
  File "renpy/text/font.py", line 702, in get_font
    face = load_face(fn)
  File "renpy/text/font.py", line 643, in load_face
    raise Exception("Could not find font {0!r}.".format(orig_fn))
Exception: Could not find font u'OpenDyslexic-Regular.otf'.

Windows-10-10.0.19041
Ren'Py 7.4.11.2266
Memory Ghosts 0.1
Sat Feb 19 21:27:31 2022
I make things sometimes

Post Reply

Who is online

Users browsing this forum: No registered users