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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations