scbdoc.h

Go to the documentation of this file.
00001 #ifndef SCBDOC_H_
00002 #define SCBDOC_H_
00003 
00004 /*
00005  * File Name  : scbdoc.h
00006  * 
00007  * Description: Scribble library document definition
00008  */
00009 
00010 /*
00011  * This file is part of liberscribble.
00012  *
00013  * liberscribble is free software: you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation, either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * liberscribble is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00025  */
00026 
00027 /**
00028  * Copyright (C) 2008 iRex Technologies B.V.
00029  * All rights reserved.
00030  */
00031  
00032 
00033 //----------------------------------------------------------------------------
00034 // Include Files
00035 //----------------------------------------------------------------------------
00036 
00037 // system include files, between < >
00038 
00039 // ereader include files, between < >
00040 #include <libermetadb/ermetadb.h>
00041 
00042 // local include files, between " "
00043 #include "scbpath.h"
00044 #include "scbpages.h"
00045     
00046 #ifdef __cplusplus
00047 extern "C"
00048 {
00049 #endif
00050 
00051 
00052 //----------------------------------------------------------------------------
00053 // Definitions
00054 //---------------------------------------------------------------------------- 
00055 
00056 
00057 //----------------------------------------------------------------------------
00058 // Forward Declarations
00059 //----------------------------------------------------------------------------
00060 
00061 
00062 //----------------------------------------------------------------------------
00063 // Type Declarations
00064 //----------------------------------------------------------------------------
00065 
00066 // Maintain current state, such as current color / pen size/ pen style
00067 // caller can update its UI widget according to doc state
00068 //
00069 // toolbar cmd ---> current state  ---> new style
00070 //                       |
00071 //                       -------------> new state
00072 //                       |
00073 //                       -------------> update UI by macro
00074 // all platform related function is defined by macro
00075 typedef enum _ScbTBState
00076 {
00077     ERSCRIBBLE_TBS_NONE, 
00078     ERSCRIBBLE_TBS_SCRIBBLE,
00079     ERSCRIBBLE_TBS_SELECT_PEN_SIZE,
00080     ERSCRIBBLE_TBS_SELECT_LINE_COLOR,
00081     ERSCRIBBLE_TBS_ERASE,
00082     ERSCRIBBLE_TBS_INVALID
00083 } ScbTBState;
00084 
00085 // Map a icon to a scribble toolbar state, so that scribble library can handle toolbar request
00086 typedef struct _ScbTBSItem
00087 {
00088     ScbTBState  state;     /**< Tool bar status */
00089     int         iconId;    /**< Id of icon */
00090 } ScbTBSItem;
00091 
00092 typedef ScbTBSItem* ScbTBSItemPtr;
00093 
00094 // Context of the scribble document instance.
00095 // ScbDocContext maintains the necessary information when scribble lib is being used.
00096 // This information can be used to initialize a new stroke, or reset the toolbar
00097 typedef struct _ScbDocContext
00098 {
00099     ScbStrokeAttributes  curStrokeAttr;      /**< current stroke attributes, be used in runtime */
00100     ScbTBState           curState;           /**< current toolbar status */
00101     GArray *             table;              /**< a table mapping the icon and status */
00102     int                  appId;              /**< current application id */
00103     gboolean             need_save_app;      /**< need save application data or not */
00104 } ScbDocContext;
00105 
00106 // Version Number
00107 typedef struct _ScbVersion
00108 {
00109     unsigned short major;                    /**< major version number */
00110     unsigned short minor;                    /**< minor version number */
00111 } ScbVersion;
00112 
00113 // Version information of the scribble library
00114 typedef struct _ScbDocVersion
00115 {
00116     ScbVersion    version_number;            /**< version number */
00117     GString*      company;                   /**< company name */
00118 }ScbDocVersion;
00119 
00120 // Screen setting of current document
00121 typedef struct _ScbScreen
00122 {
00123     unsigned int  dpi;                       /**< DPI */
00124     GString*      units;                     /**< Units used for calculation, such as "pixel" */
00125 }ScbScreen;
00126 
00127 // Scribble Document
00128 typedef struct _ScbDoc
00129 {
00130     ScbDocVersion   version;                 /**< version data */
00131     ScbScreen       screen;                  /**< screen data */
00132     ScbPath         path;                    /**< path of the target document, e.g. a pdf document*/
00133     ScbPages        pages;                   /**< list of the page intances */
00134     ScbDocContext   context;                 /**< document context */
00135     erMetadb        metadata_db;            /**< the pointer of metadata db */
00136 }ScbDoc;
00137 
00138 typedef ScbDoc * ScbDocPtr;
00139 
00140 
00141 //----------------------------------------------------------------------------
00142 // Global Constants
00143 //----------------------------------------------------------------------------
00144 
00145 
00146 //============================================================================
00147 // Public Functions
00148 //============================================================================
00149 
00150 // Create a new scribble document instance
00151 // @param target_doc_path path of the target document, e.g. a pdf document
00152 // @return the created scribble document instance, return NULL if fails
00153 ScbDocPtr erscribble_doc_new(const ScbPathPtr target_doc_path);
00154 
00155 // Create a new scribble document instance using an existing database
00156 // @param target_file_name name of the target document, e.g. a pdf document
00157 // @param metadata_db the already opened metadata database for this document
00158 // @return the created scribble document instance, return NULL if fails
00159 ScbDocPtr erscribble_doc_new_with_database(const char *target_file_name, erMetadb metadata_db);
00160 
00161 // Free an existing scribble document instance
00162 // @param the scribble document instance that needs to be released
00163 void erscribble_doc_free(ScbDocPtr doc);
00164 
00165 // Free an existing scribble document instance but keep the database open
00166 // @param the scribble document instance that needs to be released
00167 void erscribble_doc_free_without_database(ScbDocPtr doc);
00168 
00169 // Create a scribble document instance by the path of target document
00170 // @param target_doc_path path of the target document
00171 // @return the created scribble document instance if the record exists in DB
00172 // otherwise return NULL
00173 ScbDocPtr erscribble_doc_open(const ScbPathPtr target_doc_path);
00174 
00175 // Create a scribble document instance by the path of target document
00176 // Scribble library tries to search the record by target document path
00177 // in metadata DB. If the record exists, create a new document based on
00178 // the recorded setting
00179 // @param target_file_name name of the target document
00180 // @param metadata_db the already opened metadata database for this document
00181 // @return the created scribble document instance if the record exists in DB
00182 // otherwise return NULL
00183 ScbDocPtr erscribble_doc_open_with_database(const char *target_file_name, erMetadb metadata_db);
00184 
00185 // Save a scribble page into DB. The data of scribble page would be dumped into
00186 // a BLOB, then stored into metadata DB as an item.
00187 /*  memory layout of a scribble page BLOB
00188      --------------------------------------
00189      |   Version Number : unsigned short  |
00190      --------------------------------------
00191      |        Page Orientation : int      |
00192      --------------------------------------
00193      |         Page Color : ScbColor      |
00194      --------------------------------------
00195      |          Page Area : ScbRect       |
00196      --------------------------------------
00197      |         Strokes Number : int       |
00198      --------------------------------------
00199      --------------------------------------
00200      |    Stroke Color : unsigned long    |
00201      --------------------------------------
00202      |         Stroke Zoom : double       |
00203      --------------------------------------
00204      |          Stroke Layer : int        |
00205      --------------------------------------
00206      |            Shape ID : int          |
00207      --------------------------------------
00208      |            Size ID : int           |
00209      --------------------------------------
00210      |         Points Number : int        |
00211      --------------------------------------
00212      --------------------------------------
00213      |               X : int              |
00214      --------------------------------------
00215      |               Y : int              |
00216      --------------------------------------
00217      |            Pressure : int          |
00218      --------------------------------------
00219      --------------------------------------
00220      |               X : int              |
00221      --------------------------------------
00222      |               Y : int              |
00223      --------------------------------------
00224      |            Pressure : int          |
00225      --------------------------------------
00226      |                ...                 |
00227      --------------------------------------
00228 */
00229 // @param doc the scribble document instance
00230 // @param page the scribble page instance which belogs to doc
00231 // @return return TRUE if the page is successfully saved, otherwise return FALSE
00232 gboolean erscribble_doc_save_page(ScbDocPtr doc, ScbPagePtr page);
00233 
00234 // Get a scribble page instance by the ID. Scribble library searches the page in its
00235 // own cache at first. If the page is not cached, it will search the page record in
00236 // metadata DB. Then if the record exists, a new page instance is created, otherwise
00237 // return NULL.
00238 // @param doc the scribble document instance
00239 // @param id the id of the page, it acts as the start anchor
00240 // @param pos_start the start position of the page
00241 // @param pos_end the end position of the page
00242 // @return return the pointer of the page instance if the page instance has been created,
00243 // otherwise return NULL
00244 ScbPagePtr erscribble_doc_get_page(ScbDocPtr doc, const ScbPageIdPtr id);
00245 
00246 // Get all of the cached pages
00247 // NOTE, this function is deprecated
00248 // @param doc the scribble document instance
00249 // @return return the pointer of the cached pages
00250 ScbPagesPtr erscribble_doc_get_pages(ScbDocPtr doc);
00251 
00252 // Get the stroke attributes which is maintained by scribble document's context
00253 // @param doc the scribble document instance
00254 // @return return the pointer of the document's stroke attributes
00255 ScbStrokeAttributesPtr erscribble_doc_get_current_stroke_attributes(ScbDocPtr doc);
00256 
00257 // Add a new scribble page instance to document's cache, if the same page(with same id)
00258 // has been cached in advance, this operation ceases
00259 // @param doc the scribble document instance
00260 // @param page the page instance for adding in
00261 // @return return true if the page has been added into the cache
00262 gboolean erscribble_doc_add_page(ScbDocPtr doc, ScbPagePtr page);
00263 gboolean erscribble_doc_insert_page(ScbDocPtr doc, ScbPagePtr page);
00264 gboolean erscribble_doc_delete_page(ScbDocPtr doc, ScbPageIdPtr pid);
00265 
00266 
00267 // Add a new toolbar item into context's table
00268 // NOTE, this function is deprecated
00269 void erscribble_doc_add_map_item(ScbDocPtr doc, const ScbTBSItemPtr ptr);
00270 
00271 // Estimate whether it is scribbling now
00272 // @param doc the scribble document instance
00273 // @return return true if it is scribbling
00274 gboolean erscribble_state_is_scribble(ScbDocPtr doc);
00275 
00276 // Estimate whether it is erasing now
00277 // @param doc the scribble document instance
00278 // @return return true if it is erasing
00279 gboolean erscribble_state_is_erase(ScbDocPtr doc);
00280 
00281 // Dump the data of document
00282 // This function can be used for debug
00283 void erscribble_doc_dump(ScbDocPtr ptr);
00284 
00285 void erscribble_doc_disable_autodelete(gboolean do_disable);
00286 
00287 #ifdef __cplusplus
00288 }
00289 #endif
00290 
00291 #endif
Generated by  doxygen 1.6.2-20100208