void UpdateRenderOutput() { if (!_readyToRender) { return; } // //test option use be used with lcd subpixel rendering. //this demonstrate how we shift a pixel for subpixel rendering tech _devVxsTextPrinter.UseWithLcdSubPixelRenderingTechnique = true; //1. read typeface from font file TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice; switch (renderChoice) { case TypographyTest.RenderChoice.RenderWithGdiPlusPath: //not render in this example //see more at ... break; case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg: { //clear previous draw painter.Clear(PixelFarm.Drawing.Color.White); painter.UseSubPixelLcdEffect = false; painter.FillColor = PixelFarm.Drawing.Color.Black; selectedTextPrinter = _devVxsTextPrinter; selectedTextPrinter.Typeface = _basicOptions.Typeface; selectedTextPrinter.FontSizeInPoints = _basicOptions.FontSizeInPoints; selectedTextPrinter.ScriptLang = _basicOptions.ScriptLang; selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech; selectedTextPrinter.HintTechnique = HintTechnique.None; selectedTextPrinter.EnableLigature = true; _devVxsTextPrinter.UpdateGlyphLayoutSettings(); // _controllerForPixelFarm.ReadyToRender = true; _controllerForPixelFarm.UpdateOutput(); //---------------- //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; 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, _basicOptions.OpenFontStore); _devVxsTextPrinter.TargetCanvasPainter = painter; _devVxsTextPrinter.ScriptLang = _basicOptions.ScriptLang; _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont; //_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 = _contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix; //1. read typeface from font file TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice; switch (renderChoice) { case TypographyTest.RenderChoice.RenderWithGdiPlusPath: //not render in this example //see more at ... break; case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg: { //clear previous draw painter.Clear(PixelFarm.Drawing.Color.White); painter.UseSubPixelRendering = _contourAnalysisOpts.LcdTechnique; painter.FillColor = PixelFarm.Drawing.Color.Black; selectedTextPrinter = _devVxsTextPrinter; selectedTextPrinter.Typeface = _basicOptions.Typeface; selectedTextPrinter.FontSizeInPoints = _basicOptions.FontSizeInPoints; selectedTextPrinter.ScriptLang = _basicOptions.ScriptLang; selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech; selectedTextPrinter.HintTechnique = _glyphRenderOptions.HintTechnique; selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature; //test print 3 lines #if DEBUG GlyphDynamicOutline.dbugTestNewGridFitting = _contourAnalysisOpts.EnableGridFit; GlyphDynamicOutline.dbugActualPosToConsole = _contourAnalysisOpts.WriteFitOutputToConsole; GlyphDynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment; #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 TypographyTest.RenderChoice.RenderWithMsdfGen: case TypographyTest.RenderChoice.RenderWithSdfGen: { char testChar = this.txtInputChar.Text[0]; Typeface typeFace = _basicOptions.Typeface; RenderWithMsdfImg(typeFace, testChar, _basicOptions.FontSizeInPoints); } break; case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph: { selectedTextPrinter = _devVxsTextPrinter; //for test only 1 char RenderSingleCharWithMiniAgg( _basicOptions.Typeface, this.txtInputChar.Text[0], _basicOptions.FontSizeInPoints); } break; default: throw new NotSupportedException(); } }
void UpdateRenderOutput() { if (!_readyToRender) { return; } // if (_g == null) { _destImg = new MemBitmap(800, 600); _painter = AggPainter.Create(_destImg); _winBmp = new Bitmap(_destImg.Width, _destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _g = this.CreateGraphics(); _painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); _textService = new LayoutFarm.OpenFontTextService(); _textService.LoadFontsFromFolder("../../../TestFonts"); _devVxsTextPrinter = new VxsTextPrinter(_painter, _textService); _devVxsTextPrinter.ScriptLang = _basicOptions.ScriptLang; _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont; } 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 if (_contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix) { //TODO: set lcd or not here } else { //TODO: set lcd or not here } //1. read typeface from font file TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice; switch (renderChoice) { case TypographyTest.RenderChoice.RenderWithGdiPlusPath: //not render in this example //see more at ... break; case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg: { //clear previous draw _painter.Clear(PixelFarm.Drawing.Color.White); _painter.UseSubPixelLcdEffect = _contourAnalysisOpts.LcdTechnique; _painter.FillColor = PixelFarm.Drawing.Color.Black; _selectedTextPrinter = _devVxsTextPrinter; _selectedTextPrinter.Typeface = _basicOptions.Typeface; _selectedTextPrinter.FontSizeInPoints = _basicOptions.FontSizeInPoints; _selectedTextPrinter.ScriptLang = _basicOptions.ScriptLang; _selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech; _selectedTextPrinter.HintTechnique = _glyphRenderOptions.HintTechnique; _selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature; _selectedTextPrinter.SimulateSlant = _contourAnalysisOpts.SimulateSlant; //test print 3 lines #if DEBUG GlyphDynamicOutline.dbugTestNewGridFitting = _contourAnalysisOpts.EnableGridFit; GlyphDynamicOutline.dbugActualPosToConsole = _contourAnalysisOpts.WriteFitOutputToConsole; GlyphDynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment; #endif char[] printTextBuffer = this.txtInputChar.Text.ToCharArray(); float x_pos = 0, y_pos = 50; 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.CpuBlit.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 TypographyTest.RenderChoice.RenderWithMsdfGen: case TypographyTest.RenderChoice.RenderWithSdfGen: { char testChar = this.txtInputChar.Text[0]; Typeface typeFace = _basicOptions.Typeface; RenderWithMsdfImg(typeFace, testChar, _basicOptions.FontSizeInPoints); } break; case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph: { _selectedTextPrinter = _devVxsTextPrinter; //for test only 1 char RenderSingleCharWithMiniAgg( _basicOptions.Typeface, this.txtInputChar.Text[0], _basicOptions.FontSizeInPoints); } break; default: throw new NotSupportedException(); } }
void UpdateRenderOutput() { if (!_readyToRender) { return; } // if (_g == null) { InitGraphics(); } 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 if (_contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix) { //TODO: set lcd or not here } else { //TODO: set lcd or not here } //1. read typeface from font file TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice; switch (renderChoice) { case TypographyTest.RenderChoice.RenderWithGdiPlusPath: //not render in this example //see more at ... break; case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg: { //clear previous draw _painter.Clear(PixelFarm.Drawing.Color.White); _painter.UseLcdEffectSubPixelRendering = _contourAnalysisOpts.LcdTechnique; _painter.FillColor = PixelFarm.Drawing.Color.Black; _selectedTextPrinter = _devVxsTextPrinter; _selectedTextPrinter.Typeface = _basicOptions.Typeface; _selectedTextPrinter.FontSizeInPoints = _basicOptions.FontSizeInPoints; _selectedTextPrinter.ScriptLang = _basicOptions.ScriptLang; _selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech; if (_selectedTextPrinter is PixelFarm.Drawing.VxsTextSpanPrinter vxsTextPrinter) { vxsTextPrinter.HintTechnique = _glyphRenderOptions.HintTechnique; } _selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature; _selectedTextPrinter.EnableMultiTypefaces = _basicOptions.EnableMultiTypefaces; _selectedTextPrinter.SimulateSlant = _contourAnalysisOpts.SimulateSlant; _selectedTextPrinter.TextBaseline = (Typography.Text.TextBaseline)(int) lstTextBaseline.SelectedItem; //test print 3 lines #if DEBUG DynamicOutline.dbugTestNewGridFitting = _contourAnalysisOpts.EnableGridFit; DynamicOutline.dbugActualPosToConsole = _contourAnalysisOpts.WriteFitOutputToConsole; DynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment; #endif char[] printTextBuffer = this.txtInputChar.Text.ToCharArray(); float x_pos = 0, y_pos = 0; float lineSpacingPx = _selectedTextPrinter.FontLineSpacingPx; const int REF_LINE_LEN = 300; for (int i = 0; i < 3; ++i) { _selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos); #if DEBUG //show debug info... var prevColor = _painter.FillColor; var prevStrokColor = _painter.StrokeColor; _painter.FillColor = PixelFarm.Drawing.Color.Red; _painter.FillRect(x_pos, y_pos, 5, 5); // start point //see //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline switch (_selectedTextPrinter.TextBaseline) { default: { System.Diagnostics.Debug.WriteLine("UNIMPLEMENTED" + _selectedTextPrinter.TextBaseline.ToString()); goto case Typography.Text.TextBaseline.Alphabetic; // } case Typography.Text.TextBaseline.Alphabetic: { //alphabetic baseline _painter.StrokeColor = _grayColor; _painter.DrawLine(x_pos, /**/ y_pos, x_pos + REF_LINE_LEN, y_pos); _painter.StrokeColor = PixelFarm.Drawing.Color.Blue; _painter.DrawLine(x_pos, /**/ y_pos - _selectedTextPrinter.FontDescedingPx, x_pos + REF_LINE_LEN, y_pos - _selectedTextPrinter.FontDescedingPx); //bottom most } break; case Typography.Text.TextBaseline.Top: { //alphabetic baseline _painter.StrokeColor = _grayColor; _painter.DrawLine(x_pos, /**/ y_pos + _selectedTextPrinter.FontAscendingPx, x_pos + REF_LINE_LEN, y_pos + _selectedTextPrinter.FontAscendingPx); //em bottom _painter.StrokeColor = PixelFarm.Drawing.Color.Blue; _painter.DrawLine(x_pos, /**/ y_pos + (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx), x_pos + REF_LINE_LEN, y_pos + (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx)); //bottom most } break; case Typography.Text.TextBaseline.Bottom: { //alphabetic baseline _painter.StrokeColor = _grayColor; _painter.DrawLine(x_pos, /**/ y_pos + _selectedTextPrinter.FontDescedingPx, x_pos + REF_LINE_LEN, y_pos + _selectedTextPrinter.FontDescedingPx); //em bottom _painter.StrokeColor = PixelFarm.Drawing.Color.Blue; _painter.DrawLine(x_pos, /**/ y_pos, x_pos + REF_LINE_LEN, y_pos); //bottom most } break; } _painter.FillColor = prevColor; _painter.StrokeColor = prevColor; #endif y_pos += (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx); } //copy from Agg's memory buffer to gdi PixelFarm.CpuBlit.BitmapHelper.CopyToGdiPlusBitmapSameSizeNotFlip(_destImg, _winBmp); _g.Clear(Color.White); _g.DrawImage(_winBmp, new Point(0, 0)); } break; //============================================== //render 1 glyph for debug and test case TypographyTest.RenderChoice.RenderWithMsdfGen: case TypographyTest.RenderChoice.RenderWithSdfGen: { char testChar = this.txtInputChar.Text[0]; Typeface typeFace = _basicOptions.Typeface; RenderWithMsdfImg(typeFace, testChar, _basicOptions.FontSizeInPoints); } break; case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph: { _selectedTextPrinter = _devVxsTextPrinter; //for test only 1 char RenderSingleCharWithMiniAgg( _basicOptions.Typeface, this.txtInputChar.Text[0], _basicOptions.FontSizeInPoints); } break; default: throw new NotSupportedException(); } }