Exemplo n.º 1
0
        private void pnlCanvas_Paint(object sender, PaintEventArgs e)
        {
            if (guiDrawing == null)
            {
                e.Graphics.Clear(Color.Black);
                return;
            }
            using (var backBuffer = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format24bppRgb))

                using (Graphics backGraphics = Graphics.FromImage(backBuffer))
                {
                    backGraphics.SmoothingMode = SmoothingMode.HighQuality;
                    PolygonDrawing.draw(guiDrawing, backGraphics, 1);

                    e.Graphics.DrawImage(backBuffer, 0, 0);
                }
        }
Exemplo n.º 2
0
        /// <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)
        {
            //获取轮廓大小
            SizeF size = new SizeF(outline.Width, outline.Height);

            WordOutlineDrawing word = new WordOutlineDrawing(size);

            //---------------------
            wordNode.Tag = word;
            //---------------------
            int index = 0;

            //遍历填充轮廓数据
            foreach (DPolygon p in outline.Polygons)
            {
                //新增多边形实例
                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)
                {
                    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));
                        Console.WriteLine("{0}.{1}, {2}.{3}({4},{5})", fx.x.value, fx.x.fract, fx.y.value, fx.y.fract, ConvertUtil.FixedToFloat(fx.x), 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);
                    //---------------------
                }
                //加入到字符轮廓的多边形列表中
                word.Polygons.Add(polygon);
            }
            return(word);
        }