Skip to content

initial Commit for draft Bitmap Label directional label #145

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
Mar 28, 2021
Merged

initial Commit for draft Bitmap Label directional label #145

merged 13 commits into from
Mar 28, 2021

Conversation

jposada202020
Copy link
Contributor

@kmatch98 I will need your help here, as under the hood labels are different, If we want to implement directional label for the bitmaplabel, we need to do a different approach as we do not have the same tools, what would you recommend? do we need a rotation matrix, we need do -1 and also a rotation.

Thanks 🧑‍🔬

@kmatch98
Copy link
Contributor

Probably the simplest approach is to generate the bitmap_label bitmap as usual and then do some transformation into the final bitmap.

Here are two approaches I can think of:

  1. Use the bitmaptools.rotozoom function to do a rotational "blit" into a new bitmap. (This function can do any angle you want.) You will need to calculate the size of the final "rotated" bitmap before you perform the "rotozoom" into it. If you are only allowing 90 degree increments, the the bitmap size calculation is easy. One downside is there could be some integer rounding errors that could make the final result not match the original bitmap.

  2. Write a bitmap transformation function to do the 90 degree angles. Since you are only doing 90 degree angles it is much simpler math to calculate each pixel's position. And you can write this (to avoid rounding erros) to ensure the rotated bitmap exactly matches the original.

If you want to get more complex, you could modify the character-by-character blitting function and then adjust the rotation and position of each character individually. This more complex approach would probably use the lowest amount of RAM during the process, since you won't need two bitmaps (like #1 and #2 above).

Let me know your thoughts or if you'd like other suggestions.

@kmatch98
Copy link
Contributor

kmatch98 commented Mar 19, 2021

Oh! I just remembered that TileGrid has a rotation function. Since the bitmap_label is in a TileGrid, it's probably easiest to just manipulate that.

@jposada202020 jposada202020 added enhancement New feature or request help wanted Extra attention is needed labels Mar 19, 2021
@jposada202020 jposada202020 marked this pull request as draft March 19, 2021 04:14
@jposada202020
Copy link
Contributor Author

@kmatch98 Thanks for the info.
For the RTL (Right-to-Left) text and TTB Top-To-Bottom I think I will use the same approach that I used in label. You could used in release 2.17.0
I think that for text upwards and downwards text I will explore the rotozoom option as you mentioned. I just want to preserve the memory efficiency and speed of the bitmap_label and I did not wanted to do a "Tilegrid" conversion, as this is in every glyph and the the bitmap one. Thanks for pointing me in the right direction you saved me a lot of time :).
But I think it will be a win if at least people will have the Upwards and Downwards feature not too slow.
Thanks

@jposada202020 jposada202020 self-assigned this Mar 19, 2021
@jposada202020
Copy link
Contributor Author

Four directions are implemented here similar to label:

  • RTL
  • LTR
  • DWR
  • UPR

I am not seeing an easy way to implement TTB, so I think is better to maintain the memory efficiency and if people need text from top to bottom they can use label. Still having problems when anchoring positions, I try to troubleshoot a little but with no luck. I tried version 2.14 of the library and bitmap_label anchor characteristics were working. #140 . I am guessing that we are having problems in the setter, because we are receiving a None as a anchor_position.

image

@kmatch98 thanks for the suggestions, as you can see it make this a lot easier.

@jposada202020 jposada202020 marked this pull request as ready for review March 20, 2021 02:47
@jposada202020 jposada202020 removed the help wanted Extra attention is needed label Mar 23, 2021
@kmatch98
Copy link
Contributor

I evaluated this and it works as expected.

Right now you are using a different method to achieve left-to-right "LTR" versus the other options.
I recommend doing all of the transformation using just the tilegrid options (flip_x, flip_y and transpose_xy).

You can achieve "LTR" with self.tilegrid.flip_x=True.
Also, if you want to achieve upside down, you can use self.tilegrid.flip_x = self.tilegrid.flip_y = True.

Otherwise, it looks good to me.

@jposada202020
Copy link
Contributor Author

@kmatch98 Thank you for the review, as previously mentioned thanks again for point me in the right direction, it was a breeze compared to do the same feature in label after your indications.
Regarding the LTR, just to verify that I am understanding correctly, when you said flip_x I think that is more related to "RTL" that I used a string method. If so there is a difference in this

PA flip_x = Aꟼ
PA "".join(reversed(PA)) = AP

For RTL languages we write normal just in the Left-to-right direction, and not mirroring the letters, that is why methods are different.
Could you confirm your confirm that I am understanding correctly.

For the downwards, thank it was something that I discover when doing the PR, I was considering adding, but label does not have it, that is why I did not include it.

@kmatch98
Copy link
Contributor

Sorry that was a typo. You are right that it is RTL. Keep up the good work. When you are ready I will take another look.

@jposada202020
Copy link
Contributor Author

@kmatch98 what a ride :). As of you just a single little tiny, small tiny little space..... lol and a rabbit whole , anyway I include the UPD -Upside Down. Thanks.

@FoamyGuy
Copy link
Contributor

I think we need to move this check for valid direction out of LabelBase and put it into each of the subclasses since they have slightly different options with UPD and TTL.

https://github.com/jposada202020/Adafruit_CircuitPython_Display_Text/blob/69909e75f3451fa1aa2730c635f95aaafaa5db79/adafruit_display_text/__init__.py#L239

I tried making an upside down label like this

text_area = bitmap_label.Label(terminalio.FONT, text=text, label_direction="UPD")

but I got this error:

code.py output:
Traceback (most recent call last):
  File "code.py", line 10, in <module>
  File "/lib/adafruit_display_text/bitmap_label.py", line 91, in __init__
  File "/lib/adafruit_display_text/__init__.py", line 239, in __init__
RuntimeError: Please provide a valid text direction

@jposada202020
Copy link
Contributor Author

@FoamyGuy good point thank you for reviewing, I'll fix that, Thanks

Deleting duplicate in exampl.rst file
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.

Looks good to me thanks for all of your work on this @jposada202020

@FoamyGuy FoamyGuy merged commit 1da9501 into adafruit:master Mar 28, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 29, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_EMC2101 to 1.1.6 from 1.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_EMC2101#13 from dhalbert/setup-packages

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.18.1 from 2.17.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#147 from jposada202020/api_example
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#145 from jposada202020/master
  > "Increase duplicate code check threshold "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants