aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
blob: 6b98673ff1a8cc3f4438a7f7bea453e98a1ce063 (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
/*
 * Copyright 1999-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id$ */


package org.apache.fop.layoutmgr;

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;


import org.apache.fop.area.LinkResolver;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.FilledArea;
import org.apache.fop.area.inline.ForeignObject;
import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.InlineParent;
import org.apache.fop.area.inline.Space;
import org.apache.fop.area.inline.UnresolvedPageNumber;
import org.apache.fop.area.inline.Viewport;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.datatypes.Length;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FOText;
import org.apache.fop.fo.FOTreeVisitor;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FObjMixed;
import org.apache.fop.fo.TextInfo;
import org.apache.fop.fo.ToBeImplementedElement;
import org.apache.fop.fo.Unknown;
import org.apache.fop.fo.UnknownXMLObj;
import org.apache.fop.fo.XMLElement;
import org.apache.fop.fo.XMLObj;
import org.apache.fop.fo.extensions.Bookmarks;
import org.apache.fop.fo.extensions.ExtensionObj;
import org.apache.fop.fo.extensions.Label;
import org.apache.fop.fo.extensions.Outline;
import org.apache.fop.fo.extensions.svg.SVGElement;
import org.apache.fop.fo.extensions.svg.SVGObj;
import org.apache.fop.fo.flow.BasicLink;
import org.apache.fop.fo.flow.BidiOverride;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.BlockContainer;
import org.apache.fop.fo.flow.Character;
import org.apache.fop.fo.flow.ExternalGraphic;
import org.apache.fop.fo.flow.Float;
import org.apache.fop.fo.flow.Footnote;
import org.apache.fop.fo.flow.FootnoteBody;
import org.apache.fop.fo.flow.InitialPropertySet;
import org.apache.fop.fo.flow.Inline;
import org.apache.fop.fo.flow.InlineContainer;
import org.apache.fop.fo.flow.InstreamForeignObject;
import org.apache.fop.fo.flow.Leader;
import org.apache.fop.fo.flow.ListBlock;
import org.apache.fop.fo.flow.ListItem;
import org.apache.fop.fo.flow.ListItemBody;
import org.apache.fop.fo.flow.ListItemLabel;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.flow.MultiCase;
import org.apache.fop.fo.flow.MultiProperties;
import org.apache.fop.fo.flow.MultiPropertySet;
import org.apache.fop.fo.flow.MultiSwitch;
import org.apache.fop.fo.flow.MultiToggle;
import org.apache.fop.fo.flow.PageNumber;
import org.apache.fop.fo.flow.PageNumberCitation;
import org.apache.fop.fo.flow.RetrieveMarker;
import org.apache.fop.fo.flow.Table;
import org.apache.fop.fo.flow.TableAndCaption;
import org.apache.fop.fo.flow.TableBody;
import org.apache.fop.fo.flow.TableCaption;
import org.apache.fop.fo.flow.TableCell;
import org.apache.fop.fo.flow.TableColumn;
import org.apache.fop.fo.flow.TableFooter;
import org.apache.fop.fo.flow.TableHeader;
import org.apache.fop.fo.flow.TableRow;
import org.apache.fop.fo.flow.Wrapper;
import org.apache.fop.fo.pagination.ColorProfile;
import org.apache.fop.fo.pagination.ConditionalPageMasterReference;
import org.apache.fop.fo.pagination.Declarations;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.LayoutMasterSet;
import org.apache.fop.fo.pagination.PageMasterReference;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.PageSequenceMaster;
import org.apache.fop.fo.pagination.Region;
import org.apache.fop.fo.pagination.RegionAfter;
import org.apache.fop.fo.pagination.RegionBA;
import org.apache.fop.fo.pagination.RegionBASE;
import org.apache.fop.fo.pagination.RegionBefore;
import org.apache.fop.fo.pagination.RegionBody;
import org.apache.fop.fo.pagination.RegionEnd;
import org.apache.fop.fo.pagination.RegionSE;
import org.apache.fop.fo.pagination.RegionStart;
import org.apache.fop.fo.pagination.RepeatablePageMasterAlternatives;
import org.apache.fop.fo.pagination.RepeatablePageMasterReference;
import org.apache.fop.fo.pagination.Root;
import org.apache.fop.fo.pagination.SimplePageMaster;
import org.apache.fop.fo.pagination.SinglePageMasterReference;
import org.apache.fop.fo.pagination.StaticContent;
import org.apache.fop.fo.pagination.Title;
import org.apache.fop.fo.properties.CommonBackground;
import org.apache.fop.fo.properties.CommonBorderAndPadding;
import org.apache.fop.layoutmgr.list.Item;
import org.apache.fop.layoutmgr.list.ListBlockLayoutManager;
import org.apache.fop.layoutmgr.list.ListItemLayoutManager;
import org.apache.fop.layoutmgr.table.Body;
import org.apache.fop.layoutmgr.table.Cell;
import org.apache.fop.layoutmgr.table.Column;
import org.apache.fop.layoutmgr.table.Row;
import org.apache.fop.layoutmgr.table.TableLayoutManager;
import org.apache.fop.traits.MinOptMax;

/**
 * Concrete implementation of FOTreeVisitor for the purpose of adding
 * Layout Managers for nodes in the FOTree.
 * Each method is responsible to return a LayoutManager responsible for laying
 * out this FObj's content.
 * @see org.apache.fop.fo.FOTreeVisitor
 */

public class AddLMVisitor implements FOTreeVisitor {

    /** The List object to which methods in this class should add Layout
     *  Managers */
    protected List currentLMList;

    /** A List object which can be used to save and restore the currentLMList if
     * another List should temporarily be used */
    protected List saveLMList;

    /**
     *
     * @param fobj the FObj object for which a layout manager should be created
     * @param lmList the list to which the newly created layout manager(s)
     * should be added
     */
    public void addLayoutManager(FObj fobj, List lmList) {
        /* Store the List in a global variable so that it can be accessed by the
           Visitor methods */
        currentLMList = lmList;
        fobj.acceptVisitor(this);
    }

    /**
     * Accessor for the currentLMList.
     * @return the currentLMList.
     */
    public List getCurrentLMList() {
        return currentLMList;
    }

    /**
     * Accessor for the saveLMList.
     * @return the saveLMList.
     */
    public List getSaveLMList() {
        return saveLMList;
    }

    public void serveFOText(FOText foText) {
        if (foText.endIndex - foText.startIndex > 0) {
            currentLMList.add(new TextLayoutManager(foText));
        }
    }

    public void serveFObjMixed(FObjMixed node) {
        if (node.getChildren() != null) {
            InlineStackingLayoutManager lm;
            lm = new InlineStackingLayoutManager(node);
            lm.setLMiter(new LMiter(lm, node.getChildren()));
            currentLMList.add(lm);
        }
    }

    public void serveBidiOverride(BidiOverride node) {
        if (false) {
            serveFObjMixed((FObjMixed)node);
        } else {
            ArrayList childList = new ArrayList();
            saveLMList = currentLMList;
            currentLMList = childList;
            serveFObjMixed((FObjMixed)node);
            currentLMList = saveLMList;
            for (int count = childList.size() - 1; count >= 0; count--) {
                LayoutManager lm = (LayoutManager) childList.get(count);
                if (lm.generatesInlineAreas()) {
                    LayoutManager blm = new BidiLayoutManager((InlineStackingLayoutManager) lm);
                    blm.setFObj(node);
                    currentLMList.add(blm);
                } else {
                    currentLMList.add(lm);
                }
            }
        }
    }

    /**
     * @param node Inline object to process
     */
    public void serveInline(Inline node) {
        serveFObjMixed((FObjMixed)node);
    }

    public void serveFootnote(Footnote node) {
        if (node.getInlineFO() == null) {
            node.getLogger().error("inline required in footnote");
            return;
        }
        serveInline(node.getInlineFO());
    }

    public void serveInlineContainer(InlineContainer node) {
        ArrayList childList = new ArrayList();
        saveLMList = currentLMList;
        currentLMList = childList;
        serveFObj((FObj)node);
        currentLMList = saveLMList;
        LayoutManager lm = new ICLayoutManager(node, childList);
        currentLMList.add(lm);
    }

    /**
     * Add start and end properties for the link
     */
    public void serveBasicLink(final BasicLink node) {
        node.setup();
        InlineStackingLayoutManager lm;
        lm = new InlineStackingLayoutManager(node) {
            protected InlineParent createArea() {
                InlineParent area = super.createArea();
                setupBasicLinkArea(node, parentLM, area);
                return area;
            }
        };
        lm.setLMiter(new LMiter(lm, node.getChildren()));
        currentLMList.add(lm);
    }

    protected void setupBasicLinkArea(BasicLink node, LayoutManager parentLM,
                                      InlineParent area) {
         if (node.getLink() == null) {
             return;
         }
         if (node.getExternal()) {
             area.addTrait(Trait.EXTERNAL_LINK, node.getLink());
         } else {
             PageViewport page = parentLM.resolveRefID(node.getLink());
             if (page != null) {
                 area.addTrait(Trait.INTERNAL_LINK, page.getKey());
             } else {
                 LinkResolver res = new LinkResolver(node.getLink(), area);
                 parentLM.addUnresolvedArea(node.getLink(), res);
             }
         }
     }

     public void serveBlock(Block node) {
         BlockLayoutManager blm = new BlockLayoutManager(node);
         currentLMList.add(blm);
     }

     public void serveLeader(final Leader node) {
         LeafNodeLayoutManager lm = new LeafNodeLayoutManager(node) {
             public InlineArea get(LayoutContext context) {
                 return getLeaderInlineArea(node, this);
             }

             protected MinOptMax getAllocationIPD(int refIPD) {
                return getLeaderAllocIPD(node, refIPD);
             }

             /*protected void offsetArea(LayoutContext context) {
                 if(leaderPattern == LeaderPattern.DOTS) {
                     curArea.setOffset(context.getBaseline());
                 }
             }*/
         };
         lm.setAlignment(node.getProperty(Constants.PR_LEADER_ALIGNMENT).getEnum());
         currentLMList.add(lm);
     }

     public MinOptMax getLeaderAllocIPD(Leader node, int ipd) {
         // length of the leader
         int opt = node.getLength(Constants.PR_LEADER_LENGTH | Constants.CP_OPTIMUM, ipd);
         int min = node.getLength(Constants.PR_LEADER_LENGTH | Constants.CP_MINIMUM, ipd);
         int max = node.getLength(Constants.PR_LEADER_LENGTH | Constants.CP_MAXIMUM, ipd);

         return new MinOptMax(min, opt, max);
     }

     private InlineArea getLeaderInlineArea(Leader node, LayoutManager parentLM) {
         node.setup();
         InlineArea leaderArea = null;

         if (node.getLeaderPattern() == Constants.LeaderPattern.RULE) {
             org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader();
             leader.setRuleStyle(node.getRuleStyle());
             leader.setRuleThickness(node.getRuleThickness());
             leaderArea = leader;
         } else if (node.getLeaderPattern() == Constants.LeaderPattern.SPACE) {
             leaderArea = new Space();
         } else if (node.getLeaderPattern() == Constants.LeaderPattern.DOTS) {
             TextArea t = new TextArea();
             char dot = '.'; // userAgent.getLeaderDotCharacter();

             t.setTextArea("" + dot);
             t.addTrait(Trait.FONT_NAME, node.getFontState().getFontName());
             t.addTrait(Trait.FONT_SIZE,
                              new Integer(node.getFontState().getFontSize()));
             // set offset of dot within inline parent
             t.setOffset(node.getFontState().getAscender());
             int width = node.getFontState().getCharWidth(dot);
             Space spacer = null;
             if (node.getPatternWidth() > width) {
                 spacer = new Space();
                 spacer.setWidth(node.getPatternWidth() - width);
                 width = node.getPatternWidth();
             }
             FilledArea fa = new FilledArea();
             fa.setUnitWidth(width);
             fa.addChild(t);
             if (spacer != null) {
                 fa.addChild(spacer);
             }
             fa.setHeight(node.getFontState().getAscender());

             leaderArea = fa;
         } else if (node.getLeaderPattern() == Constants.LeaderPattern.USECONTENT) {
             if (node.getChildren() == null) {
                 node.getLogger().error("Leader use-content with no content");
                 return null;
             }
             InlineStackingLayoutManager lm;
             lm = new InlineStackingLayoutManager(node);
             lm.setLMiter(new LMiter(lm, node.getChildren()));
             lm.initialize();

             // get breaks then add areas to FilledArea
             FilledArea fa = new FilledArea();

             ContentLayoutManager clm = new ContentLayoutManager(fa);
             clm.setParent(parentLM);
             clm.setUserAgent(node.getUserAgent());
             lm.setParent(clm);

             clm.fillArea(lm);
             int width = clm.getStackingSize();
             Space spacer = null;
             if (node.getPatternWidth() > width) {
                 spacer = new Space();
                 spacer.setWidth(node.getPatternWidth() - width);
                 width = node.getPatternWidth();
             }
             fa.setUnitWidth(width);
             if (spacer != null) {
                 fa.addChild(spacer);
             }
             leaderArea = fa;
         }
         return leaderArea;
     }

     public void serveRetrieveMarker(RetrieveMarker node) {
         RetrieveMarkerLayoutManager rmlm;
         rmlm = new RetrieveMarkerLayoutManager(node);
         currentLMList.add(rmlm);
     }

     public void serveCharacter(Character node) {
         InlineArea inline = getCharacterInlineArea(node);
         if (inline != null) {
             LeafNodeLayoutManager lm = new LeafNodeLayoutManager(node);
             lm.setCurrentArea(inline);
             currentLMList.add(lm);
         }
     }

     public InlineArea getCharacterInlineArea(Character node) {
         String str = node.getProperty(Constants.PR_CHARACTER).getString();
         if (str.length() == 1) {
             org.apache.fop.area.inline.Character ch =
               new org.apache.fop.area.inline.Character(
                 str.charAt(0));
             return ch;
         }
         return null;
     }

     /**
      * This adds a leafnode layout manager that deals with the
      * created viewport/image area.
      */
     public void serveExternalGraphic(ExternalGraphic node) {
         InlineArea area = getExternalGraphicInlineArea(node);
         if (area != null) {
             node.setupID();
             LeafNodeLayoutManager lm = new LeafNodeLayoutManager(node);
             lm.setCurrentArea(area);
             lm.setAlignment(node.getProperty(Constants.PR_VERTICAL_ALIGN).getEnum());
             lm.setLead(node.getViewHeight());
             currentLMList.add(lm);
         }
     }

     /**
      * Get the inline area for this external grpahic.
      * This creates the image area and puts it inside a viewport.
      *
      * @return the viewport containing the image area
      */
     public InlineArea getExternalGraphicInlineArea(ExternalGraphic node) {
         node.setup();
         if (node.getURL() == null) {
             return null;
         }
         Image imArea = new Image(node.getURL());
         Viewport vp = new Viewport(imArea);
         vp.setWidth(node.getViewWidth());
         vp.setHeight(node.getViewHeight());
         vp.setClip(node.getClip());
         vp.setContentPosition(node.getPlacement());
         vp.setOffset(0);

         // Common Border, Padding, and Background Properties
         CommonBorderAndPadding bap = node.getPropertyManager().getBorderAndPadding();
         CommonBackground bProps = node.getPropertyManager().getBackgroundProps();
         TraitSetter.addBorders(vp, bap);
         TraitSetter.addBackground(vp, bProps);

         return vp;
     }

     public void serveBlockContainer(BlockContainer node) {
         BlockContainerLayoutManager blm = new BlockContainerLayoutManager(node);
         blm.setOverflow(node.getProperty(Constants.PR_OVERFLOW).getEnum());
         currentLMList.add(blm);
     }

     public void serveListBlock(ListBlock node) {
         ListBlockLayoutManager blm = new ListBlockLayoutManager(node);
         currentLMList.add(blm);
     }

     public void serveInstreamForeignObject(InstreamForeignObject node) {
         Viewport areaCurrent = getInstreamForeignObjectInlineArea(node);
         if (areaCurrent != null) {
             LeafNodeLayoutManager lm = new LeafNodeLayoutManager(node);
             lm.setCurrentArea(areaCurrent);
             lm.setAlignment(node.getProperty(Constants.PR_VERTICAL_ALIGN).getEnum());
             lm.setLead(areaCurrent.getHeight());
             currentLMList.add(lm);
         }
     }

     /**
      * Get the inline area created by this element.
      *
      * @return the viewport inline area
      */
     public Viewport getInstreamForeignObjectInlineArea(InstreamForeignObject node) {
         if (node.getChildren() == null) {
             return null;
         }

         if (node.children.size() != 1) {
             // error
             return null;
         }
         FONode fo = (FONode)node.children.get(0);
         if (!(fo instanceof XMLObj)) {
             // error
             return null;
         }
         XMLObj child = (XMLObj)fo;

         // viewport size is determined by block-progression-dimension
         // and inline-progression-dimension

         // if replaced then use height then ignore block-progression-dimension
         //int h = this.propertyList.get("height").getLength().mvalue();

         // use specified line-height then ignore dimension in height direction
         boolean hasLH = false;//propertyList.get("line-height").getSpecifiedValue() != null;

         Length len;

         int bpd = -1;
         int ipd = -1;
         boolean bpdauto = false;
         if (hasLH) {
             bpd = node.getProperty(Constants.PR_LINE_HEIGHT).getLength().getValue();
         } else {
             // this property does not apply when the line-height applies
             // isn't the block-progression-dimension always in the same
             // direction as the line height?
             len = node.getProperty(Constants.PR_BLOCK_PROGRESSION_DIMENSION | Constants.CP_OPTIMUM).getLength();
             if (!len.isAuto()) {
                 bpd = len.getValue();
             } else {
                 len = node.getProperty(Constants.PR_HEIGHT).getLength();
                 if (!len.isAuto()) {
                     bpd = len.getValue();
                 }
             }
         }

         len = node.getProperty(Constants.PR_INLINE_PROGRESSION_DIMENSION | Constants.CP_OPTIMUM).getLength();
         if (!len.isAuto()) {
             ipd = len.getValue();
         } else {
             len = node.getProperty(Constants.PR_WIDTH).getLength();
             if (!len.isAuto()) {
                 ipd = len.getValue();
             }
         }

         // if auto then use the intrinsic size of the content scaled
         // to the content-height and content-width
         int cwidth = -1;
         int cheight = -1;
         len = node.getProperty(Constants.PR_CONTENT_WIDTH).getLength();
         if (!len.isAuto()) {
             /*if(len.scaleToFit()) {
                 if(ipd != -1) {
                     cwidth = ipd;
                 }
             } else {*/
             cwidth = len.getValue();
         }
         len = node.getProperty(Constants.PR_CONTENT_HEIGHT).getLength();
         if (!len.isAuto()) {
             /*if(len.scaleToFit()) {
                 if(bpd != -1) {
                     cwidth = bpd;
                 }
             } else {*/
             cheight = len.getValue();
         }

         Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f,
                                           cheight == -1 ? -1 : cheight / 1000f);
         Point2D size = child.getDimension(csize);
         if (size == null) {
             // error
             return null;
         }
         if (cwidth == -1) {
             cwidth = (int)size.getX() * 1000;
         }
         if (cheight == -1) {
             cheight = (int)size.getY() * 1000;
         }
         int scaling = node.getProperty(Constants.PR_SCALING).getEnum();
         if (scaling == Constants.Scaling.UNIFORM) {
             // adjust the larger
             double rat1 = cwidth / (size.getX() * 1000f);
             double rat2 = cheight / (size.getY() * 1000f);
             if (rat1 < rat2) {
                 // reduce cheight
                 cheight = (int)(rat1 * size.getY() * 1000);
             } else {
                 cwidth = (int)(rat2 * size.getX() * 1000);
             }
         }

         if (ipd == -1) {
             ipd = cwidth;
         }
         if (bpd == -1) {
             bpd = cheight;
         }

         boolean clip = false;
         if (cwidth > ipd || cheight > bpd) {
             int overflow = node.getProperty(Constants.PR_OVERFLOW).getEnum();
             if (overflow == Constants.Overflow.HIDDEN) {
                 clip = true;
             } else if (overflow == Constants.Overflow.ERROR_IF_OVERFLOW) {
                 node.getLogger().error("Instream foreign object overflows the viewport: clipping");
                 clip = true;
             }
         }

         int xoffset = node.computeXOffset(ipd, cwidth);
         int yoffset = node.computeYOffset(bpd, cheight);

         Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight);

         org.w3c.dom.Document doc = child.getDOMDocument();
         String ns = child.getDocumentNamespace();

         node.children = null;
         ForeignObject foreign = new ForeignObject(doc, ns);

         Viewport areaCurrent = new Viewport(foreign);
         areaCurrent.setWidth(ipd);
         areaCurrent.setHeight(bpd);
         areaCurrent.setContentPosition(placement);
         areaCurrent.setClip(clip);
         areaCurrent.setOffset(0);

         return areaCurrent;
     }

     public void serveListItem(ListItem node) {
         if (node.getLabel() != null && node.getBody() != null) {
             ListItemLayoutManager blm = new ListItemLayoutManager(node);
             blm.setLabel(getListItemLabelLayoutManager(node.getLabel()));
             blm.setBody(getListItemBodyLayoutManager(node.getBody()));
             currentLMList.add(blm);
         } else {
             node.getLogger().error("list-item requires list-item-label and list-item-body");
         }
     }

     /**
      * @return this object's Item layout manager
      */
     public Item getListItemLabelLayoutManager(ListItemLabel node) {
         Item itemLabel = new Item(node);
         return itemLabel;
     }

     /**
      * @return Item layout manager
      */
     public Item getListItemBodyLayoutManager(ListItemBody node) {
         Item item = new Item(node);
         return item;
     }

     /**
      * Overridden from FObj
      * @param lms the list to which the layout manager(s) should be added
      */
     public void servePageNumber(final PageNumber node) {
         node.setup();
         LayoutManager lm;
         lm = new LeafNodeLayoutManager(node) {
                     public InlineArea get(LayoutContext context) {
                         // get page string from parent, build area
                         TextArea inline = new TextArea();
                         String str = parentLM.getCurrentPageNumber();
                         int width = 0;
                     for (int count = 0; count < str.length(); count++) {
                             width += node.getFontState().getCharWidth(
                                        str.charAt(count));
                         }
                         inline.setTextArea(str);
                         inline.setIPD(width);
                         inline.setHeight(node.getFontState().getAscender()
                                          - node.getFontState().getDescender());
                         inline.setOffset(node.getFontState().getAscender());

                         inline.addTrait(Trait.FONT_NAME,
                                         node.getFontState().getFontName());
                         inline.addTrait(Trait.FONT_SIZE,
                                         new Integer(node.getFontState().getFontSize()));

                         return inline;
                     }

                     protected void offsetArea(LayoutContext context) {
                         curArea.setOffset(context.getBaseline());
                     }
                 };
         currentLMList.add(lm);
     }

     public void servePageNumberCitation(final PageNumberCitation node) {
         node.setup();
         LayoutManager lm;
         lm = new LeafNodeLayoutManager(node) {
                     public InlineArea get(LayoutContext context) {
                         curArea = getPageNumberCitationInlineArea(node, parentLM);
                         return curArea;
                     }

                     public void addAreas(PositionIterator posIter,
                                          LayoutContext context) {
                         super.addAreas(posIter, context);
                         if (node.getUnresolved()) {
                             parentLM.addUnresolvedArea(node.getRefId(),
                                                        (Resolveable) curArea);
                         }
                     }

                     protected void offsetArea(LayoutContext context) {
                         curArea.setOffset(context.getBaseline());
                     }
                 };
         currentLMList.add(lm);
     }

     // if id can be resolved then simply return a word, otherwise
     // return a resolveable area
     public InlineArea getPageNumberCitationInlineArea(PageNumberCitation node,
             LayoutManager parentLM) {
         if (node.getRefId().equals("")) {
             node.getLogger().error("page-number-citation must contain \"ref-id\"");
             return null;
         }
         PageViewport page = parentLM.resolveRefID(node.getRefId());
         InlineArea inline = null;
         if (page != null) {
             String str = page.getPageNumber();
             // get page string from parent, build area
             TextArea text = new TextArea();
             inline = text;
             int width = node.getStringWidth(str);
             text.setTextArea(str);
             inline.setIPD(width);
             inline.setHeight(node.getFontState().getAscender()
                              - node.getFontState().getDescender());
             inline.setOffset(node.getFontState().getAscender());

             inline.addTrait(Trait.FONT_NAME, node.getFontState().getFontName());
             inline.addTrait(Trait.FONT_SIZE,
                             new Integer(node.getFontState().getFontSize()));
             node.setUnresolved(false);
         } else {
             node.setUnresolved(true);
             inline = new UnresolvedPageNumber(node.getRefId());
             String str = "MMM"; // reserve three spaces for page number
             int width = node.getStringWidth(str);
             inline.setIPD(width);
             inline.setHeight(node.getFontState().getAscender()
                              - node.getFontState().getDescender());
             inline.setOffset(node.getFontState().getAscender());

             inline.addTrait(Trait.FONT_NAME, node.getFontState().getFontName());
             inline.addTrait(Trait.FONT_SIZE,
                             new Integer(node.getFontState().getFontSize()));
         }
         return inline;
     }

     public void serveTable(Table node) {
         TableLayoutManager tlm = new TableLayoutManager(node);
         ArrayList columns = node.getColumns();
         if (columns != null) {
             ArrayList columnLMs = new ArrayList();
             ListIterator iter = columns.listIterator();
             while (iter.hasNext()) {
                 columnLMs.add(getTableColumnLayoutManager((TableColumn)iter.next()));
             }
             tlm.setColumns(columnLMs);
         }
         if (node.getTableHeader() != null) {
             tlm.setTableHeader(getTableBodyLayoutManager(node.getTableHeader()));
         }
         if (node.getTableFooter() != null) {
             tlm.setTableFooter(getTableBodyLayoutManager(node.getTableFooter()));
         }
         currentLMList.add(tlm);
     }

     public LayoutManager getTableColumnLayoutManager(TableColumn node) {
         node.initialize();
         Column clm = new Column(node);
         return clm;
     }

     public void serveTableBody(TableBody node) {
         currentLMList.add(getTableBodyLayoutManager(node));
     }

     public Body getTableBodyLayoutManager(TableBody node) {
         Body blm = new Body(node);
         return blm;
     }

     public void serveTableCell(TableCell node) {
         Cell clm = new Cell(node);
         currentLMList.add(clm);
     }

     public void serveTableRow(TableRow node) {
         Row rlm = new Row(node);
         currentLMList.add(rlm);
     }

     public void serveFlow(Flow node) {
         FlowLayoutManager lm = new FlowLayoutManager(node);
         currentLMList.add(lm);
     }

    /**
     * @param node FONode object to process
     */
    public void serveFONode(FONode node) {
    }

    /**
     * @param node FObj object to process
     */
    public void serveFObj(FObj node) {
        serveFONode((FONode)node);
    }

    /**
     * @param node ColorProfile object to process
     */
    public void serveColorProfile(ColorProfile node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node ConditionalPageMasterReference object to process
     */
    public void serveConditionalPageMasterReference(ConditionalPageMasterReference node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node Declarations object to process
     */
    public void serveDeclarations(Declarations node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node ExtensionObj object to process
     */
    public void serveExtensionObj(ExtensionObj node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node Bookmarks object to process
     */
    public void serveBookmarks(Bookmarks node) {
        serveExtensionObj((ExtensionObj)node);
    }

    /**
     * @param node Label object to process
     */
    public void serveLabel(Label node) {
        serveExtensionObj((ExtensionObj)node);
    }

    /**
     * @param node Outline object to process
     */
    public void serveOutline(Outline node) {
        serveExtensionObj((ExtensionObj)node);
    }

    /**
     * @param node StaticContent object to process
     */
    public void serveStaticContent(StaticContent node) {
        serveFlow((Flow)node);
    }

    /**
     * @param node Marker object to process
     */
    public void serveMarker(Marker node) {
        serveFObjMixed((FObjMixed)node);
    }

    /**
     * @param node Title object to process
     */
    public void serveTitle(Title node) {
        serveFObjMixed((FObjMixed)node);
    }

    /**
     * @param node Wrapper object to process
     */
    public void serveWrapper(Wrapper node) {
        ListIterator baseIter;
        baseIter = node.getChildren();
        if (baseIter == null) return;
        while (baseIter.hasNext()) {
            FObj child = (FObj) baseIter.next();
            child.acceptVisitor(this);
        }
    }
    
    /**
     * @param node FootnoteBody object to process
     */
    public void serveFootnoteBody(FootnoteBody node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node LayoutMasterSet object to process
     */
    public void serveLayoutMasterSet(LayoutMasterSet node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node ListItemBody object to process
     */
    public void serveListItemBody(ListItemBody node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node ListItemLabel object to process
     */
    public void serveListItemLabel(ListItemLabel node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node PageMasterReference object to process
     */
    public void servePageMasterReference(PageMasterReference node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node RepeatablePageMasterReference object to process
     */
    public void serveRepeatablePageMasterReference(RepeatablePageMasterReference node) {
        servePageMasterReference((PageMasterReference)node);
    }

    /**
     * @param node SinglePageMasterReference object to process
     */
    public void serveSinglePageMasterReference(SinglePageMasterReference node) {
        servePageMasterReference((PageMasterReference)node);
    }

    /**
     * @param node PageSequence object to process
     */
    public void servePageSequence(PageSequence node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node PageSequenceMaster object to process
     */
    public void servePageSequenceMaster(PageSequenceMaster node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node Region object to process
     */
    public void serveRegion(Region node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node RegionBASE object to process
     */
    public void serveRegionBASE(RegionBASE node) {
        serveRegion((Region)node);
    }

    /**
     * @param node RegionBA object to process
     */
    public void serveRegionBA(RegionBA node) {
        serveRegionBASE((RegionBASE)node);
    }

    /**
     * @param node RegionAfter object to process
     */
    public void serveRegionAfter(RegionAfter node) {
        serveRegionBA((RegionBA)node);
    }

    /**
     * @param node RegionBefore object to process
     */
    public void serveRegionBefore(RegionBefore node) {
        serveRegionBA((RegionBA)node);
    }

    /**
     * @param node RegionSE object to process
     */
    public void serveRegionSE(RegionSE node) {
        serveRegionBASE((RegionBASE)node);
    }

    /**
     * @param node RegionEnd object to process
     */
    public void serveRegionEnd(RegionEnd node) {
        serveRegionSE((RegionSE)node);
    }

    /**
     * @param node RegionStart object to process
     */
    public void serveRegionStart(RegionStart node) {
        serveRegionSE((RegionSE)node);
    }

    /**
     * @param node RegionBody object to process
     */
    public void serveRegionBody(RegionBody node) {
        serveRegion((Region)node);
    }

    /**
     * @param node RepeatablePageMasterAlternatives object to process
     */
    public void serveRepeatablePageMasterAlternatives(RepeatablePageMasterAlternatives node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node Root object to process
     */
    public void serveRoot(Root node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node SimplePageMaster object to process
     */
    public void serveSimplePageMaster(SimplePageMaster node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node TableFooter object to process
     */
    public void serveTableFooter(TableFooter node) {
        serveTableBody((TableBody)node);
    }

    /**
     * @param node TableHeader object to process
     */
    public void serveTableHeader(TableHeader node) {
        serveTableBody((TableBody)node);
    }

    /**
     * @param node TableColumn object to process
     */
    public void serveTableColumn(TableColumn node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node ToBeImplementedElement object to process
     */
    public void serveToBeImplementedElement(ToBeImplementedElement node) {
        serveFObj((FObj)node);
    }

    /**
     * @param node Float object to process
     */
    public void serveFloat(Float node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node InitialPropertySet object to process
     */
    public void serveInitialPropertySet(InitialPropertySet node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node MultiCase object to process
     */
    public void serveMultiCase(MultiCase node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node MultiProperties object to process
     */
    public void serveMultiProperties(MultiProperties node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node MultiPropertySet object to process
     */
    public void serveMultiPropertySet(MultiPropertySet node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node MultiSwitch object to process
     */
    public void serveMultiSwitch(MultiSwitch node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node MultiToggle object to process
     */
    public void serveMultiToggle(MultiToggle node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node TableAndCaption object to process
     */
    public void serveTableAndCaption(TableAndCaption node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node TableCaption object to process
     */
    public void serveTableCaption(TableCaption node) {
        serveToBeImplementedElement((ToBeImplementedElement)node);
    }

    /**
     * @param node Unknown object to process
     */
    public void serveUnknown(Unknown node) {
        serveFONode((FONode)node);
    }

    /**
     * @param node XMLObj object to process
     */
    public void serveXMLObj(XMLObj node) {
        serveFONode((FONode)node);
    }

    /**
     * @param node SVGObj object to process
     */
    public void serveSVGObj(SVGObj node) {
        serveXMLObj((XMLObj)node);
    }

    /**
     * @param node SVGElement object to process
     */
    public void serveSVGElement(SVGElement node) {
        serveSVGObj((SVGObj)node);
    }

    /**
     * @param node UnknownXMLObj object to process
     */
    public void serveUnknownXMLObj(UnknownXMLObj node) {
        serveXMLObj((XMLObj)node);
    }

    /**
     * @param node XMLElement object to process
     */
    public void serveXMLElement(XMLElement node) {
        serveXMLObj((XMLObj)node);
    }

}