View | Details | Raw Unified | Return to bug 49908
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java (+46 lines)
Lines 18-23 Link Here
18
package org.apache.poi.hwpf.usermodel;
18
package org.apache.poi.hwpf.usermodel;
19
19
20
import org.apache.poi.hwpf.model.CHPX;
20
import org.apache.poi.hwpf.model.CHPX;
21
import org.apache.poi.hwpf.model.Ffn;
21
import org.apache.poi.hwpf.model.StyleSheet;
22
import org.apache.poi.hwpf.model.StyleSheet;
22
import org.apache.poi.hwpf.sprm.SprmBuffer;
23
import org.apache.poi.hwpf.sprm.SprmBuffer;
23
24
Lines 557-561 Link Here
557
558
558
    return cp;
559
    return cp;
559
  }
560
  }
561
  
562
  /**
563
   * Returns true, if the CharacterRun is a special character run containing a symbol, otherwise false.
564
   *
565
   * <p>In case of a symbol, the {@link #text()} method always returns a single character 0x0028, but word actually stores
566
   * the character in a different field. Use {@link #getSymbolCharacter()} to get that character and {@link #getSymbolFont()}
567
   * to determine its font.
568
   */
569
  public boolean isSymbol()
570
  {
571
    return isSpecialCharacter() && text().equals("\u0028");
572
  }
560
573
574
  /**
575
   * Returns the symbol character, if this is a symbol character run.
576
   * 
577
   * @see #isSymbol()
578
   * @throws IllegalStateException If this is not a symbol character run: call {@link #isSymbol()} first.
579
   */
580
  public char getSymbolCharacter()
581
  {
582
    if (isSymbol()) {
583
      return (char)_props.getXchSym();
584
    } else
585
      throw new IllegalStateException("Not a symbol CharacterRun");
586
  }
587
588
  /**
589
   * Returns the symbol font, if this is a symbol character run. Might return null, if the font index is not found in the font table.
590
   * 
591
   * @see #isSymbol()
592
   * @throws IllegalStateException If this is not a symbol character run: call {@link #isSymbol()} first.
593
   */
594
  public Ffn getSymbolFont()
595
  {
596
    if (isSymbol()) {
597
      Ffn[] fontNames = _doc.getFontTable().getFontNames();
598
599
      if (fontNames.length <= _props.getFtcSym())
600
        return null;
601
602
      return fontNames[_props.getFtcSym()];
603
    } else
604
      throw new IllegalStateException("Not a symbol CharacterRun");
605
  }
606
561
}
607
}

Return to bug 49908