-
Notifications
You must be signed in to change notification settings - Fork 130
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
MeasureString error #198
Comments
Cannot replicate. Consider using the IssueSubmissionTemplate to allow us to replicate the issue.
Maybe you have to make the rectangle larger to account for rounding errors, because My code above draws both lines of text. |
I tested using the IssueSubmissionTemplate and was able to reproduce the issue when FailsafeFontResolver isn’t used. Since I’m working on a web server, this functionality isn’t available.
I can use font.GetHeight(), which returns the correct measurement.
Thank you for your insights.
De: ThomasHoevel ***@***.***>
Enviado el: miércoles, 30 de octubre de 2024 8:41
Para: empira/PDFsharp ***@***.***>
CC: carlos-FG ***@***.***>; Author ***@***.***>
Asunto: Re: [empira/PDFsharp] MeasureString error (Issue #198)
Cannot replicate. Consider using the IssueSubmissionTemplate to allow us to replicate the issue.
XTextFormatter uses font.GetHeight() internally. That gives me the same value I also get from MeasureString.
image.png (view on web) <https://github.com/user-attachments/assets/362722d2-a356-47a4-9438-570c4368c536>
Maybe you have to make the rectangle larger to account for rounding errors, because 5 * x may give a different value than x + x + x + x + x.
|
I can confirm that |
When obtaining the height of a text using MeasureString and using it as the height for an XTextFormatter with multiple lines of text, the last line does not appear. Comparing with version 1.3 of PDFsharp, I found that the measurement returned by version 6 is smaller.
XFont font = new XFont("Arial", 20, XFontStyleEx.Regular);
XTextFormatter tx = new XTextFormatter(gfx);
double textHeight = gfx.MeasureString("hello", font).Height;
// two-line text
string text = "hello\nworld";
// 2 lines height
textHeight *=2;
tx.DrawString(text, font, XBrushes.Black, new XRect(200, 200, 50, textHeight), XStringFormats.TopLeft);
The text was updated successfully, but these errors were encountered: