[bug-69555] need to work around inability to create a TextLayout in another place (caused by missing fonts most likely)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923445 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java b/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java
index bc44825..b738067 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java
@@ -259,7 +259,15 @@
*/
private static double getCellWidth(float defaultCharWidth, int colspan,
CellStyle style, double minWidth, AttributedString str) {
- TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
+ TextLayout layout;
+ try {
+ layout = new TextLayout(str.getIterator(), fontRenderContext);
+ } catch (Throwable t) {
+ if (shouldIgnoreMissingFontSystem(t)) {
+ return defaultCharWidth;
+ }
+ throw t;
+ }
final Rectangle2D bounds;
if (style.getRotation() != 0) {
/*
@@ -353,25 +361,25 @@
TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
return layout.getAdvance();
} catch (Throwable t) {
- // ignore exception and return a default char width if
- // the ignore-feature is enabled and the exception indicates that
- // the underlying font system is not available
- if (ignoreMissingFontSystem && (
- // the three types of exception usually indicate here that the font
- // system is not fully installed, i.e. system libraries missing or
- // some JDK classes cannot be loaded
- t instanceof UnsatisfiedLinkError ||
- t instanceof NoClassDefFoundError ||
- t instanceof InternalError ||
- // other fatal exceptions will always be rethrown
- !ExceptionUtil.isFatal(t))) {
+ if (shouldIgnoreMissingFontSystem(t)) {
return DEFAULT_CHAR_WIDTH;
}
-
throw t;
}
}
+ private static boolean shouldIgnoreMissingFontSystem(final Throwable t) {
+ return ignoreMissingFontSystem && (
+ // the three types of exception usually indicate here that the font
+ // system is not fully installed, i.e. system libraries missing or
+ // some JDK classes cannot be loaded
+ t instanceof UnsatisfiedLinkError ||
+ t instanceof NoClassDefFoundError ||
+ t instanceof InternalError ||
+ // other fatal exceptions will always be rethrown
+ !ExceptionUtil.isFatal(t));
+ }
+
/**
* Compute width of a single cell in a row
* Convenience method for {@link #getCellWidth}