# CAnnotation

Annotation is interactive entity which is associated with rectangle on page. They are organized in Annots array entry in page dictionary and so `CPage` is responsible for returning of all available annotations and also to provide interface to add new annotation.

Each annotations is described by dictionary, which has to contain at least Type element with Annot and Subtype element with concrete annotation type. Pdf specification describes several types of annotation types (e. g. text annotation - which describes text box floating upon normal page text, link annotation - which enables to jump to the target within document or to perform certain action when link is activated by mouse click). Rect element should be present as well, because it specifies where annotation should be spreaded.

CAnnotation represents such annotation and provides simple interface to manipulate elements in annotation dictionary. It implements `ObserverHandler` (see ) to anable user to be informed about changes inside annotation dictionary. This class provides just simple interface for internal manipulation and it is intended to be base class for specific annotation types (no such specialized class are available yet, because they are not required by project in this moment).

## Instance creation

Instance can be created in 2 different ways.

First possibility is to use existing annotation dictionary (e. g. fetched from document). This way is used in class where already existing annotations are fetched and used for CAnnotation instance.

Second way is to use factory

    	static boost::shared_ptr<CAnnotation>
    		createAnnotation(Rectangle rect, std::string annotType);

method (see ). This method uses internal `annotInit` static . Intializator is responsible for correct annotation dictionary initialization according given type and for given rectangle. This is safe way how to create new annotation instances.

## Annotation initializator

Annotation initializator represented by `IAnnotInitializator` abstract class. It provides which intialize given dictionary with correct data according given type. Initializator is designed as and so one initializator class can support initialization of several annotation types (getSupportedList returns annotation types which are supported by this initializator).

We have implemented `UniversalAnnotInitializer` which adds

    	bool registerInitializer(std::string annotType, boost::shared_ptr<IAnnotInitializator> impl, bool forceNew=false);

method responsible for registration of other initializator to composite of initializators. When `createAnnotation` is called, `UniversalAnnotInitializer` choose registered implementetator which supports such annotation type. UniversalAnnotInitializer itself just initializes common elements for all annotations (such as Type, Subtype, Rect elements).

CAnnotation class hierarchy