cvs commit: xml-fop/src/org/apache/fop/fo/pagination PageNumberGenerator.java

2001-07-07 Thread arved

arved   01/07/07 22:03:49

  Added:   src/org/apache/fop/fo/pagination PageNumberGenerator.java
  Log:
  Supports page-number formatting
  
  Revision  ChangesPath
  1.1  
xml-fop/src/org/apache/fop/fo/pagination/PageNumberGenerator.java
  
  Index: PageNumberGenerator.java
  ===
  /*-- $Id: PageNumberGenerator.java,v 1.1 2001/07/08 05:03:48 arved Exp $ --
   * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
   * For details on use and redistribution please refer to the
   * LICENSE file included with these sources.
   */
  
  package org.apache.fop.fo.pagination;
  
  import org.apache.fop.fo.properties.*;
  import org.apache.fop.messaging.MessageHandler;
  
  // Java
  import java.util.*;
  
  /**
   * This class uses the 'format', 'groupingSeparator', 'groupingSize',
   * and 'letterValue' properties on fo:page-sequence to return a String
   * corresponding to the supplied integer page number.
   */
  public class PageNumberGenerator {
  
private String format;
private char groupingSeparator;
private int groupingSize;
private int letterValue;
  
//constants
private int DECIMAL = 1;// '0*1'
private int LOWERALPHA = 2; // 'a'
private int UPPERALPHA = 3; // 'A'
private int LOWERROMAN = 4; // 'i'
private int UPPERROMAN = 5; // 'I'

// flags
private int formatType = DECIMAL;
private int minPadding = 0; // for decimal formats

// preloaded strings of zeros
private String zeros[] = { , 0, 00, 000, , 0 };

public PageNumberGenerator( String format,
char groupingSeparator, int groupingSize, int letterValue ) {
this.format = format;
this.groupingSeparator = groupingSeparator;
this.groupingSize = groupingSize;
this.letterValue = letterValue;

// the only accepted format strings are currently '0*1' 'a', 'A', 'i'
// and 'I'
int fmtLen = format.length();
if (fmtLen == 1) {
if (format.equals(1)) {
formatType = DECIMAL;
minPadding = 0;
} else if (format.equals(a)) {
formatType = LOWERALPHA;
} else if (format.equals(A)) {
formatType = UPPERALPHA;
} else if (format.equals(i)) {
formatType = LOWERROMAN;
} else if (format.equals(I)) {
formatType = UPPERROMAN;
} else {
// token not handled
MessageHandler.log('format' token not recognized; 
using '1');
formatType = DECIMAL;
minPadding = 0; 
}
}
else {
// only accepted token is '0+1'at this stage.Because of the
// wonderful regular expression support in Java, we will 
resort to a
// loop
for (int i = 0; i  fmtLen-1; i++) {
if (format.charAt(i) != '0') {
MessageHandler.log('format' token not 
recognized; using '1');
formatType = DECIMAL;
minPadding = 0; 
} else {
minPadding = fmtLen - 1;
}
}
}
}

public String makeFormattedPageNumber(int number) {
String pn = null;
if (formatType == DECIMAL) {
pn = Integer.toString(number);
if (minPadding = pn.length()) {
int nz = minPadding - pn.length() + 1;
pn = zeros[nz] + pn;
}
} else if ((formatType == LOWERROMAN) || (formatType == UPPERROMAN)) {
pn = makeRoman(number);
if (formatType == UPPERROMAN)
pn = pn.toUpperCase();
} else {
// alphabetic
pn = makeAlpha(number);
if (formatType == UPPERALPHA)
pn = pn.toUpperCase();
}
return pn;
}

private String makeRoman( int num ) {
int 

cvs commit: xml-fop/src/org/apache/fop/fo/pagination PageSequence.java

2001-07-07 Thread arved

arved   01/07/07 22:04:11

  Modified:src/org/apache/fop/fo/pagination PageSequence.java
  Log:
  Supports page-number formatting
  
  Revision  ChangesPath
  1.30  +14 -3 xml-fop/src/org/apache/fop/fo/pagination/PageSequence.java
  
  Index: PageSequence.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/pagination/PageSequence.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PageSequence.java 2001/06/22 08:52:08 1.29
  +++ PageSequence.java 2001/07/08 05:04:10 1.30
  @@ -1,4 +1,4 @@
  -/*-- $Id: PageSequence.java,v 1.29 2001/06/22 08:52:08 keiron Exp $ --
  +/*-- $Id: PageSequence.java,v 1.30 2001/07/08 05:04:10 arved Exp $ --
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -83,8 +83,10 @@
   
   private Page currentPage;
   
  + // page number and elated formatting variables
   private int currentPageNumber = 0;
  -
  + private PageNumberGenerator pageNumberGenerator;
  + 
   /** specifies page numbering type (auto|auto-even|auto-odd|explicit) */
   private int pageNumberType;
   
  @@ -144,8 +146,14 @@
   }
   
   masterName = this.properties.get(master-name).getString();
  -
   
  + // get the 'format' properties
  + this.pageNumberGenerator =
  + new PageNumberGenerator( this.properties.get(format).getString(),
  + this.properties.get(grouping-separator).getCharacter(),
  + this.properties.get(grouping-size).getNumber().intValue(),
  + this.properties.get(letter-value).getEnum()
  + );
   }
   
   public void addFlow(Flow flow) throws FOPException {
  @@ -219,6 +227,9 @@
  tempIsFirstPage, isEmptyPage);
   
   currentPage.setNumber(this.currentPageNumber);
  + String formattedPageNumber =
  + 
pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
  + currentPage.setFormattedNumber(formattedPageNumber);
   this.root.setRunningPageNumberCounter(this.currentPageNumber);
   
   MessageHandler.log( [ + currentPageNumber);
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




cvs commit: xml-fop/src/org/apache/fop/layout Page.java

2001-07-07 Thread arved

arved   01/07/07 22:04:57

  Modified:src/org/apache/fop/layout Page.java
  Log:
  Supports page-number formatting
  
  Revision  ChangesPath
  1.12  +11 -2 xml-fop/src/org/apache/fop/layout/Page.java
  
  Index: Page.java
  ===
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/layout/Page.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Page.java 2001/06/12 11:37:43 1.11
  +++ Page.java 2001/07/08 05:04:56 1.12
  @@ -1,4 +1,4 @@
  -/* $Id: Page.java,v 1.11 2001/06/12 11:37:43 keiron Exp $
  +/* $Id: Page.java,v 1.12 2001/07/08 05:04:56 arved Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
  @@ -30,7 +30,8 @@
   private AreaTree areaTree;
   
   protected int pageNumber = 0;
  -
  + protected String formattedPageNumber;
  + 
   protected Vector linkSets = new Vector();
   
   private Vector idList = new Vector();
  @@ -49,6 +50,14 @@
   
   public int getNumber() {
return this.pageNumber;
  +}
  +
  + public void setFormattedNumber(String number) {
  + this.formattedPageNumber = number;
  + }
  + 
  +public String getFormattedNumber() {
  + return this.formattedPageNumber;
   }
   
   void addAfter(AreaContainer area) {
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




format on fo:page-sequence

2001-07-07 Thread Arved_37

You can now use the format property on fo:page-sequence. It supports the
following tokens:

'1' and padded variants such as '01' and '001';
'a' and 'A';
'i' and 'I'.

Multitoken format strings are not supported.

The infrastructure is in place to make the other related properties happen quite
easily: grouping-separator, grouping-size and letter-value. Investigate
PageNumberGenerator.java if you want to add these soon, yourself, and are a
developer.

Regards,
Arved Sandstrom

P.S. Not heavily tested yet, BTW.

---
 This mail was sent through the Nova Scotia Provincial Server, 
 with technical resources provided by Chebucto Community Net.
 http://nsaccess.ns.ca/mail/ http://www.chebucto.ns.ca/


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]