Ejemplo n.º 1
0
        public PDFSearchHandle(PDFTextPage textPage, byte[] findWhatUnicode, int startIndex,
                               MatchOption flags = MatchOption.NONE)
        {
            if (textPage == null)
            {
                throw new NullReferenceException();
            }
            if (startIndex < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            PDFLibrary.AddRef("PDFSearchHandle");

            m_TextPage = textPage;

            IntPtr unmanagedPointer = Marshal.AllocHGlobal(findWhatUnicode.Length);

            Marshal.Copy(findWhatUnicode, 0, unmanagedPointer, findWhatUnicode.Length);

            m_NativePointer = FPDFText_FindStart(textPage.NativePointer, unmanagedPointer, (int)flags, startIndex);

            Marshal.FreeHGlobal(unmanagedPointer);
        }
Ejemplo n.º 2
0
        void LateUpdate()
        {
            if (!m_SearchStarted && m_NewSearchRequested)
            {
                m_CurrentPage   = 0;
                m_SearchResults = new IList <PDFSearchResult> [m_PageCount];

                m_NewSearchRequested = false;
                m_SearchStarted      = true;

                m_AbortRequested = false;

                m_Total = 0;
            }

            if (m_SearchStarted)
            {
                if (m_AbortRequested)
                {
                    m_SearchStarted      = false;
                    m_NewSearchRequested = false;

                    m_AbortRequested = false;

                    m_Total = 0;
                    return;
                }
                if (m_NewSearchRequested)
                {
                    m_CurrentPage   = 0;
                    m_SearchResults = new IList <PDFSearchResult> [m_PageCount];

                    m_NewSearchRequested = false;

                    m_Total = 0;
                }

                if (m_Search == null || m_Search.Length == 0)
                {
                    m_SearchStarted = false;

                    if (OnProgressChanged != null)
                    {
                        OnProgressChanged(this, 0);
                    }

                    var handler = OnSearchFinished;
                    if (handler != null)
                    {
                        handler(this, null);
                    }
                }
                else
                {
                    Stopwatch timer = Stopwatch.StartNew();

                    for (int i = m_CurrentPage; i < m_PageCount; ++i)
                    {
                        using (PDFTextPage textPage = m_Document.GetPage(i).GetTextPage())
                        {
                            IList <PDFSearchResult> searchResults = textPage.Search(m_Search, m_Flags);

                            m_SearchResults[i] = searchResults;

                            m_Total += searchResults.Count;

                            ++m_CurrentPage;

                            if (timer.ElapsedMilliseconds >=
                                m_TimeBudget * 1000.0f * (1.0f / Mathf.Max(Application.targetFrameRate, 1.0f / Time.deltaTime)))
                            {
                                if (OnProgressChanged != null)
                                {
                                    OnProgressChanged(this, m_Total);
                                }

                                break;
                            }
                        }
                    }

                    if (m_CurrentPage + 1 > m_PageCount)
                    {
                        m_SearchStarted = false;

                        if (OnProgressChanged != null)
                        {
                            OnProgressChanged(this, m_Total);
                        }

                        var handler = OnSearchFinished;
                        if (handler != null)
                        {
                            handler(this, m_SearchResults);
                        }

                        if (OnProgressChanged != null)
                        {
                            OnProgressChanged(this, m_Total);
                        }
                    }
                }
            }
        }