Esempio n. 1
0
        public static (float Llx, float Lly, float width, float height) GetPdfCoords(this Pdf.IWord target)
        {
            var pageWidth  = target.Parent.Width;
            var pageHeight = target.Parent.Height;
            var llx        = target.XMin;
            var lly        = pageHeight - target.YMax;
            var width      = target.XMax - target.XMin;
            var height     = target.YMax - target.YMin;

            return(llx, lly, width, height);
        }
Esempio n. 2
0
 public IEnumerable <Pdf.IWord> Aggregate(IEnumerable <Pdf.IWord> words)
 {
     Pdf.IWord oldCandidate       = null;
     Pdf.IWord paragraphCandidate = null;
     foreach (var word in words)
     {
         if (word.Text.StartsWith("§"))
         {
             paragraphCandidate = word;
         }
         else if (paragraphCandidate != null)
         {
             var candidate = $"{paragraphCandidate.Text} {word.Text}";
             if (EqualsVaguely(paragraphCandidate.YMin, word.YMin) && EqualsVaguely(paragraphCandidate.YMax, word.YMax) && ValidChain.IsMatch(candidate))
             {
                 oldCandidate       = paragraphCandidate;
                 paragraphCandidate = new AggregatedWord
                 {
                     Parent = word.Parent,
                     Text   = candidate,
                     XMax   = Math.Max(word.XMax, paragraphCandidate.XMax),
                     YMax   = Math.Max(word.YMax, paragraphCandidate.YMax),
                     XMin   = Math.Min(word.XMin, paragraphCandidate.XMin),
                     YMin   = Math.Min(word.YMin, paragraphCandidate.YMin)
                 };
             }
             else
             {
                 if (ValidParagraphExpression.IsMatch(paragraphCandidate.Text))
                 {
                     yield return(paragraphCandidate);
                 }
                 else if (ValidParagraphExpression.IsMatch(oldCandidate?.Text ?? ""))
                 {
                     yield return(oldCandidate);
                 }
                 paragraphCandidate = null;
             }
         }
         yield return(word);
     }
 }
Esempio n. 3
0
        private Rectangle GetAnnotationRect(Rectangle buttonRect, PdfFont font, IAnnotation annotation, Pdf.IWord target)
        {
            var rectU = GetUpperOrLowerAnnotationRect(buttonRect, font, annotation, target, true);
            var rect  = rectU;

            if (rectU.GetY() + rectU.GetHeight() > target.Parent.Height)
            {
                var rectL = GetUpperOrLowerAnnotationRect(buttonRect, font, annotation, target, false);
                if (rectL.GetY() + rectL.GetHeight() < target.Parent.Height && rectL.GetY() > 0)
                {
                    rect = rectL;
                }
            }

            if (rect.GetX() < 5 && rect.GetX() + 5 < target.Parent.Width)
            {
                // text is left outside of page but smaller than page plus some margin so move it inside
                rect.SetX(5);
            }
            else
            {
                var rectMaxX = rect.GetX() + rect.GetWidth();
                var delta    = rectMaxX + 5 - target.Parent.Width;
                if (delta > 0 && rect.GetWidth() < target.Parent.Width)
                {
                    // text is right outside of page but smaller than page so move it inside
                    rect.SetX(rect.GetX() - delta);
                }
            }

            return(rect);
        }
Esempio n. 4
0
        public static (float Llx, float Lly, float Urx, float Ury) GetPdfCoordsIText5(this Pdf.IWord target)
        {
            var pageWidth  = target.Parent.Width;
            var pageHeight = target.Parent.Height;
            var llx        = target.XMin;
            var lly        = pageHeight - target.YMax;
            var urx        = target.XMax;
            var ury        = pageHeight - target.YMin;

            return(llx, lly, urx, ury);
        }
Esempio n. 5
0
        private Rectangle GetUpperOrLowerAnnotationRect(Rectangle buttonRect, PdfFont font, IAnnotation annotation, Pdf.IWord target, bool upper = true)
        {
            var contentBounds = GetContentBounds(annotation.Content, target.Parent.Width / 2, font);

            var   targetWidthHalf = buttonRect.GetWidth() / 2;
            var   helpWidthHalf   = contentBounds.width / 2;
            var   annotHeight     = contentBounds.height + 6;
            float annotY;

            if (upper)
            {
                annotY = buttonRect.GetY() + buttonRect.GetHeight() + 5;
            }
            else
            {
                annotY = buttonRect.GetY() - annotHeight - 10;
            }
            var helpRect = new Rectangle(buttonRect.GetX() + targetWidthHalf - helpWidthHalf - 5, annotY, contentBounds.width + 10, annotHeight);

            return(helpRect);
        }