internal static void ReadFromDisk(PDFDocument pdf_document, PDFInkList inks)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            try
            {
                byte[] inks_data = null;
                List <LibraryDB.LibraryItem> library_items = pdf_document.LibraryRef.Xlibrary.LibraryDB.GetLibraryItems(PDFDocumentFileLocations.INKS, new List <string>()
                {
                    pdf_document.Fingerprint
                });
                ASSERT.Test(library_items.Count < 2);
                if (0 < library_items.Count)
                {
                    inks_data = library_items[0].data;
                }

                if (null != inks_data)
                {
                    Dictionary <int, byte[]> page_ink_blobs = SerializeFile.ProtoLoadFromByteArray <Dictionary <int, byte[]> >(inks_data);

                    if (null != page_ink_blobs)
                    {
                        foreach (var pair in page_ink_blobs)
                        {
                            pdf_document.AddPageInkBlob(pair.Key, pair.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem loading the Inks for document {0}", pdf_document.Fingerprint);
            }
        }
        private void RebuildInks(int page, PDFInkList pdf_ink_list)
        {
            StrokeCollection stroke_collection = pdf_ink_list.GetInkStrokeCollection(page);

            if (null != stroke_collection)
            {
                ObjInkCanvas.Strokes = stroke_collection;
            }
        }
        internal static List <PDFAnnotation> GenerateAnnotations(PDFDocument pdf_document, Dictionary <string, byte[]> library_items_inks_cache)
        {
            List <PDFAnnotation> annotations = new List <PDFAnnotation>();

            if (pdf_document.DocumentExists)
            {
                PDFInkList ink_list = pdf_document.GetInks(library_items_inks_cache);
                foreach (int page in ink_list.GetAffectedPages())
                {
                    annotations.AddRange(GenerateAnnotations(pdf_document, page, ink_list));
                }
            }

            return(annotations);
        }
예제 #4
0
        internal static List <PDFAnnotation> GenerateAnnotations(PDFDocument pdf_document)
        {
            List <PDFAnnotation> annotations = new List <PDFAnnotation>();

            if (pdf_document.DocumentExists)
            {
                PDFInkList ink_list = pdf_document.GetInks();
                foreach (int page in ink_list.GetAffectedPages())
                {
                    annotations.AddRange(GenerateAnnotations(pdf_document, page, ink_list));
                }
            }

            return(annotations);
        }
        internal static void ReadFromDisk(PDFDocument_ThreadUnsafe pdf_document, PDFInkList inks, Dictionary <string, byte[]> library_items_inks_cache)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            try
            {
                byte[] inks_data = null;
                if (null != library_items_inks_cache)
                {
                    library_items_inks_cache.TryGetValue(pdf_document.Fingerprint, out inks_data);
                }
                else
                {
                    List <LibraryDB.LibraryItem> library_items = pdf_document.Library.LibraryDB.GetLibraryItems(pdf_document.Fingerprint, PDFDocumentFileLocations.INKS);
                    if (0 < library_items.Count)
                    {
                        inks_data = library_items[0].data;
                    }
                }

                if (null != inks_data)
                {
                    Dictionary <int, byte[]> page_ink_blobs = SerializeFile.ProtoLoadFromByteArray <Dictionary <int, byte[]> >(inks_data);

                    if (null != page_ink_blobs)
                    {
                        foreach (var pair in page_ink_blobs)
                        {
                            inks.AddPageInkBlob(pair.Key, pair.Value);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem loading the Inks for document {0}", pdf_document.Fingerprint);
            }
        }
        internal static List <PDFAnnotation> GenerateAnnotations(PDFDocument pdf_document, int page, PDFInkList ink_list)
        {
            List <RegionOfInterest> regions = new List <RegionOfInterest>();

            // Collect all the highlights on this page
            StrokeCollection stroke_collection = ink_list.GetInkStrokeCollection(page);

            if (null != stroke_collection)
            {
                foreach (Stroke stroke in stroke_collection)
                {
                    double SCALE = 1000.0;
                    Rect   bound = stroke.GetBounds();
                    bound.X      /= SCALE;
                    bound.Y      /= SCALE;
                    bound.Width  /= SCALE;
                    bound.Height /= SCALE;

                    regions.Add(new RegionOfInterest(bound.Left, bound.Top, bound.Width, bound.Height));
                }
            }

            RegionOfInterest.AggregateRegions(regions);

            // Build a list of annotations
            List <PDFAnnotation> annotations = RegionOfInterest.ConvertRegionsToPDFAnnotations(regions, INKS_TAG, pdf_document, page);

            return(annotations);
        }