Skip to content

Commit

Permalink
Use block/line address when resolving volume transition properties in…
Browse files Browse the repository at this point in the history
…stead of page index
  • Loading branch information
joeha480 committed Mar 20, 2019
1 parent 7605fd6 commit bb28b93
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.daisy.dotify.formatter.test;

import java.io.File;
import java.io.IOException;

import org.daisy.dotify.api.engine.FormatterEngineMaker;
Expand Down
5 changes: 5 additions & 0 deletions src/org/daisy/dotify/formatter/impl/page/BlockProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.daisy.dotify.formatter.impl.row.BlockStatistics;
import org.daisy.dotify.formatter.impl.row.LineProperties;
import org.daisy.dotify.formatter.impl.row.RowImpl;
import org.daisy.dotify.formatter.impl.search.BlockAddress;
import org.daisy.dotify.formatter.impl.search.DefaultContext;

/**
Expand Down Expand Up @@ -77,5 +78,9 @@ BlockStatistics getBlockStatistics() {
return null;
}
}

BlockAddress getBlockAddress() {
return rowGroupProvider!=null?rowGroupProvider.getBlockAddress():null;
}

}
35 changes: 29 additions & 6 deletions src/org/daisy/dotify/formatter/impl/page/PageSequenceBuilder2.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
import org.daisy.dotify.formatter.impl.datatype.VolumeKeepPriority;
import org.daisy.dotify.formatter.impl.row.AbstractBlockContentManager;
import org.daisy.dotify.formatter.impl.row.RowImpl;
import org.daisy.dotify.formatter.impl.search.BlockAddress;
import org.daisy.dotify.formatter.impl.search.BlockLineLocation;
import org.daisy.dotify.formatter.impl.search.DefaultContext;
import org.daisy.dotify.formatter.impl.search.DocumentSpace;
import org.daisy.dotify.formatter.impl.search.PageDetails;
import org.daisy.dotify.formatter.impl.search.PageId;
import org.daisy.dotify.formatter.impl.search.SequenceId;
Expand Down Expand Up @@ -60,11 +61,14 @@ public class PageSequenceBuilder2 {
private int dataGroupsIndex;
private boolean nextEmpty = false;

private BlockLineLocation cbl;
private BlockLineLocation pcbl;

//From view, temporary
private final int fromIndex;
private int toIndex;
public PageSequenceBuilder2(int fromIndex, LayoutMaster master, int pageOffset, BlockSequence seq, FormatterContext context, DefaultContext rcontext, SequenceId seqId) {

public PageSequenceBuilder2(int fromIndex, LayoutMaster master, int pageOffset, BlockSequence seq, FormatterContext context, DefaultContext rcontext, SequenceId seqId, BlockLineLocation blc) {
this.fromIndex = fromIndex;
this.toIndex = fromIndex;
this.master = master;
Expand Down Expand Up @@ -92,7 +96,9 @@ public PageSequenceBuilder2(int fromIndex, LayoutMaster master, int pageOffset,
this.cd = new CollectionData(staticAreaContent, blockContext, master, collection);
this.dataGroupsIndex = 0;
this.seqId = seqId;
PageDetails details = new PageDetails(master.duplex(), new PageId(pageCount, getGlobalStartIndex(), seqId), pageOffset);
this.cbl = blc;
this.pcbl = null;
PageDetails details = new PageDetails(master.duplex(), new PageId(pageCount, getGlobalStartIndex(), seqId), cbl, pageOffset);
this.fieldResolver = new FieldResolver(master, context, rcontext.getRefs(), details);
}

Expand All @@ -116,6 +122,8 @@ public PageSequenceBuilder2(PageSequenceBuilder2 template) {
this.nextEmpty = template.nextEmpty;
this.fromIndex = template.fromIndex;
this.toIndex = template.toIndex;
this.cbl = template.cbl;
this.pcbl = template.pcbl;
}

public static PageSequenceBuilder2 copyUnlessNull(PageSequenceBuilder2 template) {
Expand All @@ -130,9 +138,13 @@ public static PageSequenceBuilder2 copyUnlessNull(PageSequenceBuilder2 template)
public PageId nextPageId(int offset) {
return new PageId(pageCount+offset, getGlobalStartIndex(), seqId);
}

public BlockLineLocation currentBlockLineLocation() {
return cbl;
}

private PageImpl newPage(int pageNumberOffset) {
PageDetails details = new PageDetails(master.duplex(), new PageId(pageCount, getGlobalStartIndex(), seqId), pageNumberOffset);
PageDetails details = new PageDetails(master.duplex(), new PageId(pageCount, getGlobalStartIndex(), seqId), cbl, pageNumberOffset);
PageImpl ret = new PageImpl(fieldResolver, details, master, context, staticAreaContent);
pageCount ++;
if (keepNextSheets>0) {
Expand Down Expand Up @@ -178,6 +190,9 @@ public PageImpl nextPage(int pageNumberOffset, boolean hyphenateLastLine, Option
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) {
blockContext.getRefs().setNextPageDetailsInSequence(pcbl, current.getDetails());
}
if (nextEmpty) {
nextEmpty = false;
return current;
Expand Down Expand Up @@ -329,12 +344,19 @@ private PageImpl nextPageInner(int pageNumberOffset, boolean hyphenateLastLine,
head.addAll(0, anyTransitionText);
}
}
//TODO: Get last row
if (!head.isEmpty()) {
int s = head.size();
RowGroup gr = head.get(s-1);
pcbl = cbl;
cbl = gr.getLineProperties().getBlockLineLocation();
}
addRows(head, current);
current.setAvoidVolumeBreakAfter(getVolumeKeepPriority(res.getDiscarded(), getVolumeKeepPriority(res.getHead(), VolumeKeepPriority.empty())));
if (context.getTransitionBuilder().getProperties().getApplicationRange()!=ApplicationRange.NONE) {
// no need to do this, unless there is an active transition builder
boolean hasBlockBoundary = blockBoundary.isPresent()?blockBoundary.get():res.getHead().stream().filter(r->r.isLastRowGroupInBlock()).findFirst().isPresent();
bc.getRefs().keepTransitionProperties(current.getDetails().getPageId(), new TransitionProperties(current.getAvoidVolumeBreakAfter(), hasBlockBoundary));
bc.getRefs().keepTransitionProperties(current.getDetails().getPageLocation(), new TransitionProperties(current.getAvoidVolumeBreakAfter(), hasBlockBoundary));
}
for (RowGroup rg : res.getDiscarded()) {
addProperties(current, rg);
Expand All @@ -355,6 +377,7 @@ private PageImpl nextPageInner(int pageNumberOffset, boolean hyphenateLastLine,
}
}
}

return current;
}

Expand Down
14 changes: 14 additions & 0 deletions src/org/daisy/dotify/formatter/impl/page/RowGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.daisy.dotify.api.writer.Row;
import org.daisy.dotify.common.splitter.SplitPointUnit;
import org.daisy.dotify.formatter.impl.datatype.VolumeKeepPriority;
import org.daisy.dotify.formatter.impl.row.LineProperties;
import org.daisy.dotify.formatter.impl.row.RowImpl;

class RowGroup implements SplitPointUnit {
Expand All @@ -24,6 +25,7 @@ class RowGroup implements SplitPointUnit {
private final VolumeKeepPriority avoidVolumeBreakAfterPriority;
private final boolean lastInBlock;
private final boolean mergeable;
private final LineProperties lineProps;

static class Builder {
private final List<RowImpl> rows;
Expand All @@ -37,6 +39,8 @@ static class Builder {
private VolumeKeepPriority avoidVolumeBreakAfterPriority = VolumeKeepPriority.empty();
private boolean lastInBlock = false;
private boolean mergeable = false;
private LineProperties lineProps = LineProperties.DEFAULT;

Builder(float rowDefault, RowImpl ... rows) {
this(rowDefault, Arrays.asList(rows));
}
Expand Down Expand Up @@ -111,6 +115,10 @@ Builder mergeable(boolean value) {
this.mergeable = value;
return this;
}
Builder lineProperties(LineProperties value) {
this.lineProps = value;
return this;
}
RowGroup build() {
return new RowGroup(this);
}
Expand All @@ -136,6 +144,7 @@ private RowGroup(Builder builder) {
this.avoidVolumeBreakAfterPriority = builder.avoidVolumeBreakAfterPriority;
this.lastInBlock = builder.lastInBlock;
this.mergeable = builder.mergeable;
this.lineProps = builder.lineProps;
}

/**
Expand All @@ -159,6 +168,7 @@ private RowGroup(Builder builder) {
this.avoidVolumeBreakAfterPriority = template.avoidVolumeBreakAfterPriority;
this.lastInBlock = template.lastInBlock;
this.mergeable = template.mergeable;
this.lineProps = template.lineProps;
}

private static float getRowSpacing(float rowDefault, RowImpl r) {
Expand Down Expand Up @@ -299,4 +309,8 @@ boolean isMergeable() {
return mergeable;
}

LineProperties getLineProperties() {
return lineProps;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.daisy.dotify.formatter.impl.core.BlockContext;
import org.daisy.dotify.formatter.impl.core.LayoutMaster;
import org.daisy.dotify.formatter.impl.row.LineProperties;
import org.daisy.dotify.formatter.impl.search.BlockLineLocation;

/**
* <p>Provides a data source for row groups.</p>
Expand All @@ -42,6 +43,7 @@ public RowGroup get(String id) {
private Function<Integer, Integer> reservedWidths = x->0;
private int blockIndex;
private boolean allowHyphenateLastLine;
private int offsetInBlock;

RowGroupDataSource(LayoutMaster master, BlockContext bc, List<Block> blocks, BreakBefore breakBefore, VerticalSpacing vs, Supplements<RowGroup> supplements) {
super();
Expand All @@ -54,6 +56,7 @@ public RowGroup get(String id) {
this.vs = vs;
this.blockIndex = 0;
this.allowHyphenateLastLine = true;
this.offsetInBlock = 0;
}

RowGroupDataSource(RowGroupDataSource template) {
Expand All @@ -72,6 +75,7 @@ public RowGroup get(String id) {
} else {
this.groups = new ArrayList<>();
}
this.offsetInBlock = template.offsetInBlock + offset;
this.blocks = template.blocks;
this.supplements = template.supplements;
this.breakBefore = template.breakBefore;
Expand Down Expand Up @@ -175,15 +179,19 @@ private boolean ensureBuffer(int index) {
//get next block
Block b = blocks.get(blockIndex);
blockIndex++;
offsetInBlock=0;
loadBlock(master, b, bc);
}
// Requesting all items implies that no special last line hyphenation processing is needed.
// This is reasonable: The very last line in a result would never be hyphenated, so suppressing
// hyphenation is unnecessary. Also, actively doing this would be difficult, because we do not know
// if the line produced below is the last line or not, until after the call has already been made.
int lineNumber = countRows();
processNextRowGroup(bc, new LineProperties.Builder()
.suppressHyphenation(!allowHyphenateLastLine && index>-1 && groupSize()>=index-1)
.reservedWidth(reservedWidths.apply(countRows())).build()
.reservedWidth(reservedWidths.apply(lineNumber))
.lineBlockLocation(new BlockLineLocation(getBlockAddress(), offsetInBlock+lineNumber))
.build()
);
}
return true;
Expand Down
43 changes: 27 additions & 16 deletions src/org/daisy/dotify/formatter/impl/page/RowGroupProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.daisy.dotify.formatter.impl.row.BlockStatistics;
import org.daisy.dotify.formatter.impl.row.LineProperties;
import org.daisy.dotify.formatter.impl.row.RowImpl;
import org.daisy.dotify.formatter.impl.search.BlockAddress;
import org.daisy.dotify.formatter.impl.search.CrossReferenceHandler;
import org.daisy.dotify.formatter.impl.search.DefaultContext;

Expand Down Expand Up @@ -87,6 +88,10 @@ BlockStatistics getBlockStatistics() {
return bcm;
}

BlockAddress getBlockAddress() {
return g.getBlockAddress();
}

public RowGroup next(DefaultContext context, LineProperties lineProps) {
if (this.context==null || !this.context.equals(context)) {
this.context = g.contextWithMeta(context);
Expand All @@ -100,32 +105,35 @@ private RowGroup nextInner(LineProperties lineProps) {
if (lineProps.getReservedWidth()>0 && !bcm.supportsVariableWidth()) {
return new RowGroup.Builder(master.getRowSpacing()).add(new RowImpl())
.mergeable(false)
.lineProperties(lineProps)
.collapsible(false).skippable(false).breakable(false).build();
}
if (phase==0) {
phase++;
//if there is a row group, return it (otherwise, try next phase)
if (bcm.hasCollapsiblePreContentRows()) {
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getCollapsiblePreContentRows()).
mergeable(true).
collapsible(true).skippable(false).breakable(false), hasNext(), g).build();
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getCollapsiblePreContentRows())
.mergeable(true)
.lineProperties(lineProps)
.collapsible(true).skippable(false).breakable(false), hasNext(), g).build();
}
}
if (phase==1) {
phase++;
//if there is a row group, return it (otherwise, try next phase)
if (bcm.hasInnerPreContentRows()) {
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getInnerPreContentRows()).
mergeable(false).
collapsible(false).skippable(false).breakable(false), hasNext(), g).build();
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getInnerPreContentRows())
.mergeable(false)
.lineProperties(lineProps)
.collapsible(false).skippable(false).breakable(false), hasNext(), g).build();
}
}
if (phase==2) {
phase++;
//TODO: Does this interfere with collapsing margins?
if (shouldAddGroupForEmptyContent()) {
RowGroup.Builder rgb = setPropertiesForFirstContentRowGroup(
new RowGroup.Builder(master.getRowSpacing(), new ArrayList<RowImpl>()).mergeable(true),
new RowGroup.Builder(master.getRowSpacing(), new ArrayList<RowImpl>()).mergeable(true).lineProperties(lineProps),
bc.getRefs(),
g
);
Expand All @@ -143,9 +151,10 @@ private RowGroup nextInner(LineProperties lineProps) {
keepWithNext = g.getKeepWithNext();
bc.getRefs().setRowCount(g.getBlockAddress(), bcm.getRowCount());
}
RowGroup.Builder rgb = new RowGroup.Builder(master.getRowSpacing()).add(r).
mergeable(bcm.supportsVariableWidth()).
collapsible(false).skippable(false).breakable(
RowGroup.Builder rgb = new RowGroup.Builder(master.getRowSpacing()).add(r)
.mergeable(bcm.supportsVariableWidth())
.lineProperties(lineProps)
.collapsible(false).skippable(false).breakable(
r.allowsBreakAfter()&&
owc.allowsBreakAfter(rowIndex-1)&&
keepWithNext<=0 &&
Expand All @@ -164,17 +173,19 @@ private RowGroup nextInner(LineProperties lineProps) {
if (phase==4) {
phase++;
if (bcm.hasPostContentRows()) {
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getPostContentRows()).
mergeable(false).
collapsible(false).skippable(false).breakable(keepWithNext<0), hasNext(), g).build();
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getPostContentRows())
.mergeable(false)
.lineProperties(lineProps)
.collapsible(false).skippable(false).breakable(keepWithNext<0), hasNext(), g).build();
}
}
if (phase==5) {
phase++;
if (bcm.hasSkippablePostContentRows()) {
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getSkippablePostContentRows()).
mergeable(true).
collapsible(true).skippable(true).breakable(keepWithNext<0), hasNext(), g).build();
return setPropertiesThatDependOnHasNext(new RowGroup.Builder(master.getRowSpacing(), bcm.getSkippablePostContentRows())
.mergeable(true)
.lineProperties(lineProps)
.collapsible(true).skippable(true).breakable(keepWithNext<0), hasNext(), g).build();
}
}
return null;
Expand Down
14 changes: 14 additions & 0 deletions src/org/daisy/dotify/formatter/impl/row/LineProperties.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.daisy.dotify.formatter.impl.row;

import org.daisy.dotify.formatter.impl.search.BlockLineLocation;

/**
* Provides details about a line
* @author Joel Håkansson
Expand All @@ -11,13 +13,15 @@ public final class LineProperties {
public static final LineProperties DEFAULT = new LineProperties.Builder().build();
private final boolean suppressHyphenation;
private final int reservedWidth;
private final BlockLineLocation lineBlock;

/**
* Provides a builder of line properties.
*/
public static final class Builder {
private boolean suppressHyphenation = false;
private int reservedWidth = 0;
private BlockLineLocation lineBlock = null;

/**
* Creates a new empty builder.
Expand Down Expand Up @@ -48,6 +52,11 @@ public Builder reservedWidth(int value) {
return this;
}

public Builder lineBlockLocation(BlockLineLocation value) {
this.lineBlock = value;
return this;
}

/**
* Creates a new {@link LineProperties} with the current settings.
* @return a new line properties instance.
Expand All @@ -60,6 +69,7 @@ public LineProperties build() {
private LineProperties(Builder builder) {
this.suppressHyphenation = builder.suppressHyphenation;
this.reservedWidth = builder.reservedWidth;
this.lineBlock = builder.lineBlock;
}

/**
Expand All @@ -77,4 +87,8 @@ public boolean suppressHyphenation() {
public int getReservedWidth() {
return reservedWidth;
}

public BlockLineLocation getBlockLineLocation() {
return lineBlock;
}
}
Loading

0 comments on commit bb28b93

Please sign in to comment.