00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define _GNU_SOURCE
00029
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <string.h>
00037
00038
00039
00040
00041 #include "scbconfig.h"
00042 #include "scblog.h"
00043 #include "scbpage.h"
00044 #include "scbstrokes.h"
00045 #include "scbtype.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 void erscribble_page_set_id(ScbPageIdPtr ptr, const int position, const char *anchor, const int anno_id)
00073 {
00074 if (ptr)
00075 {
00076 strncpy(ptr->id, anchor, ERSCRIBBLE_MAX_PAGEID_LEN);
00077 ptr->position = position;
00078
00079
00080 ptr->annotation_id = anno_id;
00081 }
00082 }
00083
00084
00085 void erscribble_page_copy_id(ScbPageIdPtr dst, const ScbPageIdPtr src)
00086 {
00087 if (dst && src)
00088 {
00089 strncpy(dst->id, src->id, ERSCRIBBLE_MAX_PAGEID_LEN);
00090 dst->position = src->position;
00091 dst->annotation_id = src->annotation_id;
00092 }
00093 }
00094
00095
00096 void erscribble_page_reset_id(ScbPageIdPtr ptr)
00097 {
00098 if (ptr)
00099 {
00100 memset(ptr->id, 0, ERSCRIBBLE_MAX_PAGEID_LEN);
00101 ptr->position = -1;
00102 ptr->annotation_id = -1;
00103 }
00104 }
00105
00106
00107 ScbPagePtr erscribble_page_new()
00108 {
00109 ScbPagePtr ptr = g_new0(ScbPage, 1);
00110 if (NULL == ptr)
00111 {
00112
00113 ERRORPRINTF("Not enough memory for page!");
00114 return NULL;
00115 }
00116
00117
00118 if (!erscribble_strokes_new(&ptr->strokes))
00119 {
00120 g_free(ptr);
00121 return NULL;
00122 }
00123
00124 ptr->attributes.area.left = ERSCRIBBLE_DEF_PAGE_LEFT;
00125 ptr->attributes.area.right = ERSCRIBBLE_DEF_PAGE_RIGHT;
00126 ptr->attributes.area.top = ERSCRIBBLE_DEF_PAGE_TOP;
00127 ptr->attributes.area.bottom = ERSCRIBBLE_DEF_PAGE_BOTTOM;
00128
00129
00130 ptr->id.position = -1;
00131 ptr->id.annotation_id = -1;
00132
00133
00134 ptr->is_blob_loaded = FALSE;
00135
00136 return ptr;
00137 }
00138
00139 void erscribble_page_set_size(ScbPagePtr ptr, const int width, const int height)
00140 {
00141 ptr->attributes.area.right = ptr->attributes.area.left + width;
00142 ptr->attributes.area.bottom = ptr->attributes.area.top + height;
00143 }
00144
00145 void erscribble_page_free(ScbPagePtr ptr)
00146 {
00147 ERSCRIBBLE_RET_IF(NULL == ptr, "Attempt to release NULL pointer!");
00148
00149 erscribble_page_clear_strokes(ptr);
00150 g_free(ptr);
00151 }
00152
00153
00154 void erscribble_page_clear_strokes(ScbPagePtr ptr)
00155 {
00156 ERSCRIBBLE_RET_IF(NULL == ptr, "Attempt to operate on NULL pointer!");
00157
00158 erscribble_strokes_free(&ptr->strokes);
00159 erscribble_strokes_free(&ptr->del_strokes);
00160 }
00161
00162
00163 void erscribble_page_clear(ScbPagePtr ptr)
00164 {
00165 ERSCRIBBLE_RET_IF(NULL == ptr, "Attempt to take action on NULL pointer!");
00166
00167
00168
00169 erscribble_strokes_clear(&ptr->strokes);
00170 erscribble_strokes_clear(&ptr->del_strokes);
00171 }
00172
00173
00174 int erscribble_page_get_stroke_count(ScbPagePtr ptr)
00175 {
00176 ERSCRIBBLE_RET_INT_IF(NULL == ptr, ERSCRIBBLE_INVALID_COUNT, "Invalid page pointer!");
00177 return erscribble_strokes_get_count(&ptr->strokes);
00178 }
00179
00180
00181 gboolean erscribble_page_add_stroke(ScbPagePtr page, ScbStrokePtr stroke)
00182 {
00183 ERSCRIBBLE_RET_FALSE_IF(NULL == page || NULL == stroke, "Invalid pointer!");
00184 page->strokes.strokes = g_list_append(page->strokes.strokes, stroke);
00185
00186 return TRUE;
00187 }
00188
00189
00190 ScbStrokesPtr erscribble_page_get_strokes(ScbPagePtr page)
00191 {
00192 ERSCRIBBLE_RET_NULL_IF(NULL == page, "Attempt to access NULL pointer!");
00193 return &page->strokes;
00194 }
00195
00196
00197 void erscribble_page_erase_init(ScbPageEraseCtxPtr ptr)
00198 {
00199 ptr->zoom = 1.0;
00200 ptr->bInit = FALSE;
00201 }
00202
00203
00204 ScbStrokesPtr erscribble_page_erase_hit_test(ScbPagePtr page, ScbDevPointPtr point, ScbPageEraseCtxPtr eraCtx)
00205 {
00206 ScbStrokesPtr strokes = NULL;
00207 ScbHitTestCtx ctx;
00208 ctx.size = ERSCRIBBLE_DEF_ERASE_SIZE;
00209 ctx.zoom = eraCtx->zoom;
00210 if (!eraCtx->bInit)
00211 {
00212 eraCtx->p1 = *point;
00213 eraCtx->bInit = TRUE;
00214 strokes = erscribble_strokes_point_hit_test(&page->strokes, point, &ctx);
00215 }
00216 else
00217 {
00218 eraCtx->p2 = eraCtx->p1;
00219 eraCtx->p1 = *point;
00220 strokes = erscribble_strokes_line_hit_test(&page->strokes,
00221 &eraCtx->p2,
00222 &eraCtx->p1,
00223 &ctx);
00224 }
00225
00226 return strokes;
00227 }
00228
00229
00230 int erscribble_page_get_length(ScbPagePtr ptr)
00231 {
00232
00233 ptr->attributes.strokes_number = erscribble_page_get_stroke_count(ptr);
00234
00235 int length = sizeof(ptr->attributes);
00236
00237 ScbStrokePtr stroke = NULL;
00238 GList* item = g_list_first(ptr->strokes.strokes);
00239 while(item)
00240 {
00241 stroke = (ScbStrokePtr)item->data;
00242
00243
00244 stroke->attributes.points_number = erscribble_stroke_get_point_count(stroke);
00245
00246
00247 length += sizeof(stroke->attributes);
00248
00249
00250 length += stroke->attributes.points_number * sizeof(ScbDevPoint);
00251
00252 item = g_list_next(item);
00253 }
00254
00255 return length;
00256 }
00257
00258
00259 void erscribble_page_set_minor_version_number(ScbPagePtr page, const unsigned short minor)
00260 {
00261 page->attributes.minor_version = minor;
00262 }
00263
00264
00265 gboolean erscribble_page_load(ScbPagePtr page, ScbStreamPtr stream)
00266 {
00267
00268 ERSCRIBBLE_RET_FALSE_IF(page == NULL || stream == NULL, "Invalid page structure or stream");
00269
00270 gboolean ret = erscribble_read_stream(stream, &page->attributes, sizeof(page->attributes));
00271
00272 if (ret == FALSE)
00273 {
00274 return ret;
00275 }
00276
00277 return erscribble_strokes_load(&page->strokes, stream, page->attributes.strokes_number);
00278 }
00279
00280
00281 gboolean erscribble_page_write_stream(ScbPagePtr page, ScbStreamPtr stream)
00282 {
00283
00284 if (erscribble_write_stream(stream, &page->attributes, sizeof(page->attributes)))
00285 {
00286
00287 if (erscribble_strokes_write_stream(&page->strokes, stream))
00288 {
00289 return TRUE;
00290 }
00291 }
00292
00293 return FALSE;
00294 }
00295
00296
00297 void erscribble_page_dump(ScbPagePtr ptr)
00298 {
00299 ERSCRIBBLE_RET_IF(NULL == ptr, "Attempt to dump on NULL page pointer!");
00300
00301 DUMPPRINTF("================= Page %s Information =================", ptr->id.id);
00302 DUMPPRINTF("orientation %d", ptr->attributes.style.orientation);
00303 DUMPPRINTF("rect (%d, %d) - (%d, %d)", ptr->attributes.area.left, ptr->attributes.area.top,
00304 ptr->attributes.area.right, ptr->attributes.area.bottom);
00305 erscribble_strokes_dump(&ptr->strokes);
00306 DUMPPRINTF("==================== Page %s Done =====================", ptr->id.id);
00307 }