Пример #1
0
 private void alignBlockAreas(ReferenceArea r, BlockAlignment alignment) {
   double measure = r.isVertical() ? r.getWidth() : r.getHeight();
   double consumed = 0;
   for (AreaNode c : r.getChildren()) {
     consumed += c.getBPD();
   }
   double available = measure - consumed;
   if (available > 0) {
     if (alignment == BlockAlignment.BEFORE) {
       AreaNode a = new BlockFillerArea(r.getElement(), 0, available);
       r.addChild(a, null);
     } else if (alignment == BlockAlignment.AFTER) {
       AreaNode a = new BlockFillerArea(r.getElement(), 0, available);
       r.insertChild(a, r.firstChild(), null);
     } else if (alignment == BlockAlignment.CENTER) {
       double half = available / 2;
       AreaNode a1 = new BlockFillerArea(r.getElement(), 0, half);
       AreaNode a2 = new BlockFillerArea(r.getElement(), 0, half);
       r.insertChild(a1, r.firstChild(), null);
       r.insertChild(a2, null, null);
     } else {
       // no-op
     }
   } else if (available < 0) {
     r.setOverflow(-available);
   }
 }
Пример #2
0
 private void alignLineAreas(BlockArea b, LayoutState ls) {
   BlockAlignment alignment = ls.getReferenceAlignment();
   ReferenceArea r = ls.getReferenceArea();
   double measure = r.isVertical() ? r.getWidth() : r.getHeight();
   double consumed = 0;
   int numChildren = 0;
   for (AreaNode c : b.getChildren()) {
     consumed += c.getBPD();
     ++numChildren;
   }
   double available = measure - consumed;
   if (available > 0) {
     if (alignment == BlockAlignment.BEFORE) {
       // no-op
     } else if (alignment == BlockAlignment.AFTER) {
       // no-op
     } else if (alignment == BlockAlignment.CENTER) {
       // no-op
     } else {
       justifyLineAreas(b, measure, consumed, numChildren, alignment);
     }
   } else if (available < 0) {
     b.setOverflow(-available);
   }
 }
Пример #3
0
 @Override
 public double getAvailable(Dimension dimension) {
   for (AreaNode p = getParent(); p != null; p = p.getParent()) {
     if (p instanceof ReferenceArea) return p.getAvailable(dimension);
   }
   return super.getAvailable(dimension);
 }
Пример #4
0
 public LineArea getLine() {
   for (AreaNode p = getParent(); p != null; p = p.getParent()) {
     if (p instanceof LineArea) return (LineArea) p;
     else if (p instanceof ReferenceArea) break;
   }
   return new LineArea();
 }
Пример #5
0
 @Override
 public WritingMode getWritingMode() {
   WritingMode wm = super.getWritingMode();
   if (wm != null) {
     return wm;
   } else {
     AreaNode p = getParent();
     if (p != null) return p.getWritingMode();
     else return null;
   }
 }
Пример #6
0
 @Override
 public Whitespace getWhitespace() {
   Whitespace space = super.getWhitespace();
   if (space != null) {
     return space;
   } else {
     AreaNode p = getParent();
     if (p != null) return p.getWhitespace();
     else return null;
   }
 }
Пример #7
0
 @Override
 public String getLanguage() {
   String language = super.getLanguage();
   if (language != null) {
     return language;
   } else {
     AreaNode p = getParent();
     if (p != null) return p.getLanguage();
     else return null;
   }
 }