示例#1
0
 /**
  * <summary>Creates a new text markup on the specified page, making it printable by default.
  * </summary>
  * <param name="page">Page to annotate.</param>
  * <param name="markupBoxes">Quadrilaterals encompassing a word or group of contiguous words in
  * the text underlying the annotation.</param>
  * <param name="text">Annotation text.</param>
  * <param name="markupType">Markup type.</param>
  */
 public TextMarkup(Page page, IList <Quad> markupBoxes, string text, MarkupTypeEnum markupType)
     : base(page, ToCode(markupType), markupBoxes[0].GetBounds(), text)
 {
     MarkupType  = markupType;
     MarkupBoxes = markupBoxes;
     Printable   = true;
 }
示例#2
0
 /**
  * <summary>Creates a new text markup on the specified page, making it printable by default.
  * </summary>
  * <param name="page">Page to annotate.</param>
  * <param name="markupBox">Quadrilateral encompassing a word or group of contiguous words in the
  * text underlying the annotation.</param>
  * <param name="text">Annotation text.</param>
  * <param name="markupType">Markup type.</param>
  */
 public TextMarkup(
     Page page,
     Quad markupBox,
     string text,
     MarkupTypeEnum markupType
     ) : this(page, new List <Quad>() { markupBox }, text, markupType)
 {
 }
示例#3
0
   /**
     <summary>Creates a new text markup on the specified page, making it printable by default.
     </summary>
     <param name="page">Page to annotate.</param>
     <param name="text">Annotation text.</param>
     <param name="markupType">Markup type.</param>
     <param name="markupBox">Quadrilateral encompassing a word or group of contiguous words in the
     text underlying the annotation.</param>
   */
   public TextMarkup(
 Page page,
 string text,
 MarkupTypeEnum markupType,
 Quad markupBox
 )
       : this(page, text, markupType, new List<Quad>(){markupBox})
   {
   }
示例#4
0
 public TextMarkup(
     Page page,
     RectangleF box,
     MarkupTypeEnum type
     ) : base(
         page.Document,
         ToCode(type),
         box,
         page
         )
 {
 }
示例#5
0
        /*
         * TODO: refresh should happen just before serialization, on document event (e.g. OnWrite())
         */
        private void RefreshAppearance(
            )
        {
            FormXObject normalAppearance;
            RectangleF  box = org.pdfclown.objects.Rectangle.Wrap(BaseDataObject[PdfName.Rect]).ToRectangleF();
            {
                AppearanceStates normalAppearances = Appearance.Normal;
                normalAppearance = normalAppearances[null];
                if (normalAppearance != null)
                {
                    normalAppearance.Box = box;
                    normalAppearance.BaseDataObject.Body.SetLength(0);
                }
                else
                {
                    normalAppearances[null] = normalAppearance = new FormXObject(Document, box);
                }
            }

            PrimitiveComposer composer = new PrimitiveComposer(normalAppearance);

            {
                float          yOffset    = box.Height - Page.Box.Height;
                MarkupTypeEnum markupType = MarkupType;
                switch (markupType)
                {
                case MarkupTypeEnum.Highlight:
                {
                    ExtGState defaultExtGState;
                    {
                        ExtGStateResources extGStates = normalAppearance.Resources.ExtGStates;
                        defaultExtGState = extGStates[HighlightExtGStateName];
                        if (defaultExtGState == null)
                        {
                            if (extGStates.Count > 0)
                            {
                                extGStates.Clear();
                            }

                            extGStates[HighlightExtGStateName] = defaultExtGState = new ExtGState(Document);
                            defaultExtGState.AlphaShape        = false;
                            defaultExtGState.BlendMode         = new List <BlendModeEnum>(new BlendModeEnum[] { BlendModeEnum.Multiply });
                        }
                    }

                    composer.ApplyState(defaultExtGState);
                    composer.SetFillColor(Color);
                    {
                        foreach (Quad markupBox in MarkupBoxes)
                        {
                            PointF[] points          = markupBox.Points;
                            float    markupBoxHeight = points[3].Y - points[0].Y;
                            float    markupBoxMargin = GetMarkupBoxMargin(markupBoxHeight);
                            composer.DrawCurve(
                                new PointF(points[3].X, points[3].Y + yOffset),
                                new PointF(points[0].X, points[0].Y + yOffset),
                                new PointF(points[3].X - markupBoxMargin, points[3].Y - markupBoxMargin + yOffset),
                                new PointF(points[0].X - markupBoxMargin, points[0].Y + markupBoxMargin + yOffset)
                                );
                            composer.DrawLine(
                                new PointF(points[1].X, points[1].Y + yOffset)
                                );
                            composer.DrawCurve(
                                new PointF(points[2].X, points[2].Y + yOffset),
                                new PointF(points[1].X + markupBoxMargin, points[1].Y + markupBoxMargin + yOffset),
                                new PointF(points[2].X + markupBoxMargin, points[2].Y - markupBoxMargin + yOffset)
                                );
                            composer.Fill();
                        }
                    }
                }
                break;

                case MarkupTypeEnum.Squiggly:
                {
                    composer.SetStrokeColor(Color);
                    composer.SetLineCap(LineCapEnum.Round);
                    composer.SetLineJoin(LineJoinEnum.Round);
                    {
                        foreach (Quad markupBox in MarkupBoxes)
                        {
                            PointF[] points          = markupBox.Points;
                            float    markupBoxHeight = points[3].Y - points[0].Y;
                            float    lineWidth       = markupBoxHeight * .05f;
                            float    step            = markupBoxHeight * .125f;
                            float    boxXOffset      = points[3].X;
                            float    boxYOffset      = points[3].Y + yOffset - lineWidth;
                            bool     phase           = false;
                            composer.SetLineWidth(lineWidth);
                            for (float x = 0, xEnd = points[2].X - boxXOffset; x < xEnd || !phase; x += step)
                            {
                                PointF point = new PointF(x + boxXOffset, (phase ? -step : 0) + boxYOffset);
                                if (x == 0)
                                {
                                    composer.StartPath(point);
                                }
                                else
                                {
                                    composer.DrawLine(point);
                                }
                                phase = !phase;
                            }
                        }
                        composer.Stroke();
                    }
                }
                break;

                case MarkupTypeEnum.StrikeOut:
                case MarkupTypeEnum.Underline:
                {
                    composer.SetStrokeColor(Color);
                    {
                        float lineYRatio = 0;
                        switch (markupType)
                        {
                        case MarkupTypeEnum.StrikeOut:
                            lineYRatio = .5f;
                            break;

                        case MarkupTypeEnum.Underline:
                            lineYRatio = .9f;
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                        foreach (Quad markupBox in MarkupBoxes)
                        {
                            PointF[] points          = markupBox.Points;
                            float    markupBoxHeight = points[3].Y - points[0].Y;
                            float    boxYOffset      = markupBoxHeight * lineYRatio + yOffset;
                            composer.SetLineWidth(markupBoxHeight * .065);
                            composer.DrawLine(
                                new PointF(points[3].X, points[0].Y + boxYOffset),
                                new PointF(points[2].X, points[1].Y + boxYOffset)
                                );
                        }
                        composer.Stroke();
                    }
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }
            composer.Flush();
        }
示例#6
0
 /**
  * <summary>Gets the code corresponding to the given value.</summary>
  */
 private static PdfName ToCode(
     MarkupTypeEnum value
     )
 {
     return(MarkupTypeEnumCodes[value]);
 }
示例#7
0
 public TextMarkup(Page page, MarkupTypeEnum markupType, RectangleF box, IList<Quad> markupBoxes)
     : base(page.Document, ToCode(markupType), box, page)
 {
     MarkupType = markupType;
     MarkupBoxes = markupBoxes;
 }
示例#8
0
 public TextMarkup(Page page, MarkupTypeEnum markupType, IList<Quad> markupBoxes)
     : this(page, markupType, markupBoxes[0].GetBounds(), markupBoxes)
 {
 }
示例#9
0
 public TextMarkup(Page page, MarkupTypeEnum markupType, Quad markupBox)
     : this(page, markupType, markupBox.GetBounds(), new List<Quad>() { markupBox })
 {
 }
示例#10
0
 /**
   <summary>Gets the code corresponding to the given value.</summary>
 */
 private static PdfName ToCode(
   MarkupTypeEnum value
   )
 {
     return MarkupTypeEnumCodes[value];
 }
示例#11
0
   /**
     <summary>Creates a new text markup on the specified page, making it printable by default.
     </summary>
     <param name="page">Page to annotate.</param>
     <param name="text">Annotation text.</param>
     <param name="markupType">Markup type.</param>
     <param name="markupBoxes">Quadrilaterals encompassing a word or group of contiguous words in
     the text underlying the annotation.</param>
   */
   public TextMarkup(
 Page page,
 string text,
 MarkupTypeEnum markupType,
 IList<Quad> markupBoxes
 )
       : base(page,
   ToCode(markupType),
   markupBoxes[0].GetBounds(),
   text)
   {
       MarkupType = markupType;
         MarkupBoxes = markupBoxes;
         Printable = true;
   }