#include <stdlib.h>#include <stdio.h>#include <string.h>#include <gtk/gtk.h>#include "ink_rw.h"#include "ScribbleLog.h"#include "ScribbleUtils.h"Go to the source code of this file.
Defines | |
| #define | MAX_XPATH 512 |
| #define | MAX_STOKE_STR 0x10000 |
| #define | MAX_CHARS_IN_LINE 64 |
Functions | |
| gboolean | xml_page_exist (erManifest *pXmlHandle, const char *sPageName) |
| int | xml_parse_stroke (PtrStroke pStroke, const char *strpoints) |
| PtrInk | xml_read_ink (erManifest *pXmlHandle, const char *sPageName) |
| gboolean | xml_write_stroke (erManifest *pXmlHandle, const char *xpath, const PtrStroke pStroke) |
| int | xml_write_irxHead (erManifest *pErManiHandle) |
| void | xml_write_page_head (erManifest *pXmlHandle, const char *xpath) |
| gboolean | xml_write_ink (erManifest *pXmlHandle, const char *xpath, const PtrInk pink, const char *sPageName) |
| #define MAX_CHARS_IN_LINE 64 |
Definition at line 192 of file ink_rw_xml.c.
| #define MAX_STOKE_STR 0x10000 |
Definition at line 47 of file ink_rw_xml.c.
| #define MAX_XPATH 512 |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 43 of file ink_rw_xml.c.
| gboolean xml_page_exist | ( | erManifest * | pXmlHandle, | |
| const char * | sPageName | |||
| ) |
Definition at line 49 of file ink_rw_xml.c.
00050 { 00051 if( NULL==pXmlHandle || NULL==sPageName) 00052 { 00053 SB_INKERRPRINTF("error:invalid parameter\n"); 00054 return FALSE; 00055 } 00056 00057 char sCurrXPath[MAX_XPATH]; 00058 snprintf(sCurrXPath,MAX_XPATH,"/notes/pages/page[@id=\"%s\"]",sPageName); 00059 SB_FMPRINTF("sCurrXPath=\n%s\n",sCurrXPath); 00060 if( RET_OK!=ermXmlExist(pXmlHandle, sCurrXPath) ) 00061 { 00062 SB_INKERRPRINTF("page[%s] not existed\n",sPageName); 00063 return FALSE; 00064 } 00065 return TRUE; 00066 }

| int xml_parse_stroke | ( | PtrStroke | pStroke, | |
| const char * | strpoints | |||
| ) |
Definition at line 70 of file ink_rw_xml.c.
00071 { 00072 if (strpoints == NULL || pStroke == NULL) 00073 { 00074 SB_INKERRPRINTF("failed:incorrect arguments\n"); 00075 return -1; 00076 } 00077 00078 gchar** points_set=g_strsplit_set(strpoints," \n\t",-1); 00079 if ( NULL==points_set[0]) 00080 { 00081 SB_INKERRPRINTF("returned:nPoints=0\n"); 00082 pStroke->nPoints=0; 00083 return 0; 00084 } 00085 00086 /* 00087 int i=0; 00088 printf("====================\n",i,points_set[i]); 00089 while( points_set[i] && strlen(points_set[i]) ) 00090 { 00091 printf("data[%d]=[=%s=]\n",i,points_set[i]); 00092 i++; 00093 } 00094 printf("============total data number=[%d]\n",i); 00095 */ 00096 00097 PtrInkPoint point; 00098 int i=0; 00099 while( points_set[i] && strlen(points_set[i]) ) 00100 { 00101 point = construct_point (); 00102 if ( NULL==point ) 00103 { 00104 SB_INKERRPRINTF("construct point error\n"); 00105 g_strfreev(points_set); 00106 return -1; 00107 } 00108 point->x=atoi(points_set[i]); 00109 i++; 00110 if(!points_set[i]) 00111 { 00112 SB_INKERRPRINTF("failed getting point->y for the %dth point)\n",i/3+1); 00113 break; 00114 } 00115 point->y=atoi(points_set[i]); 00116 SB_INKPRINTF("point(%d,%d) \n", point->x, point->y); 00117 ink_add_point(pStroke, point); 00118 i++; 00119 if(!points_set[i]) 00120 { 00121 SB_INKERRPRINTF("failed getting point->pressure for the %dth point)\n",i/3+1); 00122 break; 00123 } 00124 //currently ,we ignore the pen presure 00125 i++; 00126 } 00127 pStroke->nPoints=i/3; 00128 //SB_FMPRINTF("total points=%d",pStroke->nPoints); 00129 g_strfreev(points_set); 00130 return 0; 00131 }

| PtrInk xml_read_ink | ( | erManifest * | pXmlHandle, | |
| const char * | sPageName | |||
| ) |
Definition at line 135 of file ink_rw_xml.c.
00136 { 00137 if( NULL==pXmlHandle || NULL==sPageName) 00138 { 00139 SB_INKERRPRINTF("error:invalid parameter\n"); 00140 return NULL; 00141 } 00142 PtrInk pink = construct_ink (); 00143 if (NULL == pink ) 00144 { 00145 SB_INKERRPRINTF("error:construct_ink\n"); 00146 return NULL; 00147 } 00148 00149 if( !xml_page_exist(pXmlHandle,sPageName) ) 00150 { 00151 return pink; 00152 } 00153 00154 char sStrPoints[MAX_STOKE_STR]; 00155 char sStrokeXPath[MAX_XPATH]; 00156 int i=1; 00157 char sHtmlColor[HTMLCOLOR_LEN]; 00158 while(TRUE) 00159 { 00160 snprintf(sStrokeXPath,MAX_XPATH, 00161 "/notes/pages/page[@id=\"%s\"]/strokes/stroke[%d]", 00162 sPageName, i ); 00163 //SB_FMPRINTF("path=\n%s\n",sStrokeXPath); 00164 if( RET_OK!=ermXmlGetString(pXmlHandle,sStrokeXPath, 00165 sStrPoints, MAX_STOKE_STR) ) 00166 { 00167 break; 00168 } 00169 //SB_INKPRINTF("\n\npoints=%s\n\n",sStrPoints); 00170 PtrStroke pStroke = construct_stroke (); 00171 if (pStroke == NULL) 00172 { 00173 SB_INKERRPRINTF("return: construct_stroke failed \n"); 00174 break; 00175 } 00176 xml_parse_stroke (pStroke,sStrPoints); 00177 00178 ermXmlGetAttributeInt(pXmlHandle,sStrokeXPath, 00179 "pensize",&pStroke->iPenSize); 00180 ermXmlGetAttributeString(pXmlHandle,sStrokeXPath, 00181 "color",sHtmlColor,HTMLCOLOR_LEN); 00182 Util_GdkColorFromHtmlColor(&pStroke->gdkColor,sHtmlColor); 00183 00184 ink_add_stroke (pink, pStroke); 00185 i++; 00186 } 00187 SB_FMPRINTF("read %d strokes \n",i); 00188 return pink; 00189 }

| gboolean xml_write_ink | ( | erManifest * | pXmlHandle, | |
| const char * | xpath, | |||
| const PtrInk | pink, | |||
| const char * | sPageName | |||
| ) |
Definition at line 269 of file ink_rw_xml.c.
00271 { 00272 if( NULL==pXmlHandle || NULL==xpath || NULL==sPageName )//0==pink->nStrokes 00273 { 00274 return FALSE; 00275 } 00276 SB_FMPRINTF("--page,path=[%s],sPageName=%s",xpath,sPageName); 00277 00278 char sCurrXPath[MAX_XPATH]; 00279 00280 //if the page exist,we first empty it. 00281 if( !xml_page_exist(pXmlHandle,sPageName) ) 00282 { 00283 ermXmlNewString(pXmlHandle, xpath, "page", ""); 00284 00285 snprintf(sCurrXPath,MAX_XPATH,"%s/page[last()]",xpath); 00286 ermXmlSetAttributeString(pXmlHandle,sCurrXPath, 00287 "id",sPageName,strlen(sPageName) ); 00288 snprintf(sCurrXPath,MAX_XPATH,"%s/page[@id=\"%s\"]",xpath,sPageName); 00289 } 00290 else 00291 { //empty it firstly 00292 snprintf(sCurrXPath,MAX_XPATH,"%s/page[@id=\"%s\"]",xpath,sPageName); 00293 ermXmlSetString(pXmlHandle,sCurrXPath, ""); 00294 } 00295 if( NULL==pink || 0==pink->nStrokes ) 00296 { 00297 return TRUE; 00298 } 00299 00300 xml_write_page_head(pXmlHandle,sCurrXPath); 00301 00302 SB_FMPRINTF("ink->nStrokes=%d \n", pink->nStrokes); 00303 PtrStroke pStroke = pink->firstStroke; 00304 int i=1; 00305 char strokesPath[MAX_XPATH]; 00306 snprintf(strokesPath,MAX_XPATH,"%s/strokes",sCurrXPath); 00307 char sLastStrokeXPath[MAX_XPATH];//xpath for last stroke 00308 00309 while (pStroke) 00310 { 00311 ermXmlNewString(pXmlHandle, strokesPath, "stroke", ""); 00312 snprintf(sLastStrokeXPath,MAX_XPATH,"%s/stroke[%d]",strokesPath,i); 00313 //SB_FMPRINTF("\nsLastStrokeXPath=[%s]\n",sLastStrokeXPath); 00314 xml_write_stroke(pXmlHandle,sLastStrokeXPath,pStroke); 00315 pStroke = pStroke->nextStroke; 00316 i++; 00317 } 00318 return TRUE; 00319 }

| int xml_write_irxHead | ( | erManifest * | pErManiHandle | ) |
Definition at line 240 of file ink_rw_xml.c.
00241 { 00242 ermXmlNewString(pErManiHandle, "/", "notes", ""); 00243 ermXmlNewString(pErManiHandle, "/notes", "version", ""); 00244 ermXmlNewString(pErManiHandle, "/notes/version", "number", "1.0"); 00245 ermXmlNewString(pErManiHandle, "/notes/version","orgnization", "iRex Technologies"); 00246 00247 ermXmlNewString(pErManiHandle, "/notes", "screen", ""); 00248 //units can be px,mm or in. 00249 ermXmlNewString(pErManiHandle, "/notes/screen", "units", "px"); 00250 ermXmlNewInt(pErManiHandle, "/notes/screen","dpi", 160); 00251 00252 ermXmlNewString(pErManiHandle, "/notes", "pages", ""); 00253 00254 return 0; 00255 }

| void xml_write_page_head | ( | erManifest * | pXmlHandle, | |
| const char * | xpath | |||
| ) |
Definition at line 258 of file ink_rw_xml.c.
00259 { 00260 ermXmlSetAttributeString(pXmlHandle,xpath, 00261 "backgroundcolor","#000000",HTMLCOLOR_LEN); 00262 ermXmlNewInt(pXmlHandle, xpath, "orientation", 0); 00263 ermXmlNewInt(pXmlHandle, xpath, "height", 935); 00264 ermXmlNewInt(pXmlHandle, xpath, "width", 768); 00265 ermXmlNewString(pXmlHandle, xpath, "strokes", ""); 00266 }

| gboolean xml_write_stroke | ( | erManifest * | pXmlHandle, | |
| const char * | xpath, | |||
| const PtrStroke | pStroke | |||
| ) |
Definition at line 201 of file ink_rw_xml.c.
00204 { 00205 if( NULL==xpath || NULL==pStroke || 0==pStroke->nPoints) 00206 { 00207 return FALSE; 00208 } 00209 00210 ermXmlSetAttributeInt(pXmlHandle,xpath,"layer",0); 00211 ermXmlSetAttributeString(pXmlHandle,xpath,"linestyle","solid",strlen("solid")); 00212 ermXmlSetAttributeInt(pXmlHandle,xpath,"pensize",pStroke->iPenSize); 00213 00214 char sHtmlColor[10]; 00215 Util_HtmlColorFromGdkColor(sHtmlColor,10,&pStroke->gdkColor); 00216 ermXmlSetAttributeString(pXmlHandle,xpath, 00217 "color",sHtmlColor,HTMLCOLOR_LEN); 00218 00219 char dataLine[MAX_CHARS_IN_LINE]; 00220 GArray* garr_stroke=g_array_sized_new(TRUE,FALSE,sizeof(char),1024); 00221 00222 //SB_FMPRINTF("stroke->nPoints=%d \n", pStroke->nPoints); 00223 PtrInkPoint point = pStroke->firstPoint; 00224 while (point) 00225 { 00226 //write a line for a point 00227 snprintf(dataLine,MAX_CHARS_IN_LINE,"%d %d 0\n",point->x,point->y); 00228 g_array_append_vals(garr_stroke,dataLine,strlen(dataLine)); 00229 point = point->nextPoint; 00230 } 00231 //printf("\n\nfinal stroke string:%s\n\n", garr_stroke->data); 00232 ermXmlSetString(pXmlHandle, xpath, garr_stroke->data); 00233 00234 g_array_free(garr_stroke,FALSE); 00235 return TRUE; 00236 }

1.5.6