diff options
author | Dominik Stadler <centic@apache.org> | 2022-04-10 16:45:02 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2022-04-10 16:45:02 +0000 |
commit | 0f06cc77899a045bd072b8a46bfe8e65dce780c1 (patch) | |
tree | e49f4bed3a2c28162e538ce1beb2df9a2fc95757 | |
parent | d970319239e0886997ba0b6c8b9a82b553368694 (diff) | |
download | poi-0f06cc77899a045bd072b8a46bfe8e65dce780c1.tar.gz poi-0f06cc77899a045bd072b8a46bfe8e65dce780c1.zip |
Add a way to not require a functioning font-setup
New configuration-method SheetUtil.setIgnoreMissingFontSystem()
This allows to do a bit more on machines where no fonts are installed
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899709 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java | 24 |
1 files changed, 22 insertions, 2 deletions
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 cda7674c83..ebe20471c6 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 @@ -98,6 +98,18 @@ public class SheetUtil { private static final FontRenderContext fontRenderContext = new FontRenderContext(null, true, true); /** + * A system property which can be enabled to not fail when the + * font-system is not available on the current machine + */ + private static final boolean ignoreMissingFontSystem = + Boolean.parseBoolean(System.getProperty("org.apache.poi.ss.ignoreMissingFontSystem")); + + /** + * Which default char-width to use if the font-system is unavailable. + */ + public static final int DEFAULT_CHAR_WIDTH = 5; + + /** * Compute width of a single cell * * @param cell the cell whose width is to be calculated @@ -282,8 +294,16 @@ public class SheetUtil { AttributedString str = new AttributedString(String.valueOf(defaultChar)); copyAttributes(defaultFont, str, 0, 1); - TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); - return (int) layout.getAdvance(); + try { + TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext); + return (int) layout.getAdvance(); + } catch (UnsatisfiedLinkError e) { + if (ignoreMissingFontSystem) { + return DEFAULT_CHAR_WIDTH; + } + + throw e; + } } /** |