From 7919db28cfafa8633e5388b6e1b31781b873fde3 Mon Sep 17 00:00:00 2001 From: Bert Frees Date: Fri, 3 Dec 2021 18:38:38 +0100 Subject: [PATCH] Don't abort when there's not enough space in the left or right page margin (to render a marker-indicator) when the "allowsTextOverflowTrimming" option is set. Instead show a warning. This addresses Github issue https://github.com/mtmse/dotify.library/issues/23 about "handling errors gracefully instead of aborting". --- .../dotify/formatter/impl/page/PageImpl.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/org/daisy/dotify/formatter/impl/page/PageImpl.java b/src/org/daisy/dotify/formatter/impl/page/PageImpl.java index 90cc454f..0131f54e 100644 --- a/src/org/daisy/dotify/formatter/impl/page/PageImpl.java +++ b/src/org/daisy/dotify/formatter/impl/page/PageImpl.java @@ -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. @@ -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; @@ -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 {