Bug 55385 - XSSFFont.setBoldweight(short) to 300 but getBoldweight return 400
Summary: XSSFFont.setBoldweight(short) to 300 but getBoldweight return 400
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.10-dev
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Blocks: 59718
  Show dependency tree
Reported: 2013-08-08 01:06 UTC by fujian
Modified: 2016-06-18 01:20 UTC (History)
0 users

Javadocs fixes for XSSFFont (1.42 KB, patch)
2016-04-06 03:27 UTC, Javen O'Neal
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description fujian 2013-08-08 01:06:07 UTC
execute the code:

      Workbook workbook = new XSSFWorkbook();
        Sheet createSheet = workbook.createSheet();
        Row row = createSheet.createRow(0);
        Cell cell = row.createCell(0);
        CellStyle cellStyle = workbook.createCellStyle();

        Font createFont = workbook.createFont();


		short fontIndex = cell.getCellStyle().getFontIndex();
		Font fontAt = workbook.getFontAt(fontIndex);

the boldweight can't be set to 300. due to :

    public short getBoldweight()
        return getBold() ? BOLDWEIGHT_BOLD : BOLDWEIGHT_NORMAL;

is 400 or 700 only. if so, why provide the setBoldweight() to set any short value?
Comment 1 fujian 2013-08-08 01:07:28 UTC
at the sometime, HSSFFont's set/get boldweight is right,
Comment 2 Javen O'Neal 2016-04-06 02:48:00 UTC
Looking at XSSFFont.setBoldweight(short boldweight), it looks like getBoldweight and setBoldweight were never intended to be used with literals--only the Font.BOLDWEIGHT_NORMAL and Font.BOLDWEIGHT_BOLD constants. [1]

Your example can be simplified to:
Workbook wb = new XSSFWorkbook();
Font font = wb.createFont();
short weight = 314;
assumeTrue(weight != Font.BOLDWEIGHT_NORMAL);
assumeTrue(weight != Font.BOLDWEIGHT_BOLD);
assertEquals(weight, font.getBoldweight);

The XSSFFont never stores the requested boldweight.
If the OOXML format allows specifying a numeric weight in addition to a boolean bold/not-bold value, then this is a bug in POI.

From what I can make out in the 2006 OOXML schema, custom font weights are not part of the standard.

  <xsd:complexType name="CT_Font">
    <xsd:choice maxOccurs="unbounded">
      <xsd:element name="b" type="CT_BooleanProperty" minOccurs="0" maxOccurs="1">

A note should be added to XSSFFont.get/setBoldweight javadocs that only the named constants will work.

[1] https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?revision=1701134&view=markup#l300
Comment 3 Javen O'Neal 2016-04-06 03:27:51 UTC
Created attachment 33730 [details]
Javadocs fixes for XSSFFont
Comment 4 Javen O'Neal 2016-06-15 10:53:13 UTC
Or deprecate setBoldweight.
Comment 5 Javen O'Neal 2016-06-16 06:18:10 UTC
Are there any real usecases for using get/setBoldweight(short) when get/setBold(boolean) exists? I don't think Excel OOXML schema supports non-boolean bold values.
Are there any objections to deprecating get/setBoldweight?
Comment 6 Javen O'Neal 2016-06-16 06:53:05 UTC
Applied deprecation warning in r1748658.