PCB Genesis增加轮廓字 实现原理

在Genesis增加汉字自带是不支持增加汉字的,如果需增加汉字需用到CAD 汉字库才可增加汉字,这里介绍一种脱离汉字库实现

Genesis增加轮廓字(如要变为实体,填空Surface可变为实体字)

 

一.增加效果图

二.选中其中一个字放大查各节点细节

三.字坐标树结构

四.代码实现

      增加轮廓字

        private void button31_Click(object sender, EventArgs e)
        {
            Font font = new Font(new FontFamily("宋体"), 100f);
            tvList.Nodes.Clear();
            FillWordOutlines(10, 50, 20, font);
        }

 

  /// <summary>
        /// 填充所有字符轮廓
        /// </summary>
        /// <param name="x">起始X</param>
        /// <param name="y">Y值</param>
        /// <param name="spacing">字符间隔</param>
        private void FillWordOutlines(int x, int y, int spacing, Font font)    //  2步
        {
            IList<WordOutlineDrawing> wordOutlines = new List<WordOutlineDrawing>();
            string text = "pcbren共赢加油";
            if (!string.IsNullOrEmpty(text))
            {
                foreach (char t in text)
                {
                    TreeNode wordNode = new TreeNode(t.ToString());
                    tvList.Nodes.Add(wordNode);

                    //获取字符编码
                    uint ch = GetGB2312Coding(t);

                    //获取轮廓数据
                    DOutline outline = WordGraph.GetOutline(ch, font);

                    //构建轮廓实例
                    WordOutlineDrawing word = BuildWordOutline(outline, new PointF(x, y), wordNode);   // 转到 3步
                    wordOutlines.Add(word);

                    //下个字的起始位置=当前起始位置+宽度+间隔
                    x += (int)outline.Width + spacing;
                }
            }
        }

 

      /// <summary>
        /// 通过轮廓数据构建字体轮廓
        /// </summary>
        /// <param name="outline">轮廓数据</param>
        /// <param name="offset">偏移量</param>
        /// <param name="wordNode"></param>
        /// <returns></returns>
        private WordOutlineDrawing BuildWordOutline(DOutline outline, PointF offset, TreeNode wordNode)   // 3步
        {
            //获取轮廓大小
            SizeF size = new SizeF(outline.Width, outline.Height);

            WordOutlineDrawing word = new WordOutlineDrawing(size);
            //---------------------
            wordNode.Tag = word;
            //---------------------
            int index = 0;
            add add = new add();
            //遍历填充轮廓数据
            foreach (DPolygon p in outline.Polygons)    //【单个字符对应poly个数  如O  有2个poly封闭圈】
            {
                //新增多边形实例
                PolygonDrawing polygon = new PolygonDrawing();

                //---------------------
                TreeNode polygonNode = new TreeNode("多边形" + (++index));
                polygonNode.Tag = polygon;
                wordNode.Nodes.Add(polygonNode);
                //---------------------

                //起始点
                PointF start = new PointF(offset.X + ConvertUtil.FixedToFloat(p.Start.x), offset.Y - ConvertUtil.FixedToFloat(p.Start.y));



                PointF point = start;
                foreach (DLine l in p.Lines)   //【一个poly的封闭圈  线段列表】
                {
                    LineDrawing line = null;
                    //如果类型为1则为折线,为2则为曲线
                    if (l.Type == 1) { line = new PolylineDrawing(); }
                    else { line = new CurvelineDrawing(); }

                    //加入起始点
                    line.Points.Add(point);
                    //---------------------
                    StringBuilder builder = new StringBuilder(l.Type == 1 ? "" : "");
                    builder.AppendFormat(" ({0},{1}) ", point.X, point.Y);
                    //---------------------
                    foreach (POINTFX fx in l.Points)
                    {
                        point = new PointF(offset.X + ConvertUtil.FixedToFloat(fx.x), offset.Y - ConvertUtil.FixedToFloat(fx.y));
                        line.Points.Add(point);
                        builder.AppendFormat("({0},{1}) ", point.X, point.Y);
                    }
                    polygon.Lines.Add(line);


                    //---------------------
                    TreeNode lineNode = new TreeNode(builder.ToString());
                    lineNode.Tag = line;
                    polygonNode.Nodes.Add(lineNode);
                    //---------------------
                }


                if (point != start)
                {
                    //增加结束到开始的闭合线段
                    LineDrawing endLine = new BeelineDrawing();
                    endLine.Points.Add(point);
                    endLine.Points.Add(start);
                    polygon.Lines.Add(endLine);

                    //---------------------
                    TreeNode endNode = new TreeNode(string.Format("直 ({0},{1}) ({0},{1}) ", point.X, point.Y, start.X, start.Y));
                    endNode.Tag = endLine;
                    polygonNode.Nodes.Add(endNode);
                    //---------------------
                }



                for (int i = 0; i < polygon.Lines.Count; i++)
                {
                    for (int j = 0; j < polygon.Lines[i].Points.Count; j++)
                    {
                        //add.pad(polygon.Lines[i].Points[j].X, polygon.Lines[i].Points[j].Y, 500, "r");
                        if (j > 0)
                            add.line(polygon.Lines[i].Points[j - 1].X, polygon.Lines[i].Points[j - 1].Y, polygon.Lines[i].Points[j].X, polygon.Lines[i].Points[j].Y, 500);

                    }
                }

                //加入到字符轮廓的多边形列表中
                word.Polygons.Add(polygon);
            }
            return word;
        }

 

posted @ 2018-08-07 12:57  pcbren  阅读(849)  评论(0编辑  收藏  举报