/// <summary> /// get processed/scaled vxs /// </summary> /// <returns></returns> public VertexStore GetVxs(float scale = 1) { //TODO: review here again VertexStore vxs1 = new VertexStore(); if (scale == 1) { return(curveFlattener.MakeVxs(ps.Vxs, vxs1)); } else { VertexStore vxs2 = new VertexStore(); //float scale = TypeFace.CalculateFromPointToPixelScale(SizeInPoints); var mat = PixelFarm.Agg.Transform.Affine.NewMatix( new PixelFarm.Agg.Transform.AffinePlan( PixelFarm.Agg.Transform.AffineMatrixCommand.Scale, scale, scale)); //transform -> flatten ->output return(curveFlattener.MakeVxs(mat.TransformToVxs(ps.Vxs, vxs1), vxs2)); } // //if (PassHintInterpreterModule) //{ // return curveFlattener.MakeVxs(ps.Vxs, vxs1); //} //else //{ // //} }
/// <summary> /// write output to vxs, use user's curve flattener /// </summary> /// <param name="output"></param> /// <param name="scale"></param> public void WriteOutput(VertexStore output, CurveFlattener curveFlattener, float scale = 1) { if (scale == 1) { curveFlattener.MakeVxs(_vxs, output); } else { AffineMat mat = AffineMat.GetScaleMat(scale); curveFlattener.MakeVxs(_vxs, mat, output); } }
VertexStore BuildVxsForGlyph(GlyphPathBuilder builder, char character, int size, int resolution) { //TODO: review here builder.Build(character, size); var txToVxs = new GlyphTranslatorToVxs(); builder.ReadShapes(txToVxs); VertexStore v0 = _vxsPool.GetFreeVxs(); txToVxs.WriteOutput(v0); var mat = PixelFarm.Agg.Transform.Affine.NewMatix( //translate new PixelFarm.Agg.Transform.AffinePlan( PixelFarm.Agg.Transform.AffineMatrixCommand.Translate, 10, 10), //scale new PixelFarm.Agg.Transform.AffinePlan( PixelFarm.Agg.Transform.AffineMatrixCommand.Scale, 1, 1) ); VertexStore v1 = _vxsPool.GetFreeVxs(); VertexStore v2 = new VertexStore(); mat.TransformToVxs(v0, v1); curveFlattener.MakeVxs(v0, v2); _vxsPool.Release(ref v0); _vxsPool.Release(ref v1); return(v2); }
VertexStore BuildVxsForGlyph(GlyphPathBuilder builder, char character, int size, int resolution) { //----------- //TODO: review here builder.Build(character, size); var txToVxs = new GlyphTranslatorToVxs(); builder.ReadShapes(txToVxs); VertexStore v2 = new VertexStore(); using (VxsTemp.Borrow(out var v0)) { txToVxs.WriteOutput(v0); var mat = PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix( //translate new PixelFarm.CpuBlit.VertexProcessing.AffinePlan( PixelFarm.CpuBlit.VertexProcessing.AffineMatrixCommand.Translate, 10, 10), //scale new PixelFarm.CpuBlit.VertexProcessing.AffinePlan( PixelFarm.CpuBlit.VertexProcessing.AffineMatrixCommand.Scale, 1, 1) ); //mat.TransformToVxs(v0, v1); _curveFlattener.MakeVxs(v0, mat, v2); } return(v2); }
public BlurWithPainter() { //m_rbuf2 = new ReferenceImage(); m_shape_bounds = new RectD(); m_shadow_ctrl = new PolygonEditWidget(4); this.FlattenCurveChecked = true; this.BlurMethod = BlurMethod.RecursiveBlur; this.BlurRadius = 15; Font svgFont = SvgFontStore.LoadFont("svg-LiberationSansFont", 300); m_pathVxs = svgFont.GetGlyph('a').originalVxs;// typeFaceForLargeA.GetGlyphForCharacter('a'); Affine shape_mtx = Affine.NewMatix(AffinePlan.Translate(150, 100)); m_pathVxs = shape_mtx.TransformToVxs(m_pathVxs); var curveFlattener = new CurveFlattener(); m_path_2 = new VertexStoreSnap(curveFlattener.MakeVxs(m_pathVxs)); BoundingRect.GetBoundingRect(m_path_2, ref m_shape_bounds); m_shadow_ctrl.SetXN(0, m_shape_bounds.Left); m_shadow_ctrl.SetYN(0, m_shape_bounds.Bottom); m_shadow_ctrl.SetXN(1, m_shape_bounds.Right); m_shadow_ctrl.SetYN(1, m_shape_bounds.Bottom); m_shadow_ctrl.SetXN(2, m_shape_bounds.Right); m_shadow_ctrl.SetYN(2, m_shape_bounds.Top); m_shadow_ctrl.SetXN(3, m_shape_bounds.Left); m_shadow_ctrl.SetYN(3, m_shape_bounds.Top); m_shadow_ctrl.LineColor = ColorRGBAf.MakeColorRGBA(0f, 0.3f, 0.5f, 0.3f); }
//---------------- public override VertexStore FlattenCurves(VertexStore srcVxs) { if (curveFlattener == null) { curveFlattener = new CurveFlattener(); } return(curveFlattener.MakeVxs(srcVxs)); }
public ShapeBuilder Flatten(CurveFlattener flattener) { VxsTemp.Borrow(out VertexStore v2); flattener.MakeVxs(_vxs, v2); VxsTemp.ReleaseVxs(_vxs); _vxs = v2; return(this); }
public void WriteOutput(VertexStore output, VertexStorePool vxsPool, float scale = 1) { if (scale == 1) { curveFlattener.MakeVxs(ps.Vxs, output); } else { var mat = PixelFarm.Agg.Transform.Affine.NewMatix( new PixelFarm.Agg.Transform.AffinePlan( PixelFarm.Agg.Transform.AffineMatrixCommand.Scale, scale, scale)); //transform -> flatten ->output VertexStore tmpVxs = vxsPool.GetFreeVxs(); curveFlattener.MakeVxs(mat.TransformToVxs(ps.Vxs, tmpVxs), output); vxsPool.Release(ref tmpVxs); } }
/// <summary> /// write output to vxs /// </summary> /// <param name="output"></param> /// <param name="scale"></param> public void WriteOutput(VertexStore output, float scale = 1) { if (scale == 1) { curveFlattener.MakeVxs(ps.Vxs, output); } else { var mat = PixelFarm.Agg.Transform.Affine.NewMatix( new PixelFarm.Agg.Transform.AffinePlan( PixelFarm.Agg.Transform.AffineMatrixCommand.Scale, scale, scale)); //transform -> flatten ->output //TODO: review here again*** VertexStore tmpVxs = new VertexStore(); curveFlattener.MakeVxs(ps.Vxs, tmpVxs); mat.TransformToVxs(tmpVxs, output); } }
/// <summary> /// write output to vxs /// </summary> /// <param name="output"></param> /// <param name="vxsPool"></param> /// <param name="scale"></param> public void WriteOutput(VertexStore output, VertexStorePool vxsPool, float scale = 1) { if (scale == 1) { curveFlattener.MakeVxs(ps.Vxs, output); } else { //float scale = TypeFace.CalculateFromPointToPixelScale(SizeInPoints); var mat = PixelFarm.Agg.Transform.Affine.NewMatix( new PixelFarm.Agg.Transform.AffinePlan( PixelFarm.Agg.Transform.AffineMatrixCommand.Scale, scale, scale)); //transform -> flatten ->output //TODO: review here again***d //VertexStore tmpVxs = vxsPool.GetFreeVxs(); curveFlattener.MakeVxs(ps.Vxs, output); // vxsPool.Release(ref tmpVxs); } }
/// <summary> /// write output to vxs /// </summary> /// <param name="output"></param> /// <param name="scale"></param> public void WriteOutput(VertexStore output, CurveFlattener curveFlattener, float scale = 1) { if (scale == 1) { curveFlattener.MakeVxs(_vxs, output); } else { var mat = PixelFarm.CpuBlit.VertexProcessing.Affine.New( new PixelFarm.CpuBlit.VertexProcessing.AffinePlan( PixelFarm.CpuBlit.VertexProcessing.AffineMatrixCommand.Scale, scale, scale)); //transform -> flatten ->output //TODO: review here again*** using (VxsTemp.Borrow(out var v1)) { curveFlattener.MakeVxs(_vxs, mat, output); } } }
public override void Init() { base.Init(); // VertexStore myvxs = new VertexStore(); PathWriter writer = new PathWriter(myvxs); int y_offset = 20; writer.MoveTo(100, y_offset + 0); writer.Curve4( 300, y_offset + 0, 300, y_offset + 200, 100, y_offset + 200); CurveFlattener flattener = new CurveFlattener(); VertexStore output = new VertexStore(); flattener.MakeVxs(myvxs, output); this._vxs = output; }
//------------------------------------ public VertexStore ParseSvgPathDefinitionToVxs(char[] buffer) { // VectorToolBox.GetFreePathWriter(out PathWriter pathWriter); VectorToolBox.GetFreeVxs(out VertexStore flattenVxs); _svgPathDataParser.SetPathWriter(pathWriter); //tokenize the path definition data _svgPathDataParser.Parse(buffer); _curveFlattener.MakeVxs(pathWriter.Vxs, flattenVxs); //------------------------------------------------- //create a small copy of the vxs VertexStore vxs = flattenVxs.CreateTrim(); VectorToolBox.ReleaseVxs(ref flattenVxs); VectorToolBox.ReleasePathWriter(ref pathWriter); return(vxs); }
//---------------- public VertexStore FlattenCurves(VertexStore srcVxs) { return(curveFlattener.MakeVxs(srcVxs)); }
void render_gpc(Graphics2D graphics2D) { switch (this.PolygonSet) { case PolygonExampleSet.TwoSimplePaths: { //------------------------------------ // Two simple paths // PathWriter ps1 = new PathWriter(); PathWriter ps2 = new PathWriter(); double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.CloseFigure(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220, y + 222); ps1.LineTo(x + 363, y + 249); ps1.LineTo(x + 265, y + 331); ps1.MoveTo(x + 242, y + 243); ps1.LineTo(x + 268, y + 309); ps1.LineTo(x + 325, y + 261); ps1.MoveTo(x + 259, y + 259); ps1.LineTo(x + 273, y + 288); ps1.LineTo(x + 298, y + 266); ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); graphics2D.Render(ps1.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f)); graphics2D.Render(ps2.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f)); CreateAndRenderCombined(graphics2D, ps1.MakeVertexSnap(), ps2.MakeVertexSnap()); } break; case PolygonExampleSet.CloseStroke: { //------------------------------------ // Closed stroke // PathWriter ps1 = new PathWriter(); PathWriter ps2 = new PathWriter(); Stroke stroke = new Stroke(1); stroke.Width = 10; double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; //----------------------------------------- ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.CloseFigure(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220 - 50, y + 222); ps1.LineTo(x + 265 - 50, y + 331); ps1.LineTo(x + 363 - 50, y + 249); ps1.CloseFigureCCW(); //----------------------------------------- ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); ps2.CloseFigure(); graphics2D.Render(ps1.MakeVertexSnap(), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f)); var vxs = ps2.Vxs; graphics2D.Render(stroke.MakeVxs(vxs), ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f)); CreateAndRenderCombined(graphics2D, ps1.MakeVertexSnap(), new VertexStoreSnap(vxs)); } break; case PolygonExampleSet.GBAndArrow: { //------------------------------------ // Great Britain and Arrows // PathWriter gb_poly = new PathWriter(); PathWriter arrows = new PathWriter(); PixelFarm.Agg.Sample_PolygonClipping.GreatBritanPathStorage.Make(gb_poly); make_arrows(arrows); //Affine mtx1 = Affine.NewIdentity(); //mtx1 *= Affine.NewTranslation(-1150, -1150); //mtx1 *= Affine.NewScaling(2.0); Affine mtx1 = Affine.NewMatix( AffinePlan.Translate(-1150, -1150), AffinePlan.Scale(2) ); //Affine.NewIdentity(); //mtx2 = mtx1; //mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2); Affine mtx2 = mtx1 * Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2); //VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1); //VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2); var trans_gb_poly = mtx1.TransformToVxs(gb_poly.Vxs); var trans_arrows = mtx2.TransformToVxs(arrows.Vxs); graphics2D.Render(trans_gb_poly, ColorRGBAf.MakeColorRGBA(0.5f, 0.5f, 0f, 0.1f)); //stroke_gb_poly.Width = 0.1; graphics2D.Render(new Stroke(0.1).MakeVxs(trans_gb_poly), ColorRGBAf.MakeColorRGBA(0, 0, 0)); graphics2D.Render(trans_arrows, ColorRGBAf.MakeColorRGBA(0f, 0.5f, 0.5f, 0.1f)); CreateAndRenderCombined(graphics2D, new VertexStoreSnap(trans_gb_poly), new VertexStoreSnap(trans_arrows)); } break; case PolygonExampleSet.GBAndSpiral: { //------------------------------------ // Great Britain and a Spiral // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); PathWriter gb_poly = new PathWriter(); PixelFarm.Agg.Sample_PolygonClipping.GreatBritanPathStorage.Make(gb_poly); Affine mtx = Affine.NewMatix( AffinePlan.Translate(-1150, -1150), AffinePlan.Scale(2)); VertexStore s1 = mtx.TransformToVxs(gb_poly.Vxs); graphics2D.Render(s1, ColorRGBAf.MakeColorRGBA(0.5f, 0.5f, 0f, 0.1f)); graphics2D.Render(new Stroke(0.1).MakeVxs(s1), ColorRGBA.Black); var stroke_vxs = new Stroke(15).MakeVxs(sp.MakeVxs()); graphics2D.Render(stroke_vxs, ColorRGBAf.MakeColorRGBA(0.0f, 0.5f, 0.5f, 0.1f)); CreateAndRenderCombined(graphics2D, new VertexStoreSnap(s1), new VertexStoreSnap(stroke_vxs)); } break; case PolygonExampleSet.SprialAndGlyph: { //------------------------------------ // Spiral and glyph // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); Stroke stroke = new Stroke(15); PathWriter glyph = new PathWriter(); glyph.MoveTo(28.47, 6.45); glyph.Curve3(21.58, 1.12, 19.82, 0.29); glyph.Curve3(17.19, -0.93, 14.21, -0.93); glyph.Curve3(9.57, -0.93, 6.57, 2.25); glyph.Curve3(3.56, 5.42, 3.56, 10.60); glyph.Curve3(3.56, 13.87, 5.03, 16.26); glyph.Curve3(7.03, 19.58, 11.99, 22.51); glyph.Curve3(16.94, 25.44, 28.47, 29.64); glyph.LineTo(28.47, 31.40); glyph.Curve3(28.47, 38.09, 26.34, 40.58); glyph.Curve3(24.22, 43.07, 20.17, 43.07); glyph.Curve3(17.09, 43.07, 15.28, 41.41); glyph.Curve3(13.43, 39.75, 13.43, 37.60); glyph.LineTo(13.53, 34.77); glyph.Curve3(13.53, 32.52, 12.38, 31.30); glyph.Curve3(11.23, 30.08, 9.38, 30.08); glyph.Curve3(7.57, 30.08, 6.42, 31.35); glyph.Curve3(5.27, 32.62, 5.27, 34.81); glyph.Curve3(5.27, 39.01, 9.57, 42.53); glyph.Curve3(13.87, 46.04, 21.63, 46.04); glyph.Curve3(27.59, 46.04, 31.40, 44.04); glyph.Curve3(34.28, 42.53, 35.64, 39.31); glyph.Curve3(36.52, 37.21, 36.52, 30.71); glyph.LineTo(36.52, 15.53); glyph.Curve3(36.52, 9.13, 36.77, 7.69); glyph.Curve3(37.01, 6.25, 37.57, 5.76); glyph.Curve3(38.13, 5.27, 38.87, 5.27); glyph.Curve3(39.65, 5.27, 40.23, 5.62); glyph.Curve3(41.26, 6.25, 44.19, 9.18); glyph.LineTo(44.19, 6.45); glyph.Curve3(38.72, -0.88, 33.74, -0.88); glyph.Curve3(31.35, -0.88, 29.93, 0.78); glyph.Curve3(28.52, 2.44, 28.47, 6.45); glyph.CloseFigure(); glyph.MoveTo(28.47, 9.62); glyph.LineTo(28.47, 26.66); glyph.Curve3(21.09, 23.73, 18.95, 22.51); glyph.Curve3(15.09, 20.36, 13.43, 18.02); glyph.Curve3(11.77, 15.67, 11.77, 12.89); glyph.Curve3(11.77, 9.38, 13.87, 7.06); glyph.Curve3(15.97, 4.74, 18.70, 4.74); glyph.Curve3(22.41, 4.74, 28.47, 9.62); glyph.CloseFigure(); //Affine mtx = Affine.NewIdentity(); //mtx *= Affine.NewScaling(4.0); //mtx *= Affine.NewTranslation(220, 200); Affine mtx = Affine.NewMatix( AffinePlan.Scale(4), AffinePlan.Translate(220, 200)); var t_glyph = mtx.TransformToVertexSnap(glyph.Vxs); CurveFlattener curveFlattener = new CurveFlattener(); var sp1 = stroke.MakeVxs(sp.MakeVxs()); var curveVxs = curveFlattener.MakeVxs(t_glyph); CreateAndRenderCombined(graphics2D, new VertexStoreSnap(sp1), new VertexStoreSnap(curveVxs)); graphics2D.Render(stroke.MakeVxs(sp1), ColorRGBAf.MakeColorRGBA(0f, 0f, 0f, 0.1f)); graphics2D.Render(curveVxs, ColorRGBAf.MakeColorRGBA(0f, 0.6f, 0f, 0.1f)); } break; } }
public override void Draw(PixelFarm.Drawing.Painter p) { p.Clear(Drawing.Color.White); p.StrokeColor = Color.Black; p.StrokeWidth = 2; p.StrokeColor = Color.Green; p.Draw(_triangleVxs); if (!ShowReconstructionCurve) { return; } //draw Ci line p.StrokeColor = KnownColors.OrangeRed; DrawLine(p, a01, a12); DrawLine(p, a12, a20); DrawLine(p, a20, a01); //find B //DrawPoint(p, a01); //DrawPoint(p, a12); //DrawPoint(p, a20); BezierControllerArmPair c1 = BezierControllerArmPair.ReconstructControllerArms(v0, v1, v2); BezierControllerArmPair c2 = BezierControllerArmPair.ReconstructControllerArms(v1, v2, v0); BezierControllerArmPair c0 = BezierControllerArmPair.ReconstructControllerArms(v2, v0, v1); c0.UniformSmoothCoefficient = SmoothCoefficientValue; c1.UniformSmoothCoefficient = SmoothCoefficientValue; c2.UniformSmoothCoefficient = SmoothCoefficientValue; //DrawPoint(p, c0 = FindB(v0, v1, v2, out c1)); //DrawPoint(p, b2 = FindB(v1, v2, v0, out c2)); //DrawPoint(p, b0 = FindB(v2, v0, v1, out c0)); p.StrokeColor = Color.Red; DrawControllerPair(p, c0); DrawControllerPair(p, c1); DrawControllerPair(p, c2); p.StrokeColor = Color.Blue; using (Tools.BorrowVxs(out var tmpVxs1, out var tmpVxs2)) using (Tools.BorrowPathWriter(tmpVxs1, out var pw)) { pw.MoveTo(c0.mid.X, c0.mid.y); pw.Curve4(c0.right.x, c0.right.y, c1.left.x, c1.left.y, c1.mid.x, c1.mid.y); //1st curve pw.Curve4(c1.right.x, c1.right.y, c2.left.x, c2.left.y, c2.mid.x, c2.mid.y); //2nd curve pw.Curve4(c2.right.x, c2.right.y, c0.left.x, c0.left.y, c0.mid.x, c0.mid.y); //3rd curve _curveflattener.MakeVxs(tmpVxs1, tmpVxs2); p.Draw(tmpVxs2); } }