I'd like to print text using a monospace font, 80 character wide, 66 characters tall. The goal is to mimic sending raw text to an impact printer.
Here's some code:
public void Print(string printerName, string text, string desc = "")
{
PrintDialog dialog = new PrintDialog();
PrintQueue queue = new LocalPrintServer().GetPrintQueue(printerName);
dialog.PrintQueue = queue;
PageImageableArea area = queue.GetPrintCapabilities(dialog.PrintTicket).PageImageableArea;
TextBlock block = new TextBlock();
block.FontFamily = new FontFamily("Courier New");
block.Margin = new Thickness(area.OriginWidth, area.OriginHeight, area.OriginWidth, area.OriginHeight);
block.FontSize = ???
block.Text = text;
block.Measure(new Size(area.ExtentWidth, area.ExtentHeight));
block.Arrange(new Rect(new Point(0, 0), block.DesiredSize));
dialog.PrintVisual(block, desc);
}
It's my understanding that PageImageableArea gives me area.ExtentWidth
and area.ExtentHeight
which are my actual printing dimensions (in pixels), and area.OriginWidth
and area.OriginHeight
which are the size of my margins (in pixels).
If I want to fit exactly 80 characters across the page, each character should be area.ExtentWidth / 80
wide, in pixels. The area.ExtentWidth
of my printer is 768, so each character should be 9.6 pixels wide.
Additionally, if I want to fit exactly 66 lines on my page, each line should be area.ExtentHeight / 66
tall, in pixels. The area.ExtentHeight
of my printer is 1038.66, so each line should be 15.7 pixels tall.
Using these inputs, how do I choose a FontSize where each character is X pixels wide, and, when wrapped, causes each line to be Y pixels tall?