コード例 #1
0
        public frmBlockLine()
        {
            InitializeComponent();

            Model model = model1.Model;

            BlockLine blockLine = new BlockLine();

            blockLine.Start.Location = new PointF(100, 100);
            blockLine.End.Location   = new PointF(200, 200);

            model.Lines.Add(blockLine);

            Shape shape = new Shape();

            shape.Location    = new PointF(320, 320);
            shape.BorderColor = Color.Green;
            model.Shapes.Add(shape);

            Shape shape2 = new Shape();

            shape2.Location    = new PointF(20, 20);
            shape2.BorderColor = Color.Blue;
            model.Shapes.Add(shape2);
        }
コード例 #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //取得测试数据
            float rx  = float.Parse(txtRX.Text);
            float ry  = float.Parse(txtRY.Text);
            float sx  = float.Parse(txtSX.Text);
            float sy  = float.Parse(txtSY.Text);
            float ex  = float.Parse(txtEX.Text);
            float ey  = float.Parse(txtEY.Text);
            float itv = float.Parse(txtItv.Text);

            //求解
            Position_Point rp = new Position_Point(rx, ry);
            Position_Point sp = new Position_Point(sx, sy);
            Position_Point ep = new Position_Point(ex, ey);
            IPositionSet   ps = BlockLine.getBlockLine(rp, itv, sp, ep);

            //作图
            pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g = Graphics.FromImage(pictureBox1.Image);

            g.Clear(Color.White);
            //网格线
            for (float x = rx - itv; x >= 0; x -= itv)
            {
                g.DrawLine(Pens.Black, x, 0, x, pictureBox1.Height);
            }
            for (float y = ry - itv; y >= 0; y -= itv)
            {
                g.DrawLine(Pens.Black, 0, y, pictureBox1.Width, y);
            }
            for (float x = rx; x < pictureBox1.Width; x += itv)
            {
                g.DrawLine(Pens.Black, x, 0, x, pictureBox1.Height);
            }
            for (float y = ry; y < pictureBox1.Width; y += itv)
            {
                g.DrawLine(Pens.Black, 0, y, pictureBox1.Width, y);
            }
            //经过的网格
            ps.InitToTraverseSet();
            while (ps.NextPosition())
            {
                IPosition p = ps.GetPosition();
                float     x = p.GetX();
                float     y = p.GetY();
                g.FillRectangle(Brushes.Gray, x - itv / 2 + 1, y - itv / 2 + 1, itv - 1, itv - 1);
            }
            //起点和终点
            g.FillEllipse(Brushes.Black, sx - 2, sy - 2, 4, 4);
            g.FillEllipse(Brushes.Black, ex - 2, ey - 2, 4, 4);
            g.DrawLine(Pens.Red, sx, sy, ex, ey);
        }
コード例 #3
0
        bool IsEndOfLine(IBlock block, BlockLine line)
        {
            float startOfBlock = block.GetX();
            float endOfBlock   = block.GetX() + block.GetWidth();
            float endOfLine    = line.GetX() + line.GetWidth();

            if ((block.GetX() + block.GetWidth() - line.GetX()) < 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public override void RenderElement(IRenderable element, Graphics graphics, Render render)
        {
            BlockLine line = element as BlockLine;

            if (line.Points == null)
            {
                return;
            }
            if (line.Points.Count < 2)
            {
                return;
            }

            GraphicsPath path = line.GetBlockPath();
            Pen          pen  = null;

            if (line.CustomPen == null)
            {
                pen           = new Pen(line.BorderColor, line.BorderWidth);
                pen.DashStyle = line.BorderStyle;

                //Check if winforms renderer and adjust color as required
                pen.Color = render.AdjustColor(line.BorderColor, line.BorderWidth, line.Opacity);
            }
            else
            {
                pen = line.CustomPen;
            }

            //Can throw an out of memory exception in System.Drawing
            try
            {
                graphics.SmoothingMode = line.SmoothingMode;
                graphics.DrawPath(pen, path);
            }
            catch
            {
            }
        }
コード例 #5
0
 public GroupFontLineHelper(BlockLine line, Block block)
 {
     _line        = line;
     _currentFont = CreateFont(block);
 }
コード例 #6
0
        public BlockPage Process(BlockPage page)
        {
            GroupFontLineHelper groupFont = null;
            BlockLine           line      = null;
            IBlock last   = null;
            var    result = new BlockPage();


            foreach (var block in page.AllBlocks)
            {
                if (last != null)
                {
                    if (IsEndOfWord(block) || IsEndOfLine(block, line))
                    {
                        last = null;
                        result.Add(line);
                    }
                    else
                    {
                        line.Text += block.GetText();
                        line.Width = block.GetX() + block.GetWidth() - line.GetX();

                        groupFont.MergeFont((Block)block);
                    }
                }

                if ((last == null))
                {
                    var    b    = (Block)block;
                    string text = block.GetText();

                    line = new BlockLine()
                    {
                        Text   = text,
                        X      = block.GetX(),
                        H      = block.GetH(),
                        Width  = block.GetWidth(),
                        Height = block.GetHeight(),

                        HasBackColor = b.HasBackColor,

                        HasLargeSpace = false,

                        // might be inaccurate
                        FontFullName = b.FontFullName,
                        FontName     = b.FontName,
                        FontSize     = b.FontSize, // BE CAREFUL!
                        FontStyle    = b.FontStyle
                                                   // now the settings are done in GroupFontLineHelper
                    };

                    // TODO: validar a entrada duas vezes

                    if (groupFont != null)
                    {
                        groupFont.Done();
                    }

                    groupFont = new GroupFontLineHelper(line, b);

                    if (line.Width <= 0 || line.Height <= 0)
                    {
                        PdfReaderException.AlwaysThrow("line.Width <= 0 || line.Height <= 0");
                    }
                }
                last = block;
            }

            if (groupFont != null)
            {
                groupFont.Done();
            }

            return(result);
        }
コード例 #7
0
ファイル: GroupLines.cs プロジェクト: wangfujia/PdfTextReader
        public BlockPage Process(BlockPage page)
        {
            GroupFontLineHelper groupFont = null;
            BlockLine           line      = null;
            IBlock last        = null;
            string last_hidden = null;
            var    result      = new BlockPage();

            foreach (var block in page.AllBlocks)
            {
                if (block is BlockHidden)
                {
                    var blockHidden = (BlockHidden)block;

                    if (last_hidden != null)
                    {
                        PdfReaderException.Warning("last_hidden != null: hidden text will be overwritten");
                    }

                    last_hidden = blockHidden.GetHiddenText();
                    continue;
                }

                if (last != null)
                {
                    if (CheckSubfonts(line, (Block)block))
                    {
                        bool isBackspace = CheckBackspace(line, block);

                        float endofblock = block.GetX() + block.GetWidth();
                        float endofline  = line.GetX() + line.GetWidth();

                        if (endofblock > endofline)
                        {
                            line.Width = block.GetX() + block.GetWidth() - line.GetX();
                        }

                        if (line.Width <= 0)
                        {
                            PdfReaderException.AlwaysThrow("line.Width <= 0");
                        }

                        // conside same line: update text and Width
                        // we dont add space character (should we?)
                        line.Text += block.GetText();

                        // gather statistics
                        statBackspace += (isBackspace) ? 1 : 0;
                        statSubfonts++;

                        // does not update 'last' variable!!
                        continue;
                    }
                }

                if ((last == null) || (CompareLine(block, last) != 0))
                {
                    var    b    = (Block)block;
                    string text = block.GetText();

                    if (last_hidden != null)
                    {
                        text        = last_hidden + text;
                        last_hidden = null;
                    }

                    line = new BlockLine()
                    {
                        Text   = text,
                        X      = block.GetX(),
                        H      = block.GetH(),
                        Width  = block.GetWidth(),
                        Height = block.GetHeight(),

                        HasBackColor = b.HasBackColor,

                        HasLargeSpace = false,

                        // might be inaccurate
                        FontFullName = b.FontFullName,
                        FontName     = b.FontName,
                        FontSize     = b.FontSize, // BE CAREFUL!
                        FontStyle    = b.FontStyle
                                                   // now the settings are done in GroupFontLineHelper
                    };

                    // TODO: validar a entrada duas vezes

                    if (groupFont != null)
                    {
                        groupFont.Done();
                    }

                    groupFont = new GroupFontLineHelper(line, b);

                    if (line.Width <= 0 || line.Height <= 0)
                    {
                        PdfReaderException.AlwaysThrow("line.Width <= 0 || line.Height <= 0");
                    }

                    result.Add(line);
                }
                else
                {
                    string separator = (ShouldAddSpace(last, block)) ? " " : "";

                    // same line: update text and Width
                    float startOfBlock = block.GetX();
                    float endOfBlock   = block.GetX() + block.GetWidth();
                    float endOfLine    = line.GetX() + line.GetWidth();

                    line.Text += separator + block.GetText();
                    line.Width = block.GetX() + block.GetWidth() - line.GetX();

                    if (line.Width <= 0)
                    {
                        PdfReaderException.AlwaysThrow("line.Width <= 0");
                    }

                    bool couldBeTable = ShouldAddLargeSpace(last, block);

                    if (couldBeTable)
                    {
                        line.HasLargeSpace = true;
                    }

                    // walking backwards
                    // very strict check: sometimes the start overlaps with the ending
                    //if (startOfBlock < endOfLine)
                    //    throw new InvalidOperationException();
                    // soft check: end of block should never that low unless it is an overlap
                    if (endOfBlock < endOfLine)
                    {
                        PdfReaderException.AlwaysThrow("endOfBlock < endOfLine", new IBlock[] { last, block });
                    }

                    groupFont.MergeFont((Block)block);
                }

                last = block;
            }

            if (groupFont != null)
            {
                groupFont.Done();
            }

            return(result);
        }