Skip to content

Commit 00da3e2

Browse files
committed
Merge pull request #194 from Progi1984/pr180fromdevelop
#180 : Added language property to TextElement
2 parents 1597116 + d45f828 commit 00da3e2

File tree

15 files changed

+199
-46
lines changed

15 files changed

+199
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- ODPresentation & PowerPoint2007 Writer : Marker of Series in Line & Scatter chart is customizable - @Progi1984 GH-169
2020
- ODPresentation & PowerPoint2007 Writer : Outline of Series in Line & Scatter chart is customizable - @Progi1984 GH-169
2121
- PowerPoint2007 & Serialized Writer : Support for Zip Adapter - @Progi1984 GH-176
22+
- ODPresentation & PowerPoint2007 Writer : language property to TextElement - @skrajewski & @Progi1984 GH-180
2223
- ODPresentation & PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
2324

2425
## 0.6.0 - 2016-01-24

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contain the root `toctree` directive.
55
66
Welcome to PHPPresentation's documentation
7-
========================================
7+
==========================================
88

99
|PHPPresentation|
1010

@@ -34,6 +34,7 @@ PHPPresentation is a library written in pure PHP that provides a set of classes
3434

3535
shapes_chart
3636
shapes_comment
37+
shapes_richtext
3738
shapes_table
3839

3940
Indices and tables

docs/shapes.rst

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,22 @@ Example:
3030
Rich text
3131
---------
3232

33-
Rich text shapes contain paragraphs of texts. To create a rich text shape, use ``createRichTextShape`` method of slide.
34-
35-
Below are the properties that you can set for a rich text shape.
36-
37-
- ``wrap``
38-
- ``autoFit``
39-
- ``fontScale`` : font scale (in percentage) when autoFit = RichText::AUTOFIT_NORMAL
40-
- ``lnSpcReduction`` : line spacing reduction (in percentage) when autoFit = RichText::AUTOFIT_NORMAL
41-
- ``horizontalOverflow``
42-
- ``verticalOverflow``
43-
- ``upright``
44-
- ``vertical``
45-
- ``columns``
46-
- ``bottomInset`` in pixels
47-
- ``leftInset`` in pixels
48-
- ``rightInset`` in pixels
49-
- ``topInset`` in pixels
50-
- ``autoShrinkHorizontal`` (boolean)
51-
- ``autoShrinkVertical`` (boolean)
52-
53-
Properties that can be set for each paragraphs are as follow.
54-
55-
- ``alignment`` see *[Alignment](#alignment)*
56-
- ``font`` see *[Font](#font)*
57-
- ``bulletStyle`` see *[Bullet](#bullet)*
33+
The Rich text has :ref:`its own page <shapes_richtext>`.
5834

5935
Line
60-
-------
36+
----
6137

6238
To create a line, use `createLineShape` method of slide.
6339

6440
Chart
65-
-------
41+
-----
6642

67-
The Chart has now :ref:`its own page <shapes_chart>`.
43+
The Chart has :ref:`its own page <shapes_chart>`.
6844

6945
Comment
7046
-------
7147

72-
The Comment has now :ref:`its own page <shapes_comment>`.
48+
The Comment has :ref:`its own page <shapes_comment>`.
7349

7450
Drawing
7551
-------
@@ -84,6 +60,6 @@ To create a drawing, use `createDrawingShape` method of slide.
8460
->setPath('/path/to/drawing.filename');
8561
8662
Table
87-
-------
63+
-----
8864

89-
The Table has now :ref:`its own page <shapes_table>`.
65+
The Table has :ref:`its own page <shapes_table>`.

docs/shapes_comment.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _shapes_chart:
1+
.. _shapes_comment:
22

33
Comments
44
========

docs/shapes_richtext.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.. _shapes_richtext:
2+
3+
RichText
4+
========
5+
6+
Rich text shapes contain paragraphs of texts. To create a rich text shape, use ``createRichTextShape`` method of slide.
7+
8+
Below are the properties that you can set for a rich text shape.
9+
10+
- ``wrap``
11+
- ``autoFit``
12+
- ``fontScale`` : font scale (in percentage) when autoFit = RichText::AUTOFIT_NORMAL
13+
- ``lnSpcReduction`` : line spacing reduction (in percentage) when autoFit = RichText::AUTOFIT_NORMAL
14+
- ``horizontalOverflow``
15+
- ``verticalOverflow``
16+
- ``upright``
17+
- ``vertical``
18+
- ``columns``
19+
- ``bottomInset`` in pixels
20+
- ``leftInset`` in pixels
21+
- ``rightInset`` in pixels
22+
- ``topInset`` in pixels
23+
- ``autoShrinkHorizontal`` (boolean)
24+
- ``autoShrinkVertical`` (boolean)
25+
26+
Properties that can be set for each paragraphs are as follow.
27+
28+
- ``alignment`` see *[Alignment](#alignment)*
29+
- ``font`` see *[Font](#font)*
30+
- ``bulletStyle`` see *[Bullet](#bullet)*
31+
32+
33+
Run
34+
---
35+
36+
For a run, you can define the language.
37+
38+
Example:
39+
40+
.. code-block:: php
41+
42+
use PhpOffice\PhpPresentation\Shape\RichText\Run;
43+
44+
$oRun = new Run();
45+
$oComment->setLanguage('fr-FR');

src/PhpPresentation/Shape/RichText/BreakElement.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ public function getFont()
6060
return null;
6161
}
6262

63+
/**
64+
* Set language
65+
*
66+
* @param $lang
67+
* @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
68+
*/
69+
public function setLanguage($lang)
70+
{
71+
return $this;
72+
}
73+
74+
/**
75+
* Get language
76+
*
77+
* @return string Language
78+
*/
79+
public function getLanguage()
80+
{
81+
return null;
82+
}
83+
6384
/**
6485
* Get hash code
6586
*

src/PhpPresentation/Shape/RichText/TextElement.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class TextElement implements TextElementInterface
3131
*/
3232
private $text;
3333

34+
/**
35+
* @var string
36+
*/
37+
protected $language;
38+
3439
/**
3540
* Hyperlink
3641
*
@@ -120,6 +125,26 @@ public function setHyperlink(Hyperlink $pHyperlink = null)
120125
return $this;
121126
}
122127

128+
/**
129+
* Get language
130+
* @return string
131+
*/
132+
public function getLanguage()
133+
{
134+
return $this->language;
135+
}
136+
137+
/**
138+
* Set language
139+
* @param string $language
140+
* @return TextElement
141+
*/
142+
public function setLanguage($language)
143+
{
144+
$this->language = $language;
145+
return $this;
146+
}
147+
123148
/**
124149
* Get hash code
125150
*

src/PhpPresentation/Shape/RichText/TextElementInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public function setText($pText = '');
4444
*/
4545
public function getFont();
4646

47+
/**
48+
* @return string Language
49+
*/
50+
public function getLanguage();
51+
52+
/**
53+
* @param string $lang
54+
* @return \PhpOffice\PhpPresentation\Shape\RichText\TextElementInterface
55+
*/
56+
public function setLanguage($lang);
57+
4758
/**
4859
* Get hash code
4960
*

src/PhpPresentation/Writer/ODPresentation/Content.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Content extends AbstractPart
6565
/**
6666
* Stores font styles for text shapes that include lists.
6767
*
68-
* @var array
68+
* @var Run[]
6969
*/
7070
private $arrStyleTextFont = array();
7171

@@ -242,13 +242,15 @@ public function writePart(PhpPresentation $pPhpPresentation)
242242
$objWriter->writeAttribute('style:family', 'text');
243243
// style:text-properties
244244
$objWriter->startElement('style:text-properties');
245-
$objWriter->writeAttribute('fo:color', '#' . $item->getColor()->getRGB());
246-
$objWriter->writeAttribute('fo:font-family', $item->getName());
247-
$objWriter->writeAttribute('fo:font-size', $item->getSize() . 'pt');
245+
$objWriter->writeAttribute('fo:color', '#' . $item->getFont()->getColor()->getRGB());
246+
$objWriter->writeAttribute('fo:font-family', $item->getFont()->getName());
247+
$objWriter->writeAttribute('fo:font-size', $item->getFont()->getSize() . 'pt');
248248
// @todo : fo:font-style
249-
if ($item->isBold()) {
249+
if ($item->getFont()->isBold()) {
250250
$objWriter->writeAttribute('fo:font-weight', 'bold');
251251
}
252+
$objWriter->writeAttribute('fo:language', ($item->getLanguage() ? $item->getLanguage() : 'en-US'));
253+
252254
// @todo : style:text-underline-style
253255
$objWriter->endElement();
254256
$objWriter->endElement();
@@ -426,7 +428,7 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape)
426428
// text:span
427429
$objWriter->startElement('text:span');
428430
if ($richtext instanceof Run) {
429-
$objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getFont()->getHashCode());
431+
$objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getHashCode());
430432
}
431433
if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') {
432434
// text:a
@@ -491,7 +493,7 @@ public function writeShapeTxt(XMLWriter $objWriter, RichText $shape)
491493
// text:span
492494
$objWriter->startElement('text:span');
493495
if ($richtext instanceof Run) {
494-
$objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getFont()->getHashCode());
496+
$objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getHashCode());
495497
}
496498
if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') {
497499
// text:a
@@ -622,7 +624,7 @@ public function writeShapeTable(XMLWriter $objWriter, Table $shape)
622624
// text:span
623625
$objWriter->startElement('text:span');
624626
if ($shapeRichText instanceof Run) {
625-
$objWriter->writeAttribute('text:style-name', 'T_' . $shapeRichText->getFont()->getHashCode());
627+
$objWriter->writeAttribute('text:style-name', 'T_' . $shapeRichText->getHashCode());
626628
}
627629
if ($shapeRichText->hasHyperlink() === true && $shapeRichText->getHyperlink()->getUrl() != '') {
628630
// text:a
@@ -865,8 +867,8 @@ public function writeTxtStyle(XMLWriter $objWriter, RichText $shape)
865867
// Not a line break
866868
if ($richtext instanceof Run) {
867869
// Style des font text
868-
if (!isset($this->arrStyleTextFont[$richtext->getFont()->getHashCode()])) {
869-
$this->arrStyleTextFont[$richtext->getFont()->getHashCode()] = $richtext->getFont();
870+
if (!isset($this->arrStyleTextFont[$richtext->getHashCode()])) {
871+
$this->arrStyleTextFont[$richtext->getHashCode()] = $richtext;
870872
}
871873
}
872874
}
@@ -1032,8 +1034,8 @@ public function writeTableStyle(XMLWriter $objWriter, Table $shape)
10321034
foreach ($shapeParagraph->getRichTextElements() as $shapeRichText) {
10331035
if ($shapeRichText instanceof Run) {
10341036
// Style des font text
1035-
if (!isset($this->arrStyleTextFont[$shapeRichText->getFont()->getHashCode()])) {
1036-
$this->arrStyleTextFont[$shapeRichText->getFont()->getHashCode()] = $shapeRichText->getFont();
1037+
if (!isset($this->arrStyleTextFont[$shapeRichText->getHashCode()])) {
1038+
$this->arrStyleTextFont[$shapeRichText->getHashCode()] = $shapeRichText;
10371039
}
10381040
}
10391041
}

src/PhpPresentation/Writer/PowerPoint2007/PptSlides.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,9 @@ private function writeParagraphs(XMLWriter $objWriter, $paragraphs)
12001200
// a:rPr
12011201
$objWriter->startElement('a:rPr');
12021202

1203+
// Lang
1204+
$objWriter->writeAttribute('lang', ($element->getLanguage() ? $element->getLanguage() : 'en-US'));
1205+
12031206
// Bold
12041207
$objWriter->writeAttribute('b', ($element->getFont()->isBold() ? '1' : '0'));
12051208

0 commit comments

Comments
 (0)