Exemple #1
0
        VgVisualElement CreateEllipseVxs(PixelFarm.CpuBlit.RectD newBounds)
        {
            using (VxsTemp.Borrow(out var v1))
                using (VectorToolBox.Borrow(out Ellipse ellipse))
                {
                    ellipse.Set((newBounds.Left + newBounds.Right) * 0.5,
                                (newBounds.Bottom + newBounds.Top) * 0.5,
                                (newBounds.Right - newBounds.Left) * 0.5,
                                (newBounds.Top - newBounds.Bottom) * 0.5);


                    var spec = new SvgPathSpec()
                    {
                        FillColor = Color.Red
                    };
                    VgVisualDoc     renderRoot = new VgVisualDoc();
                    VgVisualElement renderE    = new VgVisualElement(WellknownSvgElementName.Path, spec, renderRoot);
                    renderE.VxsPath = ellipse.MakeVxs(v1).CreateTrim();
                    return(renderE);
                }
        }
        public static VgVisualElement CreateVgVisualElementFromGlyph(string actualFontFile, float sizeInPts, char c)
        {
            if (!s_loadedTypefaces.TryGetValue(actualFontFile, out Typography.OpenFont.Typeface typeface))
            {
                //create vgrender vx from font-glyph
                //
                using (System.IO.FileStream fs = new FileStream(actualFontFile, FileMode.Open))
                {
                    Typography.OpenFont.OpenFontReader reader = new Typography.OpenFont.OpenFontReader();
                    typeface = reader.Read(fs);
                }
            }
            if (_glyphMaskStore == null)
            {
                _glyphMaskStore = new Typography.Contours.GlyphMeshStore();
                _glyphMaskStore.FlipGlyphUpward = true;
            }
            _glyphMaskStore.SetFont(typeface, sizeInPts);
            //-----------------
            VertexStore vxs  = _glyphMaskStore.GetGlyphMesh(typeface.GetGlyphIndex(c));
            var         spec = new SvgPathSpec()
            {
                FillColor = Color.Red
            };
            VgVisualDoc     renderRoot = new VgVisualDoc();
            VgVisualElement renderE    = new VgVisualElement(WellknownSvgElementName.Path, spec, renderRoot);


            //offset the original vxs to (0,0) bounds
            //PixelFarm.CpuBlit.RectD bounds = vxs.GetBoundingRect();
            //Affine translate = Affine.NewTranslation(-bounds.Left, -bounds.Bottom);
            //renderE._vxsPath = vxs.CreateTrim(translate);


            PixelFarm.CpuBlit.RectD bounds = vxs.GetBoundingRect();
            Affine translate = Affine.NewTranslation(-bounds.Left, -bounds.Bottom);

            renderE.VxsPath = vxs.CreateTrim(translate);
            return(renderE);
        }
        VgVisualElement CreateTestRenderVx_BasicShape()
        {
            var spec = new SvgPathSpec()
            {
                FillColor = Color.Red
            };
            VgVisualDoc     renderRoot = new VgVisualDoc();
            VgVisualElement renderE    = new VgVisualElement(WellknownSvgElementName.Path, spec, renderRoot);

            using (Tools.BorrowVxs(out var v1))
            {
                //red-triangle ***
                v1.AddMoveTo(10, 10);
                v1.AddLineTo(60, 10);
                v1.AddLineTo(60, 30);
                v1.AddLineTo(10, 30);
                v1.AddCloseFigure();
                renderE.VxsPath = v1.CreateTrim();
            }

            return(renderE);
        }
        VgVisualElement CreatePath(VgVisualElement parentNode, SvgPathSpec pathSpec, SvgElement node)
        {
            VgVisualElement vgVisElem = new VgVisualElement(WellknownSvgElementName.Path, pathSpec, _vgVisualDoc); //**

            //#if DEBUG
            //            if (node.ElemId == "x11")
            //            {
            //                vgVisElem.dbugNote = node.ElemId;
            //            }
            //#endif
            //d
            AssignAttributes(pathSpec);
            vgVisElem.VxsPath = CreateVxsFromPathDefinition(pathSpec.D.ToCharArray());
            ResolveMarkers(vgVisElem, pathSpec);


            if (vgVisElem._pathMarkers != null)
            {
                //create primary instance plan for this
            }
            parentNode.AddChildElement(vgVisElem);
            return(vgVisElem);
        }