forked from flyingsaucerproject/flyingsaucer
-
Notifications
You must be signed in to change notification settings - Fork 9
/
design.txt
172 lines (116 loc) · 4.99 KB
/
design.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Plan:
- use css.* as is, from jar in Maven
- rename org.xhtmlrenderer.layout.* to org.docx4j.--- and package as a LGPL library
-
DocxRenderer:
public void layout() {
BlockBox root = BoxBuilder.createRootBox(c, _doc);
// BoxBuilder.createRootBox only creates the root box, not its children.
root.layout(c);
BlockBox.layoutChildren
// ensureChildren does BoxBuilder.createChildren.
Once you've done that, you've got a tree of Styleable objects.
/**
* This class is responsible for flowing inline content into lines. Block
* content which participates in an inline formatting context is also handled
* here as well as floating and absolutely positioned content.
*/
public class InlineBoxing
p is a BlockBox; everything else (inc div and h1) isInline
hmmm .. lots of p's are inline
These initial p's are inline, and in correct order (ie appearing after body tag),
if their css is changed so that they aren't
position: absolute;
some <code>Styleable</code> objects may not
* define an element at all (e.g. anonymous inline boxes) and some
* <code>Styleable</code> objects don't correspond to a real element
* (e.g. <code>:before</code> and <code>:after</code> pseudo-elements))
ie a Styleable is created for end of p, body, div, a etc
InlineBox etc implement Styleable
That breaks paragraphs into lines, which is not what we want! :-(
SO, minor change to InlineBoxing to create just a single line!
-------
I want to use StyleReference.getCascadedPropertiesMap, since that
returns a Map keyed by CSS property names (e.g. 'border-width'), and the
assigned value as a SAC CSSValue instance
OK.
But we need to make sure element is assigned for InlineBox. .. often it isn't
-------
DocxRenderer.writePDF processes page by page (root BlockBox .getLayer().getPages()
paintPage(c, currentPage);
-> _root.getLayer().paint(c);
does a whole lot of stuff, including:
paintBackgroundsAndBorders(c, blocks, collapsedTableBorders, rangeLists);
handles tables as well...
paintFloats(c);
paintListMarkers(c, blocks, rangeLists);
paintInlineContent(c, lines, rangeLists);
paintReplacedElements(c, blocks, rangeLists);
paintInlineContent ..
for (int i = 0; i < lines.size(); i++) {
helper.popClipRegions(c, i);
helper.pushClipRegion(c, i);
InlinePaintable paintable = (InlinePaintable)lines.get(i);
paintable.paintInline(c);
}
/**
* An interface which indicates that a box is able to paint itself in an
* inline context. This includes lines and layed out inline content, but also
* block content which participates in an inline formatting context.
*/
public interface InlinePaintable {
public void paintInline(RenderingContext c);
}
/**
* A {@link Box} which contains the portion of an inline element layed out on a
* single line. It may contain content from several {@link InlineBox} objects
* if the original inline element was interrupted by nested content.
* Unlike other boxes, its children may be either <code>Box</code> objects
* (for example, a box with <code>display: inline-block</code>) or
* <code>InlineText</code> objects. For this reason, it's children are not
* stored in the <code>children</code> property, but instead stored in the
* <code>inlineChildren</code> property.
*/
public class InlineLayoutBox extends Box implements InlinePaintable {
/**
* A block box as defined in the CSS spec. It also provides a base class for
* other kinds of block content (for example table rows or cells).
*/
public class BlockBox extends Box implements InlinePaintable {
/**
* A line box contains a single line of text (or other inline content). It
* is created during layout. It also tracks floated and absolute content
* added while laying out the line.
*/
public class LineBox extends Box implements InlinePaintable {
In practice, it is InlineLayoutBox
public void paintInline(RenderingContext c) {
:
for (int i = 0; i < getInlineChildCount(); i++) {
Object child = getInlineChild(i);
if (child instanceof InlineText) {
((InlineText)child).paint(c);
}
}
and InlineText does:
public void paint(RenderingContext c) {
c.getOutputDevice().drawText(c, this);
}
which calls Docx4jTextRenderer.drawString, which calls the method in outputDevice again.
Box has method ..
public final CalculatedStyle getStyle() {
return _style;
}
org.xhtmlrenderer.css.style.CalculatedStyle
Store current p object in RenderingContext (DocxRenderingContext?)
Can't just ask for the text; consider:
<p><strong>FRANCISCO</strong>
<br />
Bernardo hath my place.
<br />
Give you good night.</p>
Here you get the P text before the contents of the strong :-(
Better just to rewrite InlineBoxing, and dispense with the paint step?
-----------
Fonts.
I don't want a dependency on iText