Пример #1
0
        private void PopulateSignatureNames()
        {
            if (acroForm == null)
            {
                return;
            }
            IList <Object[]> sorter = new List <Object[]>();

            foreach (KeyValuePair <String, PdfFormField> entry in acroForm.GetFormFields())
            {
                PdfFormField  field  = entry.Value;
                PdfDictionary merged = field.GetPdfObject();
                if (!PdfName.Sig.Equals(merged.Get(PdfName.FT)))
                {
                    continue;
                }
                PdfDictionary v = merged.GetAsDictionary(PdfName.V);
                if (v == null)
                {
                    continue;
                }
                PdfString contents = v.GetAsString(PdfName.Contents);
                if (contents == null)
                {
                    continue;
                }
                else
                {
                    contents.MarkAsUnencryptedObject();
                }
                PdfArray ro = v.GetAsArray(PdfName.ByteRange);
                if (ro == null)
                {
                    continue;
                }
                int rangeSize = ro.Size();
                if (rangeSize < 2)
                {
                    continue;
                }
                int length = ro.GetAsNumber(rangeSize - 1).IntValue() + ro.GetAsNumber(rangeSize - 2).IntValue();
                sorter.Add(new Object[] { entry.Key, new int[] { length, 0 } });
            }
            JavaCollectionsUtil.Sort(sorter, new SignatureUtil.SorterComparator());
            if (sorter.Count > 0)
            {
                try {
                    if (((int[])sorter[sorter.Count - 1][1])[0] == document.GetReader().GetFileLength())
                    {
                        totalRevisions = sorter.Count;
                    }
                    else
                    {
                        totalRevisions = sorter.Count + 1;
                    }
                }
                catch (System.IO.IOException) {
                }
                // TODO: add exception handling (at least some logger)
                for (int k = 0; k < sorter.Count; ++k)
                {
                    Object[] objs = sorter[k];
                    String   name = (String)objs[0];
                    int[]    p    = (int[])objs[1];
                    p[1] = k + 1;
                    sigNames.Put(name, p);
                    orderedSignatureNames.Add(name);
                }
            }
        }
Пример #2
0
 /// <summary>Create new FontSelector instance.</summary>
 /// <param name="allFonts">Unsorted set of all available fonts.</param>
 /// <param name="fontFamilies">Sorted list of preferred font families.</param>
 /// <param name="fc"/>
 public FontSelector(ICollection <FontInfo> allFonts, IList <String> fontFamilies, FontCharacteristics fc)
 {
     this.fonts = new List <FontInfo>(allFonts);
     //Possible issue in .NET, virtual protected member in constructor.
     JavaCollectionsUtil.Sort(this.fonts, GetComparator(fontFamilies, fc));
 }
Пример #3
0
        private void SortWithMarks(IList <TextChunk> textChunks)
        {
            IDictionary <TextChunk, LocationTextExtractionStrategy.TextChunkMarks> marks = new Dictionary <TextChunk, LocationTextExtractionStrategy.TextChunkMarks
                                                                                                           >();
            IList <TextChunk> toSort = new List <TextChunk>();

            for (int markInd = 0; markInd < textChunks.Count; markInd++)
            {
                ITextChunkLocation location = textChunks[markInd].GetLocation();
                if (location.GetStartLocation().Equals(location.GetEndLocation()))
                {
                    bool foundBaseToAttachTo = false;
                    for (int baseInd = 0; baseInd < textChunks.Count; baseInd++)
                    {
                        if (markInd != baseInd)
                        {
                            ITextChunkLocation baseLocation = textChunks[baseInd].GetLocation();
                            if (!baseLocation.GetStartLocation().Equals(baseLocation.GetEndLocation()) && TextChunkLocationDefaultImp.
                                ContainsMark(baseLocation, location))
                            {
                                LocationTextExtractionStrategy.TextChunkMarks currentMarks = marks.Get(textChunks[baseInd]);
                                if (currentMarks == null)
                                {
                                    currentMarks = new LocationTextExtractionStrategy.TextChunkMarks();
                                    marks.Put(textChunks[baseInd], currentMarks);
                                }
                                if (markInd < baseInd)
                                {
                                    currentMarks.preceding.Add(textChunks[markInd]);
                                }
                                else
                                {
                                    currentMarks.succeeding.Add(textChunks[markInd]);
                                }
                                foundBaseToAttachTo = true;
                                break;
                            }
                        }
                    }
                    if (!foundBaseToAttachTo)
                    {
                        toSort.Add(textChunks[markInd]);
                    }
                }
                else
                {
                    toSort.Add(textChunks[markInd]);
                }
            }
            JavaCollectionsUtil.Sort(toSort, new TextChunkLocationBasedComparator(new DefaultTextChunkLocationComparator
                                                                                      (!rightToLeftRunDirection)));
            textChunks.Clear();
            foreach (TextChunk current in toSort)
            {
                LocationTextExtractionStrategy.TextChunkMarks currentMarks = marks.Get(current);
                if (currentMarks != null)
                {
                    if (!rightToLeftRunDirection)
                    {
                        for (int j = 0; j < currentMarks.preceding.Count; j++)
                        {
                            textChunks.Add(currentMarks.preceding[j]);
                        }
                    }
                    else
                    {
                        for (int j = currentMarks.succeeding.Count - 1; j >= 0; j--)
                        {
                            textChunks.Add(currentMarks.succeeding[j]);
                        }
                    }
                }
                textChunks.Add(current);
                if (currentMarks != null)
                {
                    if (!rightToLeftRunDirection)
                    {
                        for (int j = 0; j < currentMarks.succeeding.Count; j++)
                        {
                            textChunks.Add(currentMarks.succeeding[j]);
                        }
                    }
                    else
                    {
                        for (int j = currentMarks.preceding.Count - 1; j >= 0; j--)
                        {
                            textChunks.Add(currentMarks.preceding[j]);
                        }
                    }
                }
            }
        }
        private void SortWithMarks(IList <LocationTextExtractionStrategy2.TextChunk> textChunks)
        {
            IDictionary <LocationTextExtractionStrategy2.TextChunk, LocationTextExtractionStrategy2.TextChunkMarks> col = new Dictionary <LocationTextExtractionStrategy2.TextChunk, LocationTextExtractionStrategy2.TextChunkMarks>();
            IList <LocationTextExtractionStrategy2.TextChunk> list = new List <LocationTextExtractionStrategy2.TextChunk>();

            for (int i = 0; i < textChunks.Count; i++)
            {
                LocationTextExtractionStrategy2.ITextChunkLocation location = textChunks[i].GetLocation();
                if (location.GetStartLocation().Equals(location.GetEndLocation()))
                {
                    bool flag = false;
                    for (int j = 0; j < textChunks.Count; j++)
                    {
                        if (i != j)
                        {
                            LocationTextExtractionStrategy2.ITextChunkLocation location2 = textChunks[j].GetLocation();
                            if (!location2.GetStartLocation().Equals(location2.GetEndLocation()) && this.ContainsMark(location2, location))
                            {
                                LocationTextExtractionStrategy2.TextChunkMarks textChunkMarks = col.Get(textChunks[j]);
                                if (textChunkMarks == null)
                                {
                                    textChunkMarks = new LocationTextExtractionStrategy2.TextChunkMarks();
                                    col.Put(textChunks[j], textChunkMarks);
                                }
                                if (i < j)
                                {
                                    textChunkMarks.preceding.Add(textChunks[i]);
                                }
                                else
                                {
                                    textChunkMarks.succeeding.Add(textChunks[i]);
                                }
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        list.Add(textChunks[i]);
                    }
                }
                else
                {
                    list.Add(textChunks[i]);
                }
            }
            if (this.rightToLeftRunDirection)
            {
                JavaCollectionsUtil.Sort <LocationTextExtractionStrategy2.TextChunk>(list, new LocationTextExtractionStrategy2.TextChunkComparator(new LocationTextExtractionStrategy2.TextChunkLocationComparator(false)));
            }
            else
            {
                JavaCollectionsUtil.Sort <LocationTextExtractionStrategy2.TextChunk>(list);
            }
            textChunks.Clear();
            foreach (LocationTextExtractionStrategy2.TextChunk current in list)
            {
                LocationTextExtractionStrategy2.TextChunkMarks textChunkMarks2 = col.Get(current);
                if (textChunkMarks2 != null)
                {
                    if (!this.rightToLeftRunDirection)
                    {
                        for (int k = 0; k < textChunkMarks2.preceding.Count; k++)
                        {
                            textChunks.Add(textChunkMarks2.preceding[k]);
                        }
                    }
                    else
                    {
                        for (int l = textChunkMarks2.succeeding.Count - 1; l >= 0; l--)
                        {
                            textChunks.Add(textChunkMarks2.succeeding[l]);
                        }
                    }
                }
                textChunks.Add(current);
                if (textChunkMarks2 != null)
                {
                    if (!this.rightToLeftRunDirection)
                    {
                        for (int m = 0; m < textChunkMarks2.succeeding.Count; m++)
                        {
                            textChunks.Add(textChunkMarks2.succeeding[m]);
                        }
                    }
                    else
                    {
                        for (int n = textChunkMarks2.preceding.Count - 1; n >= 0; n--)
                        {
                            textChunks.Add(textChunkMarks2.preceding[n]);
                        }
                    }
                }
            }
        }