Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/org/daisy/dotify/formatter/impl/VolumeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class VolumeProvider {
private final LazyFormatterContext context;

/**
* Creates a new volume provider with the specifed parameters.
* Creates a new volume provider with the specified parameters.
*
* @param blocks the block sequences
* @param volumeTemplates volume templates
Expand Down Expand Up @@ -151,15 +151,28 @@ VolumeImpl nextVolume() {
currentVolumeNumber++;
VolumeImpl volume = new VolumeImpl(crh.getOverhead(currentVolumeNumber));
ArrayList<AnchorData> ad = new ArrayList<>();
volume.setPreVolData(updateVolumeContents(currentVolumeNumber, ad, true));
volume.setBody(nextBodyContents(currentVolumeNumber, volume.getOverhead().total(), ad));
List<Sheet> sheets = new ArrayList<>();

List<Sheet> preVolSheets = updateVolumeContents(currentVolumeNumber, ad, true);
volume.setPreVolSize(preVolSheets.size());
sheets.addAll(preVolSheets);

List<Sheet> contentSheets = nextBodyContents(currentVolumeNumber, volume.getOverhead().total(), ad);
volume.setBodyVolSize(contentSheets.size());
sheets.addAll(contentSheets);

if (logger.isLoggable(Level.FINE)) {
logger.fine("Sheets in volume " + currentVolumeNumber + ": " + (volume.getVolumeSize()) +
", content:" + volume.getBodySize() +
", overhead:" + volume.getOverhead());
}
volume.setPostVolData(updateVolumeContents(currentVolumeNumber, ad, false));

List<Sheet> postVolSheets = updateVolumeContents(currentVolumeNumber, ad, false);
volume.setPostVolSize(postVolSheets.size());
sheets.addAll(postVolSheets);

volume.setSections(SectionBuilder.getSections(sheets));

crh.setSheetsInVolume(currentVolumeNumber, volume.getBodySize() + volume.getOverhead().total());
//crh.setPagesInVolume(i, value);
crh.setAnchorData(currentVolumeNumber, ad);
Expand All @@ -175,7 +188,7 @@ VolumeImpl nextVolume() {
* @param ad the anchor data
* @return returns the contents of the next volume
*/
private SectionBuilder nextBodyContents(int volumeNumber, final int overhead, ArrayList<AnchorData> ad) {
private List<Sheet> nextBodyContents(int volumeNumber, final int overhead, ArrayList<AnchorData> ad) {
groups.currentGroup().setOverheadCount(groups.currentGroup().getOverheadCount() + overhead);
final int splitterMax = splitterLimit.getSplitterLimit(volumeNumber);
final int targetSheetsInVolume = (groups.lastInGroup() ? splitterMax : groups.sheetsInCurrentVolume());
Expand Down Expand Up @@ -234,7 +247,6 @@ public double getCost(SplitPointDataSource<Sheet, ?> units, int index, int break
crh.setVolumeScope(volumeNumber, pageIndex, pageIndex + pageCount);

pageIndex += pageCount;
SectionBuilder sb = new SectionBuilder();
boolean atFirstPageOfContents = true;
for (Sheet sheet : contents) {
for (PageImpl p : sheet.getPages()) {
Expand All @@ -255,14 +267,13 @@ public double getCost(SplitPointDataSource<Sheet, ?> units, int index, int break
}
atFirstPageOfContents = false;
}
sb.addSheet(sheet);
}
groups.currentGroup().setSheetCount(groups.currentGroup().getSheetCount() + contents.size());
groups.nextVolume();
return sb;
return contents;
}

private SectionBuilder updateVolumeContents(int volumeNumber, ArrayList<AnchorData> ad, boolean pre) {
private List<Sheet> updateVolumeContents(int volumeNumber, ArrayList<AnchorData> ad, boolean pre) {
DefaultContext c = new DefaultContext.Builder(crh)
.currentVolume(volumeNumber)
.space(pre ? Space.PRE_CONTENT : Space.POST_CONTENT)
Expand All @@ -281,7 +292,6 @@ private SectionBuilder updateVolumeContents(int volumeNumber, ArrayList<AnchorDa
}
}
List<Sheet> ret = prepareToPaginatePrePostVolumeContent(ib, c).getRemaining();
SectionBuilder sb = new SectionBuilder();
for (Sheet ps : ret) {
for (PageImpl p : ps.getPages()) {
for (String id : p.getIdentifiers()) {
Expand All @@ -291,9 +301,8 @@ private SectionBuilder updateVolumeContents(int volumeNumber, ArrayList<AnchorDa
ad.add(new AnchorData(p.getAnchors(), p.getPageNumber()));
}
}
sb.addSheet(ps);
}
return sb;
return ret;
} catch (PaginatorException e) {
return null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/org/daisy/dotify/formatter/impl/common/Volume.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.daisy.dotify.formatter.impl.common;

import java.util.List;

/**
* Provides a volume of braille.
*
* @author Joel Håkansson
*/
public interface Volume {

/**
* Sets the contents.
*
* @param sections the contents
*/
public void setSections(List<? extends Section> sections);

/**
* Gets the contents.
*
Expand Down
47 changes: 21 additions & 26 deletions src/org/daisy/dotify/formatter/impl/sheet/SectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,28 @@
* TODO: Write java doc.
*/
public class SectionBuilder {
private Stack<Section> ret = new Stack<Section>();
private SectionProperties currentProps = null;
private int sheets = 0;

public void addSheet(Sheet s) {
sheets++;
/* We're using object identity here to communicate requests for
* new sections. It is left over from a previous cleanup, and
* might not be very intuitive, but it have to do for now.
* Please improve if you wish.
*/
if (ret.isEmpty() || currentProps != s.getSectionProperties()) {
currentProps = s.getSectionProperties();
ret.add(new SectionImpl(currentProps));
}
SectionImpl sect = ((SectionImpl) ret.peek());
for (PageImpl p : s.getPages()) {
sect.addPage(p);

public static List<Section> getSections(List<Sheet> sheets) {
Stack<Section> ret = new Stack<>();
SectionProperties currentProps = null;
for (Sheet s : sheets) {
/* We're using object identity here to communicate requests for
* new sections. It is left over from a previous cleanup, and
* might not be very intuitive, but it have to do for now.
* Please improve if you wish.
*/
if (ret.isEmpty() || currentProps != s.getSectionProperties()) {
currentProps = s.getSectionProperties();
// start a new Section
ret.add(new SectionImpl(currentProps));
}
SectionImpl sect = ((SectionImpl) ret.peek());
for (PageImpl p : s.getPages()) {
sect.addPage(p);
}

}
}

List<Section> getSections() {
return ret;
}

int getSheetCount() {
return sheets;
}


}
33 changes: 14 additions & 19 deletions src/org/daisy/dotify/formatter/impl/sheet/VolumeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.daisy.dotify.formatter.impl.common.Volume;
import org.daisy.dotify.formatter.impl.search.Overhead;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -13,9 +12,7 @@
* @author Joel Håkansson
*/
public class VolumeImpl implements Volume {
private List<Section> body;
private List<Section> preVolData;
private List<Section> postVolData;
private List<? extends Section> sections;
private Overhead overhead;
private int bodyVolSize;

Expand All @@ -24,21 +21,23 @@ public VolumeImpl(Overhead overhead) {
this.bodyVolSize = 0;
}

public void setBody(SectionBuilder body) {
bodyVolSize = body.getSheetCount();
this.body = body.getSections();
public void setBodyVolSize(int sheetCount) {
this.bodyVolSize = sheetCount;
}

public void setPreVolData(SectionBuilder preVolData) {
public void setPreVolSize(int sheetCount) {
//use the highest value to avoid oscillation
overhead = overhead.withPreContentSize(Math.max(overhead.getPreContentSize(), preVolData.getSheetCount()));
this.preVolData = preVolData.getSections();
overhead = overhead.withPreContentSize(Math.max(overhead.getPreContentSize(), sheetCount));
}

public void setPostVolData(SectionBuilder postVolData) {
public void setPostVolSize(int sheetCount) {
//use the highest value to avoid oscillation
overhead = overhead.withPostContentSize(Math.max(overhead.getPostContentSize(), postVolData.getSheetCount()));
this.postVolData = postVolData.getSections();
overhead = overhead.withPostContentSize(Math.max(overhead.getPostContentSize(), sheetCount));
}

@Override
public void setSections(List<? extends Section> sections) {
this.sections = sections;
}

public Overhead getOverhead() {
Expand All @@ -55,11 +54,7 @@ public int getVolumeSize() {

@Override
public Iterable<? extends Section> getSections() {
List<Section> contents = new ArrayList<>();
contents.addAll(preVolData);
contents.addAll(body);
contents.addAll(postVolData);
return contents;
return sections;
}

}