Search in sources :

Example 1 with PAPX

use of org.apache.poi.hwpf.model.PAPX in project poi by apache.

the class Range method insertAfter.

/**
	 * Inserts text onto the end of this range and gives that text the
	 * CharacterProperties specified in props.
	 *
	 * @param text
	 *            The text to insert.
	 * @param props
	 *            The CharacterProperties to give the text.
	 * @return A new CharacterRun that has the given text and properties and is
	 *         n ow a part of the document.
	 * @deprecated POI 3.8 beta 4. User code should not work with {@link CharacterProperties}
	 */
@Deprecated
private CharacterRun insertAfter(String text, CharacterProperties props) {
    initAll();
    PAPX papx = _paragraphs.get(_parEnd - 1);
    short istd = papx.getIstd();
    StyleSheet ss = _doc.getStyleSheet();
    CharacterProperties baseStyle = ss.getCharacterStyle(istd);
    byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
    SprmBuffer buf = new SprmBuffer(grpprl, 0);
    _doc.getCharacterTable().insert(_charEnd, _end, buf);
    _charEnd++;
    return insertAfter(text);
}
Also used : StyleSheet(org.apache.poi.hwpf.model.StyleSheet) SprmBuffer(org.apache.poi.hwpf.sprm.SprmBuffer) PAPX(org.apache.poi.hwpf.model.PAPX)

Example 2 with PAPX

use of org.apache.poi.hwpf.model.PAPX in project poi by apache.

the class Range method insertBefore.

/**
	 * Inserts text into the front of this range and it gives that text the
	 * CharacterProperties specified in props.
	 *
	 * @param text
	 *            The text to insert.
	 * @param props
	 *            The CharacterProperties to give the text.
	 * @return A new CharacterRun that has the given text and properties and is
	 *         n ow a part of the document.
     * @deprecated POI 3.8 beta 4. User code should not work with {@link CharacterProperties}
	 */
@Deprecated
private CharacterRun insertBefore(String text, CharacterProperties props) {
    initAll();
    PAPX papx = _paragraphs.get(_parStart);
    short istd = papx.getIstd();
    StyleSheet ss = _doc.getStyleSheet();
    CharacterProperties baseStyle = ss.getCharacterStyle(istd);
    byte[] grpprl = CharacterSprmCompressor.compressCharacterProperty(props, baseStyle);
    SprmBuffer buf = new SprmBuffer(grpprl, 0);
    _doc.getCharacterTable().insert(_charStart, _start, buf);
    return insertBefore(text);
}
Also used : StyleSheet(org.apache.poi.hwpf.model.StyleSheet) SprmBuffer(org.apache.poi.hwpf.sprm.SprmBuffer) PAPX(org.apache.poi.hwpf.model.PAPX)

Example 3 with PAPX

use of org.apache.poi.hwpf.model.PAPX in project poi by apache.

the class Range method getCharacterRun.

/**
	 * Gets the character run at index. The index is relative to this range.
	 *
	 * @param index
	 *            The index of the character run to get.
	 * @return The character run at the specified index in this range.
	 */
public CharacterRun getCharacterRun(int index) {
    initCharacterRuns();
    if (index + _charStart >= _charEnd)
        throw new IndexOutOfBoundsException("CHPX #" + index + " (" + (index + _charStart) + ") not in range [" + _charStart + "; " + _charEnd + ")");
    CHPX chpx = _characters.get(index + _charStart);
    if (chpx == null) {
        return null;
    }
    short istd;
    if (this instanceof Paragraph) {
        istd = ((Paragraph) this)._istd;
    } else {
        int[] point = findRange(_paragraphs, Math.max(chpx.getStart(), _start), Math.min(chpx.getEnd(), _end));
        initParagraphs();
        int parStart = Math.max(point[0], _parStart);
        if (parStart >= _paragraphs.size()) {
            return null;
        }
        PAPX papx = _paragraphs.get(point[0]);
        istd = papx.getIstd();
    }
    return new CharacterRun(chpx, _doc.getStyleSheet(), istd, this);
}
Also used : CHPX(org.apache.poi.hwpf.model.CHPX) PAPX(org.apache.poi.hwpf.model.PAPX)

Example 4 with PAPX

use of org.apache.poi.hwpf.model.PAPX in project poi by apache.

the class Range method getParagraph.

/**
	 * Gets the paragraph at index. The index is relative to this range.
	 *
	 * @param index
	 *            The index of the paragraph to get.
	 * @return The paragraph at the specified index in this range.
	 */
public Paragraph getParagraph(int index) {
    initParagraphs();
    if (index + _parStart >= _parEnd)
        throw new IndexOutOfBoundsException("Paragraph #" + index + " (" + (index + _parStart) + ") not in range [" + _parStart + "; " + _parEnd + ")");
    PAPX papx = _paragraphs.get(index + _parStart);
    return Paragraph.newParagraph(this, papx);
}
Also used : PAPX(org.apache.poi.hwpf.model.PAPX)

Example 5 with PAPX

use of org.apache.poi.hwpf.model.PAPX in project poi by apache.

the class TestRangeProperties method testUnicodeParagraphDefinitions.

/**
     * Tests the raw definitions of the paragraphs of
     *  a unicode document
     */
public void testUnicodeParagraphDefinitions() {
    Range r = u.getRange();
    String[] p1_parts = u_page_1.split("\r");
    String[] p2_parts = u_page_2.split("\r");
    assertEquals(u_page_1 + page_break + "\r" + u_page_2, r.text());
    assertEquals(408, r.text().length());
    assertEquals(1, r.numSections());
    assertEquals(1, u.getSectionTable().getSections().size());
    Section s = r.getSection(0);
    assertEquals(u_page_1 + page_break + "\r" + u_page_2, s.text());
    assertEquals(0, s.getStartOffset());
    assertEquals(408, s.getEndOffset());
    List<PAPX> pDefs = r._paragraphs;
    // no PAPX reconstruction
    // assertEquals(36, pDefs.size());
    // with PAPX reconstruction
    assertEquals(36, pDefs.size());
    // Check that the last paragraph ends where it should do
    assertEquals(531, u.getOverallRange().text().length());
    PAPX pLast = pDefs.get(34);
    // assertEquals(530, pLast.getEnd());
    // Only care about the first few really though
    PAPX p0 = pDefs.get(0);
    PAPX p1 = pDefs.get(1);
    PAPX p2 = pDefs.get(2);
    PAPX p3 = pDefs.get(3);
    PAPX p4 = pDefs.get(4);
    // 5 paragraphs should get us to the end of our text
    assertTrue(p0.getStart() < 408);
    assertTrue(p0.getEnd() < 408);
    assertTrue(p1.getStart() < 408);
    assertTrue(p1.getEnd() < 408);
    assertTrue(p2.getStart() < 408);
    assertTrue(p2.getEnd() < 408);
    assertTrue(p3.getStart() < 408);
    assertTrue(p3.getEnd() < 408);
    assertTrue(p4.getStart() < 408);
    assertTrue(p4.getEnd() < 408);
    // Paragraphs should match with lines
    assertEquals(0, p0.getStart());
    assertEquals(p1_parts[0].length() + 1, p0.getEnd());
    assertEquals(p1_parts[0].length() + 1, p1.getStart());
    assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1, p1.getEnd());
    assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1, p2.getStart());
    assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1 + p1_parts[2].length() + 1, p2.getEnd());
}
Also used : PAPX(org.apache.poi.hwpf.model.PAPX)

Aggregations

PAPX (org.apache.poi.hwpf.model.PAPX)10 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)3 CHPX (org.apache.poi.hwpf.model.CHPX)3 StyleSheet (org.apache.poi.hwpf.model.StyleSheet)2 SprmBuffer (org.apache.poi.hwpf.sprm.SprmBuffer)2 SprmIterator (org.apache.poi.hwpf.sprm.SprmIterator)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 GenericPropertyNode (org.apache.poi.hwpf.model.GenericPropertyNode)1 PAPFormattedDiskPage (org.apache.poi.hwpf.model.PAPFormattedDiskPage)1 PlexOfCps (org.apache.poi.hwpf.model.PlexOfCps)1 SEPX (org.apache.poi.hwpf.model.SEPX)1 Paragraph (org.apache.poi.hwpf.usermodel.Paragraph)1