Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't abort when there's not enough space in the left or right page margin #35

Merged
merged 1 commit into from
Feb 14, 2022
Merged
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
16 changes: 14 additions & 2 deletions src/org/daisy/dotify/formatter/impl/page/PageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;

import java.util.logging.Level;
import java.util.logging.Logger;

//TODO: scope spread is currently implemented using document wide scope, i.e. across volume boundaries.
// This is wrong, but is better than the previous sequence scope.
Expand All @@ -39,6 +40,9 @@
* @author Joel Håkansson
*/
public class PageImpl implements Page {

private static final Logger logger = Logger.getLogger(PageImpl.class.getCanonicalName());

private final FieldResolver fieldResolver;
private final PageDetails details;
private final LayoutMaster master;
Expand Down Expand Up @@ -238,7 +242,15 @@ private MarginProperties getMarginRegionValue(
}
ret = sb.toString();
} else if (ret.length() > w) {
throw new PaginatorException("Cannot fit " + ret + " into a margin-region of size " + mr.getWidth());
if (fcontext.getConfiguration().isAllowingTextOverflowTrimming()) {
String trimmed = ret.substring(0, mr.getWidth());
logger.log(Level.WARNING, "Cannot fit \"" + ret + "\" into a margin-region of size " + mr.getWidth()
+ ", trimming to \"" + trimmed + "\"");
ret = trimmed;
} else {
throw new PaginatorException(
"Cannot fit \"" + ret + "\" into a margin-region of size " + mr.getWidth());
}
}
return new MarginProperties(ret, spaceOnly);
} else {
Expand Down