[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
This commit is contained in:
PJ Fanning 2025-01-29 17:24:30 +00:00
parent e51877f5a6
commit 43aded3d9c

View File

@ -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}