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

Check rendered string length #2692

Closed
nijel opened this issue Apr 17, 2019 · 2 comments
Closed

Check rendered string length #2692

nijel opened this issue Apr 17, 2019 · 2 comments
Assignees
Labels
enhancement Adding or requesting a new feature.
Milestone

Comments

@nijel
Copy link
Member

nijel commented Apr 17, 2019

Is your feature request related to a problem? Please describe.
Weblate already supports limiting text length by maxlength:N flag. However this is not good enough in some cases when the space is really limited and font rendering should be taken into consideration.

Describe the solution you'd like
Add a check which would render the text using defined font and check actual size of the rendered text.

This comes with some tricky pieces though:

  • Needs fonts, probably those could be managed in Weblate per project
    • There might be different fonts for different languages
  • Needs more parameters for check
    • Font name (or rather family defined in Weblate, see above)
    • Font size
    • Font weight
    • Kerning (optional)
    • Allowed width
    • Allowed number of lines (optional)
  • Pillow which we use for this in the widgets is probably not flexible enough, this will need Pango
  • Pango (contrary to Pillow) can not load directly font, needs first to tweak FONTCONFIG_PATH/FONTCONFIG_FILE to change fontconfig setup to find the fonts

Implementation details:

  • Font files management (4)
    • Per project
    • Upload TTF/OTF font, store file, parse font family and store it in the database (probably needs Pillow)
  • Virtual font (needs better name) (12)
    • Groups one or more fonts
    • Defines per language rules (eg. use this font for CJK languages)
  • Check (16)
    • Parses params
    • Loads correct font based on virtual font definition (needs custom fontconfig configuration)
    • Renders text using Pango and measures dimensions

Additional context
Possible renderer snippet: https://mail.python.org/pipermail/python-list/2008-December/494841.html, wrapping can be configured by https://developer.gnome.org/pygtk/stable/class-pangolayout.html#method-pangolayout--set-wrap


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@nijel nijel added the enhancement Adding or requesting a new feature. label Apr 17, 2019
@nijel nijel changed the title Limit rendered string length Check rendered string length Apr 17, 2019
@nijel nijel added this to the 3.7 milestone May 8, 2019
@nijel nijel mentioned this issue May 15, 2019
15 tasks
@nijel
Copy link
Member Author

nijel commented May 17, 2019

Video with feature preview: https://assets.saucelabs.com/jobs/f7ffe3753552478b8995521e41d6c74c/video.mp4

nijel added a commit that referenced this issue May 22, 2019
Issue #2692

Signed-off-by: Michal Čihař <michal@cihar.com>
nijel added a commit that referenced this issue May 22, 2019
This makes it easier to use flags in rest of the code. Thew new Flags
class mimic set for contains and boolean checks, allows direct access to
values and provides validation.

Issue #2692

Signed-off-by: Michal Čihař <michal@cihar.com>
@nijel nijel self-assigned this May 22, 2019
@nijel nijel closed this as completed in e9f3915 May 24, 2019
@nijel
Copy link
Member Author

nijel commented May 24, 2019

Thank you for your report, the issue you have reported has just been fixed.

  • In case you see problem with the fix, please comment on this issue.
  • In case you see similar problem, please open separate issue.
  • If you are happy with the outcome, consider supporting Weblate by donating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant