PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 2:22 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Jul 07, 2009 12:32 am 
Offline

Joined: Tue Jul 07, 2009 12:17 am
Posts: 6
XGraphics.MeasureString() uses a FormattedText object to measure string width. This is expensive because the FormattedText creates a drawing context underneath the scenes, for any unique text string that gets drawn. A better method is to use the GlyphTypeface method, such a what this blog entry does:

http://incrediblejourneysintotheknown.b ... forth.html

When rendering many pages, this performance is improved significantly by using the following code fix in XGraphics.cs (3213):

#if WPF && !GDI
/* OLD CODE:

FormattedText formattedText = new FormattedText(text, new CultureInfo("en-us"),
FlowDirection.LeftToRight, font.typeface, font.Height, System.Windows.Media.Brushes.Black);
return new XSize(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
* */

GlyphTypeface gTypeface;
if (!font.typeface.TryGetGlyphTypeface(out gTypeface))
throw new InvalidOperationException("No glyphtypeface found");
ushort[] glyphIndexes = new ushort[text.Length];
double[] advanceWidths = new double[text.Length];
double totalWidth = 0;
for (int n = 0; n < text.Length; n++)
{
ushort glyphIndex = gTypeface.CharacterToGlyphMap[text[n]];
glyphIndexes[n] = glyphIndex;

double width = gTypeface.AdvanceWidths[glyphIndex] * font.Size;
advanceWidths[n] = width;
totalWidth += width;
}
return new XSize(totalWidth, gTypeface.Height * font.Size);
#endif


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 07, 2009 12:33 am 
Offline

Joined: Tue Jul 07, 2009 12:17 am
Posts: 6
Also - the glyph typeface code is the key to implementing custom kerning... :wink:


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 13, 2009 9:14 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3092
Location: Cologne, Germany
Thank you for the feedback.

This is not my area of expertise, but I put it on the internal TODO list for the next release.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 22, 2013 9:34 pm 
Offline

Joined: Tue Jul 07, 2009 12:17 am
Posts: 6
I looked at the latest version of PdfSharp, and this fix is still not in the code. What can we do to put this fix into the source?


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2015 4:09 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3092
Location: Cologne, Germany
As of PDFsharp 1.50 beta 2, XGraphics.MeasureString() no longer uses a FormattedText object to measure strings.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group