-
Notifications
You must be signed in to change notification settings - Fork 550
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 calculateTextWidth function to Font #517
Conversation
311ed58
to
538708a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for another pull request @shtayerc!
I have one question regarding $missing
parameter. I don't like the current approach, because $missing
seems to be an array but is outlined as a non-typed variable. Furthermore having a parameter which contains additional data and is given by reference might lead to undefined/unexpected behavior. What if inside the for-loop an index reference is not set? How reliable is $missing
in such situations?
@k00ni If you prefer to not use parameter by reference, it could be done without reference by returning array, for example: [
'width' => 123,
'missing' => ['a', 'b']
] |
Can we assume that all calls using an array-index inside the function are succeed (meaning all keys we wanna access are set)? Related variables are |
538708a
to
c2f801f
Compare
I am not sure, both arrays are read from pdf file. I added check for all indexes. |
Thanks, this way we can be sure that an index is always set before accessing it. Thinking about the return value, we should keep float as return value. But is it semantically correct to assume that the width is a float equal or higher than 0? I am not sure here, maybe PDF specification is more clear. What do you think about setting |
91726cb
to
c33a4b5
Compare
|
We should be in line with the PDF specification here, even though other functions do this differently. Can you paste the part of the specification where you found this information, please? Also change return value from float to integer. |
Both specs were found here
In examples of Widths array in the same pdf there are only intergers. Because reals should be written only in decimal format I assumed that Widths are integers. But in PDF 1.7 spec chapter 3.2.2
But here it says that reals can be written without decimal part. I only checked spec 1.0 before. |
Thank you! OK, lets keep float. |
I merged #513, can you add a basic example in https://github.com/smalot/pdfparser/blob/master/doc/Usage.md how to use this new function, please? |
Character width is read from font details field 'Widths'.
c33a4b5
to
769e594
Compare
I added basic example |
I extended your example a bit. I wanna make sure I understand the meaning of this function: You call it with a text part (which must be in the PDF?) and a variable (in which any characters are stored, which have no width). It tries to find the width for the whole text part? |
Yes, it is close to what you said. Text part must be written in font from which you call the function - otherwise it is missing. Preferably it should be used with |
If you think that is important, please add a hint and/or example to the usage passage. Both of your PRs will be merged so it doesn't matter in which you do this. That will help users and avoid confusion. Thank you for your time and effort btw. |
@shtayerc, can you give me a short status info about remaining tasks here? Thanks! |
@k00ni I think everything is done. Example usage with dataTm was added in previous PR (at the end of this section) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for getting back to me so fast.
PR looks good. I will leave it open until end of this week. If there are no objections or comments, it will be merged next week.
Character width is read from font details field 'Widths'.