This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separates volume breaking and removes some (previously) disabled code
- Loading branch information
Joel Håkansson
committed
Apr 29, 2016
1 parent
b025040
commit 5ca0911
Showing
4 changed files
with
129 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
dotify.formatter.impl/src/org/daisy/dotify/formatter/impl/VolumeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.daisy.dotify.formatter.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.daisy.dotify.common.layout.SplitPoint; | ||
import org.daisy.dotify.common.layout.SplitPointHandler; | ||
|
||
/** | ||
* Provides contents for a volume | ||
* @author Joel Håkansson | ||
* | ||
*/ | ||
public class VolumeProvider { | ||
private List<Sheet> units; | ||
private final SplitPointHandler<Sheet> volSplitter = new SplitPointHandler<>(); | ||
private final CrossReferenceHandler crh; | ||
PageStruct ps; | ||
private int pageIndex = 0; | ||
//private int totalPageCount = 0; | ||
private int i=0; | ||
|
||
public VolumeProvider(PageStructBuilder contentPaginator, CrossReferenceHandler crh) { | ||
this.crh = crh; | ||
try { | ||
ps = contentPaginator.paginate(crh, new DefaultContext(null, null)); | ||
units = ps.buildSplitPoints(); | ||
} catch (PaginatorException e) { | ||
throw new RuntimeException("Error while reformatting.", e); | ||
} | ||
} | ||
|
||
List<Sheet> nextVolume(int targetSheetsInVolume, int overhead, int splitterMax, ArrayList<AnchorData> ad) { | ||
i++; | ||
SplitPoint<Sheet> sp = getSplitPoint(targetSheetsInVolume, overhead, splitterMax); | ||
units = sp.getTail(); | ||
List<Sheet> contents = sp.getHead(); | ||
int pageCount = FormatterImpl.countPages(contents); | ||
// TODO: In a volume-by-volume scenario, how can we make this work | ||
ps.setVolumeScope(i, pageIndex, pageIndex+pageCount); | ||
pageIndex += pageCount; | ||
//totalPageCount += pageCount; | ||
for (Sheet sheet : contents) { | ||
for (PageImpl p : sheet.getPages()) { | ||
for (String id : p.getIdentifiers()) { | ||
crh.setVolumeNumber(id, i); | ||
} | ||
if (p.getAnchors().size()>0) { | ||
ad.add(new AnchorData(p.getPageIndex(), p.getAnchors())); | ||
} | ||
} | ||
} | ||
return contents; | ||
} | ||
|
||
/** | ||
* The total number of pages provided so far | ||
* @return the number of pages | ||
*/ | ||
int getTotalPageCount() { | ||
//return totalPageCount; | ||
return pageIndex; | ||
} | ||
|
||
/** | ||
* Gets the current page index. | ||
* @return | ||
*/ | ||
int getPageIndex() { | ||
return pageIndex; | ||
} | ||
|
||
private SplitPoint<Sheet> getSplitPoint(int targetSheetsInVolume, int overhead, int splitterMax) { | ||
int contentSheets = targetSheetsInVolume-overhead; | ||
SplitPoint<Sheet> bp; | ||
{ | ||
int offset = -1; | ||
do { | ||
offset++; | ||
bp = volSplitter.split(contentSheets+offset, false, units); | ||
} while (bp.getHead().size()<contentSheets && targetSheetsInVolume+offset<splitterMax); | ||
bp = volSplitter.split(contentSheets + offset, true, units); | ||
} | ||
return bp; | ||
} | ||
|
||
boolean hasNext() { | ||
return !units.isEmpty(); | ||
} | ||
|
||
List<Sheet> getRemaining() { | ||
return units; | ||
} | ||
|
||
|
||
} |