DynaPDF Manual - Page 23

Previous Page 22   Index   Next Page 24

Language Bindings
Page 23 of 839
In most cases both object types are defined as normal classes, which contain their own
constructors and destructors to initialize and destroy allocated memory.
Global objects can be deleted or marked as deleted at runtime. Resource objects must never be
deleted if the object was already used.
General design requirements
We describe here only the general rules which must be taken into account when extending
DynaPDF with certain features. We do not explain how the entire library works; this would fill
an entire book. To understand how an object must be written to the file we recommended that
you debug especially the function CloseFile(). All objects must be prepared for writing in a two
stage phase to reserve object numbers. The first stage assignes object numbers to all objects and
the second run writes all objects to file. Objects must be written in the exact order in which they
were previously prepared for writing.
A PDF file is described in memory as large set of classes which can be referenced or used
multiple times by other classes. Due to the references which are stored in certain classes we
must define a strict set of rules so that no exception occurs if an object must be deleted:
1. The owner of all resources and global objects is CPDF. No other class is permitted to
destroy an object class or change its values.
2. All object classes must be derived from CBaseObject. This class holds the object number
as well as several flags to determine whether the object was used, created, or already
written, and whether it is part of the first page. This class contains the function
CreateObject() which must be called in CPDF::PreparePageObjects() if the object is part
of a page. If the object is not included in a page object then CreateObject() must be called
in CPDF::PrepareObjects().
3. All classes which hold pointers to other object classes must check the "Used" flag before
writing the object data to the file (GetUsed() is a member of CBaseObject and returns
true if the used flag was set).
4. All classes must be well initialized so that the class can be deleted at any time without
causing memory leaks or other unwanted side effects.
5. No object class is permitted to unset the "Used" flag of other object classes.
6. Page resources such as fonts, images, templates and so on must NEVER be deleted at
runtime and their "Used" flag must NEVER be unset.
7. All resource classes must be derived from CBaseResource.
8. Object classes must set the "Used" flag of the resource object, if the class is used by this

Previous topic: Custom Library Changes, Compiler Switches, Main object types

Next topic: Requirements to add your own code to DynaPDF