gwenhywfar  4.8.0beta
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 
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