コード例 #1
0
        // pdfio2.c (307, 1)
        // ptraConcatenatePdfToData(pa_data, sa, pdata, pnbytes) as int
        // ptraConcatenatePdfToData(L_PTRA *, SARRAY *, l_uint8 **, size_t *) as l_ok
        ///  <summary>
        /// (1) This only works with leptonica-formatted single-page pdf files.
        /// pdf files generated by other programs will have unpredictable
        /// (and usually bad) results.  The requirements for each pdf file:
        /// (a) The Catalog and Info objects are the first two.
        /// (b) Object 3 is Pages
        /// (c) Object 4 is Page
        /// (d) The remaining objects are Contents, XObjects, and ColorSpace<para/>
        ///
        /// (2) We remove trailers from each page, and append the full trailer
        /// for all pages at the end.<para/>
        ///
        /// (3) For all but the first file, remove the ID and the first 3
        /// objects (catalog, info, pages), so that each subsequent
        /// file has only objects of these classes:
        /// Page, Contents, XObject, ColorSpace (Indexed RGB).
        /// For those objects, we substitute these refs to objects
        /// in the local file:
        /// Page:  Parent(object 3), Contents, XObject(typically multiple)
        /// XObject:  [ColorSpace if indexed]
        /// The Pages object on the first page (object 3) has a Kids array
        /// of references to all the Page objects, with a Count equal
        /// to the number of pages.  Each Page object refers back to
        /// this parent.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraConcatenatePdfToData/*"/>
        ///  <param name="pa_data">[in] - ptra array of pdf strings, each for a single-page pdf file</param>
        ///  <param name="sa">[in] - string array [optional] of pathnames for input pdf files</param>
        ///  <param name="pdata">[out] - concatenated pdf data in memory</param>
        ///  <param name="pnbytes">[out] - number of bytes in pdf data</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int ptraConcatenatePdfToData(
            L_Ptra pa_data,
            Sarray sa,
            out Byte[] pdata,
            out uint pnbytes)
        {
            if (pa_data == null)
            {
                throw new ArgumentNullException("pa_data cannot be Nothing");
            }

            IntPtr saPtr = IntPtr.Zero;     if (sa != null)
            {
                saPtr = sa.Pointer;
            }
            IntPtr pdataPtr = IntPtr.Zero;
            int    _Result  = Natives.ptraConcatenatePdfToData(pa_data.Pointer, saPtr, out pdataPtr, out pnbytes);

            Byte[] pdataGen = new Byte[pnbytes];

            if (pdataPtr != IntPtr.Zero)
            {
                Marshal.Copy(pdataPtr, pdataGen, 0, pdataGen.Length);
            }

            pdata = pdataGen;
            return(_Result);
        }
コード例 #2
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (625, 1)
        // ptraReverse(pa) as int
        // ptraReverse(L_PTRA *) as l_ok
        ///  <summary>
        /// ptraReverse()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraReverse/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int ptraReverse(
            L_Ptra pa)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            int _Result = Natives.ptraReverse(pa.Pointer);

            return(_Result);
        }
コード例 #3
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (727, 1)
        // ptraGetActualCount(pa, pcount) as int
        // ptraGetActualCount(L_PTRA *, l_int32 *) as l_ok
        ///  <summary>
        /// (1) The actual number of items on the ptr array, patonactual,
        /// will be smaller than paton if the array is not compacted.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraGetActualCount/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///  <param name="pcount">[out] - actual number of items on the ptr array</param>
        ///   <returns>0 if OK 1 on error</returns>
        public static int ptraGetActualCount(
            L_Ptra pa,
            out int pcount)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            int _Result = Natives.ptraGetActualCount(pa.Pointer, out pcount);

            return(_Result);
        }
コード例 #4
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (699, 1)
        // ptraGetMaxIndex(pa, pmaxindex) as int
        // ptraGetMaxIndex(L_PTRA *, l_int32 *) as l_ok
        ///  <summary>
        /// (1) The largest index to an item in the array is %maxindex.
        /// %maxindex is one less than the number of items that would be
        /// in the array if there were no null pointers between 0
        /// and %maxindex - 1.  However, because the internal ptr array
        /// need not be compacted, there may be NULL pointers at
        /// indices below %maxindex for example, if items have
        /// been removed.<para/>
        ///
        /// (2) When an item is added to the end of the array, it goes
        /// into patoarray[maxindex + 1], and maxindex is then
        /// incremented by 1.<para/>
        ///
        /// (3) If there are no items in the array, this returns %maxindex = -1.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraGetMaxIndex/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///  <param name="pmaxindex">[out] - index of last item in the array</param>
        ///   <returns>0 if OK 1 on error</returns>
        public static int ptraGetMaxIndex(
            L_Ptra pa,
            out int pmaxindex)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            int _Result = Natives.ptraGetMaxIndex(pa.Pointer, out pmaxindex);

            return(_Result);
        }
コード例 #5
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (553, 1)
        // ptraSwap(pa, index1, index2) as int
        // ptraSwap(L_PTRA *, l_int32, l_int32) as l_ok
        ///  <summary>
        /// ptraSwap()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraSwap/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///  <param name="index1">[in] - </param>
        ///  <param name="index2">[in] - </param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int ptraSwap(
            L_Ptra pa,
            int index1,
            int index2)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            int _Result = Natives.ptraSwap(pa.Pointer, index1, index2);

            return(_Result);
        }
コード例 #6
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (483, 1)
        // ptraRemoveLast(pa) as Object
        // ptraRemoveLast(L_PTRA *) as void *
        ///  <summary>
        /// ptraRemoveLast()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraRemoveLast/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///   <returns>item, or NULL on error or if the array is empty</returns>
        public static Object ptraRemoveLast(
            L_Ptra pa)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            IntPtr _Result = Natives.ptraRemoveLast(pa.Pointer);

            Byte[] B = new Byte[1];
            Marshal.Copy(_Result, B, 0, B.Length);
            return(B);
        }
コード例 #7
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (649, 1)
        // ptraJoin(pa1, pa2) as int
        // ptraJoin(L_PTRA *, L_PTRA *) as l_ok
        ///  <summary>
        /// ptraJoin()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraJoin/*"/>
        ///  <param name="pa1">[in] - add to this one</param>
        ///  <param name="pa2">[in] - appended to pa1, and emptied of items can be null</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int ptraJoin(
            L_Ptra pa1,
            L_Ptra pa2)
        {
            if (pa1 == null)
            {
                throw new ArgumentNullException("pa1 cannot be Nothing");
            }

            if (pa2 == null)
            {
                throw new ArgumentNullException("pa2 cannot be Nothing");
            }

            int _Result = Natives.ptraJoin(pa1.Pointer, pa2.Pointer);

            return(_Result);
        }
コード例 #8
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (898, 1)
        // ptraaInsertPtra(paa, index, pa) as int
        // ptraaInsertPtra(L_PTRAA *, l_int32, L_PTRA *) as l_ok
        ///  <summary>
        /// (1) Caller should check return value.  On success, the Ptra
        /// is inserted in the Ptraa and is owned by it.  However,
        /// on error, the Ptra remains owned by the caller.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraaInsertPtra/*"/>
        ///  <param name="paa">[in] - ptraa</param>
        ///  <param name="index">[in] - location in array for insertion</param>
        ///  <param name="pa">[in] - to be inserted</param>
        ///   <returns>0 if OK 1 on error</returns>
        public static int ptraaInsertPtra(
            L_Ptraa paa,
            int index,
            L_Ptra pa)
        {
            if (paa == null)
            {
                throw new ArgumentNullException("paa cannot be Nothing");
            }

            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            int _Result = Natives.ptraaInsertPtra(paa.Pointer, index, pa.Pointer);

            return(_Result);
        }
コード例 #9
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (512, 1)
        // ptraReplace(pa, index, item, freeflag) as Object
        // ptraReplace(L_PTRA *, l_int32, void *, l_int32) as void *
        ///  <summary>
        /// ptraReplace()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraReplace/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///  <param name="index">[in] - element to be replaced</param>
        ///  <param name="item">[in] - new generic ptr to a struct can be null</param>
        ///  <param name="freeflag">[in] - TRUE to free old item FALSE to return it</param>
        ///   <returns>item  old item, if it exists and is not freed, or NULL on error</returns>
        public static Object ptraReplace(
            L_Ptra pa,
            int index,
            Object item,
            int freeflag)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            if (item == null)
            {
                throw new ArgumentNullException("item cannot be Nothing");
            }

            IntPtr itemPtr = IntPtr.Zero;

            if (item.GetType() == typeof(IntPtr))
            {
                itemPtr = (IntPtr)item;
            }
            else if (item.GetType() == typeof(Byte[]))
            {
                var cdata = (Byte[])item;
                itemPtr = Marshal.AllocHGlobal(cdata.Length);
                Marshal.Copy(cdata, 0, itemPtr, cdata.Length);
            }
            else if (item.GetType().GetProperty("item") != null)
            {
                var cdata = (Byte[])item.GetType().GetProperty("data").GetValue(item, null);
                itemPtr = Marshal.AllocHGlobal(cdata.Length);
                Marshal.Copy(cdata, 0, itemPtr, cdata.Length);
            }

            IntPtr _Result = Natives.ptraReplace(pa.Pointer, index, itemPtr, freeflag);

            Marshal.FreeHGlobal(itemPtr);
            Byte[] B = new Byte[1];
            Marshal.Copy(_Result, B, 0, B.Length);
            return(B);
        }
コード例 #10
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (185, 1)
        // ptraDestroy(ppa, freeflag, warnflag) as Object
        // ptraDestroy(L_PTRA **, l_int32, l_int32) as void
        ///  <summary>
        /// (1) If %freeflag == TRUE, frees each item in the array.<para/>
        ///
        /// (2) If %freeflag == FALSE and %warnflag == TRUE, and there are
        /// items on the array, this gives a warning and destroys the array.
        /// If these items are not owned elsewhere, this will cause
        /// a memory leak of all the items that were on the array.
        /// So if the items are not owned elsewhere and require their
        /// own destroy function, they must be destroyed before the ptra.<para/>
        ///
        /// (3) If %warnflag == FALSE, no warnings will be issued.  This is
        /// useful if the items are owned elsewhere, such as a
        /// PixMemoryStore().<para/>
        ///
        /// (4) To destroy the ptra, we destroy the ptr array, then
        /// the ptra, and then null the contents of the input ptr.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraDestroy/*"/>
        ///  <param name="ppa">[in,out] - ptra to be nulled</param>
        ///  <param name="freeflag">[in] - TRUE to free each remaining item in the array</param>
        ///  <param name="warnflag">[in] - TRUE to warn if any remaining items are not destroyed</param>
        public static void ptraDestroy(
            ref L_Ptra ppa,
            int freeflag,
            int warnflag)
        {
            IntPtr ppaPtr = IntPtr.Zero;    if (ppa != null)

            {
                ppaPtr = ppa.Pointer;
            }

            Natives.ptraDestroy(ref ppaPtr, freeflag, warnflag);
            if (ppaPtr == IntPtr.Zero)
            {
                ppa = null;
            }
            else
            {
                ppa = new L_Ptra(ppaPtr);
            };
        }
コード例 #11
0
ファイル: ptra.cs プロジェクト: Phreak87/LeptonicaSharp
        // ptra.c (242, 1)
        // ptraAdd(pa, item) as int
        // ptraAdd(L_PTRA *, void *) as l_ok
        ///  <summary>
        /// (1) This adds the element to the next location beyond imax,
        /// which is the largest occupied ptr in the array.  This is
        /// what you expect from a stack, where all ptrs up to and
        /// including imax are occupied, but here the occuption of
        /// items in the array is entirely arbitrary.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/ptraAdd/*"/>
        ///  <param name="pa">[in] - ptra</param>
        ///  <param name="item">[in] - generic ptr to a struct</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int ptraAdd(
            L_Ptra pa,
            Object item)
        {
            if (pa == null)
            {
                throw new ArgumentNullException("pa cannot be Nothing");
            }

            if (item == null)
            {
                throw new ArgumentNullException("item cannot be Nothing");
            }

            IntPtr itemPtr = IntPtr.Zero;

            if (item.GetType() == typeof(IntPtr))
            {
                itemPtr = (IntPtr)item;
            }
            else if (item.GetType() == typeof(Byte[]))
            {
                var cdata = (Byte[])item;
                itemPtr = Marshal.AllocHGlobal(cdata.Length);
                Marshal.Copy(cdata, 0, itemPtr, cdata.Length);
            }
            else if (item.GetType().GetProperty("item") != null)
            {
                var cdata = (Byte[])item.GetType().GetProperty("data").GetValue(item, null);
                itemPtr = Marshal.AllocHGlobal(cdata.Length);
                Marshal.Copy(cdata, 0, itemPtr, cdata.Length);
            }

            int _Result = Natives.ptraAdd(pa.Pointer, itemPtr);

            Marshal.FreeHGlobal(itemPtr);
            return(_Result);
        }