gwenhywfar  4.99.8beta
o_box.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Sat Feb 20 2010
3  copyright : (C) 2010 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #define DISABLE_DEBUGLOG
15 
16 
17 #include "o_box_l.h"
18 #include "htmlctx_l.h"
19 
20 #include <gwenhywfar/debug.h>
21 
22 
23 
24 #define LINE_EXTRA_OFFSET_DIV 20
25 
26 
27 
29  HTML_OBJECT *c;
30  HTML_OBJECT *cFirstInLine;
31  GWEN_XML_CONTEXT *ctx;
32  int w;
33  //int h;
34  int x=0;
35  int y=0;
36  int maxX=0;
37  int lineHeight=0;
38  int rv;
39  //int resX;
40  int resY;
41 
43  //h=HtmlObject_GetHeight(o);
44 
45  ctx=HtmlObject_GetXmlCtx(o);
46  //resX=HtmlCtx_GetResolutionX(ctx);
47  resY=HtmlCtx_GetResolutionY(ctx);
48 
49  c=HtmlObject_Tree_GetFirstChild(o);
50  cFirstInLine=c;
51  while(c) {
52  int th;
53 
55  x>0) {
56  /* next line */
57  if (x>maxX)
58  maxX=x;
59 
60  /* possibly justify */
61  if (w!=-1 && x<w) {
62  int diff=0;
63 
65  diff=w-x;
67  diff=(w-x)>>1;
68  }
69  if (diff) {
70  HTML_OBJECT *ct;
71 
72  ct=cFirstInLine;
73  while(ct) {
74  HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
75  if (ct==c)
76  break;
77  ct=HtmlObject_Tree_GetNext(ct);
78  }
79  }
80  }
81 
82  x=0;
83  y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
84  lineHeight=0;
85  cFirstInLine=HtmlObject_Tree_GetNext(c);
86  }
87 
88  HtmlObject_SetHeight(c, -1);
89  if (w==-1) {
90  HtmlObject_SetWidth(c, -1);
91  rv=HtmlObject_Layout(c);
92  if (rv<0) {
93  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
94  return rv;
95  }
96  }
97  else {
98  int tw;
99 
100  tw=w-x;
101  HtmlObject_SetWidth(c, tw);
102  rv=HtmlObject_Layout(c);
103  if (rv<0) {
104  DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
105  return rv;
106  }
107 
108  if (HtmlObject_GetWidth(c)>tw && x>0) {
109  /* next line */
110  if (x>maxX)
111  maxX=x;
112 
113  /* possibly justify */
114  if (x<w) {
115  int diff=0;
116 
118  diff=w-x;
120  diff=(w-x)>>1;
121  }
122  if (diff) {
123  HTML_OBJECT *ct;
124 
125  ct=cFirstInLine;
126  while(ct) {
127  HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
128  if (ct==c)
129  break;
130  ct=HtmlObject_Tree_GetNext(ct);
131  }
132  }
133  }
134 
135  x=0;
136  y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
137  lineHeight=0;
138  cFirstInLine=HtmlObject_Tree_GetNext(c);
139  }
140  }
141 
142  HtmlObject_SetX(c, x);
143  HtmlObject_SetY(c, y);
144 
145  th=HtmlObject_GetHeight(c);
146  if (th>lineHeight)
147  lineHeight=th;
148 
149  x+=HtmlObject_GetWidth(c);
150 
152  if (x>0) {
153  /* next line */
154  if (x>maxX)
155  maxX=x;
156 
157  /* possibly justify */
158  if (x<w) {
159  int diff=0;
160 
162  diff=w-x;
164  diff=(w-x)>>1;
165  }
166  if (diff) {
167  HTML_OBJECT *ct;
168 
169  ct=cFirstInLine;
170  while(ct) {
171  HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
172  if (ct==c)
173  break;
174  ct=HtmlObject_Tree_GetNext(ct);
175  }
176  }
177  }
178  }
179 
180  x=0;
181  if (lineHeight==0) {
182  HTML_PROPS *pr;
183  HTML_FONT *fnt;
184 
186  assert(pr);
187  fnt=HtmlProps_GetFont(pr);
188  lineHeight=HtmlCtx_GetTextHeight(HtmlObject_GetXmlCtx(o), fnt, "ABCD");
189  }
190  y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
191  lineHeight=0;
192  cFirstInLine=HtmlObject_Tree_GetNext(c);
193  }
194 
195  c=HtmlObject_Tree_GetNext(c);
196  }
197 
198  if (x>0) {
199  /* next line */
200  if (x>maxX)
201  maxX=x;
202 
203  /* possibly justify */
204  if (x<w) {
205  int diff=0;
206 
208  diff=w-x;
210  diff=(w-x)>>1;
211  }
212  if (diff) {
213  HTML_OBJECT *ct;
214 
215  ct=cFirstInLine;
216  while(ct) {
217  HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
218  ct=HtmlObject_Tree_GetNext(ct);
219  }
220  }
221  }
222 
223  x=0;
224  y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
225  lineHeight=0;
226  }
227 
228  /* finish layout */
229  HtmlObject_SetWidth(o, maxX+1);
230  HtmlObject_SetHeight(o, y+1);
231  return 0;
232 }
233 
234 
235 
237  HTML_OBJECT *o;
238 
241 
242  return o;
243 }
244 
245 
246 
247 
248 
HTML_OBJECT * HtmlObject_Box_new(GWEN_XML_CONTEXT *ctx)
Definition: o_box.c:236
int HtmlObject_Layout(HTML_OBJECT *o)
Definition: htmlobject.c:267
#define HTML_OBJECT_FLAGS_JUSTIFY_HCENTER
Definition: htmlobject_be.h:35
int HtmlObject_GetX(const HTML_OBJECT *o)
Definition: htmlobject.c:117
int HtmlObject_GetWidth(const HTML_OBJECT *o)
Definition: htmlobject.c:149
#define HTML_OBJECT_FLAGS_START_ON_NEWLINE
Definition: htmlobject_be.h:30
#define GWEN_LOGDOMAIN
Definition: logger.h:35
#define LINE_EXTRA_OFFSET_DIV
Definition: o_box.c:24
HTML_PROPS * HtmlObject_GetProperties(const HTML_OBJECT *o)
Definition: htmlobject.c:98
void HtmlObject_SetY(HTML_OBJECT *o, int i)
Definition: htmlobject.c:141
void HtmlObject_SetHeight(HTML_OBJECT *o, int i)
Definition: htmlobject.c:173
#define HTML_OBJECT_FLAGS_JUSTIFY_RIGHT
Definition: htmlobject_be.h:34
struct HTML_FONT HTML_FONT
Definition: htmlfont_be.h:23
HTML_OBJECT * HtmlObject_new(GWEN_XML_CONTEXT *ctx, HTML_OBJECT_TYPE t)
Definition: htmlobject.c:31
struct HTML_PROPS HTML_PROPS
Definition: htmlprops_be.h:15
void HtmlObject_SetX(HTML_OBJECT *o, int i)
Definition: htmlobject.c:125
HTML_FONT * HtmlProps_GetFont(const HTML_PROPS *pr)
Definition: htmlprops.c:78
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:164
uint32_t HtmlObject_GetFlags(const HTML_OBJECT *o)
Definition: htmlobject.c:231
#define HTML_OBJECT_FLAGS_END_WITH_NEWLINE
Definition: htmlobject_be.h:31
int HtmlCtx_GetResolutionY(const GWEN_XML_CONTEXT *ctx)
Definition: htmlctx.c:130
int HtmlCtx_GetTextHeight(GWEN_XML_CONTEXT *ctx, HTML_FONT *fnt, const char *s)
Definition: htmlctx.c:576
HTML_OBJECT_LAYOUT_FN HtmlObject_SetLayoutFn(HTML_OBJECT *o, HTML_OBJECT_LAYOUT_FN fn)
Definition: htmlobject.c:281
int HtmlObject_GetHeight(const HTML_OBJECT *o)
Definition: htmlobject.c:165
GWEN_XML_CONTEXT * HtmlObject_GetXmlCtx(const HTML_OBJECT *o)
Definition: htmlobject.c:74
void HtmlObject_SetWidth(HTML_OBJECT *o, int i)
Definition: htmlobject.c:157
static int HtmlObject_Box_Layout(HTML_OBJECT *o)
Definition: o_box.c:28
struct GWEN_XML_CONTEXT GWEN_XML_CONTEXT
Definition: xmlctx.h:39
struct HTML_OBJECT HTML_OBJECT
Definition: htmlobject_be.h:25