Search in sources :

Example 26 with CTTextCharacterProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.

the class TestXSSFDrawing method testRichText.

/**
     * ensure that rich text attributes defined in a XSSFRichTextString
     * are passed to XSSFSimpleShape.
     *
     * See Bugzilla 52219.
     */
@Test
public void testRichText() throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();
    XSSFDrawing drawing = sheet.createDrawingPatriarch();
    XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
    XSSFRichTextString rt = new XSSFRichTextString("Test String");
    XSSFFont font = wb.createFont();
    font.setColor(new XSSFColor(new Color(0, 128, 128)));
    font.setItalic(true);
    font.setBold(true);
    font.setUnderline(FontUnderline.SINGLE);
    rt.applyFont(font);
    shape.setText(rt);
    CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
    assertEquals(1, pr.sizeOfRArray());
    CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
    assertEquals(true, rPr.getB());
    assertEquals(true, rPr.getI());
    assertEquals(STTextUnderlineType.SNG, rPr.getU());
    assertArrayEquals(new byte[] { 0, (byte) 128, (byte) 128 }, rPr.getSolidFill().getSrgbClr().getVal());
    checkRewrite(wb);
    wb.close();
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) Test(org.junit.Test)

Example 27 with CTTextCharacterProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.

the class TestXSLFTextBox method testDefaultTextStyle.

/**
     * text box inherits default text proeprties from presentation.xml
     */
@Test
public void testDefaultTextStyle() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();
    // default character properties for paragraphs with level=1
    CTTextCharacterProperties pPr = ppt.getCTPresentation().getDefaultTextStyle().getLvl1PPr().getDefRPr();
    XSLFTextBox shape = slide.createTextBox();
    shape.setText("Apache POI");
    assertEquals(1, shape.getTextParagraphs().size());
    assertEquals(1, shape.getTextParagraphs().get(0).getTextRuns().size());
    XSLFTextRun r = shape.getTextParagraphs().get(0).getTextRuns().get(0);
    assertEquals(1800, pPr.getSz());
    assertEquals(18.0, r.getFontSize(), 0);
    assertEquals("Calibri", r.getFontFamily());
    pPr.setSz(900);
    pPr.getLatin().setTypeface("Arial");
    assertEquals(9.0, r.getFontSize(), 0);
    assertEquals("Arial", r.getFontFamily());
    // unset font size in presentation.xml. The value should be taken from master slide
    // from /p:sldMaster/p:txStyles/p:otherStyle/a:lvl1pPr/a:defRPr
    ppt.getCTPresentation().getDefaultTextStyle().getLvl1PPr().getDefRPr().unsetSz();
    pPr = slide.getSlideMaster().getXmlObject().getTxStyles().getOtherStyle().getLvl1PPr().getDefRPr();
    assertEquals(1800, pPr.getSz());
    assertEquals(18.0, r.getFontSize(), 0);
    pPr.setSz(2000);
    assertEquals(20.0, r.getFontSize(), 0);
    // Should never be
    pPr.unsetSz();
    assertNull(r.getFontSize());
    ppt.close();
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) Test(org.junit.Test)

Example 28 with CTTextCharacterProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.

the class TestXSLFTextShape method testTitleStyles.

@Test
public void testTitleStyles() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlideMaster master = ppt.getSlideMasters().get(0);
    XSLFTheme theme = master.getTheme();
    XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE);
    XSLFSlide slide = ppt.createSlide(layout);
    assertSame(layout, slide.getSlideLayout());
    assertSame(master, slide.getSlideMaster());
    XSLFTextShape titleShape = slide.getPlaceholder(0);
    titleShape.setText("Apache POI");
    XSLFTextParagraph paragraph = titleShape.getTextParagraphs().get(0);
    XSLFTextRun textRun = paragraph.getTextRuns().get(0);
    // level 1 : default title style on the master slide
    // /p:sldMaster/p:txStyles/p:titleStyle/a:lvl1pPr
    CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getTitleStyle().getLvl1PPr();
    CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
    assertEquals(4400, lv1CPr.getSz());
    assertEquals(44.0, textRun.getFontSize(), 0);
    assertEquals("+mj-lt", lv1CPr.getLatin().getTypeface());
    assertEquals("Calibri", theme.getMajorFont());
    assertEquals("Calibri", textRun.getFontFamily());
    lv1CPr.setSz(3200);
    assertEquals(32.0, textRun.getFontSize(), 0);
    lv1CPr.getLatin().setTypeface("Arial");
    assertEquals("Arial", textRun.getFontFamily());
    assertEquals(STTextAlignType.CTR, lv1PPr.getAlgn());
    assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
    lv1PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, paragraph.getTextAlign());
    // level 2: title placeholder on the master slide
    // /p:sldMaster/p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="title"]
    XSLFTextShape tx2 = master.getPlaceholder(0);
    CTTextParagraphProperties lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
    CTTextCharacterProperties lv2CPr = lv2PPr.addNewDefRPr();
    lv2CPr.setSz(3300);
    assertEquals(33.0, textRun.getFontSize(), 0);
    lv2CPr.addNewLatin().setTypeface("Times");
    assertEquals("Times", textRun.getFontFamily());
    lv2PPr.setAlgn(STTextAlignType.R);
    assertEquals(TextAlign.RIGHT, paragraph.getTextAlign());
    // level 3: title placeholder on the slide layout
    // /p:sldLayout /p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="ctrTitle"]
    XSLFTextShape tx3 = layout.getPlaceholder(0);
    CTTextParagraphProperties lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
    CTTextCharacterProperties lv3CPr = lv3PPr.addNewDefRPr();
    lv3CPr.setSz(3400);
    assertEquals(34.0, textRun.getFontSize(), 0);
    lv3CPr.addNewLatin().setTypeface("Courier New");
    assertEquals("Courier New", textRun.getFontFamily());
    lv3PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
    // level 4: default text properties in the shape itself
    // ./p:sp/p:txBody/a:lstStyle/a:lvl1pPr
    CTTextParagraphProperties lv4PPr = titleShape.getTextBody(true).getLstStyle().addNewLvl1PPr();
    CTTextCharacterProperties lv4CPr = lv4PPr.addNewDefRPr();
    lv4CPr.setSz(3500);
    assertEquals(35.0, textRun.getFontSize(), 0);
    lv4CPr.addNewLatin().setTypeface("Arial");
    assertEquals("Arial", textRun.getFontFamily());
    lv4PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, paragraph.getTextAlign());
    // level 5: text properties are defined in the text run
    CTTextParagraphProperties lv5PPr = paragraph.getXmlObject().addNewPPr();
    CTTextCharacterProperties lv5CPr = textRun.getRPr(false);
    lv5CPr.setSz(3600);
    assertEquals(36.0, textRun.getFontSize(), 0);
    lv5CPr.addNewLatin().setTypeface("Calibri");
    assertEquals("Calibri", textRun.getFontFamily());
    lv5PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
    ppt.close();
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties) Test(org.junit.Test)

Example 29 with CTTextCharacterProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties in project poi by apache.

the class XSLFPropertiesDelegate method getDelegate.

@SuppressWarnings("unchecked")
private static <T> T getDelegate(Class<T> clazz, XmlObject props) {
    Object obj = null;
    if (props == null) {
        return null;
    } else if (props instanceof CTShapeProperties) {
        obj = new ShapeDelegate((CTShapeProperties) props);
    } else if (props instanceof CTBackgroundProperties) {
        obj = new BackgroundDelegate((CTBackgroundProperties) props);
    } else if (props instanceof CTStyleMatrixReference) {
        obj = new StyleMatrixDelegate((CTStyleMatrixReference) props);
    } else if (props instanceof CTTableCellProperties) {
        obj = new TableCellDelegate((CTTableCellProperties) props);
    } else if (props instanceof CTNoFillProperties || props instanceof CTSolidColorFillProperties || props instanceof CTGradientFillProperties || props instanceof CTBlipFillProperties || props instanceof CTPatternFillProperties || props instanceof CTGroupFillProperties) {
        obj = new FillPartDelegate(props);
    } else if (props instanceof CTFillProperties) {
        obj = new FillDelegate((CTFillProperties) props);
    } else if (props instanceof CTLineProperties) {
        obj = new LineStyleDelegate((CTLineProperties) props);
    } else if (props instanceof CTTextCharacterProperties) {
        obj = new TextCharDelegate((CTTextCharacterProperties) props);
    } else {
        LOG.log(POILogger.ERROR, props.getClass() + " is an unknown properties type");
        return null;
    }
    if (clazz.isInstance(obj)) {
        return (T) obj;
    }
    LOG.log(POILogger.WARN, obj.getClass() + " doesn't implement " + clazz);
    return null;
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTNoFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) CTBackgroundProperties(org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties) CTTableCellProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties) CTPatternFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTPatternFillProperties) CTGradientFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) XmlObject(org.apache.xmlbeans.XmlObject) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) CTGroupFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupFillProperties)

Aggregations

CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)28 Test (org.junit.Test)6 CTTextFont (org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont)6 CharacterPropertyFetcher (org.apache.poi.xslf.model.CharacterPropertyFetcher)5 CTTextParagraph (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph)5 CTSolidColorFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)4 CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)4 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)3 Color (java.awt.Color)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)2 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)2 CTTextNormalAutofit (org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)1 CTFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties)1 CTGradientFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties)1