gwenhywfar  5.3.0
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 {
25  HTML_OBJECT *c;
26  int i;
27  const char *s;
28  HTML_PROPS *pr;
29  HTML_FONT *fnt;
30 
31  s=HtmlObject_GetText(o);
32  for (i=0; i<indent; i++)
33  fprintf(f, " ");
34  fprintf(stderr, "Object type: %d [%s] flags: %08x\n",
36  s?s:"(empty)",
38 
40  fnt=HtmlProps_GetFont(pr);
41 
42  for (i=0; i<indent+2; i++)
43  fprintf(f, " ");
44  fprintf(stderr, "fgcol=%06x, bgcol=%06x, fontsize=%d, fontflags=%08x, fontname=[%s]\n",
50 
51  c=HtmlObject_Tree_GetFirstChild(o);
52  while (c) {
53  dumpObject(c, f, indent+2);
54  c=HtmlObject_Tree_GetNext(c);
55  }
56 }
57 
58 
59 
60 int test1(int argc, char **argv)
61 {
62  GWEN_XML_CONTEXT *xmlCtx;
63  GWEN_SYNCIO *sio;
64  int rv;
65  HTML_PROPS *pr;
66  HTML_FONT *fnt;
67  HTML_OBJECT_TREE *ot;
68 
69  if (argc<2) {
70  fprintf(stderr, "Name of testfile needed.\n");
71  return 1;
72  }
73 
76  rv=GWEN_SyncIo_Connect(sio);
77  if (rv<0) {
78  DBG_ERROR(0, "here (%d)", rv);
79  GWEN_SyncIo_free(sio);
80  return 2;
81  }
82 
83  xmlCtx=HtmlCtx_new(0);
84  assert(xmlCtx);
85 
86  pr=HtmlProps_new();
87  fnt=HtmlCtx_GetFont(xmlCtx, "times new roman", 12, 0);
88  HtmlProps_SetFont(pr, fnt);
89  HtmlFont_free(fnt);
90  HtmlCtx_SetStandardProps(xmlCtx, pr);
91  HtmlProps_free(pr);
92 
93  /* read OFX file into context */
94  rv=GWEN_XMLContext_ReadFromIo(xmlCtx, sio);
95  if (rv<0) {
96  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
98  GWEN_SyncIo_free(sio);
99  return rv;
100  }
101 
102  ot=HtmlCtx_GetObjects(xmlCtx);
103  if (ot) {
104  HTML_OBJECT *o;
105 
106  o=HtmlObject_Tree_GetFirst(ot);
107  dumpObject(o, stderr, 2);
108  }
109 
111  GWEN_SyncIo_free(sio);
112  GWEN_XmlCtx_free(xmlCtx);
113 
114  return 0;
115 }
116 
117 
118 
119 
120 int main(int argc, char **argv)
121 {
122  return test1(argc, argv);
123 }
124 
const char * HtmlFont_GetFontName(const HTML_FONT *fnt)
Definition: htmlfont.c:67
int HtmlFont_GetFontSize(const HTML_FONT *fnt)
Definition: htmlfont.c:89
void HtmlCtx_SetStandardProps(GWEN_XML_CONTEXT *ctx, HTML_PROPS *pr)
Definition: htmlctx.c:386
int GWEN_SyncIo_Connect(GWEN_SYNCIO *sio)
Definition: syncio.c:97
int test1(int argc, char **argv)
uint32_t HtmlProps_GetBackgroundColor(const HTML_PROPS *pr)
Definition: htmlprops.c:120
HTML_OBJECT_TYPE HtmlObject_GetObjectType(const HTML_OBJECT *o)
Definition: htmlobject.c:86
void HtmlProps_free(HTML_PROPS *pr)
Definition: htmlprops.c:40
#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:91
uint32_t HtmlProps_GetForegroundColor(const HTML_PROPS *pr)
Definition: htmlprops.c:102
void HtmlFont_free(HTML_FONT *fnt)
Definition: htmlfont.c:39
#define GWEN_LOGDOMAIN
Definition: logger.h:35
const char * HtmlObject_GetText(const HTML_OBJECT *o)
Definition: htmlobject.c:233
HTML_PROPS * HtmlObject_GetProperties(const HTML_OBJECT *o)
Definition: htmlobject.c:104
void GWEN_XmlCtx_free(GWEN_XML_CONTEXT *ctx)
Definition: xmlctx.c:67
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:78
void GWEN_SyncIo_AddFlags(GWEN_SYNCIO *sio, uint32_t fl)
Definition: syncio.c:179
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
int GWEN_SyncIo_Disconnect(GWEN_SYNCIO *sio)
Definition: syncio.c:109
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:1203
HTML_FONT * HtmlProps_GetFont(const HTML_PROPS *pr)
Definition: htmlprops.c:82
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:178
HTML_FONT * HtmlCtx_GetFont(GWEN_XML_CONTEXT *ctx, const char *fontName, int fontSize, uint32_t fontFlags)
Definition: htmlctx.c:638
uint32_t HtmlObject_GetFlags(const HTML_OBJECT *o)
Definition: htmlobject.c:255
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:257
uint32_t HtmlFont_GetFontFlags(const HTML_FONT *fnt)
Definition: htmlfont.c:107
struct GWEN_XML_CONTEXT GWEN_XML_CONTEXT
Definition: xmlctx.h:39
struct HTML_OBJECT HTML_OBJECT
Definition: htmlobject_be.h:25