forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
2,713 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Ruby | ||
|
||
Ruby (phonetic guide) text can be added by using the ``addRuby`` method. Ruby elements require a ``RubyProperties`` object, a ``TextRun`` for the base text, and a ``TextRun`` for the actual ruby (phonetic guide) text. | ||
|
||
Here is one example for a complete ruby element setup: | ||
|
||
``` php | ||
<?php | ||
$phpWord = new PhpWord(); | ||
|
||
$section = $phpWord->addSection(); | ||
$properties = new RubyProperties(); | ||
$properties->setAlignment(RubyProperties::ALIGNMENT_RIGHT_VERTICAL); | ||
$properties->setFontFaceSize(10); | ||
$properties->setFontPointsAboveBaseText(4); | ||
$properties->setFontSizeForBaseText(18); | ||
$properties->setLanguageId('ja-JP'); | ||
|
||
$baseTextRun = new TextRun(null); | ||
$baseTextRun->addText('私'); | ||
$rubyTextRun = new TextRun(null); | ||
$rubyTextRun->addText('わたし'); | ||
|
||
$section->addRuby($baseTextRun, $rubyTextRun, $properties); | ||
``` | ||
|
||
- ``$baseTextRun``. ``TextRun`` to be used for the base text. | ||
- ``$rubyTextRun``. ``TextRun`` to be used for the ruby text. | ||
- ``$properties``. ``RubyProperties`` properties object for the ruby text. | ||
|
||
A title with a phonetic guide is a little more complex, but still possible. Make sure you add the appropraite title style to your document. | ||
|
||
```php | ||
$phpWord = new PhpWord(); | ||
$fontStyle = new Font(); | ||
$fontStyle->setAllCaps(true); | ||
$fontStyle->setBold(true); | ||
$fontStyle->setSize(24); | ||
$phpWord->addTitleStyle(1, ['name' => 'Arial', 'size' => 24, 'bold' => true, 'color' => '990000']); | ||
|
||
$section = $phpWord->addSection(); | ||
$properties = new RubyProperties(); | ||
$properties->setAlignment(RubyProperties::ALIGNMENT_RIGHT_VERTICAL); | ||
$properties->setFontFaceSize(10); | ||
$properties->setFontPointsAboveBaseText(4); | ||
$properties->setFontSizeForBaseText(18); | ||
$properties->setLanguageId('ja-JP'); | ||
|
||
$baseTextRun = new TextRun(null); | ||
$baseTextRun->addText('私'); | ||
$rubyTextRun = new TextRun(null); | ||
$rubyTextRun->addText('わたし'); | ||
|
||
$textRun = new TextRun(); | ||
$textRun->addRuby($baseTextRun, $rubyTextRun, $properties); | ||
$section->addTitle($textRun, 1); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
use PhpOffice\PhpWord\ComplexType\RubyProperties; | ||
use PhpOffice\PhpWord\Element\TextRun; | ||
|
||
include_once 'Sample_Header.php'; | ||
|
||
// New Word Document | ||
echo date('H:i:s'), ' Create sample for Ruby (Phonetic Guide) use', EOL; | ||
$phpWord = new PhpOffice\PhpWord\PhpWord(); | ||
|
||
// Section for demonstrating ruby (phonetic guide) features | ||
$section = $phpWord->addSection(); | ||
|
||
$section->addText('Here is some normal text with no ruby, also known as "phonetic guide", text.'); | ||
|
||
$properties = new RubyProperties(); | ||
$properties->setAlignment(RubyProperties::ALIGNMENT_CENTER); | ||
$properties->setFontFaceSize(10); | ||
$properties->setFontPointsAboveBaseText(20); | ||
$properties->setFontSizeForBaseText(18); | ||
$properties->setLanguageId('en-US'); | ||
|
||
$textRun = $section->addTextRun(); | ||
$textRun->addText('Here is a demonstration of ruby text for '); | ||
$baseTextRun = new TextRun(null); | ||
$baseTextRun->addText('this'); | ||
$rubyTextRun = new TextRun(null); | ||
$rubyTextRun->addText('ruby-text'); | ||
$textRun->addRuby($baseTextRun, $rubyTextRun, $properties); | ||
$textRun->addText(' word.'); | ||
|
||
$textRun = $section->addTextRun(); | ||
$properties = new RubyProperties(); | ||
$properties->setAlignment(RubyProperties::ALIGNMENT_CENTER); | ||
$properties->setFontFaceSize(10); | ||
$properties->setFontPointsAboveBaseText(20); | ||
$properties->setFontSizeForBaseText(18); | ||
$properties->setLanguageId('ja-JP'); | ||
$textRun->addText('Here is a demonstration of ruby text for Japanese text: '); | ||
$baseTextRun = new TextRun(null); | ||
$baseTextRun->addText('私'); | ||
$rubyTextRun = new TextRun(null); | ||
$rubyTextRun->addText('わたし'); | ||
$textRun->addRuby($baseTextRun, $rubyTextRun, $properties); | ||
|
||
$section->addText('You can also have ruby text for titles:'); | ||
|
||
$phpWord->addTitleStyle(1, ['name' => 'Arial', 'size' => 24, 'bold' => true, 'color' => '000099']); | ||
|
||
$properties = new RubyProperties(); | ||
$properties->setAlignment(RubyProperties::ALIGNMENT_CENTER); | ||
$properties->setFontFaceSize(10); | ||
$properties->setFontPointsAboveBaseText(50); | ||
$properties->setFontSizeForBaseText(18); | ||
$properties->setLanguageId('ja-JP'); | ||
|
||
$baseTextRun = new TextRun(null); | ||
$baseTextRun->addText('私'); | ||
$rubyTextRun = new TextRun(null); | ||
$rubyTextRun->addText('わたし'); | ||
$textRun = new TextRun(); | ||
$textRun->addRuby($baseTextRun, $rubyTextRun, $properties); | ||
$section->addTitle($textRun, 1); | ||
|
||
// Save file | ||
echo write($phpWord, basename(__FILE__, '.php'), $writers); | ||
if (!CLI) { | ||
include_once 'Sample_Footer.php'; | ||
} |
Oops, something went wrong.