void RenderWithMsdfImg(Typeface typeface, char testChar, float sizeInPoint) { p.FillColor = PixelFarm.Drawing.Color.Black; //p.UseSubPixelRendering = chkLcdTechnique.Checked; p.Clear(PixelFarm.Drawing.Color.White); //---------------------------------------------------- var builder = new MyGlyphPathBuilder(typeface); var hintTech = (HintTechnique)cmbHintTechnique.SelectedItem; builder.UseTrueTypeInstructions = false; //reset builder.UseVerticalHinting = false; //reset switch (hintTech) { case HintTechnique.TrueTypeInstruction: builder.UseTrueTypeInstructions = true; break; case HintTechnique.TrueTypeInstruction_VerticalOnly: builder.UseTrueTypeInstructions = true; builder.UseVerticalHinting = true; break; case HintTechnique.CustomAutoFit: //custom agg autofit break; } //---------------------------------------------------- builder.Build(testChar, sizeInPoint); //---------------------------------------------------- var msdfGlyphGen = new MsdfGlyphGen(); GlyphImage2 glyphImg = msdfGlyphGen.CreateMsdfImage( builder.GetOutputPoints(), builder.GetOutputContours(), builder.GetPixelScale()); var actualImg = ActualImage.CreateFromBuffer(glyphImg.Width, glyphImg.Height, PixelFormat.ARGB32, glyphImg.GetImageBuffer()); p.DrawImage(actualImg, 0, 0); //using (Bitmap bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) //{ // var bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); // System.Runtime.InteropServices.Marshal.Copy(buffer, 0, bmpdata.Scan0, buffer.Length); // bmp.UnlockBits(bmpdata); // bmp.Save("d:\\WImageTest\\a001_xn2_" + n + ".png"); //} if (chkShowGrid.Checked) { //render grid RenderGrid(800, 600, _gridSize, p); } //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); //--------------- //7. just render our bitmap g.Clear(Color.White); g.DrawImage(winBmp, new Point(30, 20)); }
void RenderWithGdiPlusPath(Typeface typeface, char testChar, float sizeInPoint, int resolution) { //render glyph path with Gdi+ path g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.Clear(Color.White); //////credit: //////http://stackoverflow.com/questions/1485745/flip-coordinates-when-drawing-to-control g.ScaleTransform(1.0F, -1.0F); // Flip the Y-Axis g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly //---------------------------------------------------- var builder = new MyGlyphPathBuilder(typeface); var hintTech = (HintTechnique)cmbHintTechnique.SelectedItem; builder.UseTrueTypeInstructions = false; //reset builder.UseVerticalHinting = false; //reset switch (hintTech) { case HintTechnique.TrueTypeInstruction: builder.UseTrueTypeInstructions = true; break; case HintTechnique.TrueTypeInstruction_VerticalOnly: builder.UseTrueTypeInstructions = true; builder.UseVerticalHinting = true; break; case HintTechnique.CustomAutoFit: //custom agg autofit break; } //---------------------------------------------------- builder.Build(testChar, sizeInPoint); var gdiPathBuilder = new GlyphPathBuilderGdi(); builder.ReadShapes(gdiPathBuilder); float pxScale = builder.GetPixelScale(); System.Drawing.Drawing2D.GraphicsPath path = gdiPathBuilder.ResultGraphicPath; path.Transform( new System.Drawing.Drawing2D.Matrix( pxScale, 0, 0, pxScale, 0, 0 )); if (chkFillBackground.Checked) { g.FillPath(Brushes.Black, path); } if (chkBorder.Checked) { g.DrawPath(Pens.Green, path); } //transform back g.ScaleTransform(1.0F, -1.0F); // Flip the Y-Axis g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly }
void RenderWithMiniAgg(Typeface typeface, char testChar, float sizeInPoint) { //---------------------------------------------------- var builder = new MyGlyphPathBuilder(typeface); var hintTech = (HintTechnique)cmbHintTechnique.SelectedItem; builder.UseTrueTypeInstructions = false; //reset builder.UseVerticalHinting = false; //reset switch (hintTech) { case HintTechnique.TrueTypeInstruction: builder.UseTrueTypeInstructions = true; break; case HintTechnique.TrueTypeInstruction_VerticalOnly: builder.UseTrueTypeInstructions = true; builder.UseVerticalHinting = true; break; case HintTechnique.CustomAutoFit: //custom agg autofit break; } //---------------------------------------------------- builder.Build(testChar, sizeInPoint); var vxsShapeBuilder = new GlyphPathBuilderVxs(); builder.ReadShapes(vxsShapeBuilder); VertexStore vxs = vxsShapeBuilder.GetVxs(); p.UseSubPixelRendering = chkLcdTechnique.Checked; //5. use PixelFarm's Agg to render to bitmap... //5.1 clear background p.Clear(PixelFarm.Drawing.Color.White); if (chkFillBackground.Checked) { //5.2 p.FillColor = PixelFarm.Drawing.Color.Black; //5.3 if (!chkYGridFitting.Checked) { p.Fill(vxs); } } if (chkBorder.Checked) { //5.4 // p.StrokeWidth = 3; p.StrokeColor = PixelFarm.Drawing.Color.Green; //user can specific border width here... //p.StrokeWidth = 2; //5.5 p.Draw(vxs); } float pxScale = builder.GetPixelScale(); //1. autofit var autoFit = new GlyphAutoFit(); autoFit.Hint( builder.GetOutputPoints(), builder.GetOutputContours(), pxScale); var vxsShapeBuilder2 = new GlyphPathBuilderVxs(); autoFit.ReadOutput(vxsShapeBuilder2); VertexStore vxs2 = vxsShapeBuilder2.GetVxs(); // p.FillColor = PixelFarm.Drawing.Color.Black; p.Fill(vxs2); if (chkShowTess.Checked) { #if DEBUG debugDrawTriangulatedGlyph(autoFit.FitOutput, pxScale); #endif } if (chkShowGrid.Checked) { //render grid RenderGrid(800, 600, _gridSize, p); } //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); //--------------- //7. just render our bitmap g.Clear(Color.White); g.DrawImage(winBmp, new Point(30, 20)); }