SyntaxEditor : CreateFixedDocument FontFamily/FontSize doesn't render

SyntaxEditor for WPF Forum

Posted 8 years ago by Mark Cunningham - Software Engineer, CNC Software, Inc.
Version: 15.1.0624
Avatar

We just found an issue with our implementation of CreateFixedDocument where the Font Family & Size doesn't render for a text document.

I debug and the LineNumberMarginFontFamily / Size are set in the editor when creating the fixed document.

       FixedDocument fixedDocument = editor.PrintSettings.CreateFixedDocument(editor);

This is just a text document from a syntax editor that has color and we allow the user to change the font / color.  The changes are rendered on screen before printing, but not in the printed output.

Can you point me in the right direction?

Thanks

-Mark

Mark Cunningham

Comments (7)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mark,

Yes the code for rendering printer views doesn't resolve to the SyntaxEditor properties like editor views do.  The main reason is that the app might be in a dark theme, which assume uses white text.  And if you set one of the SyntaxEditor-level properties, they would override the highlighting style registry that you'd use for printer views, which could lead to text not showing up in the printout (due to it being a white).  Thoughts?


Actipro Software Support

Posted 8 years ago by Mark Cunningham - Software Engineer, CNC Software, Inc.
Avatar

Yes, that makes sense.

Now, how do I set the font size and font family in a fixed document for printing?

For those that don't use Dark themes, this is needed.  Developers can write custom UI to handle those exceptions.

Thanks

Mark Cunningham

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mark,

If you change the line number margin with this sort of setting instead, it should affect both the editor and print views:

var lineNumbers = new DisplayItemClassificationTypeProvider().LineNumbers;
AmbientHighlightingStyleRegistry.Instance[lineNumbers].FontSize = 14;
AmbientHighlightingStyleRegistry.Instance[lineNumbers].FontFamilyName = "Verdana";


Actipro Software Support

Posted 8 years ago by Mark Cunningham - Software Engineer, CNC Software, Inc.
Avatar

Ah, i didn't think to change the Ambient registry, but that makes sense since it's the default.  I will try today.  I noticed a similar issue with Copy/Paste clipboard methods coming out in the default font. 

Thanks for the quick response.

Mark Cunningham

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

You could do similar things for PlainText too.


Actipro Software Support

Posted 8 years ago by Mark Cunningham - Software Engineer, CNC Software, Inc.
Avatar

Here's the code I added. 

//Stomp on the FontSize and FontFamily for creating the fixed print document, then reset afterwards.
foreach (var style in editor.HighlightingStyleRegistry.HighlightingStyles)
{
style.FontSize = editor.FontSize;
style.FontFamilyName = editor.FontFamily.Source;
}

// Create the print document
var fixedDocument = editor.PrintSettings.CreateFixedDocument(editor);

// Reset
foreach (var style in editor.HighlightingStyleRegistry.HighlightingStyles)
{
style.FontSize = 0;
style.FontFamilyName = null;
}

Mark Cunningham

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mark,

If you look at the "SyntaxEditor / User Interface Features / Printing Features / Print Options" topic, there is a section in there about how you can make a special highlighting style registry just for printouts.  Then it wouldn't affect your other editors as how you are doing.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.