Search in sources :

Example 11 with Internal

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

the class POIDocument method replaceDirectory.

/**
     * Replaces the attached directory, e.g. if this document is written
     * to a new POIFSFileSystem
     *
     * @param newDirectory the new directory
     * @return the old/previous directory
     */
@Internal
protected DirectoryNode replaceDirectory(DirectoryNode newDirectory) {
    DirectoryNode dn = directory;
    directory = newDirectory;
    return dn;
}
Also used : DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) Internal(org.apache.poi.util.Internal)

Example 12 with Internal

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

the class Paragraph method newParagraph.

@Internal
public static Paragraph newParagraph(Range parent, PAPX papx) {
    HWPFDocumentCore doc = parent._doc;
    ListTables listTables = doc.getListTables();
    StyleSheet styleSheet = doc.getStyleSheet();
    ParagraphProperties properties = new ParagraphProperties();
    properties.setIstd(papx.getIstd());
    properties = newParagraph_applyStyleProperties(styleSheet, papx, properties);
    properties = ParagraphSprmUncompressor.uncompressPAP(properties, papx.getGrpprl(), 2);
    if (properties.getIlfo() != 0 && listTables != null) {
        LFO lfo = null;
        try {
            lfo = listTables.getLfo(properties.getIlfo());
        } catch (NoSuchElementException exc) {
            log.log(POILogger.WARN, "Paragraph refers to LFO #", properties.getIlfo(), " that does not exists");
        }
        if (lfo != null) {
            final ListLevel listLevel = listTables.getLevel(lfo.getLsid(), properties.getIlvl());
            if (listLevel != null && listLevel.getGrpprlPapx() != null) {
                properties = ParagraphSprmUncompressor.uncompressPAP(properties, listLevel.getGrpprlPapx(), 0);
                // reapply style and local PAPX properties
                properties = newParagraph_applyStyleProperties(styleSheet, papx, properties);
                properties = ParagraphSprmUncompressor.uncompressPAP(properties, papx.getGrpprl(), 2);
            }
        }
    }
    if (properties.getIlfo() > 0)
        return new ListEntry(papx, properties, parent);
    return new Paragraph(papx, properties, parent);
}
Also used : HWPFDocumentCore(org.apache.poi.hwpf.HWPFDocumentCore) StyleSheet(org.apache.poi.hwpf.model.StyleSheet) LFO(org.apache.poi.hwpf.model.LFO) ListTables(org.apache.poi.hwpf.model.ListTables) NoSuchElementException(java.util.NoSuchElementException) ListLevel(org.apache.poi.hwpf.model.ListLevel) Internal(org.apache.poi.util.Internal)

Example 13 with Internal

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

the class XSLFColor method setColor.

/**
     * Sets the solid color
     *
     * @param color solid color
     */
@Internal
protected void setColor(Color color) {
    if (!(_xmlObject instanceof CTSolidColorFillProperties)) {
        LOGGER.log(POILogger.ERROR, "XSLFColor.setColor currently only supports CTSolidColorFillProperties");
        return;
    }
    CTSolidColorFillProperties fill = (CTSolidColorFillProperties) _xmlObject;
    if (fill.isSetSrgbClr()) {
        fill.unsetSrgbClr();
    }
    if (fill.isSetScrgbClr()) {
        fill.unsetScrgbClr();
    }
    if (fill.isSetHslClr()) {
        fill.unsetHslClr();
    }
    if (fill.isSetPrstClr()) {
        fill.unsetPrstClr();
    }
    if (fill.isSetSchemeClr()) {
        fill.unsetSchemeClr();
    }
    if (fill.isSetSysClr()) {
        fill.unsetSysClr();
    }
    float[] rgbaf = color.getRGBComponents(null);
    boolean addAlpha = (rgbaf.length == 4 && rgbaf[3] < 1f);
    CTPositiveFixedPercentage alphaPct;
    // see office open xml part 4 - 5.1.2.2.30 and 5.1.2.2.32
    if (isInt(rgbaf[0]) && isInt(rgbaf[1]) && isInt(rgbaf[2])) {
        // sRGB has a gamma of 2.2
        CTSRgbColor rgb = fill.addNewSrgbClr();
        byte[] rgbBytes = { (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() };
        rgb.setVal(rgbBytes);
        alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
    } else {
        CTScRgbColor rgb = fill.addNewScrgbClr();
        rgb.setR(DrawPaint.srgb2lin(rgbaf[0]));
        rgb.setG(DrawPaint.srgb2lin(rgbaf[1]));
        rgb.setB(DrawPaint.srgb2lin(rgbaf[2]));
        alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
    }
    // alpha (%)
    if (alphaPct != null) {
        alphaPct.setVal((int) (100000 * rgbaf[3]));
    }
}
Also used : CTScRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) CTSRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor) CTPositiveFixedPercentage(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveFixedPercentage) 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