void RenderWithMiniAgg(Typeface typeface, char testChar, float sizeInPoint) { //2. glyph-to-vxs builder var builder = new GlyphPathBuilderVxs(typeface); builder.Build(testChar, sizeInPoint); VertexStore vxs = builder.GetVxs(); //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 p.Fill(vxs); //} //if (chkBorder.Checked) //{ //5.4 p.StrokeColor = PixelFarm.Drawing.Color.Green; //user can specific border width here... //p.StrokeWidth = 2; //5.5 p.Draw(vxs); //} //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap //BitmapHelper.CopyToWindowsBitmap(destImg, winBmp, new RectInt(0, 0, 300, 300)); ////--------------- ////7. just render our bitmap //g.Clear(Color.White); //g.DrawImage(winBmp, new Point(10, 0)); }
void LoadGlyphs() { using (FileStream fs = new FileStream("tahoma.ttf", FileMode.Open)) { OpenTypeReader reader = new OpenTypeReader(); Typeface typeface = reader.Read(fs); var testChar = 'a'; var builder = new GlyphPathBuilderVxs(typeface); float sizeInPoint = 48; builder.Build(testChar, sizeInPoint); vxs = builder.GetVxs(); } }
List <ushort> inputGlyphs = new List <ushort>(); //not thread safe*** public void Print(Typeface typeface, float size, char[] str, List <GlyphPlan> glyphPlanBuffer) { //1. layout _glyphLayout.Layout(typeface, size, str, glyphPlanBuffer); var glyphPathBuilder = new MyGlyphPathBuilder(typeface); int j = glyphPlanBuffer.Count; float pxScale = typeface.CalculateFromPointToPixelScale(size); for (int i = 0; i < j; ++i) { GlyphPlan glyphPlan = glyphPlanBuffer[i]; //----------------------------------- //check if we static vxs/bmp for this glyph //if not, create and cache //----------------------------------- glyphPathBuilder.BuildFromGlyphIndex(glyphPlan.glyphIndex, size); //----------------------------------- var vxsBuilder = new GlyphPathBuilderVxs(); glyphPathBuilder.ReadShapes(vxsBuilder); glyphPlan.vxs = vxsBuilder.GetVxs(pxScale); } }
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)); }