You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XSSFFont.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.usermodel;
  16. import java.util.Objects;
  17. import org.apache.poi.common.usermodel.fonts.FontCharset;
  18. import org.apache.poi.ooxml.POIXMLException;
  19. import org.apache.poi.ss.usermodel.Font;
  20. import org.apache.poi.ss.usermodel.FontFamily;
  21. import org.apache.poi.ss.usermodel.FontScheme;
  22. import org.apache.poi.ss.usermodel.FontUnderline;
  23. import org.apache.poi.ss.usermodel.IndexedColors;
  24. import org.apache.poi.util.Internal;
  25. import org.apache.poi.util.Removal;
  26. import org.apache.poi.xssf.model.StylesTable;
  27. import org.apache.poi.xssf.model.ThemesTable;
  28. import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
  29. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
  30. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
  31. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
  32. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily;
  33. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
  34. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
  35. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
  36. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty;
  37. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
  38. import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
  39. import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
  40. import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
  41. /**
  42. * Represents a font used in a workbook.
  43. */
  44. public class XSSFFont implements Font {
  45. /**
  46. * By default, Microsoft Office Excel 2007 uses the Calibri font in font size 11
  47. */
  48. public static final String DEFAULT_FONT_NAME = "Calibri";
  49. /**
  50. * By default, Microsoft Office Excel 2007 uses the Calibri font in font size 11
  51. */
  52. public static final short DEFAULT_FONT_SIZE = 11;
  53. /**
  54. * Default font color is black
  55. * @see org.apache.poi.ss.usermodel.IndexedColors#BLACK
  56. */
  57. public static final short DEFAULT_FONT_COLOR = IndexedColors.BLACK.getIndex();
  58. private IndexedColorMap _indexedColorMap;
  59. private ThemesTable _themes;
  60. private final CTFont _ctFont;
  61. private int _index;
  62. /**
  63. * Create a new XSSFFont
  64. *
  65. * @param font the underlying CTFont bean
  66. */
  67. @Internal
  68. public XSSFFont(CTFont font) {
  69. _ctFont = font;
  70. _index = 0;
  71. }
  72. /**
  73. * Called from parsing styles.xml
  74. * @param font CTFont
  75. * @param index font index
  76. * @param colorMap for default or custom indexed colors
  77. */
  78. @Internal
  79. public XSSFFont(CTFont font, int index, IndexedColorMap colorMap) {
  80. _ctFont = font;
  81. _index = (short)index;
  82. _indexedColorMap = colorMap;
  83. }
  84. /**
  85. * Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
  86. */
  87. public XSSFFont() {
  88. this._ctFont = CTFont.Factory.newInstance();
  89. setFontName(DEFAULT_FONT_NAME);
  90. setFontHeight((double)DEFAULT_FONT_SIZE);
  91. }
  92. /**
  93. * get the underlying CTFont font
  94. */
  95. @Internal
  96. public CTFont getCTFont() {
  97. return _ctFont;
  98. }
  99. /**
  100. * get a boolean value for the boldness to use.
  101. *
  102. * @return boolean - bold
  103. */
  104. @Override
  105. public boolean getBold() {
  106. CTBooleanProperty bold = _ctFont.sizeOfBArray() == 0 ? null : _ctFont.getBArray(0);
  107. return (bold != null && bold.getVal());
  108. }
  109. /**
  110. * get character-set to use.
  111. *
  112. * @return int - character-set (0-255)
  113. * @see FontCharset
  114. */
  115. @Override
  116. public int getCharSet() {
  117. CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0);
  118. return charset == null ? FontCharset.ANSI.getNativeId() : FontCharset.valueOf(charset.getVal()).getNativeId();
  119. }
  120. /**
  121. * get the indexed color value for the font
  122. * References a color defined in IndexedColors.
  123. *
  124. * @return short - indexed color to use
  125. * @see IndexedColors
  126. */
  127. @Override
  128. public short getColor() {
  129. CTColor color = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.getColorArray(0);
  130. if (color == null) return IndexedColors.BLACK.getIndex();
  131. long index = color.getIndexed();
  132. if (index == XSSFFont.DEFAULT_FONT_COLOR) {
  133. return IndexedColors.BLACK.getIndex();
  134. } else if (index == IndexedColors.RED.getIndex()) {
  135. return IndexedColors.RED.getIndex();
  136. } else {
  137. return (short)index;
  138. }
  139. }
  140. /**
  141. * get the color value for the font
  142. * References a color defined as Standard Alpha Red Green Blue color value (ARGB).
  143. *
  144. * @return XSSFColor - rgb color to use
  145. */
  146. public XSSFColor getXSSFColor() {
  147. CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.getColorArray(0);
  148. if(ctColor != null) {
  149. XSSFColor color = XSSFColor.from(ctColor, _indexedColorMap);
  150. if(_themes != null) {
  151. _themes.inheritFromThemeAsRequired(color);
  152. }
  153. return color;
  154. } else {
  155. return null;
  156. }
  157. }
  158. /**
  159. * get the color value for the font
  160. * References a color defined in theme.
  161. *
  162. * @return short - theme defined to use
  163. */
  164. public short getThemeColor() {
  165. CTColor color = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.getColorArray(0);
  166. long index = color == null ? 0 : color.getTheme();
  167. return (short) index;
  168. }
  169. /**
  170. * Get the font height in unit's of 1/20th of a point.
  171. * <p>
  172. * For many users, the related {@link #getFontHeightInPoints()}
  173. * will be more helpful, as that returns font heights in the
  174. * more familiar points units, eg 10, 12, 14.
  175. * @return short - height in 1/20ths of a point
  176. * @see #getFontHeightInPoints()
  177. */
  178. @Override
  179. public short getFontHeight() {
  180. return (short)(getFontHeightRaw()*Font.TWIPS_PER_POINT);
  181. }
  182. /**
  183. * Get the font height in points.
  184. * <p>
  185. * This will return the same font height that is shown in Excel,
  186. * such as 10 or 14 or 28.
  187. * @return short - height in the familiar unit of measure - points
  188. * @see #getFontHeight()
  189. */
  190. @Override
  191. public short getFontHeightInPoints() {
  192. return (short)getFontHeightRaw();
  193. }
  194. /**
  195. * Return the raw font height, in points, but also
  196. * including fractions.
  197. */
  198. private double getFontHeightRaw() {
  199. CTFontSize size = _ctFont.sizeOfSzArray() == 0 ? null : _ctFont.getSzArray(0);
  200. if (size != null) {
  201. return size.getVal();
  202. }
  203. return DEFAULT_FONT_SIZE;
  204. }
  205. /**
  206. * get the name of the font (i.e. Arial)
  207. *
  208. * @return String - a string representing the name of the font to use
  209. */
  210. @Override
  211. public String getFontName() {
  212. CTFontName name = _ctFont.sizeOfNameArray() == 0 ? null : _ctFont.getNameArray(0);
  213. return name == null ? DEFAULT_FONT_NAME : name.getVal();
  214. }
  215. /**
  216. * get a boolean value that specify whether to use italics or not
  217. *
  218. * @return boolean - value for italic
  219. */
  220. @Override
  221. public boolean getItalic() {
  222. CTBooleanProperty italic = _ctFont.sizeOfIArray() == 0 ? null : _ctFont.getIArray(0);
  223. return italic != null && italic.getVal();
  224. }
  225. /**
  226. * get a boolean value that specify whether to use a strikeout horizontal line through the text or not
  227. *
  228. * @return boolean - value for strikeout
  229. */
  230. @Override
  231. public boolean getStrikeout() {
  232. CTBooleanProperty strike = _ctFont.sizeOfStrikeArray() == 0 ? null : _ctFont.getStrikeArray(0);
  233. return strike != null && strike.getVal();
  234. }
  235. /**
  236. * get normal,super or subscript.
  237. *
  238. * @return short - offset type to use (none,super,sub)
  239. * @see Font#SS_NONE
  240. * @see Font#SS_SUPER
  241. * @see Font#SS_SUB
  242. */
  243. @Override
  244. public short getTypeOffset() {
  245. CTVerticalAlignFontProperty vAlign = _ctFont.sizeOfVertAlignArray() == 0 ? null : _ctFont.getVertAlignArray(0);
  246. if (vAlign == null) {
  247. return Font.SS_NONE;
  248. }
  249. int val = vAlign.getVal().intValue();
  250. switch (val) {
  251. case STVerticalAlignRun.INT_BASELINE:
  252. return Font.SS_NONE;
  253. case STVerticalAlignRun.INT_SUBSCRIPT:
  254. return Font.SS_SUB;
  255. case STVerticalAlignRun.INT_SUPERSCRIPT:
  256. return Font.SS_SUPER;
  257. default:
  258. throw new POIXMLException("Wrong offset value " + val);
  259. }
  260. }
  261. /**
  262. * get type of text underlining to use
  263. *
  264. * @return byte - underlining type
  265. * @see org.apache.poi.ss.usermodel.FontUnderline
  266. */
  267. @Override
  268. public byte getUnderline() {
  269. CTUnderlineProperty underline = _ctFont.sizeOfUArray() == 0 ? null : _ctFont.getUArray(0);
  270. if (underline != null) {
  271. FontUnderline val = FontUnderline.valueOf(underline.getVal().intValue());
  272. return val.getByteValue();
  273. }
  274. return Font.U_NONE;
  275. }
  276. /**
  277. * set a boolean value for the boldness to use. If omitted, the default value is true.
  278. *
  279. * @param bold - boldness to use
  280. */
  281. @Override
  282. public void setBold(boolean bold) {
  283. if(bold){
  284. CTBooleanProperty ctBold = _ctFont.sizeOfBArray() == 0 ? _ctFont.addNewB() : _ctFont.getBArray(0);
  285. ctBold.setVal(true);
  286. } else {
  287. _ctFont.setBArray(null);
  288. }
  289. }
  290. /**
  291. * set character-set to use.
  292. *
  293. * @param charset - charset
  294. * @see FontCharset
  295. */
  296. @Override
  297. public void setCharSet(byte charset) {
  298. int cs = charset & 0xff;
  299. setCharSet(cs);
  300. }
  301. /**
  302. * set character-set to use.
  303. *
  304. * @param charset - charset
  305. * @see FontCharset
  306. */
  307. @Override
  308. public void setCharSet(int charset) {
  309. FontCharset fontCharset = FontCharset.valueOf(charset);
  310. if(fontCharset != null) {
  311. setCharSet(fontCharset);
  312. } else {
  313. throw new POIXMLException("Attention: an attempt to set a type of unknown charset and charset");
  314. }
  315. }
  316. /**
  317. * set character-set to use.
  318. *
  319. * @deprecated use {@link #setCharSet(FontCharset)} instead
  320. */
  321. @Deprecated
  322. @Removal(version = "6.0.0")
  323. public void setCharSet(org.apache.poi.ss.usermodel.FontCharset charSet) {
  324. CTIntProperty charsetProperty;
  325. if(_ctFont.sizeOfCharsetArray() == 0) {
  326. charsetProperty = _ctFont.addNewCharset();
  327. } else {
  328. charsetProperty = _ctFont.getCharsetArray(0);
  329. }
  330. // We know that FontCharset only has valid entries in it,
  331. // so we can just set the int value from it
  332. charsetProperty.setVal( charSet.getValue() );
  333. }
  334. /**
  335. * set character-set to use.
  336. *
  337. * @since 5.0.0
  338. */
  339. public void setCharSet(FontCharset charSet) {
  340. CTIntProperty charsetProperty;
  341. if(_ctFont.sizeOfCharsetArray() == 0) {
  342. charsetProperty = _ctFont.addNewCharset();
  343. } else {
  344. charsetProperty = _ctFont.getCharsetArray(0);
  345. }
  346. // We know that FontCharset only has valid entries in it,
  347. // so we can just set the int value from it
  348. charsetProperty.setVal( charSet.getNativeId() );
  349. }
  350. /**
  351. * set the indexed color for the font
  352. *
  353. * @param color - color to use
  354. * @see #DEFAULT_FONT_COLOR - Note: default font color
  355. * @see IndexedColors
  356. */
  357. @Override
  358. public void setColor(short color) {
  359. CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? _ctFont.addNewColor() : _ctFont.getColorArray(0);
  360. if (color == Font.COLOR_NORMAL) {
  361. ctColor.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
  362. } else {
  363. ctColor.setIndexed(color);
  364. }
  365. }
  366. /**
  367. * set the color for the font in Standard Alpha Red Green Blue color value
  368. *
  369. * @param color - color to use
  370. */
  371. public void setColor(XSSFColor color) {
  372. if(color == null) _ctFont.setColorArray(null);
  373. else {
  374. CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? _ctFont.addNewColor() : _ctFont.getColorArray(0);
  375. if (ctColor.isSetIndexed()) {
  376. ctColor.unsetIndexed();
  377. }
  378. ctColor.setRgb(color.getARGB());
  379. }
  380. }
  381. /**
  382. * set the font height in points.
  383. *
  384. * @param height - height in points
  385. */
  386. @Override
  387. public void setFontHeight(short height) {
  388. setFontHeight((double) height/Font.TWIPS_PER_POINT);
  389. }
  390. /**
  391. * set the font height in points.
  392. *
  393. * @param height - height in points
  394. */
  395. public void setFontHeight(double height) {
  396. CTFontSize fontSize = _ctFont.sizeOfSzArray() == 0 ? _ctFont.addNewSz() : _ctFont.getSzArray(0);
  397. fontSize.setVal(height);
  398. }
  399. /**
  400. * set the font height in points.
  401. *
  402. * @see #setFontHeight
  403. */
  404. @Override
  405. public void setFontHeightInPoints(short height) {
  406. setFontHeight((double)height);
  407. }
  408. /**
  409. * set the theme color for the font to use
  410. *
  411. * @param theme - theme color to use
  412. */
  413. public void setThemeColor(short theme) {
  414. CTColor ctColor = _ctFont.sizeOfColorArray() == 0 ? _ctFont.addNewColor() : _ctFont.getColorArray(0);
  415. ctColor.setTheme(theme);
  416. }
  417. /**
  418. * set the name for the font (i.e. Arial).
  419. * If the font doesn't exist (because it isn't installed on the system),
  420. * or the charset is invalid for that font, then another font should
  421. * be substituted.
  422. * The string length for this attribute shall be 0 to 31 characters.
  423. * Default font name is Calibri.
  424. *
  425. * @param name - value representing the name of the font to use
  426. * @see #DEFAULT_FONT_NAME
  427. */
  428. @Override
  429. public void setFontName(String name) {
  430. CTFontName fontName = _ctFont.sizeOfNameArray() == 0 ? _ctFont.addNewName() : _ctFont.getNameArray(0);
  431. fontName.setVal(name == null ? DEFAULT_FONT_NAME : name);
  432. }
  433. /**
  434. * set a boolean value for the property specifying whether to use italics or not
  435. * If omitted, the default value is true.
  436. *
  437. * @param italic - value for italics or not
  438. */
  439. @Override
  440. public void setItalic(boolean italic) {
  441. if(italic){
  442. CTBooleanProperty bool = _ctFont.sizeOfIArray() == 0 ? _ctFont.addNewI() : _ctFont.getIArray(0);
  443. bool.setVal(true);
  444. } else {
  445. _ctFont.setIArray(null);
  446. }
  447. }
  448. /**
  449. * set a boolean value for the property specifying whether to use a strikeout horizontal line through the text or not
  450. * If omitted, the default value is true.
  451. *
  452. * @param strikeout - value for strikeout or not
  453. */
  454. @Override
  455. public void setStrikeout(boolean strikeout) {
  456. if(strikeout) {
  457. CTBooleanProperty strike = _ctFont.sizeOfStrikeArray() == 0 ? _ctFont.addNewStrike() : _ctFont.getStrikeArray(0);
  458. strike.setVal(true);
  459. } else {
  460. _ctFont.setStrikeArray(null);
  461. }
  462. }
  463. /**
  464. * set normal,super or subscript, that representing the vertical-alignment setting.
  465. * Setting this to either subscript or superscript shall make the font size smaller if a
  466. * smaller font size is available.
  467. *
  468. * @param offset - offset type to use (none,super,sub)
  469. * @see #SS_NONE
  470. * @see #SS_SUPER
  471. * @see #SS_SUB
  472. */
  473. @Override
  474. public void setTypeOffset(short offset) {
  475. if(offset == Font.SS_NONE){
  476. _ctFont.setVertAlignArray(null);
  477. } else {
  478. CTVerticalAlignFontProperty offsetProperty = _ctFont.sizeOfVertAlignArray() == 0 ? _ctFont.addNewVertAlign() : _ctFont.getVertAlignArray(0);
  479. switch (offset) {
  480. case Font.SS_SUB:
  481. offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
  482. break;
  483. case Font.SS_SUPER:
  484. offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
  485. break;
  486. default:
  487. throw new IllegalStateException("Invalid type offset: " + offset);
  488. }
  489. }
  490. }
  491. /**
  492. * set the style of underlining that is used.
  493. * The none style is equivalent to not using underlining at all.
  494. *
  495. * @param underline - underline type to use
  496. * @see FontUnderline
  497. */
  498. @Override
  499. public void setUnderline(byte underline) {
  500. setUnderline(FontUnderline.valueOf(underline));
  501. }
  502. /**
  503. * set an enumeration representing the style of underlining that is used.
  504. * The none style is equivalent to not using underlining at all.
  505. * The possible values for this attribute are defined by the FontUnderline
  506. *
  507. * @param underline - FontUnderline enum value
  508. */
  509. public void setUnderline(FontUnderline underline) {
  510. if(underline == FontUnderline.NONE && _ctFont.sizeOfUArray() > 0){
  511. _ctFont.setUArray(null);
  512. } else {
  513. CTUnderlineProperty ctUnderline = _ctFont.sizeOfUArray() == 0 ? _ctFont.addNewU() : _ctFont.getUArray(0);
  514. STUnderlineValues.Enum val = STUnderlineValues.Enum.forInt(underline.getValue());
  515. ctUnderline.setVal(val);
  516. }
  517. }
  518. public String toString() {
  519. return _ctFont.toString();
  520. }
  521. /**
  522. * Perform a registration of ourselves
  523. * to the style table
  524. */
  525. public long registerTo(StylesTable styles) {
  526. return registerTo(styles, true);
  527. }
  528. public long registerTo(StylesTable styles, boolean force) {
  529. this._themes = styles.getTheme();
  530. this._index = styles.putFont(this, force);
  531. return this._index;
  532. }
  533. /**
  534. * Records the Themes Table that is associated with
  535. * the current font, used when looking up theme
  536. * based colours and properties.
  537. */
  538. public void setThemesTable(ThemesTable themes) {
  539. this._themes = themes;
  540. }
  541. /**
  542. * get the font scheme property.
  543. * is used only in StylesTable to create the default instance of font
  544. *
  545. * @return FontScheme
  546. * @see org.apache.poi.xssf.model.StylesTable#createDefaultFont()
  547. */
  548. @SuppressWarnings("JavadocReference")
  549. public FontScheme getScheme() {
  550. CTFontScheme scheme = _ctFont.sizeOfSchemeArray() == 0 ? null : _ctFont.getSchemeArray(0);
  551. return scheme == null ? FontScheme.NONE : FontScheme.valueOf(scheme.getVal().intValue());
  552. }
  553. /**
  554. * set font scheme property
  555. *
  556. * @param scheme - FontScheme enum value
  557. * @see FontScheme
  558. */
  559. public void setScheme(FontScheme scheme) {
  560. CTFontScheme ctFontScheme = _ctFont.sizeOfSchemeArray() == 0 ? _ctFont.addNewScheme() : _ctFont.getSchemeArray(0);
  561. STFontScheme.Enum val = STFontScheme.Enum.forInt(scheme.getValue());
  562. ctFontScheme.setVal(val);
  563. }
  564. /**
  565. * get the font family to use.
  566. *
  567. * @return the font family to use
  568. * @see org.apache.poi.ss.usermodel.FontFamily
  569. */
  570. public int getFamily() {
  571. CTFontFamily family = _ctFont.sizeOfFamilyArray() == 0 ? null : _ctFont.getFamilyArray(0);
  572. return family == null ? FontFamily.NOT_APPLICABLE.getValue() : FontFamily.valueOf(family.getVal()).getValue();
  573. }
  574. /**
  575. * Set the font family this font belongs to.
  576. * A font family is a set of fonts having common stroke width and serif characteristics.
  577. * The font name overrides when there are conflicting values.
  578. *
  579. * @param value - font family
  580. * @see FontFamily
  581. */
  582. public void setFamily(int value) {
  583. CTFontFamily family = _ctFont.sizeOfFamilyArray() == 0 ? _ctFont.addNewFamily() : _ctFont.getFamilyArray(0);
  584. family.setVal(value);
  585. }
  586. /**
  587. * set an enumeration representing the font family this font belongs to.
  588. * A font family is a set of fonts having common stroke width and serif characteristics.
  589. *
  590. * @param family font family
  591. * @see #setFamily(int value)
  592. */
  593. public void setFamily(FontFamily family) {
  594. setFamily(family.getValue());
  595. }
  596. @Override
  597. public int getIndex() {
  598. return _index;
  599. }
  600. /**
  601. * @return index
  602. * @deprecated use {@link #getIndex()} instead
  603. */
  604. @Deprecated
  605. @Removal(version = "6.0.0")
  606. @Override
  607. public int getIndexAsInt()
  608. {
  609. return _index;
  610. }
  611. public int hashCode(){
  612. return _ctFont.toString().hashCode();
  613. }
  614. public boolean equals(Object o){
  615. if(!(o instanceof XSSFFont)) return false;
  616. XSSFFont cf = (XSSFFont)o;
  617. // BUG 60845
  618. return Objects.equals(this.getItalic(), cf.getItalic())
  619. && Objects.equals(this.getBold(), cf.getBold())
  620. && Objects.equals(this.getStrikeout(), cf.getStrikeout())
  621. && Objects.equals(this.getCharSet(), cf.getCharSet())
  622. && Objects.equals(this.getColor(), cf.getColor())
  623. && Objects.equals(this.getFamily(), cf.getFamily())
  624. && Objects.equals(this.getFontHeight(), cf.getFontHeight())
  625. && Objects.equals(this.getFontName(), cf.getFontName())
  626. && Objects.equals(this.getScheme(), cf.getScheme())
  627. && Objects.equals(this.getThemeColor(), cf.getThemeColor())
  628. && Objects.equals(this.getTypeOffset(), cf.getTypeOffset())
  629. && Objects.equals(this.getUnderline(), cf.getUnderline())
  630. && Objects.equals(this.getXSSFColor(), cf.getXSSFColor());
  631. }
  632. }