From 3a323cc3ab303d6f2150d8f664e3aa360f47883b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20H=C3=A5kansson?= Date: Tue, 27 Nov 2012 13:24:22 +0000 Subject: [PATCH] fixed a problem with redundant increase in the number of volumes fixed an issue with volume number resolution near volume boundaries removed some unused code --- .../src/org/daisy/dotify/book/BookStruct.java | 7 ++++- .../dotify/book/CrossReferenceHandler.java | 27 ++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Dotify/src/org/daisy/dotify/book/BookStruct.java b/Dotify/src/org/daisy/dotify/book/BookStruct.java index 927e8073..6bfe4ac3 100644 --- a/Dotify/src/org/daisy/dotify/book/BookStruct.java +++ b/Dotify/src/org/daisy/dotify/book/BookStruct.java @@ -216,7 +216,12 @@ public Iterable 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."); } diff --git a/Dotify/src/org/daisy/dotify/book/CrossReferenceHandler.java b/Dotify/src/org/daisy/dotify/book/CrossReferenceHandler.java index 990405c3..5fac0021 100644 --- a/Dotify/src/org/daisy/dotify/book/CrossReferenceHandler.java +++ b/Dotify/src/org/daisy/dotify/book/CrossReferenceHandler.java @@ -18,8 +18,6 @@ class CrossReferenceHandler implements CrossReferences { private Map pageSheetMap; private PageStruct ps; private EvenSizeVolumeSplitterCalculator sdc; - - private Integer[] targetVolSize; private boolean isDirty; private boolean volumeForContentSheetChanged; @@ -31,7 +29,6 @@ public CrossReferenceHandler() { this.volData = new HashMap(); this.volSheet = new HashMap(); - this.targetVolSize = new Integer[0]; this.isDirty = false; this.volumeForContentSheetChanged = false; //this.maxKey = 0; @@ -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); @@ -192,16 +192,19 @@ private int getVolumeForContentSheet(int sheetIndex) { } int lastSheetInCurrentVolume=0; int retVolume=0; - while (lastSheetInCurrentVolume=lastSheetInCurrentVolume) { + throw new RuntimeException("Negative volume size"); + } + } while (sheetIndex>lastSheetInCurrentVolume); Integer cv = volSheet.get(sheetIndex); if (cv==null || cv!=retVolume) { volumeForContentSheetChanged = true;