createTextRun() public method

Create text run (can be formatted)
public createTextRun ( string $pText = '' ) : PhpOffice\PhpPresentation\Shape\RichText\Run
$pText string Text
return PhpOffice\PhpPresentation\Shape\RichText\Run
示例#1
0
    return;
}
// Set titles and names
$pageHeading = str_replace('_', ' ', SCRIPT_FILENAME);
$pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - ";
$pageTitle .= 'PHPPresentation';
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";
$oShapeDrawing = new Drawing\File();
$oShapeDrawing->setName('PHPPresentation logo')->setDescription('PHPPresentation logo')->setPath('./resources/phppowerpoint_logo.gif')->setHeight(36)->setOffsetX(10)->setOffsetY(10);
$oShapeDrawing->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
$oShapeDrawing->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
// Create a shape (text)
$oShapeRichText = new RichText();
$oShapeRichText->setHeight(300)->setWidth(600)->setOffsetX(170)->setOffsetY(180);
$oShapeRichText->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $oShapeRichText->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)->setSize(60)->setColor(new Color('FFE06B20'));
// Populate samples
$files = '';
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if (preg_match('/^Sample_\\d+_/', $file)) {
            $name = str_replace('_', ' ', preg_replace('/(Sample_|\\.php)/', '', $file));
            $files .= "<li><a href='{$file}'>{$name}</a></li>";
        }
    }
    closedir($handle);
}
/**
 * Write documents
 *
示例#2
0
 public function testText()
 {
     $object = new RichText();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->addText());
     $this->assertCount(1, $object->getActiveParagraph()->getRichTextElements());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->addText(new TextElement()));
     $this->assertCount(2, $object->getActiveParagraph()->getRichTextElements());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->createText());
     $this->assertCount(3, $object->getActiveParagraph()->getRichTextElements());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\TextElement', $object->createText('ALPHA'));
     $this->assertCount(4, $object->getActiveParagraph()->getRichTextElements());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $object->createBreak());
     $this->assertCount(5, $object->getActiveParagraph()->getRichTextElements());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $object->createTextRun());
     $this->assertCount(6, $object->getActiveParagraph()->getRichTextElements());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $object->createTextRun('BETA'));
     $this->assertCount(7, $object->getActiveParagraph()->getRichTextElements());
     $this->assertEquals('ALPHA' . "\r\n" . 'BETA', $object->getPlainText());
     $this->assertEquals('ALPHA' . "\r\n" . 'BETA', (string) $object);
 }