gwenhywfar 5.14.1
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{
30 HTML_OBJECT *c;
31 HTML_OBJECT *cFirstInLine;
33 int w;
34 //int h;
35 int x=0;
36 int y=0;
37 int maxX=0;
38 int lineHeight=0;
39 int rv;
40 //int resX;
41 int resY;
42
44 //h=HtmlObject_GetHeight(o);
45
47 //resX=HtmlCtx_GetResolutionX(ctx);
48 resY=HtmlCtx_GetResolutionY(ctx);
49
50 c=HtmlObject_Tree_GetFirstChild(o);
51 cFirstInLine=c;
52 while (c) {
53 int th;
54
56 x>0) {
57 /* next line */
58 if (x>maxX)
59 maxX=x;
60
61 /* possibly justify */
62 if (w!=-1 && x<w) {
63 int diff=0;
64
66 diff=w-x;
68 diff=(w-x)>>1;
69 }
70 if (diff) {
71 HTML_OBJECT *ct;
72
73 ct=cFirstInLine;
74 while (ct) {
75 HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
76 if (ct==c)
77 break;
78 ct=HtmlObject_Tree_GetNext(ct);
79 }
80 }
81 }
82
83 x=0;
84 y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
85 lineHeight=0;
86 cFirstInLine=HtmlObject_Tree_GetNext(c);
87 }
88
90 if (w==-1) {
93 if (rv<0) {
94 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
95 return rv;
96 }
97 }
98 else {
99 int tw;
100
101 tw=w-x;
102 HtmlObject_SetWidth(c, tw);
103 rv=HtmlObject_Layout(c);
104 if (rv<0) {
105 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
106 return rv;
107 }
108
109 if (HtmlObject_GetWidth(c)>tw && x>0) {
110 /* next line */
111 if (x>maxX)
112 maxX=x;
113
114 /* possibly justify */
115 if (x<w) {
116 int diff=0;
117
119 diff=w-x;
121 diff=(w-x)>>1;
122 }
123 if (diff) {
124 HTML_OBJECT *ct;
125
126 ct=cFirstInLine;
127 while (ct) {
128 HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
129 if (ct==c)
130 break;
131 ct=HtmlObject_Tree_GetNext(ct);
132 }
133 }
134 }
135
136 x=0;
137 y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
138 lineHeight=0;
139 cFirstInLine=HtmlObject_Tree_GetNext(c);
140 }
141 }
142
143 HtmlObject_SetX(c, x);
144 HtmlObject_SetY(c, y);
145
147 if (th>lineHeight)
148 lineHeight=th;
149
151
153 if (x>0) {
154 /* next line */
155 if (x>maxX)
156 maxX=x;
157
158 /* possibly justify */
159 if (x<w) {
160 int diff=0;
161
163 diff=w-x;
165 diff=(w-x)>>1;
166 }
167 if (diff) {
168 HTML_OBJECT *ct;
169
170 ct=cFirstInLine;
171 while (ct) {
172 HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
173 if (ct==c)
174 break;
175 ct=HtmlObject_Tree_GetNext(ct);
176 }
177 }
178 }
179 }
180
181 x=0;
182 if (lineHeight==0) {
183 HTML_PROPS *pr;
184 HTML_FONT *fnt;
185
187 assert(pr);
188 fnt=HtmlProps_GetFont(pr);
189 lineHeight=HtmlCtx_GetTextHeight(HtmlObject_GetXmlCtx(o), fnt, "ABCD");
190 }
191 y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
192 lineHeight=0;
193 cFirstInLine=HtmlObject_Tree_GetNext(c);
194 }
195
196 c=HtmlObject_Tree_GetNext(c);
197 }
198
199 if (x>0) {
200 /* next line */
201 if (x>maxX)
202 maxX=x;
203
204 /* possibly justify */
205 if (x<w) {
206 int diff=0;
207
209 diff=w-x;
211 diff=(w-x)>>1;
212 }
213 if (diff) {
214 HTML_OBJECT *ct;
215
216 ct=cFirstInLine;
217 while (ct) {
218 HtmlObject_SetX(ct, HtmlObject_GetX(ct)+diff);
219 ct=HtmlObject_Tree_GetNext(ct);
220 }
221 }
222 }
223
224 x=0;
225 y+=lineHeight+(resY/LINE_EXTRA_OFFSET_DIV);
226 lineHeight=0;
227 }
228
229 /* finish layout */
230 HtmlObject_SetWidth(o, maxX+1);
231 HtmlObject_SetHeight(o, y+1);
232 return 0;
233}
234
235
236
246
247
248
249
250
#define DBG_INFO(dbg_logger, format,...)
Definition debug.h:181
int HtmlCtx_GetTextHeight(GWEN_XML_CONTEXT *ctx, HTML_FONT *fnt, const char *s)
Definition htmlctx.c:603
int HtmlCtx_GetResolutionY(const GWEN_XML_CONTEXT *ctx)
Definition htmlctx.c:134
struct HTML_FONT HTML_FONT
Definition htmlfont_be.h:23
HTML_OBJECT_LAYOUT_FN HtmlObject_SetLayoutFn(HTML_OBJECT *o, HTML_OBJECT_LAYOUT_FN fn)
Definition htmlobject.c:310
HTML_OBJECT * HtmlObject_new(GWEN_XML_CONTEXT *ctx, HTML_OBJECT_TYPE t)
Definition htmlobject.c:31
void HtmlObject_SetWidth(HTML_OBJECT *o, int i)
Definition htmlobject.c:170
int HtmlObject_GetWidth(const HTML_OBJECT *o)
Definition htmlobject.c:161
uint32_t HtmlObject_GetFlags(const HTML_OBJECT *o)
Definition htmlobject.c:255
GWEN_XML_CONTEXT * HtmlObject_GetXmlCtx(const HTML_OBJECT *o)
Definition htmlobject.c:77
int HtmlObject_GetX(const HTML_OBJECT *o)
Definition htmlobject.c:125
void HtmlObject_SetY(HTML_OBJECT *o, int i)
Definition htmlobject.c:152
void HtmlObject_SetHeight(HTML_OBJECT *o, int i)
Definition htmlobject.c:188
HTML_PROPS * HtmlObject_GetProperties(const HTML_OBJECT *o)
Definition htmlobject.c:104
void HtmlObject_SetX(HTML_OBJECT *o, int i)
Definition htmlobject.c:134
int HtmlObject_GetHeight(const HTML_OBJECT *o)
Definition htmlobject.c:179
int HtmlObject_Layout(HTML_OBJECT *o)
Definition htmlobject.c:295
#define HTML_OBJECT_FLAGS_JUSTIFY_RIGHT
@ HtmlObjectType_Box
#define HTML_OBJECT_FLAGS_START_ON_NEWLINE
#define HTML_OBJECT_FLAGS_END_WITH_NEWLINE
#define HTML_OBJECT_FLAGS_JUSTIFY_HCENTER
struct HTML_OBJECT HTML_OBJECT
HTML_FONT * HtmlProps_GetFont(const HTML_PROPS *pr)
Definition htmlprops.c:82
struct HTML_PROPS HTML_PROPS
#define GWEN_LOGDOMAIN
Definition logger.h:32
#define LINE_EXTRA_OFFSET_DIV
Definition o_box.c:24
static int HtmlObject_Box_Layout(HTML_OBJECT *o)
Definition o_box.c:28
HTML_OBJECT * HtmlObject_Box_new(GWEN_XML_CONTEXT *ctx)
Definition o_box.c:237
struct GWEN_XML_CONTEXT GWEN_XML_CONTEXT
Definition xmlctx.h:39