bghull / quizmaker

A workflow automation tool for the creation of pub trivia slide decks.
https://vml.pythonanywhere.com
GNU General Public License v3.0
0 stars 0 forks source link

Text auto-sizing does not work #3

Open bghull opened 3 years ago

bghull commented 3 years ago
2021-08-17 13:12:59,101: Exception on /download [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2051, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1501, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1499, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1485, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/vml/mysite/flask_app.py", line 29, in convert
    quiz = quizmaker.build_quiz(HOMEDIR / "static/pptx_template.pptx", HOMEDIR / "uploads" / filename)
  File "/home/vml/mysite/quizmaker.py", line 83, in build_quiz
    build_normal_round(prs, 1, all_data)
  File "/home/vml/mysite/quizmaker.py", line 36, in build_normal_round
    start_round(prs, number, data)
  File "/home/vml/mysite/quizmaker.py", line 30, in start_round
    slide.placeholders[11].text_frame.fit_text(max_size=28)
  File "/usr/local/lib/python3.8/dist-packages/pptx/text/text.py", line 88, in fit_text
    font_size = self._best_fit_font_size(
  File "/usr/local/lib/python3.8/dist-packages/pptx/text/text.py", line 242, in _best_fit_font_size
    font_file = FontFiles.find(family, bold, italic)
  File "/usr/local/lib/python3.8/dist-packages/pptx/text/fonts.py", line 31, in find
    cls._font_files = cls._installed_fonts()
  File "/usr/local/lib/python3.8/dist-packages/pptx/text/fonts.py", line 42, in _installed_fonts
    for d in cls._font_directories():
  File "/usr/local/lib/python3.8/dist-packages/pptx/text/fonts.py", line 57, in _font_directories
    raise OSError("unsupported operating system")
OSError: unsupported operating system
bghull commented 3 years ago

This seems to work, which at least tells me this is just a question of font files:

text_frame.fit_text(font_family=u"Roboto", max_size=60, font_file="~/.fonts/Roboto-Medium.ttf")

bghull commented 3 years ago

It appears the text-fitting function fails when a single word is too long to fit into the text box placeholder at max_size, and I can't manage to catch the error in a try-except loop for some reason.

My next thought is a two-birds-with-one-stone thing: there appears to be documented support for text resizing in the Google Slides API, so maybe solving the "auto-upload to Google storage instead of downloading a .pptx" would fix both of these issues. (Of course at this point I would consider a rewrite of the entire script to just use Google Slides natively everywhere...)