Brief Description of the PDFViewWPF tools

The PDFViewWPF tools interact with the PDFViewWPF to draw and edit shapes, fill forms, and select text.

The ToolManager is the core class that connects all the tools to the PDFViewWPF. The toolmanager subscribes to mouse, touch, and keyboard events from the PDFViewWPF, and forwards them to the other tools. The PDFViewWPF also provides its own set of unique events, like zoom and layout changing, and more.

The ToolManager always has exactly one active tool. All tools derive from the Tool base class. The ToolManager will forward events to the currently active tool through functions correspondin to the subscribed events. The base Tool also provides some convenience functions. The events are forwarded in what we call a Tool-Loop, in which the current tool gets to handle the event, and if it detects an action that requires a different tool to take action, it will indicate that the tool needs to change by changing NextToolMode. The ToolManager will create a new tool of that type and forward the same event. This happens, for example, when the Pan tool detects a click on a link annotation.

Pan.cs, ProcessInputDown:

else if (mAnnot.GetType() == Annot.Type.e_Link)

{

mNextToolMode = ToolManager.ToolType.e_link_action;

}

While the tools interact with the PDFViewWPF, they add content on a canvas provided by the PDFViewWPF. The canvas is a regular Systems.Controls.Canvas that is hosted inside the PDFViewCtrl as a transparent overlay on top of the content on the screen. It is inside the Scroller, and the same size as the scrollable region. You can access it through PDFViewWPF.GetCanvas(). For example, when selecting text, regular rectangles (System.Windows.Shapes.Rectangle) with some transparency are added to the canvas. The ToolManager, when created, will create a separate AnnotationCanvas and TextSelectionCanvas and add both to the canvas provided by the PDFViewWPF. The TextSelect tool will add its rectangles to the TextSelectionCanvas.

The PDFViewWPF provides functions to convert between different coordinate systems. The coordinate systems mainly used by the tools are the PDFViewWPF’s coordinates (called screen coordinates, these are the system coordnates that all WPF controls have), the Page coordinates, and the coordinates of the AnnotationCanvas. The PDFViewWPF provides functions to convert from one coordinate system to another. This is done through PDFViewWPF.ConvScreenPtToPagePt and PDFViewWPF.ConvPagePtToScreenPt. To convert to the AnnotationCanvas’s coordinate system (from the screen coordinate), simple add PDFViewWPF.GetHScrollPos and PDFViewWPF.GetVScrollPos to the screen coordinates. (WARNING: Note that these conv function that involve the Canvas operate on another canvas than the annotation canvas and should generally not be used).

All the basic shape drawing tools derive from SimpleShapeCreate. SimpleShapeCreate will take care of some of the basic householding when drawing shapes like lines and rectangles. It handles mouse down, moved, and up events, and ensures that the user starts the shape on a page, calculates a bounding box for the page the user is drawing on, and snaps the points to the bounding box while drawing. ProcesInputDown and ProcessInutMove (and ProcessInputUp in SingleDragShapeCreate ) lets us handle touch and mouse events in one place.

SingleDragShapeCreate is a subclass of SimpleShapeCreate and provides a framework for shapes that are added as soon as the mouse is released. So it also handles mouse up calls.

Tools that create shapes, like LikeCreate and ArrowCreate, don’t have to worry about mouse or touch events. Instead, they only have to implement a Draw and a Create function. The Draw function draws the shape in question on the Canvas, given a start and end point. The Create function creates the PDF object that is needed, and adds it to the PDF.

Shape creation tools that take only one click and drag to create, like Lines and Rectangles, derive from SingleDragShapeCreate and only need to worry about Draw and a Create while tools that need more interaction (like FreeText and FreeHand with multistroke) have to implement mouse/touch up events too.

The AnnotEdit tool is the tool that provides annotation selection and editing. It provides both single and multi annotation selection. It also provides options in the context menu or right click, for things like appearance, copy/paste, or deletion of annotations.

The SelectionHelper and LineSelection classes are helper classes used by AnnotEdit to manipulate annotations when only one annotation is selected. It provides the widgets that can be used to resize the annotation. The SelectionHelper is the basic version that works on all annotation types and provides 8 control points for resizing, provided the annotation is scalable (mAnnotIsScalable = true). The LineSelection is a derived class that provides 2 endpoints for resizing lines and arrow, which makes it possible to rotate the them. If special selection behaviour was needed for other types of annotations, additional classes deriving from SelectionHelper can be created.