473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Creating a new font via tranformation

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
3 3308
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
1
by: Tomislav Jakopec | last post by:
Hi to all! I have one (or more) problem. I set up a system to provide web access to legacy application. Legacy application run at RISC mashine, web server is tomcat an linux. Response time is...
12
by: enak | last post by:
I have found some code that shows how to convert an html form to Word. The message said to simply put the following in the Page_load: Response.ContentType = "application/ms-word"...
2
by: Zyrthofar Blackcloak | last post by:
Hello everyone! I just wanted to know how I can create a font from bitmaps in memory (currently in an array), or from GDI+. I want to be able to use that font in a textbox, for example. I have...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
11
by: Michael7 | last post by:
Hi everyone, Me again, been a while since I've been here, but I'm back again needing help with a simple thing. I've searched for help on creating a footer, but all the help I've found, was...
2
by: uamusa | last post by:
I am Dynamically generating a proposal(report) in MS Word. By default the Paragraph Alignment is "Left". For the First 6 Paragraphs I set the Alignment to "Center", and then when attempting to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.