Example #1
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            bool timerStarted = timer1.Enabled;

            timer1.Stop();

            uint oldDocId = 0;

            if (pdfCtl.HasDoc)
            {
                oldDocId = pdfCtl.Doc.ID;
            }

            pdfCtl.OpenDocWithDlg();

            uint newDocId = 0;

            if (pdfCtl.HasDoc)
            {
                newDocId = pdfCtl.Doc.ID;
            }

            if (wordsRanges == null)
            {
                PDFXEdit.IAUX_Inst auxInst = (PDFXEdit.IAUX_Inst)pdfCtl.Inst.GetExtension("AUX");
                wordsRanges = auxInst.CreateNumArray();
                wordRange   = auxInst.CreateNumArray();
            }

            if (newDocId != oldDocId)             // new document opened
            {
                // restart
                endReached         = false;
                curPage            = -1;
                curWord            = -1;
                docHighlighter     = null;
                pageSolidHighlight = null;
                dhp.Stop(false);
            }

            if (pdfCtl.HasDoc)
            {
                if (timerStarted)
                {
                    timer1.Start();
                }
            }

            UpdateStartBtn();
        }
Example #2
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 #3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled || !pdfCtl.HasDoc)
            {
                timer1.Stop();
            }
            else
            {
                PDFXEdit.IPXV_Document doc = pdfCtl.Doc;

                bool solid  = ckSolid.Checked;
                bool smooth = ckSmooth.Checked;
                bool useDH  = ckUseDocHighlighter.Checked;

                blueHighlight = ckBlue.Checked;

                if (endReached || solidHighlight != solid || smoothHighlight != smooth || useDocHighlighter != useDH)                 // can continue?
                {
                    // restart
                    endReached         = false;
                    curPage            = -1;
                    curWord            = -1;
                    pageSolidHighlight = null;
                    if (docHighlighter != null)
                    {
                        doc.RemoveHighlighter(docHighlighter);
                        docHighlighter = null;
                    }
                }

                dhp.Stop(false);

                doc.ActiveView.PagesView.Redraw();

                useDocHighlighter = useDH;
                solidHighlight    = solid;
                smoothHighlight   = smooth;

                timer1.Interval = smoothHighlight ? 40 : 260;

                timer1.Start();
            }

            UpdateStartBtn();
        }
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);
        }