Skip to content

Bug fixes related to positioning and bounding box size #86

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

Merged
merged 13 commits into from
Aug 22, 2020

Conversation

kmatch98
Copy link
Contributor

@kmatch98 kmatch98 commented Aug 18, 2020

In doing testing of label.py and bitmap_label.py several minor issues are observed. This set of fixes brings these two files inline with the latest fixes and resolves a couple more issues, including issue: #78

Changes on both label.py and bitmap_label.py:

  1. Correct left- and right-side of bounding box (showed up only with slanted fonts):
    Problem: right side of background bounding box does not contain slanted typeface, left side is too far from text:
    IMG_6688
    After solution to correct bounding box:
    IMG_6692

  2. Correct y_offset by deleting impact of newlines (see issue y_offset should not include any impact due to newlines '\n' #78) that caused incorrect placement of text when trailing newlines \n were present.

Fixes on bitmap_label to bring it up to date with label:

  1. fix anchored_position rounding error
  2. add speedup with load_glyphs (in _text_bounding_box) including the error checking for BuiltinFont (builtin font does not have load_glyphs always #87)

…offset by deleting impact of newlines, bitmap_label: fix anchored_position rounding error, add speedup with load_glyphs
@kmatch98
Copy link
Contributor Author

kmatch98 commented Aug 19, 2020

Please wait for reviewing this further until I deal with another issue another placement issue that still need to be resolved.

Observed issue: When using a newline, "Hello\nworld." the anchor_position in the y-direction is not placed correctly.
I need to look again at the y-offset calculation based upon the number of lines. The same effect is observed on label and bitmap_label.

I also have some pylint issues to resolve.

@kattni
Copy link
Contributor

kattni commented Aug 19, 2020

@kmatch98 Please tag one of us directly when you're ready for review so this doesn't get lost! Thanks!

@kmatch98
Copy link
Contributor Author

kmatch98 commented Aug 20, 2020

@FoamyGuy and @kattni - This is ready for your review and testing.

I performed more testing and resolved a couple more bugs with positioning. Also, please note that I overrode some of the pylint messages.

Main things improved: anchored_position should work now even for slanted fonts

I performed testing on BuiltinFont (terminalio.FONT) and BDF-loaded font (Helvetica-16 and script Fayette). Also, I verified that anchored_position now works properly with the scale > 1.

One stylistic thing for consideration: The anchor_point is always referenced to the bounding_box of the text. Even if the background box is larger than the text (such as when background_tight = False and there is excess room for descenders, or if padding is used) the anchor_point is still referenced to the text boundaries. I agree this is the most intuitive way of defining anchored_position, since you usually want to make sure the text is lined up with something else on the screen. (I just found it a little disconcerting when setting

anchor_point=(1,1)
anchored_position=(display.width, display.height)

and saw the background hangs off the screen.)

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

I tested this out on PyPortal and Wio Terminal with a variety of the example scripts and a few others from recent issues. Everything appears to be working correctly

I also tested script fonts, and strings with newlines in them, both of them are working correctly after these fixes.

This looks good to me after the extra + sign is removed (If it is actually extra). I see it was removed while I was writing this

Thanks for working on these fixes @kmatch98

@kmatch98
Copy link
Contributor Author

Ok, now I'm getting a pylint error:

************* Module label
8
adafruit_display_text/label.py:359:12: W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)

This error is caused by line that raises the exception. This is strange because I didn't change any of this. Did something change in the .pylintrc requirements related to exceptions? I'm not familiar with the from statement. Any suggestions?

    @text.setter
    def text(self, new_text):
        try:
            current_anchored_position = self.anchored_position
            self._update_text(str(new_text))
            self.anchored_position = current_anchored_position
        except RuntimeError:
            raise RuntimeError("Text length exceeds max_glyphs")

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

This looks good to me now.

Thanks @kmatch98 for fighting through a few new pylint issues and all of the rest of these fixes!

@FoamyGuy
Copy link
Contributor

I tested a bit more this morning with a CLUE using some of the project scripts that we have recently had issues with and all everything is looking good.

I'm going to go ahead and merge this.

@FoamyGuy FoamyGuy merged commit 9d28b6c into adafruit:master Aug 22, 2020
@kmatch98
Copy link
Contributor Author

Awesome! Thanks for the help on this!

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 23, 2020
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.

3 participants