Search in sources :

Example 1 with CharacterPropertyFetcher

use of org.apache.poi.xslf.model.CharacterPropertyFetcher in project poi by apache.

the class XSLFTextRun method getFontSize.

@Override
public Double getFontSize() {
    double scale = 1;
    CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTextBodyPr().getNormAutofit();
    if (afit != null)
        scale = (double) afit.getFontScale() / 100000;
    CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null && props.isSetSz()) {
                setValue(props.getSz() * 0.01);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue() == null ? null : fetcher.getValue() * scale;
}
Also used : CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextNormalAutofit(org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)

Example 2 with CharacterPropertyFetcher

use of org.apache.poi.xslf.model.CharacterPropertyFetcher in project poi by apache.

the class XSLFTextRun method getFontFamily.

@Override
public String getFontFamily() {
    final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
    CharacterPropertyFetcher<String> visitor = new CharacterPropertyFetcher<String>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null) {
                CTTextFont font = props.getLatin();
                if (font != null) {
                    String typeface = font.getTypeface();
                    if ("+mj-lt".equals(typeface)) {
                        typeface = theme.getMajorFont();
                    } else if ("+mn-lt".equals(typeface)) {
                        typeface = theme.getMinorFont();
                    }
                    setValue(typeface);
                    return true;
                }
            }
            return false;
        }
    };
    fetchCharacterProperty(visitor);
    return visitor.getValue();
}
Also used : CTTextFont(org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)

Example 3 with CharacterPropertyFetcher

use of org.apache.poi.xslf.model.CharacterPropertyFetcher in project poi by apache.

the class XSLFTextRun method getFontColor.

@Override
public PaintStyle getFontColor() {
    final boolean hasPlaceholder = getParentParagraph().getParentShape().getPlaceholder() != null;
    CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props == null) {
                return false;
            }
            XSLFShape shape = _p.getParentShape();
            CTShapeStyle style = shape.getSpStyle();
            CTSchemeColor phClr = null;
            if (style != null && style.getFontRef() != null) {
                phClr = style.getFontRef().getSchemeClr();
            }
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
            XSLFSheet sheet = shape.getSheet();
            PackagePart pp = sheet.getPackagePart();
            XSLFTheme theme = sheet.getTheme();
            PaintStyle ps = XSLFShape.selectPaint(fp, phClr, pp, theme, hasPlaceholder);
            if (ps != null) {
                setValue(ps);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 4 with CharacterPropertyFetcher

use of org.apache.poi.xslf.model.CharacterPropertyFetcher in project poi by apache.

the class XSLFTextRun method getTextCap.

/**
     * @return whether a run of text will be formatted as a superscript text. Default is false.
     */
public TextCap getTextCap() {
    CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null && props.isSetCap()) {
                int idx = props.getCap().intValue() - 1;
                setValue(TextCap.values()[idx]);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue() == null ? TextCap.NONE : fetcher.getValue();
}
Also used : CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 5 with CharacterPropertyFetcher

use of org.apache.poi.xslf.model.CharacterPropertyFetcher in project poi by apache.

the class XSLFTextRun method getPitchAndFamily.

public byte getPitchAndFamily() {
    // final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
    CharacterPropertyFetcher<Byte> visitor = new CharacterPropertyFetcher<Byte>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null) {
                CTTextFont font = props.getLatin();
                if (font != null) {
                    setValue(font.getPitchFamily());
                    return true;
                }
            }
            return false;
        }
    };
    fetchCharacterProperty(visitor);
    return visitor.getValue() == null ? 0 : visitor.getValue();
}
Also used : CTTextFont(org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)

Aggregations

CharacterPropertyFetcher (org.apache.poi.xslf.model.CharacterPropertyFetcher)5 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)5 CTTextFont (org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)1 CTTextNormalAutofit (org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)1