* Table des matieres
* @throws ImpressException
*/
public void writeTOC(int sommaireIndex, TocDesc toc)
throws ImpressException {
BundleHelper bundle = BundleHelper.getInstance();
XDrawPage notesPage = findNotesPageByIndex(sommaireIndex);
// Suppression du shape principal
notesPage.remove(findShapeByType(notesPage, SHAPE_TYPE_PAGE));
// Mise en forme du shape de notes
XShape notesShape = findShapeByType(notesPage, SHAPE_TYPE_NOTES);
int xmargin = bundle.getTocXMargin() * 100;
int ymargin = bundle.getTocYMargin() * 100;
try {
notesShape.setPosition(new Point(xmargin, ymargin));
notesShape.setSize(new Size(21000 - 2 * xmargin,
29700 - 2 * ymargin));
XPropertySet xNotesShapeProps = unoCast(XPropertySet.class,
notesShape);
xNotesShapeProps.setPropertyValue("FillStyle", StyleHelper
.getFillStyle(bundle.getTocFillStyle()));
xNotesShapeProps.setPropertyValue("FillColor", bundle
.getTocFillColor());
xNotesShapeProps.setPropertyValue("ZOrder", 999);
} catch (Exception e) {
logger.warn("Probleme non prévu, mais pas forcément grace", e);
}
if (logger.isTraceEnabled()) {
traceShapes(notesPage);
}
// Zone de texte des notes
XText xNoteText = unoCast(XText.class, notesShape);
XTextCursor cursor = xNoteText.createTextCursor();
cursor.getStart();
XPropertySet xCursorProps = unoCast(XPropertySet.class, cursor);
tabStops = new TabStop[2];
tabStops[0] = new TabStop(xmargin, TabAlign.LEFT, ',', ' ');
tabStops[1] = new TabStop(21000 - 2 * xmargin - 2000, TabAlign.RIGHT,
',', '.');
// Remarque : je ne sais plus comment ça marche...
// Titre de la table de matieres
try {
applyTextStyle(xCursorProps, "preference.toc.notes.title");
xNoteText.insertString(cursor, toc.getTitle(), true);
xNoteText.insertControlCharacter(cursor,
ControlCharacter.PARAGRAPH_BREAK, false);
} catch (Exception e) {
e.printStackTrace();
}
Iterator<SlideDesc> iter = toc.getAllSlides().iterator();
int maxSize = (29700 - 2 * ymargin) / 40 - 18; // en nombre de points
int[] heights = bundle.getTocFontHeight();
int textSize = 2 * bundle.getTocTitleHeight();
while (iter.hasNext() && (textSize < maxSize)) {
SlideDesc slide = (SlideDesc) iter.next();
textSize += heights[slide.getLevel() - 1];
addContentEntry(xNoteText, cursor, slide);