By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,221 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,221 IT Pros & Developers. It's quick & easy.

Creating a new font via tranformation

P: n/a
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

Nov 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

"k" <va***@wp.plwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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

Nov 2 '06 #2

P: n/a
k
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):
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.

"k" <va***@wp.plwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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
Nov 2 '06 #3

P: n/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.

k wrote:
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):
>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.

"k" <va***@wp.plwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
>>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
Jan 31 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.