use of org.apache.poi.hwpf.model.StyleSheet in project poi by apache.
the class Range method insertAfter.
/**
* Inserts a paragraph into the end of this range. The paragraph will
* contain one character run that has the default properties for the
* paragraph's style.
*
* It is necessary for the text to end with the character '\r'
*
* @param props
* The paragraph's properties.
* @param styleIndex
* The index of the paragraph's style in the style sheet.
* @param text
* The text to insert.
* @return A newly inserted paragraph.
* @deprecated POI 3.8 beta 4. Use code shall not work with {@link ParagraphProperties}
*/
@Deprecated
protected Paragraph insertAfter(ParagraphProperties props, int styleIndex, String text) {
initAll();
StyleSheet ss = _doc.getStyleSheet();
ParagraphProperties baseStyle = ss.getParagraphStyle(styleIndex);
CharacterProperties baseChp = ss.getCharacterStyle(styleIndex);
byte[] grpprl = ParagraphSprmCompressor.compressParagraphProperty(props, baseStyle);
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, 0, (short) styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex, 2);
_doc.getParagraphTable().insert(_parEnd, _end, buf);
_parEnd++;
insertAfter(text, baseChp);
return getParagraph(numParagraphs() - 1);
}
use of org.apache.poi.hwpf.model.StyleSheet 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.StyleSheet 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.StyleSheet in project poi by apache.
the class TestProblems method testSprmAIOOB.
/**
* AIOOB for TableSprmUncompressor.unCompressTAPOperation
*/
@Test
public void testSprmAIOOB() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc");
StyleSheet styleSheet = doc.getStyleSheet();
assertNotNull(styleSheet);
Range r = doc.getRange();
for (int x = 0; x < r.numSections(); x++) {
Section s = r.getSection(x);
for (int y = 0; y < s.numParagraphs(); y++) {
Paragraph paragraph = s.getParagraph(y);
assertNotNull(paragraph);
}
}
doc.close();
}
use of org.apache.poi.hwpf.model.StyleSheet in project poi by apache.
the class TestRangeProperties method testUnicodeStyling.
public void testUnicodeStyling() {
Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r");
Paragraph p1 = r.getParagraph(0);
Paragraph p7 = r.getParagraph(6);
StyleSheet ss = r._doc.getStyleSheet();
// Line ending in its own run each time!
assertEquals(2, p1.numCharacterRuns());
assertEquals(2, p7.numCharacterRuns());
CharacterRun c1a = p1.getCharacterRun(0);
CharacterRun c1b = p1.getCharacterRun(1);
CharacterRun c7a = p7.getCharacterRun(0);
CharacterRun c7b = p7.getCharacterRun(1);
// No Calibri
assertEquals("Times New Roman", c1a.getFontName());
assertEquals(22, c1a.getFontSize());
// No Calibri
assertEquals("Times New Roman", c1b.getFontName());
assertEquals(22, c1b.getFontSize());
assertEquals("Times New Roman", c7a.getFontName());
assertEquals(48, c7a.getFontSize());
assertEquals("Times New Roman", c7b.getFontName());
assertEquals(48, c7b.getFontSize());
// All use the default base style
assertEquals("Normal", ss.getStyleDescription(c1a.getStyleIndex()).getName());
assertEquals("Normal", ss.getStyleDescription(c1b.getStyleIndex()).getName());
assertEquals("Heading 1", ss.getStyleDescription(c7a.getStyleIndex()).getName());
assertEquals("Heading 1", ss.getStyleDescription(c7b.getStyleIndex()).getName());
// Now check where they crop up
assertEquals(0, c1a.getStartOffset());
assertEquals(p1_parts[0].length(), c1a.getEndOffset());
assertEquals(p1_parts[0].length(), c1b.getStartOffset());
assertEquals(p1_parts[0].length() + 1, c1b.getEndOffset());
assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1 + p1_parts[2].length() + 1 + p1_parts[3].length() + 1 + p1_parts[4].length() + 1 + p1_parts[5].length() + 1, c7a.getStartOffset());
assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1 + p1_parts[2].length() + 1 + p1_parts[3].length() + 1 + p1_parts[4].length() + 1 + p1_parts[5].length() + 1 + 1, c7a.getEndOffset());
assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1 + p1_parts[2].length() + 1 + p1_parts[3].length() + 1 + p1_parts[4].length() + 1 + p1_parts[5].length() + 1 + 1, c7b.getStartOffset());
assertEquals(p1_parts[0].length() + 1 + p1_parts[1].length() + 1 + p1_parts[2].length() + 1 + p1_parts[3].length() + 1 + p1_parts[4].length() + 1 + p1_parts[5].length() + 1 + p1_parts[6].length() + 1, c7b.getEndOffset());
// This document also has 22 styles
assertEquals(22, ss.numStyles());
// and none of their character runs either
for (int i = 0; i < r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
int styleIndex = p.getStyleIndex();
assertTrue(styleIndex < 22);
assertNotNull(ss.getStyleDescription(styleIndex).getName());
}
for (int i = 0; i < r.numCharacterRuns(); i++) {
CharacterRun c = r.getCharacterRun(i);
int styleIndex = c.getStyleIndex();
assertTrue(styleIndex < 22);
assertNotNull(ss.getStyleDescription(styleIndex).getName());
}
}
Aggregations