Example #1
0
        public Form1()
        {
            InitializeComponent();

            dha.nSize        = System.Runtime.InteropServices.Marshal.SizeOf(dha);
            dha.nRoundRadius = 2;

            PDFXEdit.IUIX_Inst uiInst = (PDFXEdit.IUIX_Inst)pdfCtl.Inst.GetExtension("UIX");

            brush               = uiInst.CreateNewBrush();
            pen                 = uiInst.CreateNewPen();
            brush.Color0        = (uint)ColorTranslator.ToWin32(Color.Blue) | 0xFF000000;
            brush.Opacity       = 0.3;
            brush.BlendType     = PDFXEdit.UIX_BlendType.UIX_BlendType_Multiply;
            pen.Brush.Color0    = brush.Color0;
            pen.Brush.Opacity   = 0.9;
            pen.Brush.BlendType = PDFXEdit.UIX_BlendType.UIX_BlendType_Multiply;

            PDFXEdit.IAUX_Inst auxInst = (PDFXEdit.IAUX_Inst)pdfCtl.Inst.GetExtension("AUX");
            mh = auxInst.MathHelper;

            dhp       = new DrawHighlightOnPagesCallback();
            dhp.brush = brush;
            dhp.pen   = pen;
            dhp.mh    = mh;
        }
Example #2
0
            public void Stop(bool bFinal)
            {
                if (doc != null)
                {
                    doc.UnregisterPagesViewDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, this);
                    doc = null;
                }

                if (bFinal)
                {
                    quads = null;
                    poly  = null;
                    brush = null;
                    pen   = null;
                }
            }
Example #3
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            /////////////////////////////////////////////////////////////////////////////////////
            // Forced release of all COM-objects that may still captured by Garbage Collector. //
            // It is critical to release them before destroying of pdfCtl!                     //
            /////////////////////////////////////////////////////////////////////////////////////
            wordsRanges    = null;
            docHighlighter = null;
            brush          = null;
            pen            = null;
            dhp.Stop(true);
            dhp = null;
            mh  = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Example #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            PDFXEdit.IPXV_Document doc = pdfCtl.Doc;
            if (doc == null)
            {
                return;
            }

            PDFXEdit.IPXC_Document cdoc = doc.CoreDoc;

            do
            {
                bool newPage = curPage < 0;
                bool newWord = true;
                if (!newPage)
                {
                    uint wordsCnt = wordsRanges.Count / 2;

                    if (smoothHighlight && (curWord >= 0) && ((uint)curWord < wordsCnt))
                    {
                        int wl = wordsRanges[(uint)curWord * 2 + 1];
                        if ((curWordLen + 1) <= wl)
                        {
                            newWord = false;
                        }
                    }

                    if (newWord && ((uint)(curWord + 1) >= wordsCnt))
                    {
                        newPage = true;
                    }
                }

                if (newPage)
                {
                    if ((uint)(curPage + 1) >= cdoc.Pages.Count)
                    {
                        timer1.Stop();
                        endReached = true;
                        UpdateStartBtn();
                        return;
                    }

                    endReached = false;
                    curPage++;

                    PDFXEdit.IPXC_Page page = cdoc.Pages[(uint)curPage];

                    PDFXEdit.IPXC_PageText pageText = page.GetText(null);

                    pageSolidHighlight = null;
                    if (docHighlighter == null)
                    {
                        docHighlighter = doc.AddNewHighlighter(PDFXEdit.PXV_DocHighlightType.PXV_DocHighlight_Page);
                    }
                    else
                    {
                        docHighlighter.Clear();
                    }

                    wordsRanges.Clear();

                    uint charsCnt = pageText.CharsCount;
                    int  wb       = -1;
                    int  we       = 0;
                    for (uint i = 0; i < charsCnt; i++)
                    {
                        ushort ch        = pageText.CharCode[i];
                        uint   flg       = pageText.CharFlags[i];
                        bool   lineBegin = ((flg & (uint)(PDFXEdit.PXC_TextCharFlags.TCF_LineBegin)) != 0);
                        // bool wordSep = ((flg & (uint)(PDFXEdit.PXC_TextCharFlags.TCF_SearchWordSeparator)) != 0);
                        bool wordSep = ch <= 32 || ch == 160;
                        if (!wordSep && !lineBegin)
                        {
                            if (wb < 0)
                            {
                                wb = (int)i;
                            }
                            we = (int)i;
                        }
                        else
                        {
                            if (wb >= 0)
                            {
                                wordsRanges.Insert(wb);
                                wordsRanges.Insert(we - wb + 1);
                            }
                            if (wordSep)
                            {
                                wb = -1;
                            }
                            else                             // lineBegin==true
                            {
                                wb = we = (int)i;
                            }
                        }
                    }
                    if (wb >= 0)
                    {
                        wordsRanges.Insert(wb);
                        wordsRanges.Insert(we - wb + 1);
                    }

                    curWord    = -1;
                    curWordLen = 0;
                    continue;
                }

                if (newWord)
                {
                    curWord++;
                    curWordLen = 0;
                }

                int wordBegin = wordsRanges[(uint)curWord * 2];
                int wordLen   = wordsRanges[(uint)curWord * 2 + 1];

                if (smoothHighlight)
                {
                    curWordLen++;
                }
                else
                {
                    curWordLen = wordLen;
                }

                {
                    int wb = wordBegin;
                    int wl = curWordLen;

                    if (solidHighlight)
                    {
                        wb = 0;
                        wl = wordBegin + curWordLen;
                    }

                    if (useDocHighlighter)
                    {
                        wordRange.Clear();
                        wordRange.Insert(wb);
                        wordRange.Insert(wl);

                        if (pageSolidHighlight != null)
                        {
                            pageSolidHighlight.Remove();
                            pageSolidHighlight = null;
                        }

                        PDFXEdit.IUIX_Brush br = null;
                        PDFXEdit.IUIX_Pen   pn = null;

                        if (blueHighlight)
                        {
                            br = brush;
                            pn = pen;
                        }

                        PDFXEdit.IPXC_Page     pg     = cdoc.Pages[(uint)curPage];
                        PDFXEdit.IPXC_PageText pgText = pg.GetText(null);

                        PDFXEdit.IPXV_DocHighlightItem itm = docHighlighter.Add(pg, wordRange, br, pn, ref dha, (uint)(PDFXEdit.PXV_DocHighlightFlags.PXV_DocHighlightFlag_ShareBrush | PDFXEdit.PXV_DocHighlightFlags.PXV_DocHighlightFlag_SharePen));

                        // doc.ActiveView.PagesView.Obj.Redraw(); // this line is required for build <= 6.0.322.3. Look for actual dev. build: http://docu-track.co.uk/devbuilds/latest/DevRelease.x32.zip

                        if (solidHighlight || smoothHighlight)
                        {
                            pageSolidHighlight = itm;
                        }
                    }
                    else
                    {
                        HighlightQuads(doc, curPage, wb, wl);
                    }

                    // ensure visible last selected symbol
                    EnsureVisibleChar(doc, (uint)curPage, (uint)(wb + wl - 1));
                }

                break;
            }while (true);
        }