Browse Source

Added basic support for forward page-number-citations


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193455 13f79535-47bb-0310-9956-ffa450edef68
pull/32/head
Jordan Naftolin 24 years ago
parent
commit
53f0d82d8e

+ 1
- 1
src/org/apache/fop/datatypes/IDNode.java View File

@@ -96,7 +96,7 @@ public class IDNode
*
* @return page number of this node
*/
protected String getPageNumber()
public String getPageNumber()
{
return(pageNumber != -1)?new Integer(pageNumber).toString():null;
}

+ 2
- 1
src/org/apache/fop/datatypes/IDReferences.java View File

@@ -52,6 +52,7 @@
package org.apache.fop.datatypes;

import org.apache.fop.pdf.PDFGoTo;
import org.apache.fop.layout.AreaContainer;


// Java
@@ -125,7 +126,7 @@ public class IDReferences {
public void configureID(String id, Area area)
{
if ( id!=null && !id.equals("") ) {
setPosition(id,area.getPage().getBody().getXPosition()-ID_PADDING,area.getPage().getBody().getYPosition() - area.getAbsoluteHeight()+ID_PADDING);
setPosition(id,area.getPage().getBody().getXPosition()+area.getTableCellXOffset()-ID_PADDING,area.getPage().getBody().getYPosition() - area.getAbsoluteHeight()+ID_PADDING);
setPageNumber(id,area.getPage().getNumber());
area.getPage().addToIDList(id);
}

+ 10
- 3
src/org/apache/fop/fo/flow/PageNumberCitation.java View File

@@ -186,12 +186,19 @@ public class PageNumberCitation extends FObj
IDReferences idReferences= area.getIDReferences();

String pageNumber=idReferences.getPageNumber(refId);
String output = (pageNumber!=null)?pageNumber:"?";


int orig_start = this.marker;

this.marker = ((BlockArea) area).addText(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, output.toCharArray(), 0, output.length());
if(pageNumber!=null) // if we already know the page number
{
String output=pageNumber;
this.marker = ((BlockArea) area).addText(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, output.toCharArray(), 0, output.length());
}
else // add pageNumberCitation to area to be resolved during rendering
{
this.marker = ((BlockArea) area).addPageNumberCitation(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, refId);
}

if ( this.marker == -1 )
{

+ 22
- 0
src/org/apache/fop/layout/BlockArea.java View File

@@ -115,6 +115,28 @@ public class BlockArea extends Area {
}
}

public int addPageNumberCitation(FontState fontState, float red, float green,
float blue, int wrapOption, LinkSet ls,
int whiteSpaceTreatment, String refid) {

this.currentLineArea.changeFont(fontState);
this.currentLineArea.changeColor(red, green, blue);
this.currentLineArea.changeWrapOption(wrapOption);
this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment);

if (ls != null) {
this.currentLinkSet = ls;
ls.setYOffset(currentHeight);
}

this.currentLineArea.addPageNumberCitation(refid,ls);
this.hasLines = true;
return -1;

}

Imaginary Buffer Line
public int addText(FontState fontState, float red, float green,
float blue, int wrapOption, LinkSet ls,
int whiteSpaceTreatment, char data[],

+ 5
- 0
src/org/apache/fop/layout/InlineArea.java View File

@@ -55,6 +55,7 @@ import org.apache.fop.render.Renderer;
public class InlineArea extends Area {

private String text;
protected String pageNumberId=null;
private float red, green, blue;

public InlineArea(FontState fontState, float red, float green, float blue, String text, int width) {
@@ -85,4 +86,8 @@ public class InlineArea extends Area {
public String getText() {
return this.text;
}

public String getPageNumberID() {
return pageNumberId;
}
}

+ 25
- 0
src/org/apache/fop/layout/LineArea.java View File

@@ -67,6 +67,8 @@ import org.apache.fop.fo.properties.TextAlign; // for enumerated
import org.apache.fop.fo.properties.TextAlignLast; // for enumerated
// values

import org.apache.fop.datatypes.IDNode;

public class LineArea extends Area {
protected int lineHeight;
@@ -149,6 +151,29 @@ public class LineArea extends Area {
renderer.renderLineArea(this);
}

public int addPageNumberCitation(String refid, LinkSet ls)
{
/* We should add code here to handle the case where the page number doesn't fit on the current line
*/

//Space must be alloted to the page number, so currently we give it 3 spaces
int width= currentFontState.width(32) * 3;
PageNumberInlineArea pia = new PageNumberInlineArea(currentFontState,
this.red, this.green,
this.blue,
refid,
width);
pendingAreas.addElement(pia);
pendingWidth += width;
wordWidth = 0;

return -1;
}


public int addText(char odata[], int start, int end, LinkSet ls) {
boolean overrun = false;


+ 13
- 3
src/org/apache/fop/render/pdf/PDFRenderer.java View File

@@ -74,13 +74,16 @@ import java.util.Vector;
* Renderer that renders areas to PDF
*/
public class PDFRenderer implements Renderer {
/** the PDF Document being created */
protected PDFDocument pdfDoc;

/** the /Resources object of the PDF document being created */
protected PDFResources pdfResources;

/** the IDReferences for this document */
protected IDReferences idReferences;

/** the current stream to add PDF commands to */
PDFStream currentStream;

@@ -145,7 +148,7 @@ public class PDFRenderer implements Renderer {
public void render(AreaTree areaTree, PrintWriter writer)
throws IOException, FOPException {
MessageHandler.logln("rendering areas to PDF");
IDReferences idReferences=areaTree.getIDReferences();
idReferences=areaTree.getIDReferences();
this.pdfResources = this.pdfDoc.getResources();
this.pdfDoc.setIDReferences(idReferences);
Enumeration e = areaTree.getPages().elements();
@@ -431,7 +434,14 @@ public class PDFRenderer implements Renderer {
+(rx/1000f) + " " + (bl/1000f)
+ " Tm (");

String s = area.getText();
String s;
if ( area.getPageNumberID()!=null ) { // this text is a page number, so resolve it
s = idReferences.getPageNumber(area.getPageNumberID());
}
else {
s = area.getText();
}
int l = s.length();

for (int i=0; i < l; i++) {

Loading…
Cancel
Save