question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Printing from WPF is leaving random small spaces in the text when using Arial or Calibri fonts

See original GitHub issue

Description

When printing in WPF, the graphics engine is inserting small spaces within words. For instance, the French word ‘fonctions’ is printed either as ‘fonction s’ or ‘fo nctions’ depending on where the word appears within the other text.

Reproduction Steps

public void PrintItAll()
        {
            var printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                var fontFamily = new FontFamily("Arial");
                var printme = new TextBlock {
                    FontSize = 11, FontFamily = fontFamily, Width = 800, TextWrapping = TextWrapping.Wrap,
                    Text = "L'autre personne était incapable de prendre soin des enfants en raison d'une déficience des fonctions physiques ou mentales qui l'a obligée, durant une période d'au moins deux semaines, à garder le lit, à se déplacer en fauteuil roulant ou à recevoir des soins dans un hôpital ou un établissement semblable. Joignez un certificat du médecin traitant qui confirme la nature et la durée de la déficience."
                };
                printDialog.PrintVisual(printme, "Test Print");
            }
        }

Reproduction repository: https://github.com/campeters/Wpf-Print-Font-Issue

Expected behavior

The text should print correctly without extra spaces.

Actual behavior

The following file shows a space between ‘fonction’ and the ‘s’. It should be a single french word ‘fonctions’

Test Print.pdf

Regression?

This code works correctly in dot net framework and it also seems to work correctly in .net 5.

Known Workarounds

None.

Impact

This bug impacts the quality of PDF and print files generated from WPF programs using the ‘Arial’ or ‘Calibri’ fonts. Some fonts work correctly. However, the filing of some government forms require that only ‘Arial’ be used.

Configuration

This bug occurs in .net 6, confirmed in 6.0.11 and 6.0.13 and .net 7. It does not appear to be specific to the configuration. It happens on Windows 10 and Windows 11.

The exact same code works correctly in .net framework 4.8.1

Other information

No response

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
campeterscommented, Feb 13, 2023

@miloush / @dipeshmsft - I’ve reviewed this in more detail and the advanceErrorRounding is not the root of the problem. Somewhere upstream of the GlyphSerializer (maybe the DrawingContextFlattener), the GlyphRuns are separated into groups of no more than 100 characters. Within the 100 character glyph run, the spacing is correct. However, when the drawing caret is advanced to start the next 100 character glyph run, the error correction is not taken into account, leaving an extra space (or possibly two characters squished together). I’m going to look further, but if you have some idea where in the code the glyph runs are separated we could correct the root cause of this issue.

1reaction
dipeshmsftcommented, Feb 8, 2023

I can find a sample repo for this issue. I will get back to you with the sample application.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compact Printing Toggle (margins, font size, spacing, ...
When I print (in Windows App) it has huge spacing between tasks, large margins, and the font size is big. So much white...
Read more >
WPF scale text to fit only when too big
I am trying to setup a list of items in WPF which contains strings of random length (people's names). The majority of them...
Read more >
Calibri fonts not printing correctly
When using a PostScript driver to print text in Calibri, the driver substitutes it for one of the printer-resident fonts that is a...
Read more >
PostScript fonts
PostScript fonts are font files encoded in outline font specifications developed by Adobe Systems for professional digital typesetting.
Read more >
Printing problem when PDF is sent to the printer ...
I'm running into a printing problem when PDFs containing certain characters of the Calibri font are used. The text in large sections of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found