예제 #1
0
        public static Rhino.DocObjects.Font ToRhinoFont(this Eto.Drawing.Font etoFont)
        {
            Rhino.DocObjects.Font.FontStyle  rhinoStyle  = Rhino.DocObjects.Font.FontStyle.Upright;
            Rhino.DocObjects.Font.FontWeight rhinoWeight = Rhino.DocObjects.Font.FontWeight.Normal;

            if (etoFont.FontStyle == Eto.Drawing.FontStyle.Italic)
            {
                rhinoStyle = Rhino.DocObjects.Font.FontStyle.Italic;
            }
            if (etoFont.Bold)
            {
                rhinoWeight = Rhino.DocObjects.Font.FontWeight.Bold;
            }

            return(new Rhino.DocObjects.Font(etoFont.FamilyName, rhinoWeight, rhinoStyle, etoFont.Underline, etoFont.Strikethrough));
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string face    = "";
            bool   bold    = false;
            bool   italics = false;
            double size    = 0;
            string content = "";
            Plane  pl      = Plane.Unset;

            if (!DA.GetData("Face", ref face))
            {
                return;
            }
            if (!DA.GetData("Bold", ref bold))
            {
                return;
            }
            if (!DA.GetData("Italics", ref italics))
            {
                return;
            }
            if (!DA.GetData("Size", ref size))
            {
                return;
            }
            if (!DA.GetData("Text Content", ref content))
            {
                return;
            }
            if (!DA.GetData("Plane", ref pl))
            {
                return;
            }

            if (size == 0)
            {
                size = 1;
            }

            if (!string.IsNullOrEmpty(face) && size > 0 && !string.IsNullOrEmpty(content) &&
                pl.IsValid)
            {
                if (!Rhino.DocObjects.Font.AvailableFontFaceNames().Contains(face))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ("That face is not available"));
                }
                Rhino.DocObjects.Font.FontWeight weight = Rhino.DocObjects.Font.FontWeight.Normal;
                Rhino.DocObjects.Font.FontStyle  style  = Rhino.DocObjects.Font.FontStyle.Upright;

                if (bold)
                {
                    weight = Rhino.DocObjects.Font.FontWeight.Bold;
                }

                if (italics)
                {
                    style = Rhino.DocObjects.Font.FontStyle.Italic;
                }

                var te = new TextEntity()
                {
                    Plane      = pl,
                    PlainText  = content,
                    TextHeight = size,
                    Font       = new Rhino.DocObjects.Font(face, weight, style, false, false)
                };
                var crvs = te.Explode();
                DA.SetDataList("Text Curves", crvs);
                var bbox = BoundingBox.Empty;
                foreach (var curve in crvs)
                {
                    bbox.Union(curve.GetBoundingBox(true));
                }
                DA.SetData("Text Bounding Box", bbox);
            }
        }