void ReadAndRender(string fontfile) { if (string.IsNullOrEmpty(this.txtInputChar.Text)) { p.Clear(PixelFarm.Drawing.Color.White); return; } var reader = new OpenFontReader(); char testChar = txtInputChar.Text[0];//only 1 char int resolution = 96; //1. read typeface from font file RenderChoice renderChoice = (RenderChoice)this.cmbRenderChoices.SelectedItem; switch (renderChoice) { case RenderChoice.RenderWithMiniAgg: { using (var fs = new FileStream(fontfile, FileMode.Open)) { Typeface typeFace = reader.Read(fs); RenderWithMiniAgg(typeFace, testChar, fontSizeInPoint); } } break; case RenderChoice.RenderWithGdiPlusPath: { using (var fs = new FileStream(fontfile, FileMode.Open)) { Typeface typeFace = reader.Read(fs); RenderWithGdiPlusPath(typeFace, testChar, fontSizeInPoint, resolution); } } break; case RenderChoice.RenderWithTextPrinterAndMiniAgg: { RenderWithTextPrinterAndMiniAgg(fontfile, this.txtInputChar.Text, fontSizeInPoint, resolution); } break; case RenderChoice.RenderWithMsdfGen: case RenderChoice.RenderWithSdfGen: { using (var fs = new FileStream(fontfile, FileMode.Open)) { Typeface typeFace = reader.Read(fs); RenderWithMsdfImg(typeFace, testChar, fontSizeInPoint); } } break; default: throw new NotSupportedException(); } }
void UpdateRenderOutput() { if (g == null) { destImg = new ActualImage(400, 300, PixelFormat.ARGB32); imgGfx2d = new ImageGraphics2D(destImg); //no platform p = new AggCanvasPainter(imgGfx2d); winBmp = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = this.CreateGraphics(); _devVxsTextPrinter.TargetCanvasPainter = p; _devGdiTextPrinter.TargetGraphics = g; } if (string.IsNullOrEmpty(this.txtInputChar.Text)) { return; } var hintTech = (HintTechnique)lstHintList.SelectedItem; //1. read typeface from font file RenderChoice renderChoice = (RenderChoice)this.cmbRenderChoices.SelectedItem; switch (renderChoice) { case RenderChoice.RenderWithGdiPlusPath: { selectedTextPrinter = _devGdiTextPrinter; selectedTextPrinter.FontFilename = _selectedFontFilename; selectedTextPrinter.FontSizeInPoints = _fontSizeInPts; selectedTextPrinter.HintTechnique = hintTech; selectedTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem; // selectedTextPrinter.DrawString(this.txtInputChar.Text.ToCharArray(), 0, 0); } break; case RenderChoice.RenderWithTextPrinterAndMiniAgg: { //clear previous draw p.Clear(PixelFarm.Drawing.Color.White); p.UseSubPixelRendering = chkLcdTechnique.Checked; p.FillColor = PixelFarm.Drawing.Color.Black; selectedTextPrinter = _devVxsTextPrinter; selectedTextPrinter.FontFilename = _selectedFontFilename; selectedTextPrinter.FontSizeInPoints = _fontSizeInPts; selectedTextPrinter.HintTechnique = hintTech; selectedTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem; //test print 3 lines char[] printTextBuffer = this.txtInputChar.Text.ToCharArray(); float x_pos = 0, y_pos = 200; float lineSpacingPx = selectedTextPrinter.FontLineSpacingPx; for (int i = 0; i < 3; ++i) { selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos); y_pos -= lineSpacingPx; } //copy from Agg's memory buffer to gdi PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); g.Clear(Color.White); g.DrawImage(winBmp, new Point(10, 0)); } break; //============================================== //render 1 glyph for debug and test case RenderChoice.RenderWithMsdfGen: case RenderChoice.RenderWithSdfGen: { char testChar = this.txtInputChar.Text[0]; using (var fs = new FileStream(_selectedFontFilename, FileMode.Open)) { var reader = new OpenFontReader(); Typeface typeFace = reader.Read(fs); RenderWithMsdfImg(typeFace, testChar, _fontSizeInPts); } } break; case RenderChoice.RenderWithMiniAgg_SingleGlyph: { //for test only 1 char char testChar = this.txtInputChar.Text[0]; using (var fs = new FileStream(_selectedFontFilename, FileMode.Open)) { var reader = new OpenFontReader(); Typeface typeFace = reader.Read(fs); RenderWithMiniAgg(typeFace, testChar, _fontSizeInPts); } } break; default: throw new NotSupportedException(); } }
void UpdateRenderOutput() { if (!_readyToRender) { return; } // if (g == null) { destImg = new ActualImage(800, 600, PixelFormat.ARGB32); imgGfx2d = new ImageGraphics2D(destImg); //no platform painter = new AggCanvasPainter(imgGfx2d); winBmp = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = this.CreateGraphics(); painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); _devVxsTextPrinter = new VxsTextPrinter(painter, _openFontStore); _devVxsTextPrinter.TargetCanvasPainter = painter; _devVxsTextPrinter.ScriptLang = _current_script; _devVxsTextPrinter.PositionTechnique = _devGdiTextPrinter.PositionTechnique; _devGdiTextPrinter.TargetGraphics = g; } if (string.IsNullOrEmpty(this.txtInputChar.Text)) { return; } //test option use be used with lcd subpixel rendering. //this demonstrate how we shift a pixel for subpixel rendering tech _devVxsTextPrinter.UseWithLcdSubPixelRenderingTechnique = chkSetPrinterLayoutForLcdSubPix.Checked; var hintTech = (HintTechnique)lstHintList.SelectedItem; //1. read typeface from font file RenderChoice renderChoice = (RenderChoice)this.cmbRenderChoices.SelectedItem; switch (renderChoice) { case RenderChoice.RenderWithGdiPlusPath: { selectedTextPrinter = _devGdiTextPrinter; selectedTextPrinter.Typeface = _typefaceStore.GetTypeface(_selectedInstallFont); selectedTextPrinter.FontSizeInPoints = _fontSizeInPts; selectedTextPrinter.HintTechnique = hintTech; selectedTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem; #if DEBUG GlyphDynamicOutline.dbugTestNewGridFitting = chkTestGridFit.Checked; GlyphDynamicOutline.dbugActualPosToConsole = chkWriteFitOutputToConsole.Checked; GlyphDynamicOutline.dbugUseHorizontalFitValue = chkUseHorizontalFitAlign.Checked; #endif selectedTextPrinter.DrawString(this.txtInputChar.Text.ToCharArray(), 0, 0); } break; case RenderChoice.RenderWithTextPrinterAndMiniAgg: { //clear previous draw painter.Clear(PixelFarm.Drawing.Color.White); painter.UseSubPixelRendering = chkLcdTechnique.Checked; painter.FillColor = PixelFarm.Drawing.Color.Black; selectedTextPrinter = _devVxsTextPrinter; selectedTextPrinter.Typeface = _typefaceStore.GetTypeface(_selectedInstallFont); selectedTextPrinter.FontSizeInPoints = _fontSizeInPts; selectedTextPrinter.HintTechnique = hintTech; selectedTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem; //test print 3 lines #if DEBUG GlyphDynamicOutline.dbugTestNewGridFitting = chkTestGridFit.Checked; GlyphDynamicOutline.dbugActualPosToConsole = chkWriteFitOutputToConsole.Checked; GlyphDynamicOutline.dbugUseHorizontalFitValue = chkUseHorizontalFitAlign.Checked; #endif char[] printTextBuffer = this.txtInputChar.Text.ToCharArray(); float x_pos = 0, y_pos = 200; float lineSpacingPx = selectedTextPrinter.FontLineSpacingPx; for (int i = 0; i < 1; ++i) { selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos); y_pos -= lineSpacingPx; } //copy from Agg's memory buffer to gdi PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp); g.Clear(Color.White); g.DrawImage(winBmp, new Point(10, 0)); } break; //============================================== //render 1 glyph for debug and test case RenderChoice.RenderWithMsdfGen: case RenderChoice.RenderWithSdfGen: { char testChar = this.txtInputChar.Text[0]; Typeface typeFace = _typefaceStore.GetTypeface(_selectedInstallFont); RenderWithMsdfImg(typeFace, testChar, _fontSizeInPts); } break; case RenderChoice.RenderWithMiniAgg_SingleGlyph: { selectedTextPrinter = _devVxsTextPrinter; //for test only 1 char RenderSingleCharWithMiniAgg( _typefaceStore.GetTypeface(_selectedInstallFont), this.txtInputChar.Text[0], _fontSizeInPts); } break; default: throw new NotSupportedException(); } }