Creating a new font via tranformation

  • Thread starter Thread starter k
  • Start date Start date
K

k

Hi,

I'm trying to migrate from Java to C# and have encountered a problem.

I can't seem to find a way to create (ultra)condensed fonts for later
use in a program. In Java I had a really nice method
some_font.deriveFont(AffineTransform), which would return a new font.
(AffineTransform was just a simple 3x3 matrix)

I'll be most grateful for the help.

Regards,
Karol
 
This method doesn't exist for .NET fonts. You can create a font with a
specific point size but these may be grid-fitted so the quality will go down
pretty quickly below 8 points.

If you want to draw really tiny fonts with the benefit of some antialiasing
you can use a matrix to shange the drawing scale but you will need to treat
fonts and drawing objects differently.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Thank you for your fast response.

A word of explanation: I don't need to use tiny fonts but very narrow
ones (e.g. Courier new 12, with 40% of the original width) for printing
reports.

I'm now trying to transform the Graphics object. It works, but the
quality is very poor. Here is a sample code:

private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
Font fo = new Font("Courier new", 12, FontStyle.Regular););
SolidBrush br = new SolidBrush(Color.Black);
e.Graphics.ScaleTransform(0.4f, 1f);
e.Graphics.DrawString("N", fo, br, 30, 30);
e.HasMorePages = false;
}

The difference in quality of a print with and without the
transformation is very noticeable - I can provide samples if
required.

I've tried
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
before drawing the string but without visible results.

Regards,
Karol





Bob Powell [MVP] napisal(a):
 
The trouble is, in a case such as this, that the fonts are constructed
at 100% size yet the placement of the pixels in the font is affected by
the transform.

The use of the cleartype antialiasing method will work on the local font
data but the pixels will be displaced according to the transform and so
will look as horrible as before.

The only thing I can suggest is that low-level construction of the font
via interop and the use of a logfont may give you the control you seek
but it won't include cleartype so you'll be stuck with the lower quality
aliased glyphs.

In other words, no net gain.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top