예제 #1
0
        /// <summary>
        /// The process drawings.
        /// </summary>
        /// <param name="shape">
        /// The drawings.
        /// </param>
        /// <param name="stamper">
        /// The stamper.
        /// </param>
        /// <param name="reader">
        /// The reader.
        /// </param>
        private void ProcessDraw(ATShape shape, PdfStamper stamper, PdfReader reader)
        {
            var size = reader.GetPageSizeWithRotation(shape.Mark.PageIndex);

            Action <PdfContentByte, ATShape> drawAction = (cb, s) =>
            {
                var posX = s.PositionX;
                var posY = s.PositionY;
                if (Math.Abs(posX) > float.Epsilon || Math.Abs(posY) > float.Epsilon)
                {
                    posY     = size.Height - s.PositionY;
                    size.Top = size.Bottom;
                }
                cb.SetLineCap(PdfContentByte.LINE_CAP_ROUND);
                cb.SetLineJoin(PdfContentByte.LINE_JOIN_ROUND);
                var parsedPoints = this.ParseDrawing(shape.Points, size).ToList();
                if (parsedPoints.Any())
                {
                    var firstPoint = parsedPoints.First();
                    cb.MoveTo(posX + firstPoint.X, posY + firstPoint.Y);
                    foreach (var point in parsedPoints)
                    {
                        cb.LineTo(posX + point.X, posY + point.Y);
                    }
                }
            };

            this.ProcessShape(shape, drawAction, stamper);
        }
예제 #2
0
        /// <summary>
        /// Converts <see cref="ATMarkDTO"/> to requested entity type
        /// </summary>
        /// <param name="mark">the mark</param>
        /// <param name="existing">existing item</param>
        /// <returns>corresponding entity</returns>
        public ATShape ToShape(ATMarkDTO mark, ATShape existing)
        {
            var o = existing ?? new ATShape();

            o.Mark          = this.ToMark(mark, null != existing ? existing.Mark : null);
            o.Color         = mark.color;
            o.FillColor     = mark.fillColor;
            o.FillOpacity   = mark.fillOpacity;
            o.Height        = mark.height;
            o.Image         = mark.image;
            o.Points        = mark.points;
            o.PositionX     = mark.positionX;
            o.PositionY     = mark.positionY;
            o.StrokeOpacity = mark.strokeOpacity;
            o.StrokeWidth   = mark.strokeWidth;
            o.Text          = mark.text;
            o.Width         = mark.width;

            o.LabelText          = mark.labelText;
            o.LabelTextColor     = mark.labelTextColor;
            o.NumberingTextColor = mark.numberingTextColor;
            o.StampColor         = mark.stampColor;
            o.Style = mark.style;
            return(o);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ATShapeMarkDTO"/> class.
        /// </summary>
        /// <param name="item">
        /// The note.
        /// </param>
        public ATShapeMarkDTO(ATShape item)
        {
            this.displayFormat = item.Mark.DisplayFormat;
            this.pageIndex     = item.Mark.PageIndex;
            this.id            = item.Mark.Id.ToString();
            this.type          = item.Mark.Type;
            this.fileId        = item.Mark.File.Id.ToString();
            this.datechanged   = item.Mark.DateChanged.With(x => x.ConvertToUnixTimestamp());
            this.datecreated   = item.Mark.DateCreated.With(x => x.ConvertToUnixTimestamp());
            this.@readonly     = item.Mark.IsReadonly;
            this.rotation      = item.Mark.Rotation;

            this.image     = item.Image;
            this.points    = item.Points;
            this.positionX = item.PositionX;
            this.positionY = item.PositionY;
            this.width     = item.Width;
            this.height    = item.Height;

            this.color         = item.Color;
            this.text          = item.Text;
            this.fillColor     = item.FillColor;
            this.fillOpacity   = item.FillOpacity;
            this.strokeOpacity = item.StrokeOpacity;
            this.strokeWidth   = item.StrokeWidth;

            this.labelText          = item.LabelText;
            this.labelTextColor     = item.LabelTextColor;
            this.numberingTextColor = item.NumberingTextColor;
            this.stampColor         = item.StampColor;
            this.style = item.Style;
        }
예제 #4
0
        /// <summary>
        /// The process rectangle.
        /// </summary>
        /// <param name="dr">
        /// The dr.
        /// </param>
        /// <param name="stamper">
        /// The stamper.
        /// </param>
        /// <param name="pdfReader">The reader</param>
        private void ProcessRectangle(ATShape dr, PdfStamper stamper, PdfReader pdfReader)
        {
            var pageHeight = pdfReader.GetPageSizeWithRotation(dr.Mark.PageIndex).Height;

            Action <PdfContentByte, ATShape> drawAction = (cb, s) => cb.Rectangle(s.PositionX, pageHeight - (s.PositionY + s.Height), s.Width, s.Height);

            this.ProcessShape(dr, drawAction, stamper);
        }
예제 #5
0
        private void ProcessStampSolidOutline(ATShape dr, PdfStamper stamper, PdfReader pdfReader, bool isFilled)
        {
            var pageHeight = pdfReader.GetPageSizeWithRotation(dr.Mark.PageIndex).Height;
            var cb         = stamper.GetOverContent(dr.Mark.PageIndex);

            var outer = new Rectangle(dr.PositionX, pageHeight - (dr.PositionY + dr.Height), dr.PositionX + dr.Width, pageHeight - dr.PositionY);
            var color = GetColor(dr.StampColor ?? "#990000");

            cb.SetColorStroke(color);
            var strokeWidth = 4f;

            cb.SetLineWidth(strokeWidth);
            cb.RoundRectangle(
                outer.Left,
                outer.Bottom + strokeWidth,
                outer.Width - strokeWidth,
                outer.Height - strokeWidth,
                5);

            if (isFilled)
            {
                cb.SetColorFill(color);
                cb.FillStroke();
            }
            else
            {
                cb.Stroke();
            }

            var text = dr.LabelText;

            // Create a font to work with
            color = GetColor(dr.LabelTextColor ?? "#000000");
            cb.SetRGBColorFill(color.R, color.G, color.B);

            // Note: The x,y of the Pdf Matrix is from bottom left corner.
            // This command tells iTextSharp to write the text at a certain location with a certain angle.
            // Again, this will angle the text from bottom left corner to top right corner and it will
            // place the text in the middle of the page.
            var size     = 13f;
            var baseFont = BaseFont.CreateFont(BaseFont.TIMES_BOLD, Encoding.ASCII.EncodingName, true);
            var ct       = new ColumnText(cb);
            var p        = new Paragraph(text, new Font(baseFont, size));
            var t        = new PdfPTable(1);
            var c        = new PdfPCell(p);

            c.VerticalAlignment   = Element.ALIGN_MIDDLE;
            c.HorizontalAlignment = Element.ALIGN_CENTER;
            c.FixedHeight         = outer.Height + 10;
            c.BorderWidth         = 0;
            c.SetLeading(0f, 1.2f);
            c.PaddingBottom = c.PaddingLeft = c.PaddingRight = c.PaddingTop = 0;
            t.AddCell(c);
            // TODO: remove this hardcoded adjust, was added to conform client
            ct.SetSimpleColumn(outer.Left - 2, outer.Bottom, outer.Right + 2, outer.Top + 12);
            ct.AddElement(t);
            ct.Go();
        }
예제 #6
0
        /// <summary>
        /// The process rectangle.
        /// </summary>
        /// <param name="dr">
        /// The dr.
        /// </param>
        /// <param name="stamper">
        /// The stamper.
        /// </param>
        /// <param name="pdfReader">The reader</param>
        private void ProcessRules(ATShape dr, PdfStamper stamper, PdfReader pdfReader)
        {
            for (int i = 1; i <= pdfReader.NumberOfPages; i++)
            {
                var page         = pdfReader.GetPageSizeWithRotation(i);
                var pageWidth    = page.Width;
                var pageHeight   = page.Height;
                var columnsCount = Math.Max(1, (int)dr.Width);
                int rowsCount    = 0;
                var cellWidth    = pageWidth / columnsCount;
                var cellHeight   = 0f;

                if (dr.Style == "1") // square cells
                {
                    cellHeight = cellWidth;
                    rowsCount  = (int)Math.Floor(pageHeight / cellHeight) + 1;
                }
                else
                {
                    rowsCount  = Math.Max(1, (int)dr.Height);
                    cellHeight = pageHeight / rowsCount;
                }

                var cb = stamper.GetOverContent(i);
                var bc = GetColor(dr.Color);

                cb.SaveState();

                for (int column = 1; column < columnsCount; column++)
                {
                    cb.SetColorStroke(bc);
                    cb.SetLineWidth(dr.StrokeWidth);
                    cb.MoveTo(column * cellWidth, pageHeight);
                    cb.LineTo(column * cellWidth, 0);
                    cb.ClosePathStroke();
                }

                for (int row = 1; row < rowsCount; row++)
                {
                    cb.SetColorStroke(bc);
                    cb.SetLineWidth(dr.StrokeWidth);
                    cb.MoveTo(0, row * cellHeight);
                    cb.LineTo(pageWidth, row * cellHeight);
                    cb.ClosePathStroke();
                }

                cb.RestoreState();
            }
        }
예제 #7
0
        /// <summary>
        /// The process drawings.
        /// </summary>
        /// <param name="shape">
        /// The drawings.
        /// </param>
        /// <param name="drawAction">actual draw action</param>
        /// <param name="stamper">
        /// The stamper.
        /// </param>
        private void ProcessShape(ATShape shape, Action <PdfContentByte, ATShape> drawAction, PdfStamper stamper)
        {
            var cb = stamper.GetOverContent(shape.Mark.PageIndex);

            var bc = GetColor(shape.Color);

            cb.SetColorStroke(bc);

            var isFilled = shape.Mark.Type == EntityTypes.FilledEllipse ||
                           shape.Mark.Type == EntityTypes.FilledRectangle;

            if (isFilled)
            {
                cb.SetColorFill(bc);
            }

            cb.SetLineWidth(shape.StrokeWidth);
            cb.SetLineCap(PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
            cb.SetLineJoin(PdfContentByte.LINE_JOIN_MITER);

            cb.SaveState();
            var gs      = new PdfGState();
            var opacity = Math.Max(0, Math.Max(shape.FillOpacity, shape.StrokeOpacity));

            if (opacity > 0)
            {
                gs.FillOpacity   = opacity;
                gs.StrokeOpacity = opacity;
            }

            cb.SetGState(gs);

            drawAction(cb, shape);

            if (isFilled)
            {
                cb.FillStroke();
            }
            else
            {
                cb.Stroke();
            }

            cb.RestoreState();
        }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ATMarkDTO"/> class.
        /// </summary>
        /// <param name="shape">
        /// The shape.
        /// </param>
        public ATMarkDTO(ATShape shape) : this(shape.Mark)
        {
            this.color         = shape.Color;
            this.positionX     = shape.PositionX;
            this.positionY     = shape.PositionY;
            this.width         = shape.Width;
            this.height        = shape.Height;
            this.points        = shape.Points;
            this.fillColor     = shape.FillColor;
            this.fillOpacity   = shape.FillOpacity;
            this.strokeOpacity = shape.StrokeOpacity;
            this.strokeWidth   = shape.StrokeWidth;

            this.labelText          = shape.LabelText;
            this.labelTextColor     = shape.LabelTextColor;
            this.numberingTextColor = shape.NumberingTextColor;
            this.stampColor         = shape.StampColor;
            this.style = shape.Style;

            this.text = shape.Text;
        }
예제 #9
0
        /// <summary>
        /// The process drawings.
        /// </summary>
        /// <param name="shape">
        /// The drawings.
        /// </param>
        /// <param name="stamper">
        /// The stamper.
        /// </param>
        /// <param name="reader">
        /// The reader.
        /// </param>
        private void ProcessShape(ATShape shape, PdfStamper stamper, PdfReader reader)
        {
            var size = reader.GetPageSizeWithRotation(shape.Mark.PageIndex);

            Action <PdfContentByte, ATShape> drawAction = (cb, s) =>
            {
                var parsedPoints = this.ParseDrawing(shape.Points, size).ToList();
                if (parsedPoints.Any())
                {
                    var posX = s.PositionX;
                    var posY = s.PositionY;
                    if (Math.Abs(posX) > float.Epsilon || Math.Abs(posY) > float.Epsilon)
                    {
                        posY = size.Height - s.PositionY;
                    }
                    var vectors =
                        Enumerable.Range(0, (parsedPoints.Count + 1) / 2)
                        .Select(i => new { start = parsedPoints[2 * i], end = parsedPoints.ElementAtOrDefault(2 * i + 1) });
                    Point last = null;
                    foreach (var v in vectors)
                    {
                        var start = null != v.end ? v.start : last ?? v.start;
                        var end   = v.end ?? v.start;

                        if (null == last || Math.Abs(start.X - last.X) > float.Epsilon || Math.Abs(start.Y - last.Y) > float.Epsilon)
                        {
                            cb.MoveTo(posX + start.X, posY + start.Y);
                        }

                        cb.LineTo(posX + end.X, posY + end.Y);

                        last = end;
                    }
                }
            };

            this.ProcessShape(shape, drawAction, stamper);
        }
예제 #10
0
        /// <summary>
        /// The get marks for file.
        /// </summary>
        /// <param name="fileId">
        /// The file id.
        /// </param>
        /// <returns>
        /// The <see cref="Tuple"/>.
        /// </returns>
#pragma warning disable 168
        public Tuple <List <ATShape>, List <ATDrawing>, List <ATHighlightStrikeOut>, List <ATTextItem>, List <ATRotation> > GetMarksForFile(Guid fileId)
        {
            // trick to make NHibernate to load all child instances in one roundtrip to db (if db supports it)
            var result = new Tuple <List <ATShape>, List <ATDrawing>, List <ATHighlightStrikeOut>, List <ATTextItem>, List <ATRotation> >
                             (new List <ATShape>(), new List <ATDrawing>(), new List <ATHighlightStrikeOut>(), new List <ATTextItem>(), new List <ATRotation>());
            ATMark               mark                 = null;
            ATShape              note                 = null;
            ATDrawing            atDrawing            = null;
            ATHighlightStrikeOut atHighlightStrikeOut = null;
            ATTextItem           textItem             = null;
            ATRotation           rotationItem         = null;

            // Query to load the companies
            var marks = this.Repository.Session.QueryOver(() => mark).Where(x => x.File.Id == fileId).Fetch(x => x.File).Eager.Future <ATMark>();

            // Query to load the Notes
            var notes = this.Repository.Session.QueryOver(() => note)
                        .JoinAlias(p => p.Mark, () => mark)
                        .Future <ATShape>();

            // Query to load the Drawings
            var drawings = this.Repository.Session.QueryOver(() => atDrawing)
                           .JoinAlias(p => p.Mark, () => mark)
                           .Future <ATDrawing>();

            // Query to load the Highlights
            var highlights = this.Repository.Session.QueryOver(() => atHighlightStrikeOut)
                             .JoinAlias(p => p.Mark, () => mark)
                             .Future <ATHighlightStrikeOut>();

            // Query to load the TextItems
            var textItems = this.Repository.Session.QueryOver(() => textItem)
                            .JoinAlias(p => p.Mark, () => mark)
                            .Future <ATTextItem>();

            // Query to load the Rotations
            var rotationItems = this.Repository.Session.QueryOver(() => rotationItem)
                                .JoinAlias(p => p.Mark, () => mark)
                                .Future <ATRotation>();

            // when this is executed, the three queries are executed in one roundtrip
            var results = marks.ToList();

            foreach (var joinedMark in results)
            {
                foreach (var joinedNote in joinedMark.Shapes)
                {
                    result.Item1.Add(joinedNote);
                }
                foreach (var joinedDrawing in joinedMark.Drawings)
                {
                    result.Item2.Add(joinedDrawing);
                }
                foreach (var joinedHighlight in joinedMark.HighlightStrikeOuts)
                {
                    result.Item3.Add(joinedHighlight);
                }
                foreach (var joinedText in joinedMark.TextItems)
                {
                    result.Item4.Add(joinedText);
                }
                foreach (var rotation in joinedMark.Rotations)
                {
                    result.Item5.Add(rotation);
                }
            }
            return(result);
        }
예제 #11
0
        private void ProcessExhibitStamp(ATShape dr, PdfStamper stamper, PdfReader pdfReader)
        {
            var pageHeight = pdfReader.GetPageSizeWithRotation(dr.Mark.PageIndex).Height;
            var cb         = stamper.GetOverContent(dr.Mark.PageIndex);

            var outer = new Rectangle(dr.PositionX, pageHeight - (dr.PositionY + dr.Height), dr.PositionX + dr.Width, pageHeight - dr.PositionY);
            var color = GetColor(dr.StampColor ?? "#2036E0");

            cb.SetColorStroke(color);
            cb.SetColorFill(color);
            cb.SetLineWidth(0);
            cb.RoundRectangle(outer.Left + 2, outer.Bottom, outer.Width - 2, outer.Height, 5);
            cb.FillStroke();

            const float shift     = 8;
            var         inner     = new Rectangle(outer.Left + shift, outer.Bottom + shift / 2, outer.Right - shift, outer.Bottom + shift / 2 + 30);
            var         whiteFill = GetColor("#FFFFFF");

            cb.SetColorStroke(whiteFill);
            cb.SetColorFill(whiteFill);
            cb.RoundRectangle(inner.Left + 2, inner.Bottom, inner.Width - 1, inner.Height, 4);
            cb.FillStroke();

            // adjust outer for text alignment
            outer.Bottom = inner.Top;

            var text = dr.LabelText ??
                       (dr.Mark.Type == EntityTypes.ExhibitDefendant
                           ? "Defendant's\nExhibit"
                           : dr.Mark.Type == EntityTypes.ExhibitPlaintiff
                               ? "Plaintiff'sExhibit"
                               : "Exhibit");

            cb.BeginText(); // Start working with text.

            // Create a font to work with
            var labelTextColor = !string.IsNullOrEmpty(dr.LabelTextColor) ? GetColor(dr.LabelTextColor) : whiteFill;

            cb.SetRGBColorFill(labelTextColor.R, labelTextColor.G, labelTextColor.B);

            var size     = 12f;
            var baseFont = BaseFont.CreateFont(BaseFont.TIMES_BOLD, Encoding.ASCII.EncodingName, true);
            var ct       = new ColumnText(cb);
            var p        = new Paragraph(text, new Font(baseFont, size));
            var t        = new PdfPTable(1);
            var c        = new PdfPCell(p)
            {
                VerticalAlignment   = Element.ALIGN_MIDDLE,
                HorizontalAlignment = Element.ALIGN_CENTER,
            };

            c.FixedHeight = outer.Height + 10;
            c.BorderWidth = 0;
            c.SetLeading(0f, 1.2f);
            c.PaddingBottom = c.PaddingLeft = c.PaddingRight = c.PaddingTop = 0;
            t.AddCell(c);
            ct.SetSimpleColumn(outer.Left, outer.Bottom, outer.Right, outer.Top + 10);
            ct.AddElement(t);
            ct.Go();

            cb.EndText(); // Done working with text

            if (!string.IsNullOrWhiteSpace(dr.Text))
            {
                cb.BeginText(); // Start working with text.

                // Create a font to work with
                baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, false);
                cb.SetFontAndSize(baseFont, 14); // 40 point font
                var textColor =
                    GetColor(!string.IsNullOrEmpty(dr.NumberingTextColor) ? dr.NumberingTextColor : "#000000");
                cb.SetRGBColorFill(textColor.R, textColor.G, textColor.B);

                // Note: The x,y of the Pdf Matrix is from bottom left corner.
                // This command tells iTextSharp to write the text at a certain location with a certain angle.
                // Again, this will angle the text from bottom left corner to top right corner and it will
                // place the text in the middle of the page.
                cb.ShowTextAligned(
                    PdfContentByte.ALIGN_CENTER,
                    dr.Text,
                    dr.PositionX + dr.Width / 2,
                    pageHeight - (dr.PositionY + dr.Height / 2 + 18),
                    0);

                cb.EndText(); // Done working with text
            }
        }
예제 #12
0
        public IEnumerable <ATMark> GetMarks(Guid fileId)
        {
            ATMark               mark                 = null;
            ATShape              note                 = null;
            ATDrawing            atDrawing            = null;
            ATHighlightStrikeOut atHighlightStrikeOut = null;
            ATTextItem           textItem             = null;
            ATRotation           rotationItem         = null;
            ATPicture            pictureItem          = null;
            ATFormula            formulaItem          = null;
            ATAnnotation         annotationItem       = null;

            // Query to load the companies
            //     var marks = this.Repository.Session.QueryOver(() => mark).Where(x => x.File.Id == fileId).Fetch(x => x.File).Eager.Future<ATMark>();



            var mrs = this.Repository.Session.QueryOver <ATMark>()
                      .Left.JoinAlias(p => p.Annotations, () => annotationItem)
                      .Left.JoinAlias(p => p.Shapes, () => note)
                      .Left.JoinAlias(p => p.Drawings, () => atDrawing)
                      .Left.JoinAlias(p => p.HighlightStrikeOuts, () => atHighlightStrikeOut)
                      .Left.JoinAlias(p => p.TextItems, () => textItem)
                      .Left.JoinAlias(p => p.Rotations, () => rotationItem)
                      .Left.JoinAlias(p => p.Pictures, () => pictureItem)
                      .Left.JoinAlias(p => p.Formulas, () => formulaItem)
                      .Where(p => p.File.Id == fileId)
                      .Fetch(p => p.File).Eager.Future <ATMark>();

            //  .List();

            //// Query to load the Notes
            //var notes = this.Repository.Session.QueryOver(() => note)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATShape>();

            //// Query to load the Drawings
            //var drawings = this.Repository.Session.QueryOver(() => atDrawing)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATDrawing>();

            //// Query to load the Highlights
            //var highlights = this.Repository.Session.QueryOver(() => atHighlightStrikeOut)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATHighlightStrikeOut>();

            //// Query to load the TextItems
            //var textItems = this.Repository.Session.QueryOver(() => textItem)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATTextItem>();

            //// Query to load the Rotations
            //var rotationItems = this.Repository.Session.QueryOver(() => rotationItem)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATRotation>();

            //// Query to load the Pictures
            //var pictureItems = this.Repository.Session.QueryOver(() => pictureItem)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATPicture>();

            //// Query to load the Formulas
            //var formulaItems = this.Repository.Session.QueryOver(() => formulaItem)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATFormula>();

            //// Query to load the Annotations
            //var annotationItems = this.Repository.Session.QueryOver(() => annotationItem)
            //    .JoinAlias(p => p.Mark, () => mark)
            //    .Future<ATAnnotation>();

            return(mrs.OrderBy(x => x.DateChanged).ToList());
        }