void setImprinted(boolean imprint);
int getFontSize();
- float getFontSizeAsFloat();
+ Double getFontSizeAsDouble();
void setFontSize(int halfPoints);
- void setFontSize(float halfPoints);
+ void setFontSize(double halfPoints);
int getCharacterSpacing();
void setCharacterSpacing(int twips);
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
/**
* Default Character Run style, from which other styles will override
* TODO Share logic with {@link XWPFRun} which also uses CTRPr
}
public int getFontSize() {
- if (rpr.isSetSz())
- return rpr.getSz().getVal().intValue() / 2;
- return -1;
+ BigDecimal bd = getFontSizeAsBigDecimal(0);
+ return bd == null ? -1 : bd.intValue();
+ }
+
+ public Double getFontSizeAsDouble() {
+ BigDecimal bd = getFontSizeAsBigDecimal(1);
+ return bd == null ? null : bd.doubleValue();
+ }
+
+ private BigDecimal getFontSizeAsBigDecimal(int scale) {
+ return (rpr != null && rpr.isSetSz()) ?
+ new BigDecimal(rpr.getSz().getVal()).divide(BigDecimal.valueOf(2)).setScale(scale, RoundingMode.HALF_UP) :
+ null;
}
}
* characters in the contents of this run when displayed.
*
* @return value representing the font size (non-integer size will be rounded with half rounding up)
- * @deprecated use {@link #getFontSizeAsFloat()}
+ * @deprecated use {@link #getFontSizeAsDouble()}
*/
@Deprecated
@Removal(version = "6.0.0")
@Override
public int getFontSize() {
- return getFontSizeAsBigDecimal(0).intValue();
+ BigDecimal bd = getFontSizeAsBigDecimal(0);
+ return bd == null ? -1 : bd.intValue();
}
/**
* @since POI 5.0.0
*/
@Override
- public float getFontSizeAsFloat() {
- return getFontSizeAsBigDecimal(1).floatValue();
+ public Double getFontSizeAsDouble() {
+ BigDecimal bd = getFontSizeAsBigDecimal(1);
+ return bd == null ? null : bd.doubleValue();
}
private BigDecimal getFontSizeAsBigDecimal(int scale) {
CTRPr pr = getRunProperties(false);
return (pr != null && pr.isSetSz()) ?
new BigDecimal(pr.getSz().getVal()).divide(BigDecimal.valueOf(2)).setScale(scale, RoundingMode.HALF_UP) :
- BigDecimal.valueOf(-1);
+ null;
}
/**
* @since POI 5.0.0
*/
@Override
- public void setFontSize(float size) {
+ public void setFontSize(double size) {
BigDecimal bd = BigDecimal.valueOf(size);
CTRPr pr = getRunProperties(true);
CTHpsMeasure ctSize = pr.isSetSz() ? pr.getSz() : pr.addNewSz();
XWPFRun run = new XWPFRun(ctRun, irb);
assertEquals(7, run.getFontSize());
- assertEquals(7.0f, run.getFontSizeAsFloat(), 0.01);
+ assertEquals(7.0, run.getFontSizeAsDouble(), 0.01);
run.setFontSize(24);
assertEquals(48, rpr.getSz().getVal().longValue());
run.setFontSize(24.5f);
assertEquals(49, rpr.getSz().getVal().longValue());
assertEquals(25, run.getFontSize());
- assertEquals(24.5f, run.getFontSizeAsFloat(), 0.01);
+ assertEquals(24.5, run.getFontSizeAsDouble(), 0.01);
}
@Test
assertNotNull(styles.getDefaultParagraphStyle());
assertEquals(11, styles.getDefaultRunStyle().getFontSize());
+ assertEquals(11.0, styles.getDefaultRunStyle().getFontSizeAsDouble(), 0.01);
assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
}
}
return _props.getHps();
}
- public float getFontSizeAsFloat()
+ public Double getFontSizeAsDouble()
{
- return (float)getFontSize();
+ return (double)getFontSize();
}
public void setFontSize(int halfPoints)
}
- public void setFontSize(float halfPoints)
+ public void setFontSize(double halfPoints)
{
setFontSize(BigDecimal.valueOf(halfPoints).setScale(0, RoundingMode.HALF_UP).intValue());
}