HTML writer fixes

* fixed HTML superscript, and added allcaps, smallcaps, and letter-spacing
* make Comment constructor attributes optional
This commit is contained in:
troosan 2017-11-05 00:27:14 +01:00 committed by GitHub
commit aa4c3f8486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 30 additions and 13 deletions

1
.gitignore vendored
View File

@ -19,4 +19,5 @@ vendor
phpword.ini
/.buildpath
/.project
/nbproject
/.php_cs.cache

View File

@ -29,6 +29,7 @@ This is the last version to support PHP 5.3
- Impossible to add element PreserveText in Section - @rvanlaak #452
- Added missing options for numbering format - @troosan #1041
- Fixed impossibility to set a different footer for first page - @ctrlaltca #1116
- Fixed styles not being applied by HTML writer, better pdf output - @sarke #1047 #500 #1139
v0.13.0 (31 July 2016)
-------------------

View File

@ -29,6 +29,9 @@
{
"name": "Roman Syroeshko",
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
},
{
"name": "Antoine de Troostembergh"
}
],
"require": {

View File

@ -41,14 +41,14 @@ master_doc = 'index'
# General information about the project.
project = u'PHPWord'
copyright = u'2014-2015, PHPWord Contributors'
copyright = u'2014-2017, PHPWord Contributors'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.13.0'
version = '0.14.0'
# The full version, including alpha/beta/rc tags.
release = version
@ -120,7 +120,7 @@ html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
#html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.

View File

@ -432,7 +432,7 @@ Comments
---------
Comments can be added to a document by using ``addComment``.
The comment can contain formatted text. Once the comment has been added, it can be linked to any to any element.
The comment can contain formatted text. Once the comment has been added, it can be linked to any element with ``setCommentStart``.
.. code-block:: php

View File

@ -34,7 +34,7 @@ Example:
{
"require": {
"phpoffice/phpword": "v0.13.*"
"phpoffice/phpword": "v0.14.*"
}
}

View File

@ -4,7 +4,7 @@ References
==========
ISO/IEC 29500, Third edition, 2012-09-01
---------------------
----------------------------------------
- `Part 1: Fundamentals and Markup Language Reference
<http://standards.iso.org/ittf/PubliclyAvailableStandards/c061750_ISO_IEC_29500-1_2012.zip>`__

View File

@ -21,7 +21,7 @@ $textrun->addText(' a test');
$section->addTextBreak(2);
// Let's create a comment that we will link to a start element and an end element
$commentWithStartAndEnd = new \PhpOffice\PhpWord\Element\Comment('Foo Bar', new \DateTime(), '');
$commentWithStartAndEnd = new \PhpOffice\PhpWord\Element\Comment('Foo Bar', new \DateTime());
$commentWithStartAndEnd->addText('A comment with a start and an end');
$phpWord->addComment($commentWithStartAndEnd);
@ -36,7 +36,7 @@ $textToEndOn->setCommentRangeEnd($commentWithStartAndEnd);
$section->addTextBreak(2);
// Let's add a comment on an image
$commentOnImage = new \PhpOffice\PhpWord\Element\Comment('Mr Smart', new \DateTime(), '');
$commentOnImage = new \PhpOffice\PhpWord\Element\Comment('Mr Smart', new \DateTime());
$imageComment = $commentOnImage->addTextRun();
$imageComment->addText('Hey, Mars does look ');
$imageComment->addText('red', array('color' => 'FF0000'));

View File

@ -57,7 +57,7 @@ class Comment extends TrackChange
* @param \DateTime $date
* @param string $initials
*/
public function __construct($author, $date, $initials)
public function __construct($author, $date = null, $initials = null)
{
parent::__construct($author, $date);
$this->initials = $initials;

View File

@ -47,7 +47,7 @@ class TrackChange extends AbstractContainer
* @param string $author
* @param \DateTime $date
*/
public function __construct($author, \DateTime $date)
public function __construct($author, \DateTime $date = null)
{
$this->author = $author;
$this->date = $date;

View File

@ -164,6 +164,8 @@ class Text extends AbstractElement
if ($pStyleIsObject) {
$styleWriter = new ParagraphStyleWriter($paragraphStyle);
$style = $styleWriter->write();
} elseif (is_string($paragraphStyle)) {
$style = $paragraphStyle;
}
if ($style) {
$attribute = $pStyleIsObject ? 'style' : 'class';
@ -186,6 +188,8 @@ class Text extends AbstractElement
if ($fStyleIsObject) {
$styleWriter = new FontStyleWriter($fontStyle);
$style = $styleWriter->write();
} elseif (is_string($fontStyle)) {
$style = $fontStyle;
}
if ($style) {
$attribute = $fStyleIsObject ? 'style' : 'class';

View File

@ -52,12 +52,17 @@ class Font extends AbstractStyle
$css['background'] = $this->getValueIf($fgColor != '', $fgColor);
$css['font-weight'] = $this->getValueIf($style->isBold(), 'bold');
$css['font-style'] = $this->getValueIf($style->isItalic(), 'italic');
$css['vertical-align'] = $this->getValueIf($style->isSuperScript(), 'italic');
$css['vertical-align'] = $this->getValueIf($style->isSuperScript(), 'super');
$css['vertical-align'] = $this->getValueIf($style->isSubScript(), 'sub');
$css['vertical-align'] = '';
$css['vertical-align'] .= $this->getValueIf($style->isSuperScript(), 'super');
$css['vertical-align'] .= $this->getValueIf($style->isSubScript(), 'sub');
$css['text-decoration'] = '';
$css['text-decoration'] .= $this->getValueIf($underline, 'underline ');
$css['text-decoration'] .= $this->getValueIf($lineThrough, 'line-through ');
$css['text-transform'] = $this->getValueIf($style->isAllCaps(), 'uppercase');
$css['font-variant'] = $this->getValueIf($style->isSmallCaps(), 'small-caps');
$spacing = $style->getSpacing();
$css['letter-spacing'] = $this->getValueIf(!is_null($spacing), ($spacing / 20) . 'pt');
return $this->assembleCss($css);
}

View File

@ -80,6 +80,9 @@ class Paragraph extends AbstractStyle
$after = $spacing->getAfter();
$css['margin-top'] = $this->getValueIf(!is_null($before), ($before / 20) . 'pt');
$css['margin-bottom'] = $this->getValueIf(!is_null($after), ($after / 20) . 'pt');
} else {
$css['margin-top'] = '0';
$css['margin-bottom'] = '0';
}
return $this->assembleCss($css);