Search in sources :

Example 6 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class XSLFSlideShow method getSlideComments.

/**
	 * Returns all the comments for the given slide
	 */
@Internal
public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackageRelationshipCollection commentRels;
    PackagePart slidePart = getSlidePart(slide);
    try {
        commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation());
    } catch (InvalidFormatException e) {
        throw new IllegalStateException(e);
    }
    if (commentRels.size() == 0) {
        // No comments for this slide
        return null;
    }
    if (commentRels.size() > 1) {
        throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size());
    }
    try {
        PackagePart cPart = slidePart.getRelatedPart(commentRels.getRelationship(0));
        CmLstDocument commDoc = CmLstDocument.Factory.parse(cPart.getInputStream(), DEFAULT_XML_OPTIONS);
        return commDoc.getCmLst();
    } catch (InvalidFormatException e) {
        throw new IllegalStateException(e);
    }
}
Also used : CmLstDocument(org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument) PackageRelationshipCollection(org.apache.poi.openxml4j.opc.PackageRelationshipCollection) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) Internal(org.apache.poi.util.Internal)

Example 7 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class HSLFSlideMaster method setSlideShow.

/**
     * Assign SlideShow for this slide master.
     */
@Internal
@Override
protected void setSlideShow(HSLFSlideShow ss) {
    super.setSlideShow(ss);
    //after the slide show is assigned collect all available style records
    assert (_txmaster == null);
    _txmaster = new TxMasterStyleAtom[9];
    TxMasterStyleAtom txdoc = getSlideShow().getDocumentRecord().getEnvironment().getTxMasterStyleAtom();
    _txmaster[txdoc.getTextType()] = txdoc;
    TxMasterStyleAtom[] txrec = ((MainMaster) getSheetContainer()).getTxMasterStyleAtoms();
    for (int i = 0; i < txrec.length; i++) {
        int txType = txrec[i].getTextType();
        if (txType < _txmaster.length && _txmaster[txType] == null) {
            _txmaster[txType] = txrec[i];
        }
    }
    for (List<HSLFTextParagraph> paras : getTextParagraphs()) {
        for (HSLFTextParagraph htp : paras) {
            int txType = htp.getRunType();
            if (txType >= _txmaster.length || _txmaster[txType] == null) {
                throw new HSLFException("Master styles not initialized");
            }
            int level = htp.getIndentLevel();
            List<TextPropCollection> charStyles = _txmaster[txType].getCharacterStyles();
            List<TextPropCollection> paragraphStyles = _txmaster[txType].getParagraphStyles();
            if (charStyles == null || paragraphStyles == null || charStyles.size() <= level || paragraphStyles.size() <= level) {
                throw new HSLFException("Master styles not initialized");
            }
            htp.setMasterStyleReference(paragraphStyles.get(level));
            for (HSLFTextRun htr : htp.getTextRuns()) {
                htr.setMasterStyleReference(charStyles.get(level));
            }
        }
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) MainMaster(org.apache.poi.hslf.record.MainMaster) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection) TxMasterStyleAtom(org.apache.poi.hslf.record.TxMasterStyleAtom) Internal(org.apache.poi.util.Internal)

Example 8 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class SheetUtil method getDefaultCharWidth.

/**
     * Get default character width using the Workbook's default font
     *
     * @param wb the workbook to get the default character width from
     * @return default character width in pixels
     */
@Internal
public static int getDefaultCharWidth(final Workbook wb) {
    Font defaultFont = wb.getFontAt((short) 0);
    AttributedString str = new AttributedString(String.valueOf(defaultChar));
    copyAttributes(defaultFont, str, 0, 1);
    TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
    return (int) layout.getAdvance();
}
Also used : AttributedString(java.text.AttributedString) Font(org.apache.poi.ss.usermodel.Font) TextLayout(java.awt.font.TextLayout) Internal(org.apache.poi.util.Internal)

Example 9 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class PAPX method getParagraphProperties.

@Deprecated
@Internal
public ParagraphProperties getParagraphProperties(StyleSheet ss) {
    if (ss == null) {
        // TODO Fix up for Word 6/95
        return new ParagraphProperties();
    }
    short istd = getIstd();
    ParagraphProperties baseStyle = ss.getParagraphStyle(istd);
    ParagraphProperties props = ParagraphSprmUncompressor.uncompressPAP(baseStyle, getGrpprl(), 2);
    return props;
}
Also used : ParagraphProperties(org.apache.poi.hwpf.usermodel.ParagraphProperties) Internal(org.apache.poi.util.Internal)

Example 10 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class XSSFRowShifter method updateRowFormulas.

/**
     * Update the formulas in specified row using the formula shifting policy specified by shifter
     *
     * @param row the row to update the formulas on
     * @param shifter the formula shifting policy
     */
@Internal
public void updateRowFormulas(Row row, FormulaShifter shifter) {
    XSSFSheet sheet = (XSSFSheet) row.getSheet();
    for (Cell c : row) {
        XSSFCell cell = (XSSFCell) c;
        CTCell ctCell = cell.getCTCell();
        if (ctCell.isSetF()) {
            CTCellFormula f = ctCell.getF();
            String formula = f.getStringValue();
            if (formula.length() > 0) {
                String shiftedFormula = shiftFormula(row, formula, shifter);
                if (shiftedFormula != null) {
                    f.setStringValue(shiftedFormula);
                    if (f.getT() == STCellFormulaType.SHARED) {
                        int si = (int) f.getSi();
                        CTCellFormula sf = sheet.getSharedFormula(si);
                        sf.setStringValue(shiftedFormula);
                        updateRefInCTCellFormula(row, shifter, sf);
                    }
                }
            }
            //Range of cells which the formula applies to.
            updateRefInCTCellFormula(row, shifter, f);
        }
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) CTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) CTCellFormula(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula) CTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell) Cell(org.apache.poi.ss.usermodel.Cell) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) Internal(org.apache.poi.util.Internal)

Aggregations

Internal (org.apache.poi.util.Internal)13 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)4 TextLayout (java.awt.font.TextLayout)1 AttributedString (java.text.AttributedString)1 NoSuchElementException (java.util.NoSuchElementException)1 Stack (java.util.Stack)1 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)1 MainMaster (org.apache.poi.hslf.record.MainMaster)1 TxMasterStyleAtom (org.apache.poi.hslf.record.TxMasterStyleAtom)1 HWPFDocumentCore (org.apache.poi.hwpf.HWPFDocumentCore)1 LFO (org.apache.poi.hwpf.model.LFO)1 ListLevel (org.apache.poi.hwpf.model.ListLevel)1 ListTables (org.apache.poi.hwpf.model.ListTables)1 StyleSheet (org.apache.poi.hwpf.model.StyleSheet)1 ParagraphProperties (org.apache.poi.hwpf.usermodel.ParagraphProperties)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)1 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)1 Cell (org.apache.poi.ss.usermodel.Cell)1