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

Added getTextBounds() optional arguments xF and yF. #430

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tedtoal
Copy link

@tedtoal tedtoal commented Jul 5, 2023

There are extensive comments in getTextBounds() header in the .cpp file.

The arguments are pointers to places to return values, just like several already-existing arguments to the function. They have default values of NULL, so that if they are not specified in the call, no value is returned for them. Therefore, no change is needed to existing code.

The change applies to all platforms. It has no known limitations.

The reason for this change has to do with the idiosyncrasies of the way the code writes character data to the device. That is accomplished by calling the device setCursor() function to set the position to be written, then calling the device print() function. However, there is no clear relationship between the initial cursor position that is set, and the upper-left (or lower-left) corner of the resulting text boundary box. This is because the font data is specified in a way that allows it to start either slightly left or right of the cursor position, and in addition, the cursor y-position is not necessarily the position of the bottom of the text string, but instead is the position of the text BASELINE, ignoring character DESCENDERS (as on "g" for example).

More directly, the reason for this is that a user of the code might want to JUSTIFY a string, left or right or centered, top or bottom or centered. This cannot be done with the code as it was. The new arguments provide additional information about the size of the text string, that allow it to be properly justified. Previously the function reported the correct string width and height, but it did not report the data needed to set the initial cursor position so that the string would appear where you wanted it.

I tried hard to put in clear comments in the header section of getTextBounds(), but this is such a baffling and obscure issue that I just had to do my best and leave it at that.

@tedtoal
Copy link
Author

tedtoal commented Jul 5, 2023

One other comment. I renamed the arguments (x1, y1) of getTextBounds() to (xL, yT), to make it clear these are the left and top coordinates of the bounding box.

@tedtoal
Copy link
Author

tedtoal commented Jul 8, 2023

Great, I hope you can incorporate the changes, thanks!

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.

None yet

1 participant