use of org.apache.poi.hwpf.model.CHPX 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.CHPX in project poi by apache.
the class HWPFLister method dumpChpx.
public void dumpChpx(boolean withProperties, boolean withSprms) {
for (CHPX chpx : _doc.getCharacterTable().getTextRuns()) {
System.out.println(chpx);
if (withProperties) {
System.out.println(chpx.getCharacterProperties(_doc.getStyleSheet(), (short) StyleSheet.NIL_STYLE));
}
if (withSprms) {
SprmIterator sprmIt = new SprmIterator(chpx.getGrpprl(), 0);
while (sprmIt.hasNext()) {
SprmOperation sprm = sprmIt.next();
System.out.println("\t" + sprm);
}
}
String text = new Range(chpx.getStart(), chpx.getEnd(), _doc.getOverallRange()) {
public String toString() {
return "CHPX range (" + super.toString() + ")";
}
}.text();
StringBuilder stringBuilder = new StringBuilder();
for (char c : text.toCharArray()) {
if (c < 30)
stringBuilder.append("\\0x").append(Integer.toHexString(c));
else
stringBuilder.append(c);
}
System.out.println(stringBuilder);
}
}
use of org.apache.poi.hwpf.model.CHPX in project poi by apache.
the class Range method sanityCheck.
/**
* Method for debug purposes. Checks that all resolved elements are inside
* of current range.
*/
public boolean sanityCheck() {
if (_start < 0)
throw new AssertionError();
if (_start > _text.length())
throw new AssertionError();
if (_end < 0)
throw new AssertionError();
if (_end > _text.length())
throw new AssertionError();
if (_start > _end)
throw new AssertionError();
if (_charRangeFound) {
for (int c = _charStart; c < _charEnd; c++) {
CHPX chpx = _characters.get(c);
int left = Math.max(this._start, chpx.getStart());
int right = Math.min(this._end, chpx.getEnd());
if (left >= right)
throw new AssertionError();
}
}
if (_parRangeFound) {
for (int p = _parStart; p < _parEnd; p++) {
PAPX papx = _paragraphs.get(p);
int left = Math.max(this._start, papx.getStart());
int right = Math.min(this._end, papx.getEnd());
if (left >= right)
throw new AssertionError();
}
}
return true;
}
use of org.apache.poi.hwpf.model.CHPX in project poi by apache.
the class Range method delete.
public void delete() {
initAll();
int numSections = _sections.size();
int numRuns = _characters.size();
int numParagraphs = _paragraphs.size();
for (int x = _charStart; x < numRuns; x++) {
CHPX chpx = _characters.get(x);
chpx.adjustForDelete(_start, _end - _start);
}
for (int x = _parStart; x < numParagraphs; x++) {
PAPX papx = _paragraphs.get(x);
// System.err.println("Paragraph " + x + " was " + papx.getStart() +
// " -> " + papx.getEnd());
papx.adjustForDelete(_start, _end - _start);
// System.err.println("Paragraph " + x + " is now " +
// papx.getStart() + " -> " + papx.getEnd());
}
for (int x = _sectionStart; x < numSections; x++) {
SEPX sepx = _sections.get(x);
// System.err.println("Section " + x + " was " + sepx.getStart() +
// " -> " + sepx.getEnd());
sepx.adjustForDelete(_start, _end - _start);
// System.err.println("Section " + x + " is now " + sepx.getStart()
// + " -> " + sepx.getEnd());
}
if (_doc instanceof HWPFDocument) {
((BookmarksImpl) ((HWPFDocument) _doc).getBookmarks()).afterDelete(_start, (_end - _start));
}
_text.delete(_start, _end);
Range parent = _parent.get();
if (parent != null) {
parent.adjustForInsert(-(_end - _start));
}
// update the FIB.CCPText + friends field
adjustFIB(-(_end - _start));
}
Aggregations