gwenhywfar  4.99.8beta
src/html/libtest.c
Go to the documentation of this file.
1 
2 
3 
4 #include <gwenhywfar/gwenhywfar.h>
5 #include <gwenhywfar/debug.h>
6 #include <gwenhywfar/xml.h>
7 #include <gwenhywfar/syncio_file.h>
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <errno.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 
16 
17 #include "htmlctx_l.h"
18 #include "htmlprops_be.h"
19 #include "htmlfont_be.h"
20 
21 
22 
23 void dumpObject(HTML_OBJECT *o, FILE *f, int indent) {
24  HTML_OBJECT *c;
25  int i;
26  const char *s;
27  HTML_PROPS *pr;
28  HTML_FONT *fnt;
29 
30  s=HtmlObject_GetText(o);
31  for (i=0; i<indent; i++) fprintf(f, " ");
32  fprintf(stderr, "Object type: %d [%s] flags: %08x\n",
34  s?s:"(empty)",
36 
38  fnt=HtmlProps_GetFont(pr);
39 
40  for (i=0; i<indent+2; i++) fprintf(f, " ");
41  fprintf(stderr, "fgcol=%06x, bgcol=%06x, fontsize=%d, fontflags=%08x, fontname=[%s]\n",
47 
48  c=HtmlObject_Tree_GetFirstChild(o);
49  while(c) {
50  dumpObject(c, f, indent+2);
51  c=HtmlObject_Tree_GetNext(c);
52  }
53 }
54 
55 
56 
57 int test1(int argc, char **argv) {
58  GWEN_XML_CONTEXT *xmlCtx;
59  GWEN_SYNCIO *sio;
60  int rv;
61  HTML_PROPS *pr;
62  HTML_FONT *fnt;
63  HTML_OBJECT_TREE *ot;
64 
65  if (argc<2) {
66  fprintf(stderr, "Name of testfile needed.\n");
67  return 1;
68  }
69 
72  rv=GWEN_SyncIo_Connect(sio);
73  if (rv<0) {
74  DBG_ERROR(0, "here (%d)", rv);
75  GWEN_SyncIo_free(sio);
76  return 2;
77  }
78 
79  xmlCtx=HtmlCtx_new(0);
80  assert(xmlCtx);
81 
82  pr=HtmlProps_new();
83  fnt=HtmlCtx_GetFont(xmlCtx, "times new roman", 12, 0);
84  HtmlProps_SetFont(pr, fnt);
85  HtmlFont_free(fnt);
86  HtmlCtx_SetStandardProps(xmlCtx, pr);
87  HtmlProps_free(pr);
88 
89  /* read OFX file into context */
90  rv=GWEN_XMLContext_ReadFromIo(xmlCtx, sio);
91  if (rv<0) {
92  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
94  GWEN_SyncIo_free(sio);
95  return rv;
96  }
97 
98  ot=HtmlCtx_GetObjects(xmlCtx);
99  if (ot) {
100  HTML_OBJECT *o;
101 
102  o=HtmlObject_Tree_GetFirst(ot);
103  dumpObject(o, stderr, 2);
104  }
105 
107  GWEN_SyncIo_free(sio);
108  GWEN_XmlCtx_free(xmlCtx);
109 
110  return 0;
111 }
112 
113 
114 
115 
116 int main(int argc, char **argv) {
117  return test1(argc, argv);
118 }
119 
const char * HtmlFont_GetFontName(const HTML_FONT *fnt)
Definition: htmlfont.c:64
int HtmlFont_GetFontSize(const HTML_FONT *fnt)
Definition: htmlfont.c:82
void HtmlCtx_SetStandardProps(GWEN_XML_CONTEXT *ctx, HTML_PROPS *pr)
Definition: htmlctx.c:366
int GWEN_SyncIo_Connect(GWEN_SYNCIO *sio)
Definition: syncio.c:94
int test1(int argc, char **argv)
uint32_t HtmlProps_GetBackgroundColor(const HTML_PROPS *pr)
Definition: htmlprops.c:112
HTML_OBJECT_TYPE HtmlObject_GetObjectType(const HTML_OBJECT *o)
Definition: htmlobject.c:82
void HtmlProps_free(HTML_PROPS *pr)
Definition: htmlprops.c:39
#define GWEN_SYNCIO_FILE_FLAGS_READ
Definition: syncio_file.h:53
int main(int argc, char **argv)
HTML_PROPS * HtmlProps_new(void)
Definition: htmlprops.c:26
void HtmlProps_SetFont(HTML_PROPS *pr, HTML_FONT *fnt)
Definition: htmlprops.c:86
uint32_t HtmlProps_GetForegroundColor(const HTML_PROPS *pr)
Definition: htmlprops.c:96
void HtmlFont_free(HTML_FONT *fnt)
Definition: htmlfont.c:38
#define GWEN_LOGDOMAIN
Definition: logger.h:35
const char * HtmlObject_GetText(const HTML_OBJECT *o)
Definition: htmlobject.c:213
HTML_PROPS * HtmlObject_GetProperties(const HTML_OBJECT *o)
Definition: htmlobject.c:98
void GWEN_XmlCtx_free(GWEN_XML_CONTEXT *ctx)
Definition: xmlctx.c:66
struct GWEN_SYNCIO GWEN_SYNCIO
Definition: syncio.h:40
struct HTML_FONT HTML_FONT
Definition: htmlfont_be.h:23
void dumpObject(HTML_OBJECT *o, FILE *f, int indent)
struct HTML_PROPS HTML_PROPS
Definition: htmlprops_be.h:15
void GWEN_SyncIo_free(GWEN_SYNCIO *sio)
Definition: syncio.c:76
void GWEN_SyncIo_AddFlags(GWEN_SYNCIO *sio, uint32_t fl)
Definition: syncio.c:169
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
int GWEN_SyncIo_Disconnect(GWEN_SYNCIO *sio)
Definition: syncio.c:105
GWEN_XML_CONTEXT * HtmlCtx_new(uint32_t flags)
Definition: htmlctx.c:34
GWENHYWFAR_API int GWEN_XMLContext_ReadFromIo(GWEN_XML_CONTEXT *ctx, GWEN_SYNCIO *io)
Definition: xmlrw.c:882
HTML_FONT * HtmlProps_GetFont(const HTML_PROPS *pr)
Definition: htmlprops.c:78
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:164
HTML_FONT * HtmlCtx_GetFont(GWEN_XML_CONTEXT *ctx, const char *fontName, int fontSize, uint32_t fontFlags)
Definition: htmlctx.c:609
uint32_t HtmlObject_GetFlags(const HTML_OBJECT *o)
Definition: htmlobject.c:231
GWENHYWFAR_API GWEN_SYNCIO * GWEN_SyncIo_File_new(const char *path, GWEN_SYNCIO_FILE_CREATIONMODE cm)
HTML_OBJECT_TREE * HtmlCtx_GetObjects(const GWEN_XML_CONTEXT *ctx)
Definition: htmlctx.c:242
uint32_t HtmlFont_GetFontFlags(const HTML_FONT *fnt)
Definition: htmlfont.c:98
struct GWEN_XML_CONTEXT GWEN_XML_CONTEXT
Definition: xmlctx.h:39
struct HTML_OBJECT HTML_OBJECT
Definition: htmlobject_be.h:25