annotate dw/style.cc @ 1760:cbca357af616

Full CSS border-style implementation The drawBorder{Top,Bottom,Left,Right} functions are similar. They use a trapezium as draw polygon, or drawTypedLine() for dots and dashes. Although the concept is simple, achieving pixel accuracy is laborious [1]. [1] http://www.dillo.org/css_compat/tests/border-style.html
author Jorge Arellano Cid <jcid@dillo.org>
date Sat, 13 Nov 2010 13:15:55 -0300
parents c75d0b8f71fc
children f5b91fafcbd4
rev   line source
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
1 /*
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
2 * Dillo Widget
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
3 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
5 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
9 * (at your option) any later version.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
10 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
14 * GNU General Public License for more details.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
15 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
972
d7dbd3dcfa38 Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents: 930
diff changeset
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
18 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
19
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
20
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
21
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
22 #include <stdio.h>
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
23 #include <string.h>
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
24 #include <unistd.h>
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
25 #include <ctype.h>
1760
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
26 #include <math.h>
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
27
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
28 #include "core.hh"
772
c1104104babf Added lout/msg.h and normalized debug messages to use it.
Jorge Arellano Cid <jcid@dillo.org>
parents: 699
diff changeset
29 #include "../lout/msg.h"
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
30
1347
4704ad910042 remove "using namespace" statements from header files
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
31 using namespace lout;
4704ad910042 remove "using namespace" statements from header files
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
32
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
33 namespace dw {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
34 namespace core {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
35 namespace style {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
36
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
37 void StyleAttrs::initValues ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
38 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
39 x_link = -1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
40 x_img = -1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
41 x_tooltip = NULL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
42 textDecoration = TEXT_DECORATION_NONE;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
43 textAlign = TEXT_ALIGN_LEFT;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
44 textAlignChar = '.';
1464
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
45 listStylePosition = LIST_STYLE_POSITION_OUTSIDE;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
46 listStyleType = LIST_STYLE_TYPE_DISC;
1331
c1c0fd4a81be default valign is baseline
corvid <corvid@lavabit.com>
parents: 1299
diff changeset
47 valign = VALIGN_BASELINE;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
48 backgroundColor = NULL;
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1492
diff changeset
49 width = height = lineHeight = LENGTH_AUTO;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
50 margin.setVal (0);
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
51 borderWidth.setVal (0);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
52 padding.setVal (0);
1756
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1712
diff changeset
53 borderCollapse = BORDER_MODEL_SEPARATE;
1757
c75d0b8f71fc imported patch border-collapse
Jorge Arellano Cid <jcid@dillo.org>
parents: 1756
diff changeset
54 collapseStyleSet = false;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
55 setBorderColor (NULL);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
56 setBorderStyle (BORDER_NONE);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
57 hBorderSpacing = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
58 vBorderSpacing = 0;
1650
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
59 wordSpacing = 0;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
60
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
61 display = DISPLAY_INLINE;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
62 whiteSpace = WHITE_SPACE_NORMAL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
63 cursor = CURSOR_DEFAULT;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
64 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
65
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
66 /**
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
67 * \brief Reset those style attributes to their standard values, which are
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
68 * not inherited, according to CSS.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
69 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
70 void StyleAttrs::resetValues ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
71 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
72 x_img = -1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
73
1331
c1c0fd4a81be default valign is baseline
corvid <corvid@lavabit.com>
parents: 1299
diff changeset
74 valign = VALIGN_BASELINE;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
75 textAlignChar = '.';
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
76 backgroundColor = NULL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
77 width = LENGTH_AUTO;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
78 height = LENGTH_AUTO;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
79
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
80 margin.setVal (0);
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
81 borderWidth.setVal (0);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
82 padding.setVal (0);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
83 setBorderColor (NULL);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
84 setBorderStyle (BORDER_NONE);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
85 hBorderSpacing = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
86 vBorderSpacing = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
87
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
88 display = DISPLAY_INLINE;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
89 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
90
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
91 /**
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
92 * \brief This method returns whether something may change its size, when
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
93 * its style changes from this style to \em otherStyle.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
94 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
95 * It is mainly for optimizing style changes where only colors etc change
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
96 * (where false would be returned), in some cases it may return true, although
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
97 * a size change does not actually happen (e.g. when in a certain
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
98 * context a particular attribute is ignored).
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
99 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
100 * \todo Should for CSS implemented properly. Currently, size changes are
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
101 * not needed, so always false is returned. See also
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
102 * dw::core::Widget::setStyle.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
103 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
104 bool StyleAttrs::sizeDiffs (StyleAttrs *otherStyle)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
105 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
106 return false;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
107 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
108
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
109 bool StyleAttrs::equals (object::Object *other) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
110 StyleAttrs *otherAttrs = (StyleAttrs *) other;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
111
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
112 return this == otherAttrs ||
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
113 (font == otherAttrs->font &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
114 textDecoration == otherAttrs->textDecoration &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
115 color == otherAttrs->color &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
116 backgroundColor == otherAttrs->backgroundColor &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
117 textAlign == otherAttrs->textAlign &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
118 valign == otherAttrs->valign &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
119 textAlignChar == otherAttrs->textAlignChar &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
120 hBorderSpacing == otherAttrs->hBorderSpacing &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
121 vBorderSpacing == otherAttrs->vBorderSpacing &&
1650
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
122 wordSpacing == otherAttrs->wordSpacing &&
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
123 width == otherAttrs->width &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
124 height == otherAttrs->height &&
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1492
diff changeset
125 lineHeight == otherAttrs->lineHeight &&
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
126 margin.equals (&otherAttrs->margin) &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
127 borderWidth.equals (&otherAttrs->borderWidth) &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
128 padding.equals (&otherAttrs->padding) &&
1756
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1712
diff changeset
129 borderCollapse == otherAttrs->borderCollapse &&
1757
c75d0b8f71fc imported patch border-collapse
Jorge Arellano Cid <jcid@dillo.org>
parents: 1756
diff changeset
130 collapseStyleSet == otherAttrs->collapseStyleSet &&
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
131 borderColor.top == otherAttrs->borderColor.top &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
132 borderColor.right == otherAttrs->borderColor.right &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
133 borderColor.bottom == otherAttrs->borderColor.bottom &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
134 borderColor.left == otherAttrs->borderColor.left &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
135 borderStyle.top == otherAttrs->borderStyle.top &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
136 borderStyle.right == otherAttrs->borderStyle.right &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
137 borderStyle.bottom == otherAttrs->borderStyle.bottom &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
138 borderStyle.left == otherAttrs->borderStyle.left &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
139 display == otherAttrs->display &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
140 whiteSpace == otherAttrs->whiteSpace &&
1464
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
141 listStylePosition == otherAttrs->listStylePosition &&
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
142 listStyleType == otherAttrs->listStyleType &&
1492
b9a3ee3fbcb8 check cursor in StyleAttrs::equals() and StyleAttrs::hashValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
143 cursor == otherAttrs->cursor &&
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
144 x_link == otherAttrs->x_link &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
145 x_img == otherAttrs->x_img &&
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
146 x_tooltip == otherAttrs->x_tooltip);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
147 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
148
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
149 int StyleAttrs::hashValue () {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
150 return (intptr_t) font +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
151 textDecoration +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
152 (intptr_t) color +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
153 (intptr_t) backgroundColor +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
154 textAlign +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
155 valign +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
156 textAlignChar +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
157 hBorderSpacing +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
158 vBorderSpacing +
1650
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
159 wordSpacing +
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
160 width +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
161 height +
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1492
diff changeset
162 lineHeight +
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
163 margin.hashValue () +
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 844
diff changeset
164 borderWidth.hashValue () +
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
165 padding.hashValue () +
1756
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1712
diff changeset
166 borderCollapse +
1757
c75d0b8f71fc imported patch border-collapse
Jorge Arellano Cid <jcid@dillo.org>
parents: 1756
diff changeset
167 collapseStyleSet +
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
168 (intptr_t) borderColor.top +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
169 (intptr_t) borderColor.right +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
170 (intptr_t) borderColor.bottom +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
171 (intptr_t) borderColor.left +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
172 borderStyle.top +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
173 borderStyle.right +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
174 borderStyle.bottom +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
175 borderStyle.left +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
176 display +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
177 whiteSpace +
1464
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
178 listStylePosition +
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
179 listStyleType +
1492
b9a3ee3fbcb8 check cursor in StyleAttrs::equals() and StyleAttrs::hashValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
180 cursor +
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
181 x_link +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
182 x_img +
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
183 (intptr_t) x_tooltip;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
184 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
185
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
186 int Style::totalRef = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
187 container::typed::HashTable <StyleAttrs, Style> * Style::styleTable =
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
188 new container::typed::HashTable <StyleAttrs, Style> (false, false, 1024);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
189
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
190 Style::Style (StyleAttrs *attrs)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
191 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
192 copyAttrs (attrs);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
193
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
194 refCount = 1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
195
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
196 font->ref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
197 if (color)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
198 color->ref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
199 if (backgroundColor)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
200 backgroundColor->ref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
201 if (borderColor.top)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
202 borderColor.top->ref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
203 if (borderColor.bottom)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
204 borderColor.bottom->ref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
205 if (borderColor.left)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
206 borderColor.left->ref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
207 if (borderColor.right)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
208 borderColor.right->ref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
209 if (x_tooltip)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
210 x_tooltip->ref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
211
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
212 totalRef++;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
213 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
214
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
215 Style::~Style ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
216 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
217 font->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
218
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
219 if (color)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
220 color->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
221 if (backgroundColor)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
222 backgroundColor->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
223 if (borderColor.top)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
224 borderColor.top->unref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
225 if (borderColor.bottom)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
226 borderColor.bottom->unref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
227 if (borderColor.left)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
228 borderColor.left->unref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
229 if (borderColor.right)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
230 borderColor.right->unref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
231 if (x_tooltip)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
232 x_tooltip->unref();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
233
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
234 styleTable->remove (this);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 844
diff changeset
235 totalRef--;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
236 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
237
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
238 void Style::copyAttrs (StyleAttrs *attrs)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
239 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
240 font = attrs->font;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
241 textDecoration = attrs->textDecoration;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
242 color = attrs->color;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
243 backgroundColor = attrs->backgroundColor;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
244 textAlign = attrs->textAlign;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
245 valign = attrs->valign;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
246 textAlignChar = attrs->textAlignChar;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
247 hBorderSpacing = attrs->hBorderSpacing;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
248 vBorderSpacing = attrs->vBorderSpacing;
1650
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
249 wordSpacing = attrs->wordSpacing;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
250 width = attrs->width;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
251 height = attrs->height;
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1492
diff changeset
252 lineHeight = attrs->lineHeight;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
253 margin = attrs->margin;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
254 borderWidth = attrs->borderWidth;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
255 padding = attrs->padding;
1756
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1712
diff changeset
256 borderCollapse = attrs->borderCollapse;
1757
c75d0b8f71fc imported patch border-collapse
Jorge Arellano Cid <jcid@dillo.org>
parents: 1756
diff changeset
257 collapseStyleSet = attrs->collapseStyleSet;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
258 borderColor = attrs->borderColor;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
259 borderStyle = attrs->borderStyle;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
260 display = attrs->display;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
261 whiteSpace = attrs->whiteSpace;
1464
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
262 listStylePosition = attrs->listStylePosition;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
263 listStyleType = attrs->listStyleType;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
264 cursor = attrs->cursor;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
265 x_link = attrs->x_link;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
266 x_img = attrs->x_img;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
267 x_tooltip = attrs->x_tooltip;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
268 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
269
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
270 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
271
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
272 bool FontAttrs::equals(object::Object *other)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
273 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
274 FontAttrs *otherAttrs = (FontAttrs*)other;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
275 return
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
276 this == otherAttrs ||
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
277 (size == otherAttrs->size &&
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
278 weight == otherAttrs->weight &&
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
279 style == otherAttrs->style &&
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
280 letterSpacing == otherAttrs->letterSpacing &&
1712
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
281 fontVariant == otherAttrs->fontVariant &&
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
282 strcmp (name, otherAttrs->name) == 0);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
283 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
284
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
285 int FontAttrs::hashValue()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
286 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
287 int h = object::String::hashValue (name);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
288 h = (h << 5) - h + size;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
289 h = (h << 5) - h + weight;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
290 h = (h << 5) - h + style;
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
291 h = (h << 5) - h + letterSpacing;
1712
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
292 h = (h << 5) - h + fontVariant;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
293 return h;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
294 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
295
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
296 Font::~Font ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
297 {
844
16f0a313536d make StyleAttrs::name const again (by jcid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 837
diff changeset
298 free ((char*)name);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
299 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
300
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
301 void Font::copyAttrs (FontAttrs *attrs)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
302 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
303 name = strdup (attrs->name);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
304 size = attrs->size;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
305 weight = attrs->weight;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
306 style = attrs->style;
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
307 letterSpacing = attrs->letterSpacing;
1712
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
308 fontVariant = attrs->fontVariant;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
309 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
310
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
311 Font *Font::create0 (Layout *layout, FontAttrs *attrs,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
312 bool tryEverything)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
313 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
314 return layout->createFont (attrs, tryEverything);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
315 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
316
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
317 Font *Font::create (Layout *layout, FontAttrs *attrs)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
318 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
319 return create0 (layout, attrs, false);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
320 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
321
1436
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1364
diff changeset
322 bool Font::exists (Layout *layout, const char *name)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
323 {
1436
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1364
diff changeset
324 return layout->fontExists (name);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
325 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
326
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
327 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
328
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
329 bool ColorAttrs::equals(object::Object *other)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
330 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
331 ColorAttrs *oc = (ColorAttrs*)other;
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 662
diff changeset
332 return this == oc || (color == oc->color);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
333 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
334
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
335 int ColorAttrs::hashValue()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
336 {
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 662
diff changeset
337 return color;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
338 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
339
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
340 Color::~Color ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
341 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
342 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
343
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
344 int Color::shadeColor (int color, int d)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
345 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
346 int red = (color >> 16) & 255;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
347 int green = (color >> 8) & 255;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
348 int blue = color & 255;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
349
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
350 double oldLightness = ((double) misc::max (red, green, blue)) / 255;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
351 double newLightness;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
352
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
353 if (oldLightness > 0.8) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
354 if (d > 0)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
355 newLightness = oldLightness - 0.2;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
356 else
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
357 newLightness = oldLightness - 0.4;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
358 } else if (oldLightness < 0.2) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
359 if (d > 0)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
360 newLightness = oldLightness + 0.4;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
361 else
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
362 newLightness = oldLightness + 0.2;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
363 } else
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
364 newLightness = oldLightness + d * 0.2;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
365
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
366 if (oldLightness) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
367 double f = (newLightness / oldLightness);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
368 red = (int)(red * f);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
369 green = (int)(green * f);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
370 blue = (int)(blue * f);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
371 } else {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
372 red = green = blue = (int)(newLightness * 255);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
373 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
374
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
375 return (red << 16) | (green << 8) | blue;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
376 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
377
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
378 int Color::shadeColor (int color, Shading shading)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
379 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
380 switch (shading) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
381 case SHADING_NORMAL:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
382 return color;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
383
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
384 case SHADING_LIGHT:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
385 return shadeColor(color, +1);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
386
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
387 case SHADING_INVERSE:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
388 return color ^ 0xffffff;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
389
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
390 case SHADING_DARK:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
391 return shadeColor(color, -1);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
392
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
393 default:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
394 // compiler happiness
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
395 misc::assertNotReached ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
396 return -1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
397 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
398 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
399
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 844
diff changeset
400
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 662
diff changeset
401 Color *Color::create (Layout *layout, int col)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
402 {
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 662
diff changeset
403 ColorAttrs attrs(col);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
404
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 662
diff changeset
405 return layout->createColor (col);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
406 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
407
1340
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1331
diff changeset
408 Tooltip *Tooltip::create (Layout *layout, const char *text)
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1331
diff changeset
409 {
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1331
diff changeset
410 return layout->createTooltip (text);
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1331
diff changeset
411 }
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1331
diff changeset
412
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
413 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
414
1760
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
415 /*
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
416 * The drawBorder{Top,Bottom,Left,Right} functions are similar. They
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
417 * use a trapezium as draw polygon, or drawTypedLine() for dots and dashes.
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
418 * Although the concept is simple, achieving pixel accuracy is laborious [1].
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
419 *
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
420 * [1] http://www.dillo.org/css_compat/tests/border-style.html
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
421 */
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
422 static void drawBorderTop(View *view, Style *style,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
423 int x1, int y1, int x2, int y2)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
424
1760
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
425 {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
426 int points[4][2], d, w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
427 bool ridge = false, inset = false, dotted = false;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
428 Color::Shading shading = Color::SHADING_NORMAL;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
429
1760
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
430 if (!style->borderColor.top)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
431 return;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
432
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
433 switch (style->borderStyle.top) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
434 case BORDER_NONE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
435 case BORDER_HIDDEN:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
436 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
437 case BORDER_DOTTED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
438 dotted = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
439 case BORDER_DASHED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
440 w = style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
441 view->drawTypedLine(style->borderColor.top, shading,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
442 dotted ? LINE_DOTTED : LINE_DASHED,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
443 w, x1+w/2, y1+w/2, x2-w/2, y2+w/2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
444 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
445 case BORDER_SOLID:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
446 case BORDER_INSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
447 inset = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
448 case BORDER_OUTSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
449 if (style->borderStyle.top != BORDER_SOLID)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
450 shading = (inset) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
451
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
452 if (style->borderWidth.top == 1) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
453 view->drawLine(style->borderColor.top, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
454 } else {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
455 points[0][0] = x1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
456 points[1][0] = x2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
457 points[0][1] = points[1][1] = y1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
458 points[2][0] = points[1][0] - style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
459 points[3][0] = x1 + style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
460 points[2][1] = points[3][1] = points[0][1] + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
461 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
462 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
463 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
464 case BORDER_RIDGE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
465 ridge = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
466 case BORDER_GROOVE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
467 d = style->borderWidth.top & 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
468 points[0][0] = x1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
469 points[1][0] = x2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
470 points[0][1] = points[1][1] = y1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
471 points[2][0] = x2 - style->borderWidth.right / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
472 points[3][0] = x1 + style->borderWidth.left / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
473 points[2][1] = points[3][1] = y1 + style->borderWidth.top / 2 + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
474 shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
475 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
476 points[0][0] = x1 + style->borderWidth.left / 2 + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
477 points[1][0] = x2 - style->borderWidth.right / 2 + 1 - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
478 points[0][1] = points[1][1] = y1 + style->borderWidth.top / 2 + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
479 points[2][0] = x2 - style->borderWidth.right + 1 - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
480 points[3][0] = x1 + style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
481 points[2][1] = points[3][1] = y1 + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
482 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
483 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
484 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
485 case BORDER_DOUBLE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
486 w = (int) rint(style->borderWidth.top / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
487 d = w ? style->borderWidth.top - 2 * w : 0;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
488 int w_l = (int) rint(style->borderWidth.left / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
489 int w_r = (int) rint(style->borderWidth.right / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
490 if (style->borderWidth.top == 1) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
491 view->drawLine(style->borderColor.top, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
492 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
493 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
494 points[0][0] = x1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
495 points[1][0] = x2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
496 points[0][1] = points[1][1] = y1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
497 points[2][0] = points[1][0] - w_r;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
498 points[3][0] = points[0][0] + w_l;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
499 points[2][1] = points[3][1] = points[0][1] + w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
500 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
501 points[0][0] = x1 + style->borderWidth.left - w_l;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
502 points[1][0] = x2 + 1 - style->borderWidth.right + w_r;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
503 points[0][1] = points[1][1] = y1 + w + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
504 points[2][0] = x2 + 1 - style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
505 points[3][0] = x1 + style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
506 points[2][1] = points[3][1] = y1 + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
507 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
508 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
509 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
510 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
511
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
512 static void drawBorderBottom(View *view, Style *style,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
513 int x1, int y1, int x2, int y2)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
514
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
515 {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
516 int points[4][2], d, w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
517 bool ridge = false, inset = false, dotted = false;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
518 Color::Shading shading = Color::SHADING_NORMAL;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
519
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
520 if (!style->borderColor.bottom)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
521 return;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
522
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
523 switch (style->borderStyle.bottom) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
524 case BORDER_NONE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
525 case BORDER_HIDDEN:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
526 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
527 case BORDER_DOTTED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
528 dotted = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
529 case BORDER_DASHED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
530 w = style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
531 view->drawTypedLine(style->borderColor.top, shading,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
532 dotted ? LINE_DOTTED : LINE_DASHED,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
533 w, x1+w/2, y1-w/2, x2-w/2, y2-w/2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
534 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
535 case BORDER_SOLID:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
536 case BORDER_INSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
537 inset = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
538 case BORDER_OUTSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
539 if (style->borderStyle.bottom != BORDER_SOLID)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
540 shading = (inset) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
541
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
542 if (style->borderWidth.bottom == 1) { /* 1 pixel line */
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
543 view->drawLine(style->borderColor.bottom, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
544 } else {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
545 points[0][0] = x1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
546 points[1][0] = x2 + 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
547 points[0][1] = points[1][1] = y1 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
548 points[2][0] = points[1][0] - style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
549 points[3][0] = points[0][0] + style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
550 points[2][1] = points[3][1] = points[0][1]-style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
551 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
552 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
553 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
554 case BORDER_RIDGE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
555 ridge = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
556 case BORDER_GROOVE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
557 w = style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
558 d = w & 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
559 points[0][0] = x1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
560 points[1][0] = x2 + 2 - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
561 points[0][1] = points[1][1] = y1 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
562 points[2][0] = points[1][0] - style->borderWidth.right / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
563 points[3][0] = points[0][0] + style->borderWidth.left / 2 + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
564 points[2][1] = points[3][1] = points[0][1] - w/2 - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
565 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
566 view->drawPolygon (style->borderColor.bottom, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
567 // clockwise
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
568 points[0][0] = x1 + style->borderWidth.left - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
569 points[1][0] = x2 + 1 - style->borderWidth.right + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
570 points[0][1] = points[1][1] = y1 - w + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
571 points[2][0] = points[1][0] + style->borderWidth.right / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
572 points[3][0] = points[0][0] - style->borderWidth.left / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
573 points[2][1] = points[3][1] = points[0][1] + w/2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
574 shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
575 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
576 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
577 case BORDER_DOUBLE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
578 w = (int) rint(style->borderWidth.bottom / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
579 d = w ? style->borderWidth.bottom - 2 * w : 0;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
580 int w_l = (int) rint(style->borderWidth.left / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
581 int w_r = (int) rint(style->borderWidth.right / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
582 if (style->borderWidth.bottom == 1) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
583 view->drawLine(style->borderColor.bottom, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
584 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
585 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
586 points[0][0] = x2 + 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
587 points[1][0] = x1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
588 points[0][1] = points[1][1] = y1 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
589 points[2][0] = points[1][0] + w_l;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
590 points[3][0] = points[0][0] - w_r;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
591 points[2][1] = points[3][1] = points[0][1] - w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
592 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
593 points[0][0] = x2 + 2 - style->borderWidth.right + w_r;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
594 points[1][0] = x1 - 1 + style->borderWidth.left - w_l;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
595 points[0][1] = points[1][1] = y1 + 1 - w - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
596 points[2][0] = x1 - 1 + style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
597 points[3][0] = x2 + 2 - style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
598 points[2][1] = points[3][1] = y1 + 1 - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
599 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
600 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
601 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
602 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
603
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
604 static void drawBorderLeft(View *view, Style *style,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
605 int x1, int y1, int x2, int y2)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
606
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
607 {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
608 int points[4][2], d, w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
609 bool ridge = false, inset = false, dotted = false;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
610 Color::Shading shading = Color::SHADING_NORMAL;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
611
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
612 if (!style->borderColor.left)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
613 return;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
614
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
615 switch (style->borderStyle.left) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
616 case BORDER_NONE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
617 case BORDER_HIDDEN:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
618 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
619 case BORDER_DOTTED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
620 dotted = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
621 case BORDER_DASHED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
622 w = style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
623 view->drawTypedLine(style->borderColor.left, shading,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
624 dotted ? LINE_DOTTED : LINE_DASHED,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
625 w, x1+w/2, y1+w/2, x1+w/2, y2-w/2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
626 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
627 case BORDER_SOLID:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
628 case BORDER_INSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
629 inset = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
630 case BORDER_OUTSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
631 if (style->borderStyle.left != BORDER_SOLID)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
632 shading = (inset) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
633 if (style->borderWidth.left == 1) { /* 1 pixel line */
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
634 view->drawLine(style->borderColor.left, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
635 } else {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
636 points[0][0] = points[1][0] = x1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
637 points[0][1] = y1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
638 points[1][1] = y2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
639 points[2][0] = points[3][0] = points[0][0] + style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
640 points[2][1] = points[1][1] - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
641 points[3][1] = points[0][1] + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
642 view->drawPolygon (style->borderColor.left, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
643 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
644 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
645 case BORDER_RIDGE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
646 ridge = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
647 case BORDER_GROOVE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
648 w = style->borderWidth.left;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
649 d = w & 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
650 points[0][0] = points[1][0] = x1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
651 points[0][1] = y1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
652 points[1][1] = y2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
653 points[2][0] = points[3][0] = x1 + w / 2 + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
654 points[2][1] = y2 - style->borderWidth.bottom / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
655 points[3][1] = y1 + style->borderWidth.top / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
656 shading = (ridge) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
657 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
658 points[0][0] = points[1][0] = x1 + w / 2 + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
659 points[0][1] = y1 + style->borderWidth.top / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
660 points[1][1] = y2 - style->borderWidth.bottom / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
661 points[2][0] = points[3][0] = x1 + w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
662 points[2][1] = y2 - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
663 points[3][1] = y1 + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
664 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
665 view->drawPolygon (style->borderColor.top, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
666 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
667 case BORDER_DOUBLE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
668 w = (int) rint(style->borderWidth.left / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
669 d = w ? style->borderWidth.left - 2 * w : 0;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
670 int w_b = (int) rint(style->borderWidth.bottom / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
671 int w_t = (int) rint(style->borderWidth.top / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
672 if (style->borderWidth.left == 1) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
673 view->drawLine(style->borderColor.left, shading, x1, y1, x2, y2-1);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
674 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
675 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
676 points[0][0] = points[1][0] = x1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
677 points[0][1] = y1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
678 points[1][1] = y2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
679 points[2][0] = points[3][0] = points[0][0] + w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
680 points[2][1] = points[1][1] - w_b;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
681 points[3][1] = points[0][1] + w_t;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
682 view->drawPolygon (style->borderColor.left, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
683 points[0][0] = points[1][0] = x1 + w + d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
684 points[0][1] = y1 - 1 + style->borderWidth.top - w_t;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
685 points[1][1] = y2 + 1 - style->borderWidth.bottom + w_b;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
686 points[2][0] = points[3][0] = points[0][0] + w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
687 points[2][1] = y2 + 1 - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
688 points[3][1] = y1 - 1 + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
689 view->drawPolygon (style->borderColor.left, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
690 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
691 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
692 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
693
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
694 static void drawBorderRight(View *view, Style *style,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
695 int x1, int y1, int x2, int y2)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
696
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
697 {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
698 int points[4][2], d, w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
699 bool ridge = false, inset = false, dotted = false;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
700 Color::Shading shading = Color::SHADING_NORMAL;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
701
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
702 if (!style->borderColor.right)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
703 return;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
704
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
705 switch (style->borderStyle.right) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
706 case BORDER_NONE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
707 case BORDER_HIDDEN:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
708 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
709 case BORDER_DOTTED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
710 dotted = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
711 case BORDER_DASHED:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
712 w = style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
713 view->drawTypedLine(style->borderColor.right, shading,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
714 dotted ? LINE_DOTTED : LINE_DASHED,
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
715 w, x1 - w/2, y1 + w/2, x1 - w/2, y2 - w/2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
716 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
717 case BORDER_SOLID:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
718 case BORDER_INSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
719 inset = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
720 case BORDER_OUTSET:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
721 if (style->borderStyle.right != BORDER_SOLID)
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
722 shading = (inset) ? Color::SHADING_LIGHT : Color::SHADING_DARK;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
723 if (style->borderWidth.right == 1) { /* 1 pixel line */
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
724 view->drawLine(style->borderColor.right, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
725 } else {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
726 points[0][0] = points[1][0] = x1 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
727 points[0][1] = y1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
728 points[1][1] = y2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
729 points[2][0] = points[3][0] = points[0][0]-style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
730 points[2][1] = points[1][1] - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
731 points[3][1] = points[0][1] + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
732 view->drawPolygon (style->borderColor.right, shading, true,points,4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
733 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
734 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
735 case BORDER_RIDGE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
736 ridge = true;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
737 case BORDER_GROOVE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
738 w = style->borderWidth.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
739 d = w & 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
740 points[0][0] = points[1][0] = x1 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
741 points[0][1] = y1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
742 points[1][1] = y2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
743 points[2][0] = points[3][0] = points[0][0] - w / 2 - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
744 points[2][1] = y2 - style->borderWidth.bottom / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
745 points[3][1] = points[0][1] + style->borderWidth.top / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
746 shading = (ridge) ? Color::SHADING_DARK : Color::SHADING_LIGHT;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
747 view->drawPolygon (style->borderColor.right, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
748 points[0][0] = points[1][0] = x1 + 1 - w / 2 - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
749 points[0][1] = y1 + style->borderWidth.top / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
750 points[1][1] = y2 - style->borderWidth.bottom / 2;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
751 points[2][0] = points[3][0] = x1 + 1 - w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
752 points[2][1] = y2 - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
753 points[3][1] = y1 + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
754 shading = (ridge) ? Color::SHADING_LIGHT: Color::SHADING_DARK;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
755 view->drawPolygon (style->borderColor.right, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
756 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
757 case BORDER_DOUBLE:
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
758 w = (int) rint(style->borderWidth.right / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
759 d = w ? style->borderWidth.right - 2 * w : 0;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
760 int w_b = (int) rint(style->borderWidth.bottom / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
761 int w_t = (int) rint(style->borderWidth.top / 3.0);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
762 if (style->borderWidth.right == 1) {
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
763 view->drawLine(style->borderColor.right, shading, x1, y1, x2, y2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
764 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
765 }
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
766 points[0][0] = points[1][0] = x1 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
767 points[0][1] = y1 - 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
768 points[1][1] = y2 + 1;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
769 points[2][0] = points[3][0] = points[0][0] - w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
770 points[2][1] = points[1][1] - w_b;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
771 points[3][1] = points[0][1] + w_t;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
772 view->drawPolygon (style->borderColor.right, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
773 points[0][0] = points[1][0] = x1 + 1 - w - d;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
774 points[0][1] = y1 - 1 + style->borderWidth.top - w_t;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
775 points[1][1] = y2 + 1 - style->borderWidth.bottom + w_b;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
776 points[2][0] = points[3][0] = points[0][0] - w;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
777 points[2][1] = y2 + 1 - style->borderWidth.bottom;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
778 points[3][1] = y1 - 1 + style->borderWidth.top;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
779 view->drawPolygon (style->borderColor.right, shading, true, points, 4);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
780 break;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
781 }
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
782 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
783
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
784 /**
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
785 * \brief Draw the border of a region in window, according to style.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
786 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
787 * Used by dw::core::Widget::drawBox and dw::core::Widget::drawWidgetBox.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
788 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
789 void drawBorder (View *view, Rectangle *area,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
790 int x, int y, int width, int height,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
791 Style *style, bool inverse)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
792 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
793 /** \todo a lot! */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
794 Color::Shading dark, light, normal;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
795 int xb1, yb1, xb2, yb2, xp1, yp1, xp2, yp2;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
796
1291
63837a774687 update Style::drawBorder()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1289
diff changeset
797 // top left and bottom right point of outer border boundary
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
798 xb1 = x + style->margin.left;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
799 yb1 = y + style->margin.top;
1760
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
800 xb2 = x + (width > 0 ? width - 1 : 0) - style->margin.right;
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
801 yb2 = y + (height > 0 ? height - 1 : 0) - style->margin.bottom;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
802
1291
63837a774687 update Style::drawBorder()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1289
diff changeset
803 // top left and bottom right point of inner border boundary
63837a774687 update Style::drawBorder()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1289
diff changeset
804 xp1 = xb1 + style->borderWidth.left;
63837a774687 update Style::drawBorder()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1289
diff changeset
805 yp1 = yb1 + style->borderWidth.top;
63837a774687 update Style::drawBorder()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1289
diff changeset
806 xp2 = xb2 - style->borderWidth.right;
63837a774687 update Style::drawBorder()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1289
diff changeset
807 yp2 = yb2 - style->borderWidth.bottom;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
808
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
809 light = inverse ? Color::SHADING_DARK : Color::SHADING_LIGHT;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
810 dark = inverse ? Color::SHADING_LIGHT : Color::SHADING_DARK;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
811 normal = inverse ? Color::SHADING_INVERSE : Color::SHADING_NORMAL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
812
1760
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
813 drawBorderRight(view, style, xb2, yb1, xb2, yb2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
814 drawBorderLeft(view, style, xb1, yb1, xb1, yb2);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
815 drawBorderTop(view, style, xb1, yb1, xb2, yb1);
cbca357af616 Full CSS border-style implementation
Jorge Arellano Cid <jcid@dillo.org>
parents: 1757
diff changeset
816 drawBorderBottom(view, style, xb1, yb2, xb2, yb2);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
817 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
818
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
819
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
820 /**
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
821 * \brief Draw the background (content plus padding) of a region in window,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
822 * according to style.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
823 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
824 * Used by dw::core::Widget::drawBox and dw::core::Widget::drawWidgetBox.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
825 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
826 void drawBackground (View *view, Rectangle *area,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
827 int x, int y, int width, int height,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
828 Style *style, bool inverse)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
829 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
830 Rectangle bgArea, intersection;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
831
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
832 if (style->backgroundColor) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
833 bgArea.x = x + style->margin.left + style->borderWidth.left;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
834 bgArea.y = y + style->margin.top + style->borderWidth.top;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
835 bgArea.width =
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
836 width - style->margin.left - style->borderWidth.left -
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
837 style->margin.right - style->borderWidth.right;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
838 bgArea.height =
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
839 height - style->margin.top - style->borderWidth.top -
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
840 style->margin.bottom - style->borderWidth.bottom;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
841
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
842 if (area->intersectsWith (&bgArea, &intersection))
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
843 view->drawRectangle (style->backgroundColor,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
844 inverse ?
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
845 Color::SHADING_INVERSE : Color::SHADING_NORMAL,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
846 true, intersection.x, intersection.y,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
847 intersection.width, intersection.height);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
848 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
849 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
850
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
851 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
852
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
853 static const char
479
cd066a3f0405 Added some const quialifiers.
corvid <corvid@lavabit.com>
parents: 347
diff changeset
854 *const roman_I0[] = { "","I","II","III","IV","V","VI","VII","VIII","IX" },
cd066a3f0405 Added some const quialifiers.
corvid <corvid@lavabit.com>
parents: 347
diff changeset
855 *const roman_I1[] = { "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC" },
cd066a3f0405 Added some const quialifiers.
corvid <corvid@lavabit.com>
parents: 347
diff changeset
856 *const roman_I2[] = { "","C","CC","CCC","CD","D","DC","DCC","DCCC","CM" },
cd066a3f0405 Added some const quialifiers.
corvid <corvid@lavabit.com>
parents: 347
diff changeset
857 *const roman_I3[] = { "","M","MM","MMM","MMMM" };
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
858
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
859 static void strtolower (char *s)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
860 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
861 for ( ; *s; s++)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
862 *s = tolower (*s);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
863 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
864
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
865 /**
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
866 * \brief Convert a number into a string, in a given list style.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
867 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
868 * Used for ordered lists.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
869 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
870 void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
871 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
872 int i3, i2, i1, i0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
873 bool low = false;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
874 int start_ch = 'A';
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
875
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
876 if (buflen <= 0)
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
877 return;
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
878
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
879 switch(listStyleType){
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
880 case LIST_STYLE_TYPE_LOWER_ALPHA:
1364
f6cf5158796b recognize latin list style types as synonyms for alpha
corvid <corvid@lavabit.com>
parents: 1350
diff changeset
881 case LIST_STYLE_TYPE_LOWER_LATIN:
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
882 start_ch = 'a';
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
883 case LIST_STYLE_TYPE_UPPER_ALPHA:
1364
f6cf5158796b recognize latin list style types as synonyms for alpha
corvid <corvid@lavabit.com>
parents: 1350
diff changeset
884 case LIST_STYLE_TYPE_UPPER_LATIN:
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
885 i0 = num - 1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
886 i1 = i0/26 - 1; i2 = i1/26 - 1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
887 if (i2 > 25) /* more than 26+26^2+26^3=18278 elements ? */
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
888 snprintf(buf, buflen, "****.");
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
889 else
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
890 snprintf(buf, buflen, "%c%c%c.",
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
891 i2<0 ? ' ' : start_ch + i2%26,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
892 i1<0 ? ' ' : start_ch + i1%26,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
893 i0<0 ? ' ' : start_ch + i0%26);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
894 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
895 case LIST_STYLE_TYPE_LOWER_ROMAN:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
896 low = true;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
897 case LIST_STYLE_TYPE_UPPER_ROMAN:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
898 i0 = num;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
899 i1 = i0/10; i2 = i1/10; i3 = i2/10;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
900 i0 %= 10; i1 %= 10; i2 %= 10;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
901 if (num < 0 || i3 > 4) /* more than 4999 elements ? */
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
902 snprintf(buf, buflen, "****.");
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
903 else
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
904 snprintf(buf, buflen, "%s%s%s%s.", roman_I3[i3], roman_I2[i2],
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
905 roman_I1[i1], roman_I0[i0]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
906 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
907 case LIST_STYLE_TYPE_DECIMAL:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
908 default:
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
909 snprintf(buf, buflen, "%d.", num);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
910 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
911 }
1111
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
912
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
913 // ensure termination
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
914 buf[buflen - 1] = '\0';
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
915
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
916 if (low)
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
917 strtolower(buf);
9845cc109124 consistently use snprintf
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 972
diff changeset
918
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
919 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
920
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
921 } // namespace style
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
922 } // namespace dw
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
923 } // namespace core