Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
fixed a problem with redundant increase in the number of volumes
Browse files Browse the repository at this point in the history
fixed an issue with volume number resolution near volume boundaries
removed some unused code
  • Loading branch information
Joel Håkansson committed Nov 27, 2012
1 parent 3b9e42d commit 3a323cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
7 changes: 6 additions & 1 deletion Dotify/src/org/daisy/dotify/book/BookStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ public Iterable<Volume> getVolumes() {
ok2 = false;
logger.fine("There is more content... sheets: " + volBreaks.getRemaining() + ", pages: " +(pages.size()-pageIndex));
if (volumeOffset<1) {
volumeOffset++;
//First check to see if the page increase can will be handled automatically without increasing volume offset
//in the next iteration (by supplying up-to-date overhead values)
EvenSizeVolumeSplitterCalculator esv = new EvenSizeVolumeSplitterCalculator(contents+totalPreCount+totalPostCount, splitterMax, volumeOffset);
if (esv.getVolumeCount()==crh.getExpectedVolumeCount()) {
volumeOffset++;
}
} else {
logger.warning("Could not fit contents even when adding a new volume.");
}
Expand Down
27 changes: 15 additions & 12 deletions Dotify/src/org/daisy/dotify/book/CrossReferenceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class CrossReferenceHandler implements CrossReferences {
private Map<Page, Integer> pageSheetMap;
private PageStruct ps;
private EvenSizeVolumeSplitterCalculator sdc;

private Integer[] targetVolSize;

private boolean isDirty;
private boolean volumeForContentSheetChanged;
Expand All @@ -31,7 +29,6 @@ public CrossReferenceHandler() {

this.volData = new HashMap<Integer, VolData>();
this.volSheet = new HashMap<Integer, Integer>();
this.targetVolSize = new Integer[0];
this.isDirty = false;
this.volumeForContentSheetChanged = false;
//this.maxKey = 0;
Expand Down Expand Up @@ -99,6 +96,9 @@ public void setTargetVolSize(int volumeNumber, int targetVolSize) {
}

public VolDataInterface getVolData(int volumeNumber) {
if (volumeNumber<1) {
throw new IndexOutOfBoundsException("Volume must be greater than or equal to 1");
}
if (volData.get(volumeNumber)==null) {
setVolData(volumeNumber, new VolData());
setDirty(true);
Expand Down Expand Up @@ -192,16 +192,19 @@ private int getVolumeForContentSheet(int sheetIndex) {
}
int lastSheetInCurrentVolume=0;
int retVolume=0;
while (lastSheetInCurrentVolume<sheetIndex) {
int overhead = getVolData(retVolume+1).getVolOverhead();
lastSheetInCurrentVolume -= overhead;
if (retVolume<targetVolSize.length && targetVolSize[retVolume]!=null) {
lastSheetInCurrentVolume += targetVolSize[retVolume];
} else {
lastSheetInCurrentVolume += sdc.sheetsInVolume(retVolume+1);
}
do {
retVolume++;
}
int prvVal = lastSheetInCurrentVolume;
int volSize = getVolData(retVolume).getTargetVolSize();
if (volSize==0) {
volSize = sdc.sheetsInVolume(retVolume);
}
lastSheetInCurrentVolume += volSize;
lastSheetInCurrentVolume -= getVolData(retVolume).getVolOverhead();
if (prvVal>=lastSheetInCurrentVolume) {
throw new RuntimeException("Negative volume size");
}
} while (sheetIndex>lastSheetInCurrentVolume);
Integer cv = volSheet.get(sheetIndex);
if (cv==null || cv!=retVolume) {
volumeForContentSheetChanged = true;
Expand Down

0 comments on commit 3a323cc

Please sign in to comment.