コード例 #1
0
        public static void SortQuotations(List <KnowledgeItem> quotations)
        {
            if (quotations.Count <= 1)
            {
                return;
            }

            Reference reference = quotations.FirstOrDefault().Reference;

            if (reference == null)
            {
                return;
            }

            var locations = quotations.GetPDFLocations();

            if (locations == null)
            {
                return;
            }

            List <PageWidth> store = new List <PageWidth>();

            foreach (Location location in locations)
            {
                Document document = null;

                var address = location.Address.Resolve().LocalPath;
                document = new Document(address);

                if (document != null)
                {
                    for (int i = 1; i <= document.GetPageCount(); i++)
                    {
                        pdftron.PDF.Page page = document.GetPage(i);
                        if (page.IsValid())
                        {
                            var re = page.GetCropBox();
                            store.Add(new PageWidth(location, i, re.Width()));
                        }
                        else
                        {
                            store.Add(new PageWidth(location, i, 0.00));
                        }
                    }
                }
            }

            quotations.Sort(new KnowledgeItemComparer(store));

            var firstQuotation = quotations.First();

            for (int i = 1; i < quotations.Count; i++)
            {
                reference.Quotations.Move(quotations[i], firstQuotation);
                firstQuotation = quotations[i];
            }
        }
コード例 #2
0
        public static void SortKnowledgeItemsInCategorySorter(MainForm mainForm)
        {
            var category = mainForm.GetSelectedKnowledgeOrganizerCategory();

            var knowledgeItems = category.KnowledgeItems.ToList();

            if (knowledgeItems.Count > 1)
            {
                var pdfLocations = knowledgeItems.GetPDFLocations();

                List <PageWidth> store = new List <PageWidth>();

                foreach (Location location in pdfLocations)
                {
                    Document document = null;

                    var address = location.Address.Resolve().LocalPath;
                    document = new Document(address);

                    if (document != null)
                    {
                        for (int i = 1; i <= document.GetPageCount(); i++)
                        {
                            pdftron.PDF.Page page = document.GetPage(i);
                            if (page.IsValid())
                            {
                                var re = page.GetCropBox();
                                store.Add(new PageWidth(location, i, re.Width()));
                            }
                            else
                            {
                                store.Add(new PageWidth(location, i, 0.00));
                            }
                        }
                    }
                } // end foreach

                knowledgeItems.Sort(new KnowledgeItemComparer(store));

                var firstKnowledgeItem = knowledgeItems.First();
                for (int i = 1; i < knowledgeItems.Count; i++)
                {
                    category.KnowledgeItems.Move(knowledgeItems[i], firstKnowledgeItem);
                    firstKnowledgeItem = knowledgeItems[i];
                }

                CreateSubheadings(knowledgeItems, category, true);
            }
        }
コード例 #3
0
        public static void AssignPageRangeFromPrecedingQuotation(List <KnowledgeItem> quotations)
        {
            Reference reference = quotations.FirstOrDefault().Reference;

            if (reference == null)
            {
                return;
            }

            List <KnowledgeItem> referenceQuotations = reference.Quotations.ToList();

            if (referenceQuotations == null)
            {
                return;
            }

            var pdfLocations = reference.GetPDFLocations();

            List <PageWidth> store = new List <PageWidth>();

            if (pdfLocations != null)
            {
                foreach (Location location in pdfLocations)
                {
                    Document document = null;

                    var address = location.Address.Resolve().LocalPath;
                    document = new Document(address);

                    if (document != null)
                    {
                        for (int i = 1; i <= document.GetPageCount(); i++)
                        {
                            pdftron.PDF.Page page = document.GetPage(i);
                            if (page.IsValid())
                            {
                                var re = page.GetCropBox();
                                store.Add(new PageWidth(location, i, re.Width()));
                            }
                            else
                            {
                                store.Add(new PageWidth(location, i, 0.00));
                            }
                        }
                    }
                }
            }


            referenceQuotations.Sort(new KnowledgeItemComparer(store));

            foreach (KnowledgeItem quotation in quotations)
            {
                int index = referenceQuotations.FindIndex(q => q == quotation);
                if (index <= 1)
                {
                    continue;
                }

                KnowledgeItem previousQuotation = referenceQuotations[index - 1];
                if (previousQuotation == null)
                {
                    continue;
                }

                quotation.PageRange = previousQuotation.PageRange;
                quotation.PageRange = quotation.PageRange.Update(previousQuotation.PageRange.NumberingType);
                quotation.PageRange = quotation.PageRange.Update(previousQuotation.PageRange.NumeralSystem);
            }
        }
コード例 #4
0
        public static KnowledgeItem CombineQuotations(List <KnowledgeItem> quotations)
        {
            if (quotations.Count() == 1)
            {
                return(quotations.FirstOrDefault());
            }
            if (quotations.Count == 0)
            {
                return(null);
            }

            // Static Variables

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return(null);
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return(null);
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return(null);
            }

            Reference reference = quotations.FirstOrDefault().Reference;

            if (reference == null)
            {
                return(null);
            }

            Project project = Program.ActiveProjectShell.Project;

            if (project == null)
            {
                return(null);
            }

            List <Location> locations = quotations.GetPDFLocations().Distinct().ToList();

            if (locations.Count != 1)
            {
                return(null);
            }
            Location location = locations.FirstOrDefault();

            List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList();
            var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight);

            quotationTypes.Remove(itemToRemove);

            QuotationType quotationType = quotationTypes.FirstOrDefault();

            if (quotationTypes.Count == 0)
            {
                quotationType = QuotationType.Highlight;
            }

            // Dynamic Variables

            KnowledgeItem newQuotation = new KnowledgeItem(reference, quotationType);

            string text = string.Empty;

            List <Quad>      quads          = new List <Quad>();
            List <PageRange> pageRangesList = new List <PageRange>();
            string           pageRangeText  = string.Empty;

            List <PageWidth> store = new List <PageWidth>();

            // The Magic

            if (document != null)
            {
                for (int i = 1; i <= document.GetPageCount(); i++)
                {
                    pdftron.PDF.Page page = document.GetPage(i);
                    if (page.IsValid())
                    {
                        var re = page.GetCropBox();
                        store.Add(new PageWidth(location, i, re.Width()));
                    }
                    else
                    {
                        store.Add(new PageWidth(location, i, 0.00));
                    }
                }
            }

            quotations.Sort(new KnowledgeItemComparer(store));

            foreach (KnowledgeItem quotation in quotations)
            {
                if (!string.IsNullOrEmpty(quotation.Text))
                {
                    text = MergeRTF(text, quotation.TextRtf);
                }
                if (!string.IsNullOrEmpty(quotation.PageRange.OriginalString))
                {
                    pageRangesList.Add(quotation.PageRange);
                }
            }

            pageRangesList = PageRangeMerger.MergeAdjacent(pageRangesList);
            pageRangeText  = PageRangeMerger.PageRangeListToString(pageRangesList);

            newQuotation.TextRtf   = text;
            newQuotation.PageRange = pageRangeText;
            newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumberingType);
            newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumeralSystem);

            reference.Quotations.Add(newQuotation);
            project.AllKnowledgeItems.Add(newQuotation);

            return(newQuotation);
        }