Added Line element

This commit is contained in:
Bas-Jan 't Jong 2014-05-29 16:44:00 +02:00
parent 0fcea8209f
commit 1580113d7b
10 changed files with 1151 additions and 1 deletions

View File

@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
## 0.11.0 - Not yet released ## 0.11.0 - Not yet released
This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three new elements were added: TextBox, ListItemRun, and Field. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemeted. RTF reader were initiated. This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three new elements were added: TextBox, ListItemRun, Line and Field. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemeted. RTF reader were initiated.
### Features ### Features
@ -30,6 +30,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three
- RTF Writer: Ability to write document properties - @ivanlanin - RTF Writer: Ability to write document properties - @ivanlanin
- RTF Writer: Ability to write image - @ivanlanin - RTF Writer: Ability to write image - @ivanlanin
- Element: New `Field` element - @basjan GH-251 - Element: New `Field` element - @basjan GH-251
- Element: New `Line` element - @basjan
- RTF Reader: Basic RTF reader - @ivanlanin GH-72 - RTF Reader: Basic RTF reader - @ivanlanin GH-72
### Bugfixes ### Bugfixes

268
CHANGELOG.md~ Normal file
View File

@ -0,0 +1,268 @@
# Changelog
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
## 0.11.0 - Not yet released
This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Three new elements were added: TextBox, ListItemRun, and Field. Relative and absolute positioning for images and textboxes were added. Writer classes were refactored into parts, elements, and styles. ODT and RTF features were enhanced. Ability to add elements to PHPWord object via HTML were implemeted. RTF reader were initiated.
### Features
- Image: Ability to define relative and absolute positioning - @basjan GH-217
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
- Element: New `TextBox` element - @basjan @ivanlanin GH-228 GH-229 GH-231
- HTML: Ability to add elements to PHPWord object via html - @basjan GH-231
- Element: New `ListItemRun` element that can add a list item with inline formatting like a textrun - @basjan GH-235
- Table: Ability to add table inside a cell (nested table) - @ivanlanin GH-149
- RTF Writer: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin GH-158
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237
- RTF Writer: Ability to add links and page breaks in RTF - @ivanlanin GH-196
- ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200
- ODT Writer: Enable inline font style in TextRun - @ivanlanin
- ODT Writer: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin
- ODT Writer: Enable section and column - @ivanlanin
- PDF Writer: Add TCPDF and mPDF as optional PDF renderer library - @ivanlanin
- ODT Writer: Enable title element and custom document properties - @ivanlanin
- ODT Reader: Ability to read standard and custom document properties - @ivanlanin
- Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
- Image: Enable "image float left" - @ivanlanin GH-244
- RTF Writer: Ability to write document properties - @ivanlanin
- RTF Writer: Ability to write image - @ivanlanin
- Element: New `Field` element - @basjan GH-251
- RTF Reader: Basic RTF reader - @ivanlanin GH-72
### Bugfixes
- Header: All images added to the second header were assigned to the first header - @basjan GH-222
- Conversion: Fix conversion from cm to pixel, pixel to cm, and pixel to point - @basjan GH-233 GH-234
- PageBreak: Page break adds new line in the beginning of the new page - @ivanlanin GH-150
- Image: `marginLeft` and `marginTop` cannot accept float value - @ivanlanin GH-248
### Deprecated
- Static classes `Footnotes`, `Endnotes`, and `TOC`
- `Writer\Word2007\Part`: `Numbering::writeNumbering()`, `Settings::writeSettings()`, `WebSettings::writeWebSettings()`, `ContentTypes::writeContentTypes()`, `Styles::writeStyles()`, `Document::writeDocument()` all changed into `write()`
- `Writer\Word2007\Part\DocProps`: Split into `Writer\Word2007\Part\DocPropsCore` and `Writer\Word2007\Part\DocPropsApp`
- `Element\Title::getBookmarkId()` replaced by `Element\Title::getRelationId()`
- `Writer\HTML::writeDocument`: Replaced by `Writer\HTML::getContent`
### Miscellaneous
- License: Change the project license from LGPL 2.1 into LGPL 3.0 - GH-211
- Word2007 Writer: New `Style\Image` class - @ivanlanin
- Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin GH-206
- QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin
- Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin
- Docs: Create gh-pages branch for API documentation - @Progi1984 GH-154
- QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin GH-186
- Writer: Refactor writer parts using composite pattern - @ivanlanin
- Docs: Show code quality and test code coverage badge on README
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
- Shared: Unify PHP ZipArchive and PCLZip features into PhpWord ZipArchive - @ivanlanin
## 0.10.1 - 21 May 2014
This is a bugfix release for `php-zip` requirement in Composer.
- Change Composer requirements for php-zip from `require` to `suggest` - @bskrtich GH-246
## 0.10.0 - 4 May 2014
This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled. Basic ODText reader is introduced.
### Features
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
- Table: Add `tblGrid` element for Libre/Open Office table sizing - @gianis6 GH-183
- Footnote: Ability to insert textbreak in footnote `$footnote->addTextBreak()` - @ivanlanin
- Footnote: Ability to style footnote reference mark by using `FootnoteReference` style - @ivanlanin
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185
- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb GH-189
- Table: Ability to add footnote in table cell - @ivanlanin GH-187
- Footnote: Ability to add image in footnote - @ivanlanin GH-187
- ListItem: Ability to add list item in header/footer - @ivanlanin GH-187
- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
- Link: Ability to add link in header/footer - @ivanlanin GH-187
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
- General: Add `Style::resetStyles()` - @ivanlanin GH-187
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
- Endnote: Ability to add endnotes - @ivanlanin
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
- ODT Writer: Basic table writing support - @ivanlanin
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
- HTML Writer: Basic HTML writer: text, textrun, link, title, textbreak, table, image (as Base64), footnote, endnote - @ivanlanin GH-203 GH-67 GH-147
- PDF Writer: Basic PDF writer using DomPDF: All HTML element except image - @ivanlanin GH-68
- DOCX Writer: Change `docProps/app.xml` `Application` to `PHPWord` - @ivanlanin
- DOCX Writer: Create `word/settings.xml` and `word/webSettings.xml` dynamically - @ivanlanin
- ODT Writer: Basic image writing - @ivanlanin
- ODT Writer: Link writing - @ivanlanin
- ODT Reader: Basic ODText Reader - @ivanlanin GH-71
- Section: Ability to define gutter and line numbering - @ivanlanin
- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199
- Style: Remove `bgColor` from `Font`, `Table`, and `Cell` and put it into the new `Shading` style - @ivanlanin
- Style: New `Indentation` and `Spacing` style - @ivanlanin
- Paragraph: Ability to define first line and right indentation - @ivanlanin
### Bugfixes
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
- Documentation: Error in a function - @theBeerNut GH-195
### Deprecated
- `createTextRun` replaced by `addTextRun`
- `createFootnote` replaced by `addFootnote`
- `createHeader` replaced by `addHeader`
- `createFooter` replaced by `addFooter`
- `createSection` replaced by `addSection`
- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
- All current methods on `Media`
- `Element\Link::getLinkSrc` replaced by `Element\Link::getTarget`
- `Element\Link::getLinkName` replaced by `Element\Link::getText`
- `Style\Cell::getDefaultBorderColor`
### Miscellaneous
- Documentation: Simplify page level docblock - @ivanlanin GH-179
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
- Refactor: Remove Style\Tabs - @ivanlanin
- Refactor: Apply composite pattern for writers - @ivanlanin
- Refactor: Split `AbstractContainer` from `AbstractElement` - @ivanlanin
- Refactor: Apply composite pattern for Word2007 reader - @ivanlanin
## 0.9.1 - 27 Mar 2014
This is a bugfix release for PSR-4 compatibility.
- Fixed PSR-4 composer autoloader - @AntonTyutin
## 0.9.0 - 26 Mar 2014
This release marked the transformation to namespaces (PHP 5.3+).
### Features
- Image: Ability to use remote or GD images using `addImage()` on sections, headers, footer, cells, and textruns - @ivanlanin
- Header: Ability to use remote or GD images using `addWatermark()` - @ivanlanin
### Bugfixes
- Preserve text doesn't render correctly when the text is not the first word, e.g. 'Page {PAGE}' - @ivanlanin
### Miscellaneous
- Move documentation to [Read The Docs](http://phpword.readthedocs.org/en/develop/) - @Progi1984 @ivanlanin GH-82
- Reorganize and redesign samples folder - @ivanlanin GH-137
- Use `PhpOffice\PhpWord` namespace for PSR compliance - @RomanSyroeshko @gabrielbull GH-159 GH-58
- Restructure folders and change folder name `Classes` to `src` and `Tests` to `test` for PSR compliance - @RomanSyroeshko @gabrielbull
- Compliance to phpDocumentor - @ivanlanin
- Merge Style\TableFull into Style\Table. Style\TableFull is deprecated - @ivanlanin GH-160
- Merge Section\MemoryImage into Section\Image. Section\Image is deprecated - @ivanlanin GH-160
## 0.8.1 - 17 Mar 2014
This is a bugfix release for image detection functionality.
- Added fallback for computers that do not have exif_imagetype - @bskrtich, @gabrielbull
## 0.8.0 - 15 Mar 2014
This release merged a lot of improvements from the community. Unit tests introduced in this release and has reached 90% code coverage.
### Features
- Template: Permit to save a template generated as a file (PHPWord_Template::saveAs()) - @RomanSyroeshko GH-56 GH-57
- Word2007: Support sections page numbering - @gabrielbull
- Word2007: Added line height methods to mirror the line height settings in Word in the paragraph styling - @gabrielbull
- Word2007: Added support for page header & page footer height - @JillElaine GH-5
- General: Add ability to manage line breaks after image insertion - @bskrtich GH-6 GH-66 GH-84
- Template: Ability to limit number of replacements performed by setValue() method of Template class - @RomanSyroeshko GH-52 GH-53 GH-85
- Table row: Repeat as header row & allow row to break across pages - @ivanlanin GH-48 GH-86
- Table: Table width in percentage - @ivanlanin GH-48 GH-86
- Font: Superscript and subscript - @ivanlanin GH-48 GH-86
- Paragraph: Hanging paragraph - @ivanlanin GH-48 GH-86
- Section: Multicolumn and section break - @ivanlanin GH-48 GH-86
- Template: Ability to apply XSL style sheet to Template - @RomanSyroeshko GH-46 GH-47 GH-83
- General: PHPWord_Shared_Font::pointSizeToTwips() converter - @ivanlanin GH-87
- Paragraph: Ability to define normal paragraph style with PHPWord::setNormalStyle() - @ivanlanin GH-87
- Paragraph: Ability to define parent style (basedOn) and style for following paragraph (next) - @ivanlanin GH-87
- Clone table rows on the fly when using a template document - @jeroenmoors GH-44 GH-88
- Initial addition of basic footnote support - @deds GH-16
- Paragraph: Ability to define paragraph pagination: widow control, keep next, keep lines, and page break before - @ivanlanin GH-92
- General: PHPWord_Style_Font refactoring - @ivanlanin GH-93
- Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing. - @ivanlanin GH-93
- Paragraph: setTabs() function - @ivanlanin GH-92
- General: Basic support for TextRun on ODT and RTF - @ivanlanin GH-99
- Reader: Basic Reader for Word2007 - @ivanlanin GH-104
- TextRun: Allow Text Break in Text Run - @bskrtich GH-109
- General: Support for East Asian fontstyle - @jhfangying GH-111 GH-118
- Image: Use exif_imagetype to check image format instead of extension name - @gabrielbull GH-114
- General: Setting for XMLWriter Compatibility option - @bskrtich GH-103
- MemoryImage: Allow remote image when allow_url_open = on - @ivanlanin GH-122
- TextBreak: Allow font and paragraph style for text break - @ivanlanin GH-18
### Bugfixes
- Fixed bug with cell styling - @gabrielbull
- Fixed bug list items inside of cells - @gabrielbull
- Adding a value that contains "&" in a template breaks it - @SiebelsTim GH-51
- Example in README.md is broken - @Progi1984 GH-89
- General: PHPWord_Shared_Drawing::centimetersToPixels() conversion - @ivanlanin GH-94
- Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote - @ivanlanin GH-125
### Miscellaneous
- UnitTests - @Progi1984
## 0.7.0 - 28 Jan 2014
This is the first release after a long development hiatus in [CodePlex](https://phpword.codeplex.com/). This release initialized ODT and RTF Writer, along with some other new features for the existing Word2007 Writer, e.g. tab, multiple header, rowspan and colspan. [Composer](https://packagist.org/packages/phpoffice/phpword) and [Travis](https://travis-ci.org/PHPOffice/PHPWord) were added.
### Features
- Implement RTF Writer - @Progi1984 GH-1
- Implement ODT Writer - @Progi1984 GH-2
- Word2007: Add rowspan and colspan to cells - @kaystrobach
- Word2007: Support for tab stops - @RLovelett
- Word2007: Support Multiple headers - @RLovelett
- Word2007: Wrapping Styles to Images - @gabrielbull
- Added support for image wrapping style - @gabrielbull
### Bugfixes
- "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found - @RomanSyroeshko GH-32
- PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input - @RomanSyroeshko GH-34
- Temporary files naming logic in PHPWord_Template can lead to a collision - @RomanSyroeshko GH-38
### Miscellaneous
- Add superscript/subscript styling in Excel2007 Writer - @MarkBaker
- add indentation support to paragraphs - @deds
- Support for Composer - @Progi1984 GH-27
- Basic CI with Travis - @Progi1984
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
- IMPROVED: Moved examples out of Classes directory - @Progi1984
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo CP-49

View File

@ -0,0 +1,64 @@
<?php
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->addSection();
// Add Line elements
// See Element/Line.php for all options
$section->addText('Horizontal Line (Inline style):');
$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
'positioning' => 'absolute'
)
);
$section->addText('Vertical Line (Inline style):');
$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1),
'positioning' => 'absolute'
)
);
// Two text break
$section->addTextBreak(1);
$section->addText('Positioned Line (red):');
$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1),
'positioning' => 'absolute',
'posHorizontalRel' => 'page',
'posVerticalRel' => 'page',
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(10),
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(8),
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
'color' => 'red'
)
);
$section->addText('Horizontal Formatted Line');
$section->addLine(
array(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
'positioning' => 'absolute',
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10
)
);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}

View File

@ -156,6 +156,19 @@ abstract class AbstractContainer extends AbstractElement
} }
/**
* Add line element
*
* @param mixed $lineStyle
* @return \PhpOffice\PhpWord\Element\Line
*/
public function addLine($lineStyle = null)
{
return $this->addElement('Line', $lineStyle);
}
/** /**
* Add link element * Add link element
* *
@ -331,6 +344,7 @@ abstract class AbstractContainer extends AbstractElement
'Image' => $allContainers, 'Image' => $allContainers,
'Object' => $allContainers, 'Object' => $allContainers,
'Field' => $allContainers, 'Field' => $allContainers,
'Line' => $allContainers,
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),

View File

@ -0,0 +1,54 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Line as LineStyle;
/**
* Line element
*/
class Line extends AbstractElement
{
/**
* Line style
*
* @var LineStyle
*/
private $style;
/**
* Create new line element
*
* @param string $source
* @param mixed $style
*/
public function __construct($style = null)
{
$this->style = $this->setStyle(new LineStyle(), $style);
}
/**
* Get Image style
*
* @return ImageStyle
*/
public function getStyle()
{
return $this->style;
}
}

256
src/PhpWord/Style/Line.php Normal file
View File

@ -0,0 +1,256 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Style;
/**
* Line style
*/
class Line extends Image
{
/**
* Connector types
*
* @const string
*/
const CONNECTOR_TYPE_STRAIGHT = 'straight';
/**
* Arrow styles
*
* @const string
*/
const ARROW_STYLE_BLOCK = 'block';
const ARROW_STYLE_OPEN = 'open';
const ARROW_STYLE_CLASSIC = 'classic';
const ARROW_STYLE_DIAMOND = 'diamond';
const ARROW_STYLE_OVAL = 'oval';
/**
* Dash styles
*
* @const string
*/
const DASH_STYLE_DASH = 'dash';
const DASH_STYLE_ROUND_DOT = 'rounddot';
const DASH_STYLE_SQUARE_DOT = 'squaredot';
const DASH_STYLE_DASH_DOT = 'dashdot';
const DASH_STYLE_LONG_DASH = 'longdash';
const DASH_STYLE_LONG_DASH_DOT = 'longdashdot';
const DASH_STYLE_LONG_DASH_DOT_DOT = 'longdashdotdot';
/**
* flip Line
*
* @var boolean
*/
private $flip = false;
/**
* connectorType
*
* @var string
*/
private $connectorType = self::CONNECTOR_TYPE_STRAIGHT;
/**
* Line Weight
*
* @var int
*/
private $weight = null;
/**
* Line color
*
* @var string
*/
private $color;
/**
* Dash style
*
* @var string
*/
private $dash = null;
/**
* Begin arrow
*
* @var string
*/
private $beginArrow = null;
/**
* End arrow
*
* @var string
*/
private $endArrow = null;
/**
* Set flip
*
* @param boolean $value
*/
public function setFlip($value = null)
{
$this->flip = $value;
}
/**
* Get flip
*
* @return boolean
*/
public function getFlip()
{
return $this->flip;
}
/**
* Set connectorType
*
* @param string $value
*/
public function setConnectorType($value = null)
{
$enum = array(
self::CONNECTOR_TYPE_STRAIGHT
);
$this->connectorType = $this->setEnumVal($value, $enum, $this->connectorType);
}
/**
* Get connectorType
*
* @return string
*/
public function getConnectorType()
{
return $this->connectorType;
}
/**
* Set weight
*
* @param int $value Weight in points
*/
public function setWeight($value = null)
{
$this->weight = $value;
}
/**
* Get weight
*
* @return int
*/
public function getWeight()
{
return $this->weight;
}
/**
* Set color
*
* @param string $value
*/
public function setColor($value = null)
{
$this->color = $value;
}
/**
* Get color
*
* @return string
*/
public function getColor()
{
return $this->color;
}
/**
* Set beginArrow
*
* @param string $value
*/
public function setBeginArrow($value = null)
{
$enum = array(
self::ARROW_STYLE_BLOCK, self::ARROW_STYLE_CLASSIC, self::ARROW_STYLE_DIAMOND,
self::ARROW_STYLE_OPEN, self::ARROW_STYLE_OVAL
);
$this->beginArrow = $this->setEnumVal($value, $enum, $this->beginArrow);
}
/**
* Get beginArrow
*
* @return string
*/
public function getBeginArrow()
{
return $this->beginArrow;
}
/**
* Set endArrow
*
* @param string $value
*/
public function setEndArrow($value = null)
{
$enum = array(
self::ARROW_STYLE_BLOCK, self::ARROW_STYLE_CLASSIC, self::ARROW_STYLE_DIAMOND,
self::ARROW_STYLE_OPEN, self::ARROW_STYLE_OVAL
);
$this->endArrow = $this->setEnumVal($value, $enum, $this->endArrow);
}
/**
* Get endArrow
*
* @return string
*/
public function getEndArrow()
{
return $this->endArrow;
}
/**
* Set Dash
*
* @param string $value
*/
public function setDash($value = null)
{
$enum = array(
self::DASH_STYLE_DASH, self::DASH_STYLE_DASH_DOT, self::DASH_STYLE_LONG_DASH,
self::DASH_STYLE_LONG_DASH_DOT, self::DASH_STYLE_LONG_DASH_DOT_DOT, self::DASH_STYLE_ROUND_DOT,
self::DASH_STYLE_SQUARE_DOT
);
$this->dash = $this->setEnumVal($value, $enum, $this->dash);
}
/**
* Get Dash
*
* @return string
*/
public function getDash()
{
return $this->dash;
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Element\Line as LineElement;
use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Line as LineStyleWriter;
/**
* Line element writer
*
*/
class Line extends AbstractElement
{
/**
* Write element
*/
public function write()
{
$xmlWriter = $this->getXmlWriter();
$element = $this->getElement();
if (!$element instanceof LineElement) {
return;
}
$style = $element->getStyle();
$styleWriter = new LineStyleWriter($xmlWriter, $style);
$id=$element->getElementIndex();
if (!$this->withoutP) {
$xmlWriter->startElement('w:p');
$styleWriter->writeAlignment();
}
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:pict');
if ($id==1) { //shapetype could be defined for each line separately, but then a unique id would be necessary
$xmlWriter->startElement('v:shapetype');
$xmlWriter->writeAttribute('id', '_x0000_t32');
$xmlWriter->writeAttribute('coordsize', '21600,21600');
$xmlWriter->writeAttribute('o:spt', '32');
$xmlWriter->writeAttribute('o:oned', 't');
$xmlWriter->writeAttribute('path', 'm,l21600,21600e');
$xmlWriter->writeAttribute('filled', 'f');
$xmlWriter->startElement('v:path');
$xmlWriter->writeAttribute('arrowok', 't');
$xmlWriter->writeAttribute('fillok', 'f');
$xmlWriter->writeAttribute('o:connecttype', 'none');
$xmlWriter->endElement(); // v:path
$xmlWriter->startElement('o:lock');
$xmlWriter->writeAttribute('v:ext', 'edit');
$xmlWriter->writeAttribute('shapetype', 't');
$xmlWriter->endElement(); // o:lock
$xmlWriter->endElement(); // v:shapetype
}
$xmlWriter->startElement('v:shape');
$xmlWriter->writeAttribute('id', sprintf('_x0000_s1%1$03d', $id));
$xmlWriter->writeAttribute('type', '#_x0000_t32'); //type should correspond to shapetype id
$styleWriter->write();
$styleWriter->writeStroke();
$styleWriter->writeW10Wrap();
$xmlWriter->endElement(); // v:shape
$xmlWriter->endElement(); // w:pict
$xmlWriter->endElement(); // w:r
if (!$this->withoutP) {
$xmlWriter->endElement(); // w:p
}
}
}

View File

@ -0,0 +1,180 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Style;
use PhpOffice\PhpWord\Style\Alignment as AlignmentStyle;
use PhpOffice\PhpWord\Style\Line as LineStyle;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Line style writer
*
*/
class Line extends Image
{
/**
* Write style
*/
public function write()
{
$style = $this->getStyle();
if (!$style instanceof LineStyle) {
return;
}
$this->writeStyle($style);
}
/**
* Write style attribute
*
* Copied function from Image/writeStyle in order to override getElementStyle
*/
protected function writeStyle(ImageStyle $style)
{
$xmlWriter = $this->getXmlWriter();
// Default style array
$styleArray = array(
'mso-width-percent' => '0',
'mso-height-percent' => '0',
'mso-width-relative' => 'margin',
'mso-height-relative' => 'margin',
);
$styleArray = array_merge($styleArray, $this->getElementStyle($style));
// Absolute/relative positioning
$positioning = $style->getPositioning();
$styleArray['position'] = $positioning;
if ($positioning !== null) {
$styleArray['mso-position-horizontal'] = $style->getPosHorizontal();
$styleArray['mso-position-vertical'] = $style->getPosVertical();
$styleArray['mso-position-horizontal-relative'] = $style->getPosHorizontalRel();
$styleArray['mso-position-vertical-relative'] = $style->getPosVerticalRel();
}
// Wrapping style
$wrapping = $style->getWrappingStyle();
if ($wrapping == LineStyle::WRAPPING_STYLE_INLINE) {
// Nothing to do when inline
} elseif ($wrapping == LineStyle::WRAPPING_STYLE_BEHIND) {
$styleArray['z-index'] = -251658752;
} else {
$styleArray['z-index'] = 251659264;
$styleArray['mso-position-horizontal'] = 'absolute';
$styleArray['mso-position-vertical'] = 'absolute';
}
// w10 wrapping
if ($wrapping == LineStyle::WRAPPING_STYLE_SQUARE) {
$this->w10wrap = 'square';
} elseif ($wrapping == LineStyle::WRAPPING_STYLE_TIGHT) {
$this->w10wrap = 'tight';
}
$imageStyle = $this->assembleStyle($styleArray);
$xmlWriter->writeAttribute('style', $imageStyle);
$xmlWriter->writeAttribute('o:connectortype', $style->getConnectorType());
// Weight
$weight = $style->getWeight();
if ($weight !== null) {
$xmlWriter->writeAttribute('strokeweight', $weight . 'pt');
}
// Color
$color = $style->getColor();
if ($color !== null) {
$xmlWriter->writeAttribute('strokecolor', $color);
}
}
/**
* Get element style
*
* @param \PhpOffice\PhpWord\Style\Image $style
* @return array
*/
private function getElementStyle(LineStyle $style)
{
$styles = array();
$styleValues = array(
'width' => $style->getWidth(),
'height' => $style->getHeight(),
'margin-top' => $style->getMarginTop(),
'margin-left' => $style->getMarginLeft()
);
foreach ($styleValues as $key => $value) {
if (!is_null($value)) {
$styles[$key] = $value . 'px';
}
}
if ($style->getFlip()) {
$styles['flip']='y';
}
return $styles;
}
public function writeStroke()
{
$style = $this->getStyle();
$xmlWriter = $this->getXmlWriter();
$dash = $style->getDash();
$beginArrow = $style->getBeginArrow();
$endArrow = $style->getEndArrow();
if (($dash !== null) || ($beginArrow !== null) || ($endArrow !== null)) {
$xmlWriter->startElement('v:stroke');
if ($beginArrow !== null) {
$xmlWriter->writeAttribute('startarrow', $beginArrow);
}
if ($endArrow !== null) {
$xmlWriter->writeAttribute('endarrow', $endArrow);
}
if ($dash !==null) {
switch ($dash) {
case LineStyle::DASH_STYLE_DASH:
$xmlWriter->writeAttribute('dashstyle', 'dash');
break;
case LineStyle::DASH_STYLE_ROUND_DOT:
$xmlWriter->writeAttribute('dashstyle', '1 1');
$xmlWriter->writeAttribute('endcap', 'round');
break;
case LineStyle::DASH_STYLE_SQUARE_DOT:
$xmlWriter->writeAttribute('dashstyle', '1 1');
break;
case LineStyle::DASH_STYLE_DASH_DOT:
$xmlWriter->writeAttribute('dashstyle', 'dashDot');
break;
case LineStyle::DASH_STYLE_LONG_DASH:
$xmlWriter->writeAttribute('dashstyle', 'longDash');
break;
case LineStyle::DASH_STYLE_LONG_DASH_DOT:
$xmlWriter->writeAttribute('dashstyle', 'longDashDot');
break;
case LineStyle::DASH_STYLE_LONG_DASH_DOT_DOT:
$xmlWriter->writeAttribute('dashstyle', 'longDashDotDot');
break;
}
}
$xmlWriter->endElement(); //v:stroke
}
}
}

View File

@ -0,0 +1,76 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Element\Line;
/**
* Test class for PhpOffice\PhpWord\Element\Line
*
* @coversDefaultClass \PhpOffice\PhpWord\Element\Line
* @runTestsInSeparateProcesses
*/
class LineTest extends \PHPUnit_Framework_TestCase
{
/**
* Create new instance
*/
public function testConstruct()
{
$oLine = new Line();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Line', $oLine);
$this->assertEquals($oLine->getStyle(), null);
}
/**
* Get style name
*/
public function testStyleText()
{
$oLine = new Line('lineStyle');
$this->assertEquals($oLine->getStyle(), 'lineStyle');
}
/**
* Get style array
*/
public function testStyleArray()
{
$oLine = new Line(
array(
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(14),
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
'positioning' => 'absolute',
'posHorizontalRel' => 'page',
'posVerticalRel' => 'page',
'flip' => true,
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(5),
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10
)
);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Line', $oLine->getStyle());
}
}

View File

@ -0,0 +1,153 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\Line;
/**
* Test class for PhpOffice\PhpWord\Style\Image
*
* @coversDefaultClass \PhpOffice\PhpWord\Style\Image
* @runTestsInSeparateProcesses
*/
class LineTest extends \PHPUnit_Framework_TestCase
{
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new Line();
$properties = array(
'flip' => true,
'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT,
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10,
'color' => 'red'
);
foreach ($properties as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test setStyleValue method
*/
public function testSetStyleValue()
{
$object = new Line();
$properties = array(
'flip' => true,
'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT,
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10,
'color' => 'red'
);
foreach ($properties as $key => $value) {
$get = "get{$key}";
$object->setStyleValue("{$key}", $value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test set/get flip
*/
public function testSetGetFlip()
{
$expected=true;
$object = new Line();
$object->setFlip($expected);
$this->assertEquals($expected, $object->getFlip());
}
/**
* Test set/get connectorType
*/
public function testSetGetConnectorType()
{
$expected=\PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT;
$object = new Line();
$object->setConnectorType($expected);
$this->assertEquals($expected, $object->getConnectorType());
}
/**
* Test set/get weight
*/
public function testSetGetWeight()
{
$expected=10;
$object = new Line();
$object->setWeight($expected);
$this->assertEquals($expected, $object->getWeight());
}
/**
* Test set/get color
*/
public function testSetGetColor()
{
$expected='red';
$object = new Line();
$object->setColor($expected);
$this->assertEquals($expected, $object->getColor());
}
/**
* Test set/get dash
*/
public function testSetGetDash()
{
$expected=\PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT;
$object = new Line();
$object->setDash($expected);
$this->assertEquals($expected, $object->getDash());
}
/**
* Test set/get beginArrow
*/
public function testSetGetBeginArrow()
{
$expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK;
$object = new Line();
$object->setBeginArrow($expected);
$this->assertEquals($expected, $object->getBeginArrow());
}
/**
* Test set/get endArrow
*/
public function testSetGetEndArrow()
{
$expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC;
$object = new Line();
$object->setEndArrow($expected);
$this->assertEquals($expected, $object->getEndArrow());
}
}