Author: fanningpj
Date: Wed Jan 29 17:24:30 2025
New Revision: 1923445
URL: http://svn.apache.org/viewvc?rev=1923445&view=rev
Log:
[bug-69555] need to work around inability to create a TextLayout in another
place (caused by missing fonts most likely)
Modified:
poi/trunk/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java?rev=1923445&r1=1923444&r2=1923445&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java Wed Jan
29 17:24:30 2025
@@ -259,7 +259,15 @@ public class SheetUtil {
*/
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 @@ public class SheetUtil {
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}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]