* @param areaclass the area class of the region to set
* @param port the region viewport to set
*/
- public void setRegion(int areaclass, RegionViewport port) {
+ public void setRegionViewport(int areaclass, RegionViewport port) {
if (areaclass == Region.BEFORE_CODE) {
regionBefore = port;
} else if (areaclass == Region.START_CODE) {
* @param areaclass the region area class
* @return the region viewport or null if none
*/
- public RegionViewport getRegion(int areaclass) {
+ public RegionViewport getRegionViewport(int areaclass) {
if (areaclass == Region.BEFORE_CODE) {
return regionBefore;
} else if (areaclass == Region.START_CODE) {
import org.apache.fop.area.BeforeFloat;
import org.apache.fop.area.Footnote;
import org.apache.fop.area.Resolveable;
+import org.apache.fop.area.Trait;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.fo.properties.RetrieveBoundary;
import org.apache.fop.fo.pagination.SimplePageMaster;
import org.apache.fop.fo.pagination.StaticContent;
-
import org.apache.fop.fo.properties.CommonBackground;
import org.apache.fop.fo.properties.CommonBorderAndPadding;
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.fo.properties.Constants;
import org.apache.fop.fo.properties.Overflow;
+import org.apache.fop.traits.BorderProps;
import java.util.ArrayList;
import java.util.List;
}
curPage.setPageNumber(getCurrentPageNumber());
- RegionViewport reg = curPage.getPage().getRegion(
+ RegionViewport rv = curPage.getPage().getRegionViewport(
Region.BODY_CODE);
- curBody = (BodyRegion) reg.getRegion();
- flowBPD = (int)reg.getViewArea().getHeight();
+ curBody = (BodyRegion) rv.getRegion();
+ flowBPD = (int) rv.getViewArea().getHeight();
+
+ // adjust flowBPD for borders and padding
+ BorderProps bps = (BorderProps) rv.getTrait(Trait.BORDER_BEFORE);
+ if (bps != null) {
+ flowBPD -= bps.width;
+ }
+
+ bps = (BorderProps) rv.getTrait(Trait.BORDER_AFTER);
+ if (bps != null) {
+ flowBPD -= bps.width;
+ }
+
+ java.lang.Integer padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_BEFORE);
+ if (padWidth != null) {
+ flowBPD -= padWidth.intValue();
+ }
+
+ padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_AFTER);
+ if (padWidth != null) {
+ flowBPD -= padWidth.intValue();
+ }
+
return curPage;
}
if (flow == null) {
return;
}
- RegionViewport reg = curPage.getPage().getRegion(regionClass);
+ RegionViewport reg = curPage.getPage().getRegionViewport(regionClass);
reg.getRegion().setIPD((int)reg.getViewArea().getWidth());
if (reg == null) {
getLogger().error("no region viewport: shouldn't happen");
//else newpos = new MinOptMax();
curSpan = new Span(numCols);
// get Width or Height as IPD for span
- curSpan.setIPD((int) curPage.getPage().getRegion(
- Region.BODY_CODE).getViewArea().getWidth());
+
+ RegionViewport rv = curPage.getPage().getRegionViewport(Region.BODY_CODE);
+ int ipdWidth = (int) rv.getViewArea().getWidth();
+
+ // adjust IPD for borders and padding
+ BorderProps bps = (BorderProps) rv.getTrait(Trait.BORDER_START);
+ if (bps != null) {
+ ipdWidth -= bps.width;
+ }
+
+ bps = (BorderProps) rv.getTrait(Trait.BORDER_END);
+ if (bps != null) {
+ ipdWidth -= bps.width;
+ }
+ java.lang.Integer padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_START);
+ if (padWidth != null) {
+ ipdWidth -= padWidth.intValue();
+ }
+
+ padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_END);
+ if (padWidth != null) {
+ ipdWidth -= padWidth.intValue();
+ }
+
+ curSpan.setIPD(ipdWidth);
//curSpan.setPosition(BPD, newpos);
curBody.getMainReference().addSpan(curSpan);
createFlow();
} else {
rvp.setRegion(makeRegionReferenceArea(r, rvp.getViewArea()));
}
- page.setRegion(r.getRegionClassCode(), rvp);
+ page.setRegionViewport(r.getRegionClassCode(), rvp);
if (r.getRegionClassCode() == Region.BODY_CODE) {
bHasBody = true;
}
/** Start index of first character in this parent Area */
private short iAreaStart = 0;
- /** Start index of next "word" */
+ /** Start index of next TextArea */
private short iNextStart = 0;
/** Size since last makeArea call, except for last break */
private MinOptMax ipdTotal;
public boolean canBreakBefore(LayoutContext context) {
char c = chars[iNextStart];
return ((c == NEWLINE)
- || (textInfo.bWrap && (CharUtilities.isSpace(c)
+ || (textInfo.bWrap && (CharUtilities.isBreakableSpace(c)
|| BREAK_CHARS.indexOf(c) >= 0)));
}
}
- /* Start of this "word", plus any non-suppressed leading space.
+ /* Start of this TextArea, plus any non-suppressed leading space.
* Collapse any remaining word-space with leading space from
* ancestor FOs.
- * Add up other leading space which is counted in the word IPD.
+ * Add up other leading space which is counted in the TextArea IPD.
*/
SpaceSpecifier pendingSpace = new SpaceSpecifier(false);
char c = chars[iNextStart];
if ((c == NEWLINE) || // Include any breakable white-space as break char
// even if fixed width
- (textInfo.bWrap && (CharUtilities.isSpace(c)
+ (textInfo.bWrap && (CharUtilities.isBreakableSpace(c)
|| BREAK_CHARS.indexOf(c) >= 0))) {
iFlags |= BreakPoss.CAN_BREAK_AFTER;
if (c != SPACE) {
/**
* Generate and add areas to parent area.
- * This can either generate an area for each "word" and each space, or
+ * This can either generate an area for each TextArea and each space, or
* an area containing all text with a parameter controlling the size of
* the word space. The latter is most efficient for PDF generation.
* Set size of each area.
*/
public void addAreas(PositionIterator posIter, LayoutContext context) {
// Add word areas
- AreaInfo ai = null ;
+ AreaInfo ai = null;
int iStart = -1;
int iWScount = 0;
iAdjust = (int)((double)(ai.ipdArea.opt
- ai.ipdArea.min) * dSpaceAdjust);
}
- // System.err.println("Text adjustment factor = " + dSpaceAdjust +
- // " total=" + iAdjust);
+// System.err.println("\nText adjustment factor = " + dSpaceAdjust +
+// " total=" + iAdjust + "; breakIndex = " + ai.iBreakIndex);
// Make an area containing all characters between start and end.
InlineArea word = null;
int adjust = 0;
- // ingnore newline character
+
+ // ignore newline character
if (chars[ai.iBreakIndex - 1] == NEWLINE) {
adjust = 1;
}
String str = new String(chars, iStart, ai.iBreakIndex - iStart - adjust);
+
if (" ".equals(str)) {
word = new Space();
word.setWidth(ai.ipdArea.opt + iAdjust);
} else {
- TextArea t = createText(
- str,
- ai.ipdArea.opt + iAdjust, context.getBaseline());
+ TextArea t = createTextArea(str, ai.ipdArea.opt + iAdjust,
+ context.getBaseline());
if (iWScount > 0) {
//getLogger().error("Adjustment per word-space= " +
// iAdjust / iWScount);
/**
* Create an inline word area.
- * This creates a Word and sets up the various attributes.
+ * This creates a TextArea and sets up the various attributes.
*
- * @param str the string for the word
- * @param width the width that the word uses
+ * @param str the string for the TextArea
+ * @param width the width that the TextArea uses
* @param base the baseline position
* @return the new word area
*/
- protected TextArea createText(String str, int width, int base) {
- TextArea curWordArea = new TextArea();
- curWordArea.setWidth(width);
- curWordArea.setHeight(textInfo.fs.getAscender()
+ protected TextArea createTextArea(String str, int width, int base) {
+ TextArea textArea = new TextArea();
+ textArea.setWidth(width);
+ textArea.setHeight(textInfo.fs.getAscender()
- textInfo.fs.getDescender());
- curWordArea.setOffset(textInfo.fs.getAscender());
- curWordArea.setOffset(base);
+ textArea.setOffset(textInfo.fs.getAscender());
+ textArea.setOffset(base);
- curWordArea.setTextArea(str);
- curWordArea.addTrait(Trait.FONT_NAME, textInfo.fs.getFontName());
- curWordArea.addTrait(Trait.FONT_SIZE,
+ textArea.setTextArea(str);
+ textArea.addTrait(Trait.FONT_NAME, textInfo.fs.getFontName());
+ textArea.addTrait(Trait.FONT_SIZE,
new Integer(textInfo.fs.getFontSize()));
- curWordArea.addTrait(Trait.COLOR, this.textInfo.color);
- return curWordArea;
+ textArea.addTrait(Trait.COLOR, this.textInfo.color);
+ return textArea;
}
}
decision is to have fo:region-body on top, hence it is rendered
last here. */
RegionViewport viewport;
- viewport = page.getRegion(Region.BEFORE_CODE);
+ viewport = page.getRegionViewport(Region.BEFORE_CODE);
renderRegionViewport(viewport);
- viewport = page.getRegion(Region.START_CODE);
+ viewport = page.getRegionViewport(Region.START_CODE);
renderRegionViewport(viewport);
- viewport = page.getRegion(Region.END_CODE);
+ viewport = page.getRegionViewport(Region.END_CODE);
renderRegionViewport(viewport);
- viewport = page.getRegion(Region.AFTER_CODE);
+ viewport = page.getRegionViewport(Region.AFTER_CODE);
renderRegionViewport(viewport);
- viewport = page.getRegion(Region.BODY_CODE);
+ viewport = page.getRegionViewport(Region.BODY_CODE);
renderRegionViewport(viewport);
}
// where previous line area failed to take up entire allocated space
int rx = currentBlockIPPosition + IPMarginOffset;
int bl = currentBPPosition + BPMarginOffset + text.getOffset();
-
-/* System.out.println("BlockIP Position: " + currentBlockIPPosition +
+/*
+ System.out.println("\nBlockIP Position: " + currentBlockIPPosition +
"; currentBPPosition: " + currentBPPosition +
"; offset: " + text.getOffset() +
- "; Text = " + text.getTextArea()); */
-
+ "; Text = " + text.getTextArea());
+*/
// Set letterSpacing
//float ls = fs.getLetterSpacing() / this.currentFontSize;
//pdf.append(ls).append(" Tc\n");
Node obj = childs.item(i);
if (obj.getNodeName().equals("regionBefore")) {
reg.setRegion(readRegion((Element) obj, Region.BEFORE_CODE));
- page.setRegion(Region.BEFORE_CODE, reg);
+ page.setRegionViewport(Region.BEFORE_CODE, reg);
} else if (obj.getNodeName().equals("regionStart")) {
reg.setRegion(readRegion((Element) obj, Region.START_CODE));
- page.setRegion(Region.START_CODE, reg);
+ page.setRegionViewport(Region.START_CODE, reg);
} else if (obj.getNodeName().equals("regionBody")) {
reg.setRegion(readRegion((Element) obj, Region.BODY_CODE));
- page.setRegion(Region.BODY_CODE, reg);
+ page.setRegionViewport(Region.BODY_CODE, reg);
} else if (obj.getNodeName().equals("regionEnd")) {
reg.setRegion(readRegion((Element) obj, Region.END_CODE));
- page.setRegion(Region.END_CODE, reg);
+ page.setRegionViewport(Region.END_CODE, reg);
} else if (obj.getNodeName().equals("regionAfter")) {
reg.setRegion(readRegion((Element) obj, Region.AFTER_CODE));
- page.setRegion(Region.AFTER_CODE, reg);
+ page.setRegionViewport(Region.AFTER_CODE, reg);
}
}
max -= op.min;
}
+ public String toString() {
+ return "MinOptMax: min=" + min + "; opt=" + opt + "; max=" + max;
+ }
}
/**
* Helper method to determine if the character is a
- * space with normal behaviour. Normal behaviour means that
+ * space with normal behavior. Normal behavior means that
* it's not non-breaking.
* @param c character to inspect
* @return True if the character is a normal space
*/
- public static boolean isSpace(char c) {
+ public static boolean isBreakableSpace(char c) {
return (c == ' '
|| (c >= '\u2000' && c <= '\u200B'));
// c == '\u2000' // en quad
* @param c character to check
* @return True if the character is a nbsp
*/
- public static boolean isNBSP(char c) {
+ public static boolean isNonBreakableSpace(char c) {
return
(c == '\u00A0' // no-break space
|| c == '\u202F' // narrow no-break space
* @return True if the character represents any kind of space
*/
public static boolean isAnySpace(char c) {
- boolean ret = (isSpace(c) || isNBSP(c));
+ boolean ret = (isBreakableSpace(c) || isNonBreakableSpace(c));
return ret;
}
}