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 Apr 30, 2019
1 parent 1785699 commit d386eff
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 43 deletions.
15 changes: 13 additions & 2 deletions src/org/daisy/dotify/formatter/impl/page/BlockProcessor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.daisy.dotify.formatter.impl.page;

import java.util.Optional;

import org.daisy.dotify.api.formatter.FormattingTypes.BreakBefore;
import org.daisy.dotify.formatter.impl.core.Block;
import org.daisy.dotify.formatter.impl.core.BlockContext;
Expand All @@ -8,6 +10,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 @@ -45,9 +48,13 @@ protected void loadBlock(LayoutMaster master, Block g, BlockContext bc) {
rowGroupProvider = new RowGroupProvider(master, g, bcm, bc, keepWithNext);
}

protected void processNextRowGroup(DefaultContext context, LineProperties lineProps) {
protected Optional<RowGroup> processNextRowGroup(DefaultContext context, LineProperties lineProps) {
if (hasNextInBlock()) {
addRowGroup(rowGroupProvider.next(context, lineProps));
RowGroup ret = rowGroupProvider.next(context, lineProps);
addRowGroup(ret);
return Optional.of(ret);
} else {
return Optional.empty();
}
}

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

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

}
33 changes: 28 additions & 5 deletions src/org/daisy/dotify/formatter/impl/page/PageSequenceBuilder2.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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.BlockLineLocation;
import org.daisy.dotify.formatter.impl.search.DefaultContext;
import org.daisy.dotify.formatter.impl.search.PageDetails;
import org.daisy.dotify.formatter.impl.search.PageId;
Expand Down Expand Up @@ -59,11 +60,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 @@ -91,7 +95,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 @@ -115,6 +121,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 @@ -129,9 +137,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 @@ -175,6 +187,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 @@ -326,12 +341,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 @@ -352,6 +374,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;
}

}
14 changes: 11 additions & 3 deletions src/org/daisy/dotify/formatter/impl/page/RowGroupDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import org.daisy.dotify.api.formatter.FormattingTypes.BreakBefore;
Expand All @@ -16,6 +17,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 +44,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 +57,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 +76,7 @@ public RowGroup get(String id) {
} else {
this.groups = new ArrayList<>();
}
this.offsetInBlock = template.offsetInBlock;
this.blocks = template.blocks;
this.supplements = template.supplements;
this.breakBefore = template.breakBefore;
Expand Down Expand Up @@ -175,16 +180,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.
processNextRowGroup(bc, new LineProperties.Builder()
Optional<RowGroup> added = processNextRowGroup(bc, new LineProperties.Builder()
.suppressHyphenation(!allowHyphenateLastLine && index>-1 && groupSize()>=index-1)
.reservedWidth(reservedWidths.apply(countRows())).build()
);
.reservedWidth(reservedWidths.apply(countRows()))
.lineBlockLocation(new BlockLineLocation(getBlockAddress(), offsetInBlock))
.build());
offsetInBlock += added.map(v->v.getRows().size()).orElse(0);
}
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
Loading

0 comments on commit d386eff

Please sign in to comment.