Skip to content

Commit

Permalink
updated for page numbers rotation in vertical layout from metanorma/x…
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Jan 31, 2025
1 parent a690380 commit 9ef4251
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 17 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/apache/fop/area/inline/ResolvedPageNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.IOException;
import java.io.ObjectInputStream;

import org.apache.fop.fonts.Font;

/**
* Always (pre-) resolved page number area. Needed by BIDI code to distinguish
* from UnresolvedPageNumber.
Expand All @@ -30,8 +32,27 @@ public class ResolvedPageNumber extends TextArea {

private static final long serialVersionUID = -1758369835371647979L;

//Transient fields
transient Font font;

private boolean isVertical;

public ResolvedPageNumber(Font f, boolean v) {
font = f;
isVertical = v;
}

private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
}

@Override
public void addWord(String word, int offset, int level) {
if(isVertical) {
for(int i=0; i<word.length(); i++) {
addWord(word.substring(i, i+1), font.getFontSize(), null, null, null, offset, false, true);
}
} else
super.addWord(word, offset, level);
}
}
24 changes: 17 additions & 7 deletions src/main/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* This is a word area that resolves itself to a page number
* from an id reference.
*/
public class UnresolvedPageNumber extends TextArea implements Resolvable {
public class UnresolvedPageNumber extends ResolvedPageNumber implements Resolvable {


private static final long serialVersionUID = -1758090835371647980L;
Expand All @@ -48,11 +48,8 @@ public class UnresolvedPageNumber extends TextArea implements Resolvable {
/** Indicates that the reference refers to the last area generated by a formatting object. */
public static final boolean LAST = false;

//Transient fields
private transient Font font;

public UnresolvedPageNumber() {
this(null, null, FIRST);
this(null, null, FIRST, false);
}

/**
Expand All @@ -62,7 +59,7 @@ public UnresolvedPageNumber() {
* @param f the font for formatting the page number
*/
public UnresolvedPageNumber(String id, Font f) {
this(id, f, FIRST);
this(id, f, FIRST, false);
}

/**
Expand All @@ -74,8 +71,21 @@ public UnresolvedPageNumber(String id, Font f) {
* a formatting object
*/
public UnresolvedPageNumber(String id, Font f, boolean type) {
this(id, f, FIRST, false);
}

/**
* Create a new unresolved page number.
*
* @param id the id reference for resolving this
* @param f the font for formatting the page number
* @param type indicates whether the reference refers to the first or last area generated by
* a formatting object
* @param vert indicates whether the writing mode is vertical
*/
public UnresolvedPageNumber(String id, Font f, boolean type, boolean v) {
super(f, v);
pageIDRef = id;
font = f;
text = "?";
pageType = type;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/fop/layoutmgr/AbstractBreaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public boolean doLayout(int flowBPD, boolean autoHeight) {
+ " pageBreaks.size()= " + alg.getPageBreaks().size());

//*** Phase 3: Add areas ***
doPhase3(alg, optimalPageCount, blockList, blockList);
doPhase3(alg, optimalPageCount, blockList, blockList, childLC);
}
}
} catch (PagePositionOnlyException e) {
Expand Down Expand Up @@ -519,7 +519,7 @@ protected boolean containsNonRestartableLM(Position position) {
* @param effectiveList effective Knuth element list (after adjustments)
*/
protected abstract void doPhase3(PageBreakingAlgorithm alg, int partCount,
BlockSequence originalList, BlockSequence effectiveList);
BlockSequence originalList, BlockSequence effectiveList, LayoutContext context);

/**
* Phase 3 of Knuth algorithm: Adds the areas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ protected void addAreas(PositionIterator posIter, LayoutContext context) {
}

protected void doPhase3(PageBreakingAlgorithm alg, int partCount,
BlockSequence originalList, BlockSequence effectiveList) {
BlockSequence originalList, BlockSequence effectiveList, LayoutContext context) {
//Defer adding of areas until addAreas is called by the parent LM
this.deferredAlg = alg;
this.deferredOriginalList = originalList;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apache/fop/layoutmgr/LayoutContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ public String toString() {
+ "\nKeeps: \t[keep-with-next=" + getKeepWithNextPending()
+ "][keep-with-previous=" + getKeepWithPreviousPending() + "] pending"
+ "\nBreaks: \tforced [" + (breakBefore != Constants.EN_AUTO ? "break-before" : "") + "]["
+ (breakAfter != Constants.EN_AUTO ? "break-after" : "") + "]";
+ (breakAfter != Constants.EN_AUTO ? "break-after" : "") + "]"
+ "\nWriting Mode: \t" + getWritingMode();
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/apache/fop/layoutmgr/LocalBreaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void addAreas(PositionIterator posIter, LayoutContext context) {
}

protected void doPhase3(PageBreakingAlgorithm alg, int partCount, BlockSequence originalList,
BlockSequence effectiveList) {
BlockSequence effectiveList, LayoutContext context) {
if (partCount > 1) {
PageBreakPosition pos = alg.getPageBreaks().getFirst();
int firstPartLength = ElementListUtils.calcContentLength(effectiveList,
Expand All @@ -148,7 +148,9 @@ protected void doPhase3(PageBreakingAlgorithm alg, int partCount, BlockSequence
// overflow should be visible.
alg.removeAllPageBreaks();
// Directly add areas after finding the breaks
this.addAreas(alg, 1, originalList, effectiveList);
LayoutContext childLC = LayoutContext.newInstance();
childLC.setWritingMode(context.getWritingMode());
this.addAreas(alg, 0, 1, originalList, effectiveList, childLC);
}

protected void finishPart(PageBreakingAlgorithm alg, PageBreakPosition pbp) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/fop/layoutmgr/PageBreaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected void addAreas(PositionIterator posIter, LayoutContext context) {
* or whether to take into account a 'last-page' condition.
*/
protected void doPhase3(PageBreakingAlgorithm alg, int partCount,
BlockSequence originalList, BlockSequence effectiveList) {
BlockSequence originalList, BlockSequence effectiveList, LayoutContext context) {

if (needColumnBalancing) {
//column balancing for the last part
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.apache.fop.layoutmgr.inline;

import java.util.List;

import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.InlineArea;
Expand All @@ -28,6 +30,7 @@
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.traits.MinOptMax;
Expand All @@ -48,6 +51,9 @@ public abstract class AbstractPageNumberCitationLayoutManager extends LeafNodeLa

private String citationString;

/** Indicate whether the writing mode is vertical */
private boolean isVertical;

/**
* Constructor
*
Expand Down Expand Up @@ -120,6 +126,13 @@ protected InlineArea getEffectiveArea(LayoutContext layoutContext) {
return area;
}

/** {@inheritDoc} */
@Override
public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int alignment) {
isVertical = context.getWritingMode().isVertical();
return super.getNextKnuthElements(context, alignment);
}

private InlineArea getPageNumberCitationArea() {
TextArea text;
if (resolved) {
Expand All @@ -129,7 +142,7 @@ private InlineArea getPageNumberCitationArea() {
text.addWord(citationString, getStringWidth(citationString), null, null, null, 0);
} else {
UnresolvedPageNumber unresolved = new UnresolvedPageNumber(citation.getRefId(), font,
getReferenceType());
getReferenceType(), isVertical);
getPSLM().addUnresolvedArea(citation.getRefId(), unresolved);
text = unresolved;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

package org.apache.fop.layoutmgr.inline;

import java.util.List;

import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.ResolvedPageNumber;
import org.apache.fop.fo.flow.PageNumber;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.traits.MinOptMax;
Expand Down Expand Up @@ -73,7 +76,7 @@ protected AlignmentContext makeAlignmentContext(LayoutContext context) {
/** {@inheritDoc} */
public InlineArea get(LayoutContext context) {
// get page string from parent, build area
ResolvedPageNumber pn = new ResolvedPageNumber();
ResolvedPageNumber pn = new ResolvedPageNumber(font, context.getWritingMode().isVertical());
String str = getCurrentPV().getPageNumberString();
int width = getStringWidth(str);
int level = getBidiLevel();
Expand All @@ -94,7 +97,7 @@ protected InlineArea getEffectiveArea(LayoutContext layoutContext) {
//TODO Maybe replace that with a clone() call or better, a copy constructor
//TODO or even better: delay area creation until addAreas() stage
//ResolvedPageNumber is cloned because the LM is reused in static areas and the area can't be.
ResolvedPageNumber pn = new ResolvedPageNumber();
ResolvedPageNumber pn = new ResolvedPageNumber(font, layoutContext.getWritingMode().isVertical());
TraitSetter.setProducerID(pn, fobj.getId());
pn.setIPD(baseArea.getIPD());
pn.setBPD(baseArea.getBPD());
Expand Down

0 comments on commit 9ef4251

Please sign in to comment.