PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

1.50 - text cut off after newline, offset introduced
https://forum.pdfsharp.net/viewtopic.php?f=3&t=3259
Page 1 of 1

Author:  inexorabletash [ Mon Jan 04, 2016 12:15 am ]
Post subject:  1.50 - text cut off after newline, offset introduced

Two separate issues and I don't have minimal repros. If they don't sound familiar I'll try and reduce them.

GDI+ API, rendering to bitmap (under ASP.NET, not desktop app):

Here's the pre-1.50 (correct) output:

Image

Here's a render, code unchanged, against 1.50:

Image

Note the string "Zhodani\nConsulate" is now truncated at the newline.

Now if I reload the page (i.e. render again, without restarting the process) I get this:

Image

Note that the other text is now offset as if rendered centered vs. top-left. If I restart the process (e.g. rebuild) then the odd offsets reset. The offsets don't accumulate; it's either present or not.

Author:  inexorabletash [ Mon Jan 04, 2016 1:18 am ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

inexorabletash wrote:
Note the string "Zhodani\nConsulate" is now truncated at the newline.

This appears to be due to the new logic in FontHelper.MeasureString() which does not handle newlines:

https://github.com/empira/PDFsharp/blob ... per.cs#L70

Note "// HACK: Unclear what to do here." when ch < 32.

Previously, native support for measuring was used. For compatibility, this should probably split on newlines and return (max(widths), sum(heights)).

Author:  inexorabletash [ Mon Jan 04, 2016 1:35 am ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

inexorabletash wrote:
Note that the other text is now offset as if rendered centered vs. top-left. If I restart the process (e.g. rebuild) then the odd offsets reset. The offsets don't accumulate; it's either present or not.


This appears to be because I was saving XStringFormat instances - see viewtopic.php?f=3&t=2403 - rather than using the accessors that mint new instances in XStringFormats:

i.e. instead of this:
Code:
            g.DrawString(glyph.Characters, font, brush, x, y, XStringFormats.Center);


I was doing this:
Code:
            g.DrawString(glyph.Characters, font, brush, x, y, StringFormatCentered);

//...

        private static XStringFormat CreateStringFormat(XStringAlignment alignment, XLineAlignment
lineAlignment)
        {
            XStringFormat format = new XStringFormat();
            format.Alignment = alignment;
            format.LineAlignment = lineAlignment;
            return format;
        }

        public static XStringFormat StringFormatCentered { get { return centeredFormat; } }
        private static readonly XStringFormat centeredFormat = CreateStringFormat(XStringAlignment.
Center, XLineAlignment.Center);


So something in 1.50 changed how "saved" XStringFormat instances behave when used for different rendering passes.

Author:  inexorabletash [ Tue Mar 08, 2016 3:05 am ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

Would standalone repros help here?

Author:  TH-Soft [ Wed Mar 09, 2016 7:13 am ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

inexorabletash wrote:
Would standalone repros help here?
Yes.

Author:  Thomas Hoevel [ Wed Mar 09, 2016 9:21 am ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

Hi!

PDFsharp 1.50 no longer supports line breaks in strings, so you have to handle that in your code.

The offset is an issue that might be worth investigation. I was not able to replicate that problem creating PDF files.
If you can provide standalone repros for the Bitmap case then we'll have a look.

Author:  woehrl01 [ Tue Aug 02, 2016 12:20 pm ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

hi there, I had the same issue and found the root cause:

its in in
Code:
internal StringFormat RealizeGdiStringFormat()
as
Code:
StringFormat.GenericTypographic
is a global instance you override the alignment for all the next alignments no matter what.

you need to change this into using
Code:
.Clone()


I use the following code to fix it from "the outside". This method is called before and after any call to MeasureString / DrawString
Code:
public static void RestGenericTypographic()
{
     var format = StringFormat.GenericTypographic;
     format.Alignment = StringAlignment.Near;
     format.LineAlignment = StringAlignment.Near;
     format.FormatFlags = StringFormatFlags.NoClip | StringFormatFlags.FitBlackBox | StringFormatFlags.LineLimit;
}

Author:  inexorabletash [ Sat Aug 06, 2016 9:32 pm ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

Thanks for tracking this down!

Author:  Thomas Hoevel [ Tue Aug 16, 2016 11:07 am ]
Post subject:  Re: 1.50 - text cut off after newline, offset introduced

woehrl01 wrote:
hi there, I had the same issue and found the root cause
Thanks for the feedback.

I added ".Clone()" to the current internal build:
Code:
_stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();


I don't have test code to replicate the issue so I trust you that this fixes the problem.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/