Skip to content

Commit

Permalink
Various changes needed in order to handle Dedicon test books (#97)
Browse files Browse the repository at this point in the history
* Only save "NextPageDetailsInSequence" and "TransitionProperties" info when needed
* EvenSizeVolumeSplitter: take into account the extra overhead when adding volumes
* Combine nested if statements
  • Loading branch information
bertfrees authored and kalaspuffar committed Sep 16, 2019
1 parent aead60b commit 54733b2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,18 @@
<row>⠼⠁⠋</row>
<row>⠤⠼⠉⠠⠋⠤⠤</row>
</page>
</section>
<section>
<page>
<row>⠼⠁⠛</row>
<row>⠏⠕⠎⠞⠀⠉⠕⠝⠤</row>
<row>⠞⠑⠝⠞</row>
</page>
</section>
</volume>
<volume cols="10" rows="6" rowgap="0" duplex="false">
<section>
<page>
<row>⠼⠁⠓</row>
<row>⠏⠗⠑⠀⠉⠕⠝⠤</row>
<row>⠞⠑⠝⠞</row>
</page>
</section>
<section>
<page>
<row>⠼⠁⠊</row>
<row>⠤⠼⠉⠠⠛⠤⠤</row>
</page>
<page>
<row>⠼⠃⠚</row>
<row>⠼⠁⠓</row>
<row>⠤⠼⠉⠠⠓⠤⠤</row>
</page>
</section>
<section>
<page>
<row>⠼⠃⠁</row>
<row>⠼⠁⠊</row>
<row>⠏⠕⠎⠞⠀⠉⠕⠝⠤</row>
<row>⠞⠑⠝⠞</row>
</page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠿⠿⠿</row>
<row>⠿⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
</page>
</section>
</volume>
<volume cols="10" rows="6" rowgap="0" duplex="true">
<section>
<page>
<row>⠿⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠿⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
</page>
<page>
<row>⠿⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠿⠿⠿</row>
</page>
</section>
</volume>
<volume cols="10" rows="6" rowgap="0" duplex="true">
<section>
<page>
<row>⠿⠤⠀⠤⠤⠀⠤⠤</row>
<row>⠤⠤⠀⠤⠤⠀⠤⠤</row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@ public PageImpl nextPage(int pageNumberOffset,
private PageImpl nextPageInner(int pageNumberOffset, boolean hyphenateLastLine, Optional<TransitionContent> transitionContent, boolean wasSplitInSequence, boolean isFirst) throws PaginatorException, RestartPaginationException // pagination must be restarted in PageStructBuilder.paginateInner
{
PageImpl current = newPage(pageNumberOffset);
if (pcbl!=null) {
if (pcbl!=null
// Store a mapping from the BlockLineLocation of the last line of the page before the
// previous page to the BlockLineLocation of the last line of the previous page. This
// info is used (in the next iteration) in SheetDataSource to obtain info about the
// verso page of a sheet when we are on a recto page of that sheet.
&& transitionContent.isPresent() && transitionContent.get().getType()==TransitionContent.Type.INTERRUPT) {

blockContext.getRefs().setNextPageDetailsInSequence(pcbl, current.getDetails());
}
if (nextEmpty) {
Expand Down Expand Up @@ -477,7 +479,9 @@ private PageImpl nextPageInner(int pageNumberOffset, boolean hyphenateLastLine,
// Determine whether there is a block boundary on the page, with enough space
// available after this point for sequence-interrupted and any-interrupted.
boolean hasBlockBoundary = blockBoundary.isPresent()?blockBoundary.get():res.getHead().stream().filter(r->r.isLastRowGroupInBlock()).findFirst().isPresent();
bc.getRefs().keepTransitionProperties(current.getDetails().getPageLocation(), new TransitionProperties(current.getAvoidVolumeBreakAfter(), hasBlockBoundary));
if (transitionContent.isPresent() && transitionContent.get().getType()==TransitionContent.Type.INTERRUPT) {
bc.getRefs().keepTransitionProperties(current.getDetails().getPageLocation(), new TransitionProperties(current.getAvoidVolumeBreakAfter(), hasBlockBoundary));
}
}
// Discard collapsed margins, but retain their properties (identifiers, markers,
// keep-with-next-sheets, keep-with-previous-sheets).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class EvenSizeVolumeSplitter implements VolumeSplitter {
// number of volumes to add on top of the number of volumes strictly needed to accommodate the
// total number of sheets
int volumeOffset = 0;
int initialSheets; // initial number of sheets; assuming that this is the number of sheets
// required to fit everything into one volume, without the overhead

/*
* This map keeps track of which split suggestions resulted in a successful split. We
Expand All @@ -55,6 +57,7 @@ class EvenSizeVolumeSplitter implements VolumeSplitter {
public void updateSheetCount(int sheets, int remainingSheets) {
if (sdc == null) {
sdc = new EvenSizeVolumeSplitterCalculator(sheets, splitterMax, volumeOffset);
initialSheets = sheets;
} else {
boolean sheetsFitInVolumes = remainingSheets == 0;
EvenSizeVolumeSplitterCalculator prvSdc = sdc;
Expand All @@ -75,12 +78,22 @@ public void updateSheetCount(int sheets, int remainingSheets) {
inc *= .75;
volumeInc = (int)Math.floor(inc);
}

// estimate of extra overhead per added volume
double overheadPerVolumeEstimate = (sheets - initialSheets) * 1.0 / prvSdc.getVolumeCount();
int extraOverheadSheets = (int)Math.floor(
overheadPerVolumeEstimate * (volumeInc + esc.getVolumeCount() - prvSdc.getVolumeCount()));
sheets += extraOverheadSheets;

if (volumeInc > 0) {
volumeOffset += volumeInc;
sdc = new EvenSizeVolumeSplitterCalculator(sheets, splitterMax, volumeOffset);
} else {

// Try with adjusted number of sheets
if (extraOverheadSheets > 0) {
esc = new EvenSizeVolumeSplitterCalculator(sheets, splitterMax, volumeOffset);
}
if (!previouslyTried.containsKey(esc) || previouslyTried.get(esc)) {
sdc = esc;
} else {
Expand Down

0 comments on commit 54733b2

Please sign in to comment.