vinaynahata
August 1st, 2007, 07:21 AM
Hi all
I have written a simple application to create an enhanced meta file that uses DrawDriverString method to render a text however it doesn't take any parameter as the starting position but still it shows me the text at a particular place in the user space which itconsiders as the origin.My question is what transformation led to this origin.The parameters DrawDriverString method takes is the glyphcount and glyphpositions,flag(in my case i am using it as '1' which means it takes rendering position from a lookup tables as mentioned in msdn though i am not sure what this CMapLookUp is all about neither i have used it in my application).
The code looks like:
void CStartingGDIPlusDlg::OnPaint()
{
using namespace Gdiplus;
CPaintDC dc(this);
Metafile metafile(L"c:\\myMetafile.emf",dc);
{
Graphics graphics(&metafile);
Pen greenPen(Color(255, 0, 255, 0));
SolidBrush solidBrush(Color(255, 0, 0, 255));
FontFamily myfontFamily(L"Century");
Font myfont(&myfontFamily, 12, FontStyleRegular, UnitPixel);
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
graphics.DrawString(L"Smooth Text", 11, &myfont,PointF(0.0f, -19.0f),
&solidBrush);
const Color color(255,0,0,255);
SolidBrush brush(color);
Brush *mybrush;
mybrush=&brush;
PointF positions[6];
positions[0].X=0.0f;
positions[1].X=30.0f;
positions[2].X=20.0f;
positions[3].X=40.0f;
positions[4].X=60.0f;
positions[5].X=70.0f;
positions[0].Y=0.0f;
positions[1].Y=20.0f;
positions[2].Y=30.0f;
positions[3].Y=50.0f;
positions[4].Y=60.0f;
positions[5].Y=70.0f;
PointF position(25.0f,25.0f);
Matrix mat(1.0,0.0,0.0,1.0,0,0);
UINT16 text[]={65,66,67,67,65,78};
graphics.DrawDriverString(text,6,&myfont,&solidBrush,positions,1,&mat);
RectF box(0.0f,0.0f,0.0f,0.0f);
graphics.MeasureDriverString(text,6,&myfont,positions,1,&mat,&box);
graphics.DrawRectangle(&greenPen, Rect(box.X, box.Y, box.Width, box.Height)); //rectangle enclosing my text
}
Graphics playbackGraphics(dc);
playbackGraphics.DrawImage(&metafile, 0, 0);
}
I have written a simple application to create an enhanced meta file that uses DrawDriverString method to render a text however it doesn't take any parameter as the starting position but still it shows me the text at a particular place in the user space which itconsiders as the origin.My question is what transformation led to this origin.The parameters DrawDriverString method takes is the glyphcount and glyphpositions,flag(in my case i am using it as '1' which means it takes rendering position from a lookup tables as mentioned in msdn though i am not sure what this CMapLookUp is all about neither i have used it in my application).
The code looks like:
void CStartingGDIPlusDlg::OnPaint()
{
using namespace Gdiplus;
CPaintDC dc(this);
Metafile metafile(L"c:\\myMetafile.emf",dc);
{
Graphics graphics(&metafile);
Pen greenPen(Color(255, 0, 255, 0));
SolidBrush solidBrush(Color(255, 0, 0, 255));
FontFamily myfontFamily(L"Century");
Font myfont(&myfontFamily, 12, FontStyleRegular, UnitPixel);
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
graphics.DrawString(L"Smooth Text", 11, &myfont,PointF(0.0f, -19.0f),
&solidBrush);
const Color color(255,0,0,255);
SolidBrush brush(color);
Brush *mybrush;
mybrush=&brush;
PointF positions[6];
positions[0].X=0.0f;
positions[1].X=30.0f;
positions[2].X=20.0f;
positions[3].X=40.0f;
positions[4].X=60.0f;
positions[5].X=70.0f;
positions[0].Y=0.0f;
positions[1].Y=20.0f;
positions[2].Y=30.0f;
positions[3].Y=50.0f;
positions[4].Y=60.0f;
positions[5].Y=70.0f;
PointF position(25.0f,25.0f);
Matrix mat(1.0,0.0,0.0,1.0,0,0);
UINT16 text[]={65,66,67,67,65,78};
graphics.DrawDriverString(text,6,&myfont,&solidBrush,positions,1,&mat);
RectF box(0.0f,0.0f,0.0f,0.0f);
graphics.MeasureDriverString(text,6,&myfont,positions,1,&mat,&box);
graphics.DrawRectangle(&greenPen, Rect(box.X, box.Y, box.Width, box.Height)); //rectangle enclosing my text
}
Graphics playbackGraphics(dc);
playbackGraphics.DrawImage(&metafile, 0, 0);
}