void SoftAggControl_Load(object sender, EventArgs e) { if (_useGdiPlusOutput) { // This example assumes the existence of a form called Form1. // Gets a reference to the current BufferedGraphicsContext //BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; //_myBuffGfx = currentContext.Allocate(this.CreateGraphics(), // this.DisplayRectangle); // Creates a BufferedGraphics instance associated with Form1, and with // dimensions the same size as the drawing surface of Form1. thisGfx = this.CreateGraphics(); //for render to output bufferBmpRect = this.DisplayRectangle; bufferBmp = new Bitmap(bufferBmpRect.Width, bufferBmpRect.Height); var gdiPlusCanvasPainter = new PixelFarm.Drawing.WinGdi.GdiPlusCanvasPainter(bufferBmp); gdiPlusCanvasPainter.SmoothingMode = _gdiAntiAlias ? PixelFarm.Drawing.SmoothingMode.AntiAlias : PixelFarm.Drawing.SmoothingMode.HighSpeed; painter = gdiPlusCanvasPainter; painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 10); } else { ImageGraphics2D imgGfx2d = Initialize(myWidth, myHeight, 32); AggCanvasPainter aggPainter = new AggCanvasPainter(imgGfx2d); //set text printer for agg canvas painter aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 10); VxsTextPrinter textPrinter = new VxsTextPrinter(aggPainter); aggPainter.TextPrinter = textPrinter; painter = aggPainter; } painter.Clear(PixelFarm.Drawing.Color.White); }
protected override void OnDrawSample(SKCanvas canvas, int width, int height) { if (!buildVxs) { destImg = new ActualImage(400, 300, PixelFarm.Agg.PixelFormat.ARGB32); imgGfx2d = new ImageGraphics2D(destImg); //no platform p = new AggCanvasPainter(imgGfx2d); buildVxs = true; ReadAndRender("tahoma.ttf", "A"); } canvas.Clear(SKColors.White); using (SKBitmap bitmap = new SKBitmap(destImg.Width, destImg.Height, false)) { //IntPtr pixelHeader = bitmap.GetPixels(); //byte[] srcBuffer = ActualImage.GetBuffer(destImg); bitmap.LockPixels(); //System.Runtime.InteropServices.Marshal.Copy( // srcBuffer, 0, // pixelHeader, srcBuffer.Length); //bitmap.UnlockPixels(); PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize( destImg, destImg.Width, destImg.Height, destImg.Stride, bitmap.GetPixels()); bitmap.UnlockPixels(); canvas.DrawBitmap(bitmap, 10, 10); } }
public void BindHostGraphics(Graphics hostControlGraphics) { g = hostControlGraphics; // 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); }
private void Form1_Load(object sender, EventArgs e) { if (DesignMode) { return; } // _basicOptions = basicFontOptionsUserControl1.Options; _basicOptions.TypefaceChanged += (s, e2) => { if (_devVxsTextPrinter != null) { _devVxsTextPrinter.Typeface = e2.SelectedTypeface; } }; _basicOptions.UpdateRenderOutput += (s, e2) => { UpdateRenderOutput(); }; // //---------- _renderOptions = glyphRenderOptionsUserControl1.Options; _renderOptions.UpdateRenderOutput += (s, e2) => { UpdateRenderOutput(); }; //share text printer to our sample textbox //but you can create another text printer that specific to text textbox control 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.sampleTextBox1.CreateGraphics(); painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14); _devVxsTextPrinter = new VxsTextPrinter(painter, _basicOptions.OpenFontStore); _devVxsTextPrinter.ScriptLang = _basicOptions.ScriptLang; _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont; _devVxsTextPrinter.FontSizeInPoints = 10; _controllerForPixelFarm.BindHostGraphics(g); _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter; this.sampleTextBox1.SetController(_controllerForPixelFarm); _readyToRender = true; _basicOptions.UpdateRenderOutput += (s, e2) => UpdateRenderOutput(); //---------- //txtInputChar.TextChanged += (s, e2) => UpdateRenderOutput(); //---------- }
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(); } ReadAndRender(_currentSelectedFontFile); }
static void DrawEdge(AggCanvasPainter p, EdgeLine edge, float scale) { if (edge.IsOutside) { //free side switch (edge.SlopKind) { default: p.StrokeColor = PixelFarm.Drawing.Color.Green; break; case LineSlopeKind.Vertical: if (edge.IsLeftSide) { p.StrokeColor = PixelFarm.Drawing.Color.Blue; } else { p.StrokeColor = PixelFarm.Drawing.Color.LightGray; } break; case LineSlopeKind.Horizontal: if (edge.IsUpper) { p.StrokeColor = PixelFarm.Drawing.Color.Red; } else { p.StrokeColor = PixelFarm.Drawing.Color.LightGray; } break; } } else { switch (edge.SlopKind) { default: p.StrokeColor = PixelFarm.Drawing.Color.LightGray; break; case LineSlopeKind.Vertical: p.StrokeColor = PixelFarm.Drawing.Color.Blue; break; case LineSlopeKind.Horizontal: p.StrokeColor = PixelFarm.Drawing.Color.Yellow; break; } } p.Line(edge.x0 * scale, edge.y0 * scale, edge.x1 * scale, edge.y1 * scale); }
public override void Draw(CanvasPainter p) { //----------------------------------------------------------------- //control CanvasPainter painter = p; painter.Clear(this.WhiteOnBlack ? ColorRGBA.Black : ColorRGBA.White); painter.FillColor = new ColorRGBA(127, 127, 127); painter.FillCircle(m_x[0], m_y[0], 3); //left-bottom control box painter.FillCircle(m_x[1], m_y[1], 3); //right-top control box //----------------------------------------------------------------- double d = this.SubPixelOffset; AggCanvasPainter p2 = p as AggCanvasPainter; IPixelBlender prevBlender = null; Graphics2D gx = null; if (p2 != null) { //for agg only gx = p2.Graphics; prevBlender = gx.PixelBlender; //change gamma blender gx.PixelBlender = new PixelBlenderGammaBGRA(this.Gamma); } if (this.FillRoundRect) { painter.FillColor = this.WhiteOnBlack ? ColorRGBA.White : ColorRGBA.Black; painter.FillRoundRectangle( m_x[0] + d, m_y[0] + d, m_x[1] + d, m_y[1] + d, this.Radius); } else { painter.StrokeColor = this.WhiteOnBlack ? ColorRGBA.White : ColorRGBA.Black; painter.DrawRoundRect( m_x[0] + d, m_y[0] + d, m_x[1] + d, m_y[1] + d, this.Radius); } if (gx != null) { gx.PixelBlender = prevBlender; } }
public void BindHostGraphics(Graphics hostControlGraphics) { g = hostControlGraphics; // 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); _printer = new VxsTextPrinter(p, null); _visualLine = new VisualLine(); _visualLine.BindLine(_line); _visualLine.Y = 100; }
void RenderGrid(int width, int height, int sqSize, AggCanvasPainter p) { //render grid p.FillColor = PixelFarm.Drawing.Color.Gray; for (int y = 0; y < height;) { for (int x = 0; x < width;) { p.FillRectLBWH(x, y, 1, 1); x += sqSize; } y += sqSize; } }
void DrawGlyphContour(GlyphContour cnt, AggCanvasPainter p) { //for debug List <GlyphPart> parts = cnt.parts; int j = parts.Count; for (int i = 0; i < j; ++i) { GlyphPart part = parts[i]; switch (part.Kind) { default: throw new NotSupportedException(); case GlyphPartKind.Line: { GlyphLine line = (GlyphLine)part; p.FillColor = PixelFarm.Drawing.Color.Red; p.FillRectLBWH(line.x0, line.y0, 2, 2); p.FillRectLBWH(line.x1, line.y1, 2, 2); } break; case GlyphPartKind.Curve3: { GlyphCurve3 c = (GlyphCurve3)part; p.FillColor = PixelFarm.Drawing.Color.Red; p.FillRectLBWH(c.x0, c.y0, 2, 2); p.FillColor = PixelFarm.Drawing.Color.Blue; p.FillRectLBWH(c.p2x, c.p2y, 2, 2); p.FillColor = PixelFarm.Drawing.Color.Red; p.FillRectLBWH(c.x, c.y, 2, 2); } break; case GlyphPartKind.Curve4: { GlyphCurve4 c = (GlyphCurve4)part; p.FillColor = PixelFarm.Drawing.Color.Red; p.FillRectLBWH(c.x0, c.y0, 2, 2); p.FillColor = PixelFarm.Drawing.Color.Blue; p.FillRectLBWH(c.p2x, c.p2y, 2, 2); p.FillRectLBWH(c.p3x, c.p3y, 2, 2); p.FillColor = PixelFarm.Drawing.Color.Red; p.FillRectLBWH(c.x, c.y, 2, 2); } break; } } }
void RunSampleA(CanvasPainter p) { //1. create simple vertical line to test agg's lcd rendernig technique //create gray-scale actual image ActualImage glyphImg = new ActualImage(100, 100, PixelFormat.ARGB32); ImageGraphics2D glyph2d = new ImageGraphics2D(glyphImg); AggCanvasPainter painter = new AggCanvasPainter(glyph2d); painter.StrokeColor = PixelFarm.Drawing.Color.Black; painter.StrokeWidth = 2.0f * 3; int x = 10, y = 10; painter.Line(x * 3, 0, y * 3, 20); //scale horizontal 3 times, int lineLen = 4; //painter.Line(x * 3, 0, y * 3, 20); //scale horizontal 3 times, //painter.Line(2, 0, 2, 15); //painter.Line(2, 0, 20, 20); //painter.Line(2, 0, 30, 15); //painter.Line(2, 0, 30, 5); //clear surface bg p.Clear(PixelFarm.Drawing.Color.White); //draw img into that bg //--------------- //convert glyphImg from RGBA to grey Scale buffer //--------------- //lcd process ... byte[] glyphGreyScale = CreateGreyScaleBuffer(glyphImg); //--------------- //swap gray scale int newGreyImgStride; byte[] expanedGreyScaleBuffer = CreateNewExpandedLcdGrayScale(glyphGreyScale, glyphImg.Width, glyphImg.Height, out newGreyImgStride); //blend lcd var aggPainer = (PixelFarm.Agg.AggCanvasPainter)p; Blend(aggPainer.Graphics.DestActualImage, expanedGreyScaleBuffer, newGreyImgStride, glyphImg.Height); //--------------- p.DrawImage(glyphImg, 0, 50); }
protected override void OnInitGLProgram(object sender, EventArgs args) { lionShape = new SpriteShape(); lionShape.ParseLion(); RectD lionBounds = lionShape.Bounds; //------------- aggImage = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height, PixelFarm.Agg.PixelFormat.ARGB32); imgGfx2d = new ImageGraphics2D(aggImage); aggPainter = new AggCanvasPainter(imgGfx2d); DrawLion(aggPainter, lionShape, lionShape.Path.Vxs); //convert affImage to texture glBmp = LoadTexture(aggImage); int max = Math.Max(this.Width, this.Height); canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max); //------------------------- painter = new GLCanvasPainter(canvas2d, max, max); }
void RunSampleB(CanvasPainter p) { //version 2: //1. create simple vertical line to test agg's lcd rendernig technique //create gray-scale actual image ActualImage glyphImg = new ActualImage(100, 100, PixelFormat.ARGB32); ImageGraphics2D glyph2d = new ImageGraphics2D(glyphImg); AggCanvasPainter painter = new AggCanvasPainter(glyph2d); // painter.StrokeColor = PixelFarm.Drawing.Color.Black; painter.StrokeWidth = 2.0f; painter.Line(2, 0, 3, 15);//not need to scale3 // //clear surface bg p.Clear(PixelFarm.Drawing.Color.White); //-------------------------- var aggPainer = (PixelFarm.Agg.AggCanvasPainter)p; BlendWithLcdTechnique(aggPainer.Graphics.DestActualImage, glyphImg, PixelFarm.Drawing.Color.Black); //--------------- p.DrawImage(glyphImg, 0, 50); //--------------- }
public AggTextSpanPrinter(GLCanvasPainter canvasPainter, int w, int h) { //this class print long text into agg canvas //then copy pixel buffer from aff canvas to gl-bmp //then draw the gl-bmp into target gl canvas //TODO: review here this.canvasPainter = canvasPainter; this.canvas = canvasPainter.Canvas; bmpWidth = w; bmpHeight = h; actualImage = new ActualImage(bmpWidth, bmpHeight, PixelFormat.ARGB32); imgGfx2d = new ImageGraphics2D(actualImage); _aggPainter = new AggCanvasPainter(imgGfx2d); _aggPainter.FillColor = Color.Black; _aggPainter.StrokeColor = Color.Black; //set default1 _aggPainter.CurrentFont = canvasPainter.CurrentFont; textPrinter = new VxsTextPrinter(_aggPainter, YourImplementation.BootStrapOpenGLES2.myFontLoader); _aggPainter.TextPrinter = textPrinter; }
public override void Draw(CanvasPainter p) { if (p is GdiPlusCanvasPainter) { DrawWithWinGdi((GdiPlusCanvasPainter)p); return; } AggCanvasPainter p2 = (AggCanvasPainter)p; Graphics2D gx = p2.Graphics; var widgetsSubImage = gx.DestImage; var scline = gx.ScanlinePacked8; int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; //change value *** if (isMaskSliderValueChanged) { generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height); this.isMaskSliderValueChanged = false; } var rasterizer = gx.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1); PixelFarm.Agg.Imaging.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Imaging.AlphaMaskAdaptor(widgetsSubImage, alphaMask); ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor); ClipProxyImage clippingProxy = new ClipProxyImage(widgetsSubImage); ////Affine transform = Affine.NewIdentity(); ////transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y); ////transform *= Affine.NewScaling(lionScale, lionScale); ////transform *= Affine.NewRotation(angle + Math.PI); ////transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0); ////transform *= Affine.NewTranslation(Width / 2, Height / 2); Affine transform = Affine.NewMatix( AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y), AffinePlan.Scale(lionScale, lionScale), AffinePlan.Rotate(angle + Math.PI), AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0), AffinePlan.Translate(width / 2, height / 2)); clippingProxy.Clear(Drawing.Color.White); ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; // draw a background to show how the mask is working better int rect_w = 30; var v1 = GetFreeVxs(); for (int i = 0; i < 40; i++) { for (int j = 0; j < 40; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0); rect.NormalizeRadius(); // Drawing as an outline rasterizer.AddPath(rect.MakeVxs(v1)); v1.Clear(); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, Drawing.Color.Make(.9f, .9f, .9f)); } } } ReleaseVxs(ref v1); ////int x, y; //// Render the lion ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); ////var vxlist = new System.Collections.Generic.List<VertexData>(); ////trans.DoTransform(vxlist); var tmpVxs1 = new VertexStore(); transform.TransformToVxs(lionShape.Path.Vxs, tmpVxs1); sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy, rasterizer, scline, tmpVxs1, lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); ///* //// Render random Bresenham lines and markers //agg::renderer_markers<amask_ren_type> m(r); //for(i = 0; i < 50; i++) //{ // m.line_color(agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // (randGenerator.Next() & 0x7F) + 0x7F)); // m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // (randGenerator.Next() & 0x7F) + 0x7F)); // m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height), // m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height)); // m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5, // agg::marker_e(randGenerator.Next() % agg::end_of_markers)); //} //// Render random anti-aliased lines //double w = 5.0; //agg::line_profile_aa profile; //profile.width(w); //typedef agg::renderer_outline_aa<amask_ren_type> renderer_type; //renderer_type ren(r, profile); //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type; //rasterizer_type ras(ren); //ras.round_cap(true); //for(i = 0; i < 50; i++) //{ // ren.Color = agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // //255)); // (randGenerator.Next() & 0x7F) + 0x7F); // ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height); // ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height); // ras.render(false); //} //// Render random circles with gradient //typedef agg::gradient_linear_color<color_type> grad_color; //typedef agg::gradient_circle grad_func; //typedef agg::span_interpolator_linear<> interpolator_type; //typedef agg::span_gradient<color_type, // interpolator_type, // grad_func, // grad_color> span_grad_type; //agg::trans_affine grm; //grad_func grf; //grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0)); //agg::ellipse ell; //agg::span_allocator<color_type> sa; //interpolator_type inter(grm); //span_grad_type sg(inter, grf, grc, 0, 10); //agg::renderer_scanline_aa<amask_ren_type, // agg::span_allocator<color_type>, // span_grad_type> rg(r, sa, sg); //for(i = 0; i < 50; i++) //{ // x = randGenerator.Next() % width; // y = randGenerator.Next() % height; // double r = randGenerator.Next() % 10 + 5; // grm.reset(); // grm *= agg::trans_affine_scaling(r / 10.0); // grm *= agg::trans_affine_translation(x, y); // grm.invert(); // grc.colors(agg::rgba8(255, 255, 255, 0), // agg::rgba8(randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // randGenerator.Next() & 0x7F, // 255)); // sg.color_function(grc); // ell.init(x, y, r, r, 32); // g_rasterizer.add_path(ell); // agg::render_scanlines(g_rasterizer, g_scanline, rg); //} // */ ////m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy); }
public override void DrawRect(CGRect dirtyRect) { if (!drawInit) { this.Window.Title = "PixelFarm"; drawInit = true; destImg = new ActualImage(destImgW, destImgH, PixelFarm.Agg.PixelFormat.ARGB32); imgGfx2d = new ImageGraphics2D(destImg); //no platform p = new AggCanvasPainter(imgGfx2d); stride = destImg.Stride; LoadGlyphs(); } //base.Draw(rect); base.DrawRect(dirtyRect); p.Clear(Color.Yellow); p.FillColor = Color.Black; p.Fill(vxs); var data = Foundation.NSData.FromArray(ActualImage.GetBuffer(destImg)); CGDataProvider provider = new CGDataProvider(data); using (var myImg2 = new CGImage( destImgW, destImgH, 8, 32, stride, CGColorSpace.CreateGenericRgb(), CGBitmapFlags.PremultipliedLast, provider, null, true, CGColorRenderingIntent.AbsoluteColorimetric)) using (var nsGraphics = AppKit.NSGraphicsContext.CurrentContext) { CGContext g = nsGraphics.CGContext; CGColor color0 = new CGColor(1, 1, 1, 1); g.SetFillColor(color0); //g.ClearRect(new CGRect(0, 0, 800, 600)); //---------- CGColor color1 = new CGColor(1, 0, 0, 1); g.SetFillColor(color1); CGRect s1 = CGRect.FromLTRB(0, 0, 50, 50); CGPath gpath = new CGPath(); gpath.AddRect(CGAffineTransform.MakeTranslation(20, 20), s1); g.AddPath(gpath); g.FillPath(); CGRect s2 = new CGRect(50, 50, destImgW, destImgH); g.DrawImage(s2, myImg2); // //g.FillRect(s1); CGColor color2 = new CGColor(0, 0, 1, 1); g.SetFillColor(color2); g.TranslateCTM(30, 30); var strAttr = new CTStringAttributes { ForegroundColorFromContext = true, Font = new CTFont("Arial", 24) }; g.ScaleCTM(1, -1); //flip NSAttributedString a_str = new NSAttributedString("abcd", strAttr); using (CTLine line = new CTLine(a_str)) { line.Draw(g); } ////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.ClearRect(rect); //g.DrawImage(winBmp, new Point(10, 0)); } //// scale and translate the CTM so the image appears upright //g.ScaleCTM (1, -1); //g.TranslateCTM (0, -Bounds.Height); //g.DrawImage (rect, UIImage.FromFile ("MyImage.png").CGImage); //// translate the CTM by the font size so it displays on screen //float fontSize = 35f; //g.TranslateCTM (0, fontSize); //// set general-purpose graphics state //g.SetLineWidth (1.0f); //g.SetStrokeColor (UIColor.Yellow.CGColor); //g.SetFillColor (UIColor.Red.CGColor); //g.SetShadow (new CGSize (5, 5), 0, UIColor.Blue.CGColor); //// set text specific graphics state //g.SetTextDrawingMode (CGTextDrawingMode.FillStroke); //g.SelectFont ("Helvetica", fontSize, CGTextEncoding.MacRoman); //// show the text //g.ShowText ("Hello Core Graphics"); }
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(); } }
//template<class Scanline, class Ras> public void RenderGourand(CanvasPainter p) { float alpha = this.AlphaValue; float brc = 1; #if SourceDepth24 pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr()); #else #endif ////var destImage = gx.DestImage; ////span_allocator span_alloc = new span_allocator(); //specific for agg AggCanvasPainter painter = p as AggCanvasPainter; if (painter == null) { return; } // Graphics2D gx = painter.Graphics; SpanGenGouraudRGBA gouraudSpanGen = new SpanGenGouraudRGBA(); gx.ScanlineRasterizer.ResetGamma(new GammaLinear(0.0f, this.LinearGamma)); double d = this.DilationValue; // Six triangles double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0; double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0; double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2); double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2); double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2); double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2); double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2); double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2); gouraudSpanGen.SetColor(Drawing.Color.Make(1, 0, 0, alpha), Drawing.Color.Make(0, 1, 0, alpha), Drawing.Color.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d); var tmpVxs = _tmpVxs; painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(Drawing.Color.Make(0, 1, 0, alpha), Drawing.Color.Make(0, 0, 1, alpha), Drawing.Color.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(Drawing.Color.Make(0, 0, 1, alpha), Drawing.Color.Make(1, 0, 0, alpha), Drawing.Color.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); brc = 1 - brc; gouraudSpanGen.SetColor(Drawing.Color.Make(1, 0, 0, alpha), Drawing.Color.Make(0, 1, 0, alpha), Drawing.Color.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(Drawing.Color.Make(0, 1, 0, alpha), Drawing.Color.Make(0, 0, 1, alpha), Drawing.Color.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); gouraudSpanGen.SetColor(Drawing.Color.Make(0, 0, 1, alpha), Drawing.Color.Make(1, 0, 0, alpha), Drawing.Color.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d); painter.Fill(gouraudSpanGen.MakeVxs(tmpVxs), gouraudSpanGen); tmpVxs.Clear(); }
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(); } }