-
Notifications
You must be signed in to change notification settings - Fork 124
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
Exception: WidthCannotBeNegative #173
Comments
What's the point of measuring 9.8 million characters? Do you want to write them all in a single line? |
In our implementation, the width from |
If the text length is more than e.g. 1000 characters, your code could (and IMHO should) start line-breaking without calling MeasureString. I don't think we should change MeasureString from "int" to "longint", as this would make the code slower. |
I agree - there's no point in changing |
With uint we risk having an undetected overflow at around 19 million characters. |
PDFsharp/src/foundation/src/PDFsharp/src/PdfSharp/Fonts.Internal/FontHelper.cs
Line 169 in 5fbf6ed
The integer
width
gets negative once the value ofwidth
tries to go above 2147483647 (i.e. maximum integer value).I have a string with a length of a little over 9.8 million characters and when I try to measure width for that string it throws following exception
Exception Message: WidthCannotBeNegative
Stack:
at PdfSharp.Fonts.Internal.FontHelper.MeasureString(CodePointGlyphIndexPair[] codeRun, XFont font) at PdfSharp.Drawing.XGraphics.MeasureString(String text, XFont font, XStringFormat stringFormat) at PdfSharp.Drawing.XGraphics.MeasureString(String text, XFont font)
The text was updated successfully, but these errors were encountered: