PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Oct 22, 2017 3:29 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Jan 04, 2016 12:15 am 
Offline

Joined: Sat Mar 23, 2013 11:48 pm
Posts: 11
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2016 1:18 am 
Offline

Joined: Sat Mar 23, 2013 11:48 pm
Posts: 11
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)).


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 04, 2016 1:35 am 
Offline

Joined: Sat Mar 23, 2013 11:48 pm
Posts: 11
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 08, 2016 3:05 am 
Offline

Joined: Sat Mar 23, 2013 11:48 pm
Posts: 11
Would standalone repros help here?


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 09, 2016 7:13 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 287
Location: CCAA
inexorabletash wrote:
Would standalone repros help here?
Yes.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 09, 2016 9:21 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2720
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 02, 2016 12:20 pm 
Offline

Joined: Tue Aug 02, 2016 12:13 pm
Posts: 1
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;
}


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 06, 2016 9:32 pm 
Offline

Joined: Sat Mar 23, 2013 11:48 pm
Posts: 11
Thanks for tracking this down!


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 16, 2016 11:07 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2720
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group