Skip to content

Added Line element #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers

## 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

Expand All @@ -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 image - @ivanlanin
- Element: New `Field` element - @basjan GH-251
- Element: New `Line` element - @basjan
- RTF Reader: Basic RTF reader - @ivanlanin GH-72

### Bugfixes
Expand Down
268 changes: 268 additions & 0 deletions CHANGELOG.md~

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions samples/Sample_28_Line.php
Original file line number Diff line number Diff line change
@@ -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';
}
14 changes: 14 additions & 0 deletions src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ public function addField($type = null, $properties = array(), $options = array()

}

/**
* Add line element
*
* @param mixed $lineStyle
* @return \PhpOffice\PhpWord\Element\Line
*/
public function addLine($lineStyle = null)
{
return $this->addElement('Line', $lineStyle);

}


/**
* Add link element
*
Expand Down Expand Up @@ -331,6 +344,7 @@ private function checkValidity($method)
'Image' => $allContainers,
'Object' => $allContainers,
'Field' => $allContainers,
'Line' => $allContainers,
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
Expand Down
54 changes: 54 additions & 0 deletions src/PhpWord/Element/Line.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading