Search in sources :

Example 11 with CTTextCharacterProperties

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

the class XSSFTextRun method getPitchAndFamily.

public byte getPitchAndFamily() {
    CTTextCharacterProperties rPr = getRPr();
    CTTextFont font = rPr.getLatin();
    if (font != null) {
        return font.getPitchFamily();
    }
    return 0;
}
Also used : CTTextFont(org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)

Example 12 with CTTextCharacterProperties

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

the class TestXSLFAutoShape method testTextRun.

@Test
public void testTextRun() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();
    XSLFAutoShape shape = slide.createAutoShape();
    assertEquals(0, shape.getTextParagraphs().size());
    XSLFTextParagraph p = shape.addNewTextParagraph();
    assertEquals(1, shape.getTextParagraphs().size());
    assertEquals(0, p.getTextRuns().size());
    XSLFTextRun r = p.addNewTextRun();
    CTTextCharacterProperties rPr = r.getRPr(false);
    assertNotNull(rPr);
    assertEquals(1, p.getTextRuns().size());
    assertSame(r, p.getTextRuns().get(0));
    // default font size for text boxes
    assertEquals(18.0, r.getFontSize(), 0);
    assertFalse(rPr.isSetSz());
    r.setFontSize(10.0);
    assertEquals(1000, rPr.getSz());
    r.setFontSize(12.5);
    assertEquals(1250, rPr.getSz());
    r.setFontSize(null);
    assertFalse(rPr.isSetSz());
    assertFalse(rPr.isSetLatin());
    // comes from the slide master
    assertEquals("Calibri", r.getFontFamily());
    r.setFontFamily(null);
    // comes from the slide master
    assertEquals("Calibri", r.getFontFamily());
    r.setFontFamily("Arial");
    assertEquals("Arial", r.getFontFamily());
    assertEquals("Arial", rPr.getLatin().getTypeface());
    r.setFontFamily("Symbol");
    assertEquals("Symbol", r.getFontFamily());
    assertEquals("Symbol", rPr.getLatin().getTypeface());
    r.setFontFamily(null);
    // comes from the slide master
    assertEquals("Calibri", r.getFontFamily());
    assertFalse(rPr.isSetLatin());
    assertFalse(r.isStrikethrough());
    assertFalse(rPr.isSetStrike());
    r.setStrikethrough(true);
    assertTrue(r.isStrikethrough());
    assertEquals(STTextStrikeType.SNG_STRIKE, rPr.getStrike());
    assertFalse(r.isBold());
    assertFalse(rPr.isSetB());
    r.setBold(true);
    assertTrue(r.isBold());
    assertEquals(true, rPr.getB());
    assertFalse(r.isItalic());
    assertFalse(rPr.isSetI());
    r.setItalic(true);
    assertTrue(r.isItalic());
    assertEquals(true, rPr.getI());
    assertFalse(r.isUnderlined());
    assertFalse(rPr.isSetU());
    r.setUnderlined(true);
    assertTrue(r.isUnderlined());
    assertEquals(STTextUnderlineType.SNG, rPr.getU());
    r.setText("Apache");
    assertEquals("Apache", r.getRawText());
    r.setText("POI");
    assertEquals("POI", r.getRawText());
    r.setText(null);
    assertNull(r.getRawText());
    ppt.close();
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) Test(org.junit.Test)

Example 13 with CTTextCharacterProperties

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

the class TestXSSFDrawing method testRichTextFontAndColor.

/**
     * ensure that font and color rich text attributes defined in a XSSFRichTextString
     * are passed to XSSFSimpleShape.
     *
     * See Bugzilla 54969.
     */
@Test
public void testRichTextFontAndColor() 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.setFontName("Arial");
    rt.applyFont(font);
    shape.setText(rt);
    CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
    assertEquals(1, pr.sizeOfRArray());
    CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
    assertEquals("Arial", rPr.getLatin().getTypeface());
    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 14 with CTTextCharacterProperties

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

the class XSLFAutoShape method initTextBody.

protected static void initTextBody(CTTextBody txBody) {
    CTTextBodyProperties bodypr = txBody.addNewBodyPr();
    bodypr.setAnchor(STTextAnchoringType.T);
    bodypr.setRtlCol(false);
    CTTextParagraph p = txBody.addNewP();
    p.addNewPPr().setAlgn(STTextAlignType.L);
    CTTextCharacterProperties endPr = p.addNewEndParaRPr();
    endPr.setLang("en-US");
    endPr.setSz(1100);
    p.addNewR().setT("");
    txBody.addNewLstStyle();
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextBodyProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties)

Example 15 with CTTextCharacterProperties

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

the class XSSFSimpleShape method prototype.

/**
     * Prototype with the default structure of a new auto-shape.
     */
protected static CTShape prototype() {
    if (prototype == null) {
        CTShape shape = CTShape.Factory.newInstance();
        CTShapeNonVisual nv = shape.addNewNvSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        nv.addNewCNvSpPr();
        CTShapeProperties sp = shape.addNewSpPr();
        CTTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPresetGeometry2D geom = sp.addNewPrstGeom();
        geom.setPrst(STShapeType.RECT);
        geom.addNewAvLst();
        CTTextBody body = shape.addNewTxBody();
        CTTextBodyProperties bodypr = body.addNewBodyPr();
        bodypr.setAnchor(STTextAnchoringType.T);
        bodypr.setRtlCol(false);
        CTTextParagraph p = body.addNewP();
        p.addNewPPr().setAlgn(STTextAlignType.L);
        CTTextCharacterProperties endPr = p.addNewEndParaRPr();
        endPr.setLang("en-US");
        endPr.setSz(1100);
        CTSolidColorFillProperties scfpr = endPr.addNewSolidFill();
        scfpr.addNewSrgbClr().setVal(new byte[] { 0, 0, 0 });
        body.addNewLstStyle();
        prototype = shape;
    }
    return prototype;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)

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