Skip to content

Commit

Permalink
Merge branch 'master' into wordunimplemented2
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Jan 29, 2025
2 parents 93daccb + 2d27595 commit 870c827
Show file tree
Hide file tree
Showing 39 changed files with 1,888 additions and 49 deletions.
3 changes: 3 additions & 0 deletions docs/changes/1.x/1.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- Writer Word2007: Support for padding in Table Cell by [@Azamat8405](https://github.com/Azamat8405) in [#2697](https://github.com/PHPOffice/PHPWord/pull/2697)
- Added support for PHP 8.4 by [@Progi1984](https://github.com/Progi1984) in [#2660](https://github.com/PHPOffice/PHPWord/pull/2660)
- Autoload : Allow to use PHPWord without Composer fixing [#2543](https://github.com/PHPOffice/PHPWord/issues/2543), [#2552](https://github.com/PHPOffice/PHPWord/issues/2552), [#2716](https://github.com/PHPOffice/PHPWord/issues/2716), [#2717](https://github.com/PHPOffice/PHPWord/issues/2717) in [#2722](https://github.com/PHPOffice/PHPWord/pull/2722)
- Add Default font color for Word by [@Collie-IT](https://github.com/Collie-IT) in [#2700](https://github.com/PHPOffice/PHPWord/pull/2700)
- Writer HTML: Support Default font color by [@MichaelPFrey](https://github.com/MichaelPFrey)
- Add basic ruby text (phonetic guide) support for Word2007 and HTML Reader/Writer, RTF Writer, basic support for ODT writing by [@Deadpikle](https://github.com/Deadpikle) in [#2727](https://github.com/PHPOffice/PHPWord/pull/2727)

### Bug fixes

Expand Down
57 changes: 57 additions & 0 deletions docs/usage/elements/ruby.md
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);
```
5 changes: 3 additions & 2 deletions docs/usage/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ You can alter the default paper by using the following function:

### Default font

By default, every text appears in Arial 10 point. You can alter the
default font by using the following two functions:
By default, every text appears in Arial 10 point in the color black (000000).
You can alter the default font by using the following functions:

``` php
<?php

$phpWord->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontColor('FF0000');
$phpWord->setDefaultFontSize(12);
```

Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ nav:
- OLE Object: 'usage/elements/oleobject.md'
- Page Break: 'usage/elements/pagebreak.md'
- Preserve Text: 'usage/elements/preservetext.md'
- Ruby: 'usage/elements/ruby.md'
- Text: 'usage/elements/text.md'
- TextBox: 'usage/elements/textbox.md'
- Text Break: 'usage/elements/textbreak.md'
Expand Down
20 changes: 15 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ parameters:
count: 1
path: src/PhpWord/Shared/Html.php

-
message: "#^Method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseRuby\\(\\) has no return type specified\\.$#"
count: 1
path: src/PhpWord/Shared/Html.php

-
message: "#^Method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseStyleDeclarations\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -437,7 +442,7 @@ parameters:

-
message: "#^Parameter \\#1 \\$attribute of static method PhpOffice\\\\PhpWord\\\\Shared\\\\Html\\:\\:parseStyle\\(\\) expects DOMAttr, DOMNode given\\.$#"
count: 1
count: 3
path: src/PhpWord/Shared/Html.php

-
Expand Down Expand Up @@ -1046,14 +1051,14 @@ parameters:
path: src/PhpWord/Writer/ODText/Element/Table.php

-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:replacetabs\\(\\) has parameter \\$text with no type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\AbstractElement\\:\\:replaceTabs\\(\\) has parameter \\$text with no type specified\\.$#"
count: 1
path: src/PhpWord/Writer/ODText/Element/Text.php
path: src/PhpWord/Writer/ODText/Element/AbstractElement.php

-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:replacetabs\\(\\) has parameter \\$xmlWriter with no type specified\\.$#"
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\AbstractElement\\:\\:replaceTabs\\(\\) has parameter \\$xmlWriter with no type specified\\.$#"
count: 1
path: src/PhpWord/Writer/ODText/Element/Text.php
path: src/PhpWord/Writer/ODText/Element/AbstractElement.php

-
message: "#^Method PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Element\\\\Text\\:\\:writeChangeInsertion\\(\\) has parameter \\$start with no type specified\\.$#"
Expand Down Expand Up @@ -1684,6 +1689,11 @@ parameters:
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
count: 9
path: tests/PhpWordTests/Writer/HTML/ElementTest.php

-
message: "#^Cannot access property \\$length on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
count: 2
path: tests/PhpWordTests/Writer/HTML/Element/RubyTest.php

-
message: "#^Cannot call method item\\(\\) on DOMNodeList\\<DOMNode\\>\\|false\\.$#"
Expand Down
1 change: 1 addition & 0 deletions phpword.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ outputEscapingEnabled = false

defaultFontName = Arial
defaultFontSize = 10
defaultFontColor = 000000

[Paper]

Expand Down
70 changes: 70 additions & 0 deletions samples/Sample_46_RubyPhoneticGuide.php
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';
}
Loading

0 comments on commit 870c827

Please sign in to comment.