Vertical and Angled Text

G

Guest

I write software that needs to draw simple engineering drawings for factory
workers to read.

A standard for drawings is to be able to read the text from the bottom right
corner.
The GDI defaults vertical text to be readable from the left side of the page
(upside down). It seems from the news group that many people are having
problems with this.

Additionally we have the need to be able to draw text along an angled line,
we have been able to do this for the last 30 years on Plotters, Laser
printers, Postscript printers, Non-Microsoft Graphic screens, Printer
plotters and our own bit map printer support.

I think it is about time we could draw text directly at any angle from 0 to
360 degress it in the Windows GDI.

Is it possible to do this now and if not how about making it possible ?
 
C

Cor Ligthert

Philip,

Did you know that this is a typical question for the newsgroup

microsoft.public.dotnet.framework.drawing

Cor
 
G

Guest

Thanks Cor but I could only find one item in there about this, it was also in
the managed section and had to do with rounding the inches position. I had
already looked through the managed news group as well, most were more related
to controls or using bit maps to get around the problem. This is a fairly
fundemental issue of what can be drawn to a device, it should be supported
directly in the GDI and I am surprised that it is not, when non-Microsoft
inplementors of printers etc.. include this as standard fair. I can get
around it by drawing into a bitmap or metadata and including that in my
drawing but this should not be needed. It should be possible to draw such
basic stuff from the GDI and I am surprised that the GDI does not support
this directly. I was hopeing it was there or to prompt MS to add it.
 
G

Guest

I have done this to work around it in C# GDI+ but I should not have to do
this.
(It ignores Graphics scaling and it makes little bitmaps for the text)

/// <summary>
/// Assumes the graphics device is operating in GraphicsUnit.Pixels.
/// </summary>
/// <param name="strText">The text string to write.</param>
/// <param name="font">The font to be used for this text.</param>
/// <param name="brush">The brush to be used for this text.</param>
/// <param name="fX">The X coordinate in pixels.</param>
/// <param name="fY">The Y coordinate in pixels.</param>
/// <param name="orientation">ReadFromLHSPage or ReadFromRHSPage</param>
public void DrawVertText(String strText, Font font, Brush brush, float
fX, float fY, VTextROrientation orientation)
{
StringFormat strf = new
StringFormat(StringFormatFlags.DirectionVertical);

//
// No translation
//
if( orientation == VTextROrientation.ReadFromLHSPage )
{
graph.DrawString(strText, font, brush, fX, fY, strf);
}
else if( orientation == VTextROrientation.ReadFromRHSPage )
{
//
// Get size of drawn text in Pixels
//
SizeF sizeText = graph.MeasureString(strText, font, 2000, strf);
int width = Convert.ToInt32(sizeText.Width);
int height = Convert.ToInt32(sizeText.Height);

//
// Make a bitmap make it transparent (uses white as transparency
color !)
// draw the string in it
// then flip that image.
//
Bitmap bmp = new Bitmap(width , height);
bmp.MakeTransparent(Color.White);
Graphics grfBmp = Graphics.FromImage( bmp );
grfBmp.DrawString(strText, font, brush, 0, 0, strf);
bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);

//
// Draw the bitmap into the page.
//
Rectangle rect = new Rectangle(Convert.ToInt32(fX),
Convert.ToInt32(fY),
Convert.ToInt32(sizeText.Width),
Convert.ToInt32(sizeText.Height) );
graph.DrawImage(bmp, rect, 0, 0, width , height,
GraphicsUnit.Pixel);
}
}
 

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

Top