Example #1
0
        private void HighlightQuads(PDFXEdit.IPXV_Document doc, int page, int wb, int wl)
        {
            if (dhp.doc != null)
            {
                dhp.doc.InvalidatePageRects((uint)dhp.page, dhp.bbox, 1);
            }

            PDFXEdit.IPXC_Document cdoc = doc.CoreDoc;
            if (dhp.doc != doc)
            {
                dhp.Start(pdfCtl.Inst, doc);
            }

            dhp.page = page;
            dhp.quads.Clear();

            PDFXEdit.IPXC_PageText pageText = cdoc.Pages[(uint)page].GetText(null);
            if (pageText != null)
            {
                pageText.GetTextQuads3((uint)wb, (uint)wl, dhp.quads, out dhp.bbox);                 // method added in build 6.0.322.4
            }
            if (dhp.doc != null)
            {
                dhp.doc.InvalidatePageRects((uint)dhp.page, dhp.bbox, 1);
            }
        }
Example #2
0
 private void EnsureVisibleChar(PDFXEdit.IPXV_Document doc, uint page, uint charIndex)
 {
     PDFXEdit.IPXC_PageText pgText = doc.CoreDoc.Pages[(uint)page].GetText(null);
     if (pgText == null)
     {
         return;
     }
     PDFXEdit.PXC_RectF bboxOnThePage = mh.Quad_To_RectF(pgText.CharQuad[charIndex]);
     PDFXEdit.PXC_Rect  t;
     t.left   = bboxOnThePage.left;
     t.right  = bboxOnThePage.right;
     t.top    = bboxOnThePage.top;
     t.bottom = bboxOnThePage.bottom;
     doc.ActiveView.PagesView.Layout.EnsureVisible(page, t, false);
 }
Example #3
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 #4
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 #5
0
            public void Start(PDFXEdit.IPXV_Inst inst, PDFXEdit.IPXV_Document doc_)
            {
                Stop(false);

                doc = doc_;

                if (quads == null)
                {
                    PDFXEdit.IPXC_Inst pxcInst = (PDFXEdit.IPXC_Inst)inst.GetExtension("PXC");
                    quads = pxcInst.CreateQuads();
                }

                if (poly == null)
                {
                    PDFXEdit.IUIX_Inst uiInst = (PDFXEdit.IUIX_Inst)inst.GetExtension("UIX");
                    poly = uiInst.CreatePolyPolygonSrc();
                }

                doc.RegisterPagesViewDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, this, 0);
            }
Example #6
0
        public virtual bool Run(MainFrm mainFrm, bool bShowOpDlg, bool bAllowOpUI)
        {
            PDFXEdit.IOperation op = null;
            try
            {
                op = mainFrm.pdfCtl.Inst.CreateOp(ID);
            }
            catch
            {
                return(false);
            }

            if (op == null)
            {
                return(false);
            }

            Form ui = UI;

            if (ui != null)
            {
                IFormHelper hlp = (IFormHelper)ui;
                if (hlp != null)
                {
                    hlp.OnSerialize(op);
                }
            }

            uint flags = Flags;

            if ((flags & (uint)DemoFlags.Input_Doc) != 0)
            {
                PDFXEdit.IPXV_Document doc = mainFrm.pdfCtl.Doc;
                if (doc == null)
                {
                    return(false);
                }
                PDFXEdit.ICabNode input = op.Params.Root["Input"];
                if (input.Type == PDFXEdit.CabDataTypeID.dt_Array)
                {
                    input.Add().v = doc;
                }
                else
                {
                    input.v = doc;
                }
            }
            else if (!bShowOpDlg && ((flags & (uint)DemoFlags.Input_Mask) != 0))
            {
                string fileFilter = "";
                if ((flags & (uint)DemoFlags.Input_AllSupp) != 0)
                {
                    fileFilter = "<allSupp>";
                }
                else if ((flags & (uint)DemoFlags.Input_AllSuppImg) != 0)
                {
                    fileFilter = "<allSuppImg>";
                }
                else if ((flags & (uint)DemoFlags.Input_AllSuppRasterImg) != 0)
                {
                    fileFilter = "<allSuppRasterImg>";
                }
                else if ((flags & (uint)DemoFlags.Input_PdfFile) != 0)
                {
                    fileFilter = "PDF Documents (*.pdf)|*.pdf";
                }
                else if ((flags & (uint)DemoFlags.Input_TxtFile) != 0)
                {
                    fileFilter = "Plain Text Documents (*.txt)|*.txt";
                }
                else if ((flags & (uint)DemoFlags.Input_RtfFile) != 0)
                {
                    fileFilter = "RTF Files (*.rtf)|*.rtf";
                }

                PDFXEdit.IAFS_NamesCollection fileNames = mainFrm.ShowOpenFilesDlg((flags & (uint)DemoFlags.Input_MultFiles) != 0, fileFilter);
                if (fileNames == null || (fileNames.Count == 0))
                {
                    return(false);
                }

                PDFXEdit.ICabNode input = op.Params.Root["Input"];
                if (input.Type == PDFXEdit.CabDataTypeID.dt_Array)
                {
                    for (uint i = 0; i < fileNames.Count; i++)
                    {
                        input.Add().v = fileNames[i];
                    }
                }
                else
                {
                    input.v = fileNames[0];
                }
            }

            if (bShowOpDlg)
            {
                try
                {
                    op.ShowSetupUI((uint)mainFrm.Handle);
                }
                catch (Exception ex)
                {
                    int hr = Marshal.GetHRForException(ex);
                    if (hr != HResults.E_NOTIMPL)
                    {
                        return(false);
                    }
                }
            }

            if (!OnBeforeRun(mainFrm, op))
            {
                return(false);
            }


            int opExecFlags = 0;

            if (!bAllowOpUI)
            {
                opExecFlags |= (int)PDFXEdit.OpExecFlags.OpExecFlag_NoUI;
            }

            try
            {
                if ((flags & (int)DemoFlags.SyncDo) != 0)
                {
                    op.Do(opExecFlags);
                }
                else
                {
                    mainFrm.pdfCtl.Inst.AsyncDoAndWaitForFinish(op, (uint)opExecFlags);
                }
            }
            catch (Exception ex)
            {
                int hr = Marshal.GetHRForException(ex);
                mainFrm.ShowErrMsg(hr);

                return(false);
            }

            if ((flags & (int)DemoFlags.Output_Doc) != 0)
            {
                PDFXEdit.ICabNode      output     = op.Params.Root["Output"];
                PDFXEdit.IPXC_Document newCoreDoc = null;
                try
                {
                    if (output.Type == PDFXEdit.CabDataTypeID.dt_Array)
                    {
                        if (output.Count != 0)
                        {
                            newCoreDoc = (PDFXEdit.IPXC_Document)output[0].Unknown;
                        }
                    }
                    else
                    {
                        newCoreDoc = (PDFXEdit.IPXC_Document)output.Unknown;
                    }

                    if (newCoreDoc != null)
                    {
                        mainFrm.pdfCtl.OpenDocFrom(newCoreDoc);
                    }
                }
                catch { }
            }

            return(true);
        }
Example #7
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);
        }