It would be great if this method worked with mixed fonts/styling.
Unfortunately not possible since PDFKit is an immediate mode API: text is written to the PDF immediately upon calling the text method. PDFKit has no way of knowing what text/styles will come next.
I must be misunderstanding something about how this works. This is what it looks like to me:
heightOfString calls _text. _text doesn't actually draw it just calculates where the lines would be drawn and passes the result on back with lineCallback. heightOfString passes in a closure that just updates the lineHeight of the whole operation line by line. text passes in a closure for lineCallback that actually draws the text.
So if heightOfString is only doing measurements, and not actually drawing anything, then why does it matter if it's an immediate mode API. heightOfString shouldn't be writing anything to the PDF.
I need to be able to measure the a block of mixed text and I don't see any way to do it without using private APIs, or doing all of the wrapping myself.
Most helpful comment
I must be misunderstanding something about how this works. This is what it looks like to me:
heightOfString calls _text. _text doesn't actually draw it just calculates where the lines would be drawn and passes the result on back with lineCallback. heightOfString passes in a closure that just updates the lineHeight of the whole operation line by line. text passes in a closure for lineCallback that actually draws the text.
So if heightOfString is only doing measurements, and not actually drawing anything, then why does it matter if it's an immediate mode API. heightOfString shouldn't be writing anything to the PDF.
I need to be able to measure the a block of mixed text and I don't see any way to do it without using private APIs, or doing all of the wrapping myself.