mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
remove obsolete JDK6 workarounds
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1866862 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f59d60263e
commit
8e95d5d9c1
@ -30,7 +30,6 @@ log4j.logger.org.apache.poi.hdgf.chunks.Chunk=FATAL
|
||||
log4j.logger.org.apache.poi.hpsf.CodePageString=ERROR
|
||||
log4j.logger.org.apache.poi.hdgf.chunks.ChunkFactory=ERROR
|
||||
log4j.logger.org.apache.poi.hslf.model.textproperties.BitMaskTextProp=ERROR
|
||||
log4j.logger.org.apache.poi.util.JvmBugs=ERROR
|
||||
log4j.logger.org.apache.poi.hslf.usermodel.HSLFTextParagraph=ERROR
|
||||
log4j.logger.org.apache.poi.openxml4j.opc.ZipPackage=ERROR
|
||||
log4j.logger.org.apache.poi.POIDocument=WARN
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
/* ====================================================================
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
package org.apache.poi.util;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class JvmBugs {
|
||||
private static final POILogger LOG = POILogFactory.getLogger(JvmBugs.class);
|
||||
|
||||
/**
|
||||
* The LineBreakMeasurer is used for calculating text bounds.
|
||||
* The last official JDK 6 version (1.6.0_45) and also JDK 7 (1.7.0_21)
|
||||
* for Windows are affected. For JDK 7 - update to a more recent version.
|
||||
* For JDK 6 - replace the fontmanager.dll with the previous release (1.6.0_43).
|
||||
*
|
||||
* For performance reasons, this method only checks for a windows jvm
|
||||
* with version 1.6.0_45 and 1.7.0_21.
|
||||
*
|
||||
* Set system property "org.apache.poi.JvmBugs.LineBreakMeasurer.ignore" to "true"
|
||||
* to bypass this check and use the normal fonts.
|
||||
*
|
||||
* @return true, if jvm is bugged, caller code should use Lucida Sans
|
||||
* instead of Calibri and Lucida Bright instead of Cambria
|
||||
*
|
||||
* @see <a href="http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java?view=markup">Workaround for XSLF</a>
|
||||
* @see <a href="http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java?view=markup">Workaround for XSSF and HSSF</a>
|
||||
* @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=54904">POI Bug #54904</a>
|
||||
* @see <a href="http://bugs.java.com/view_bug.do?bug_id=6501991">JDK Bug #6501991</a>
|
||||
* @see <a href="http://bugs.java.com/view_bug.do?bug_id=8013716">JDK Bug #8013716</a>
|
||||
* @see <a href="https://bitbucket.org/fakraemer/line-break-measurer-test">LineBreakMeasurerTest</a>
|
||||
*/
|
||||
public static boolean hasLineBreakMeasurerBug() {
|
||||
String version = System.getProperty("java.version");
|
||||
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||
boolean ignore = Boolean.getBoolean("org.apache.poi.JvmBugs.LineBreakMeasurer.ignore");
|
||||
boolean hasBug = (!ignore && (os.contains("win") && ("1.6.0_45".equals(version) || "1.7.0_21".equals(version))));
|
||||
if (hasBug) {
|
||||
LOG.log(POILogger.WARN, "JVM has LineBreakMeasurer bug - see POI bug #54904 - caller code might default to Lucida Sans");
|
||||
}
|
||||
return hasBug;
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,6 @@ import java.util.Locale;
|
||||
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.util.JvmBugs;
|
||||
import org.apache.poi.util.LocaleUtil;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
@ -64,7 +63,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void numericCells() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
DataFormat df = workbook.getCreationHelper().createDataFormat();
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
@ -107,7 +105,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void booleanCells() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
|
||||
@ -139,7 +136,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void dateCells() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
DataFormat df = workbook.getCreationHelper().createDataFormat();
|
||||
@ -207,7 +203,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void stringCells() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
Row row = sheet.createRow(0);
|
||||
@ -234,8 +229,7 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
assertTrue(2*sheet.getColumnWidth(0) < sheet.getColumnWidth(1)); // width is roughly proportional to the number of characters
|
||||
assertTrue(2*sheet.getColumnWidth(1) < sheet.getColumnWidth(2));
|
||||
assertEquals(sheet.getColumnWidth(4), sheet.getColumnWidth(3));
|
||||
boolean ignoreFontSizeX2 = JvmBugs.hasLineBreakMeasurerBug();
|
||||
assertTrue(ignoreFontSizeX2 || sheet.getColumnWidth(5) > sheet.getColumnWidth(4)); //larger font results in a wider column width
|
||||
assertTrue(sheet.getColumnWidth(5) > sheet.getColumnWidth(4)); //larger font results in a wider column width
|
||||
|
||||
workbook.close();
|
||||
}
|
||||
@ -243,7 +237,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void rotatedText() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
Row row = sheet.createRow(0);
|
||||
@ -271,7 +264,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void mergedCells() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
|
||||
@ -299,7 +291,6 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
@Test
|
||||
public void largeRowNumbers() throws Exception {
|
||||
Workbook workbook = _testDataProvider.createWorkbook();
|
||||
fixFonts(workbook);
|
||||
Sheet sheet = workbook.createSheet();
|
||||
trackColumnsForAutoSizingIfSXSSF(sheet);
|
||||
|
||||
@ -350,16 +341,4 @@ public abstract class BaseTestSheetAutosizeColumn {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void fixFonts(Workbook workbook) {
|
||||
if (!JvmBugs.hasLineBreakMeasurerBug()) return;
|
||||
for (int i=workbook.getNumberOfFontsAsInt()-1; i>=0; i--) {
|
||||
Font f = workbook.getFontAt(0);
|
||||
if ("Calibri".equals(f.getFontName())) {
|
||||
f.setFontName("Lucida Sans");
|
||||
} else if ("Cambria".equals(f.getFontName())) {
|
||||
f.setFontName("Lucida Bright");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user