fix code formatting
This commit is contained in:
parent
e1bbc85cc4
commit
1b7b43a4e5
|
|
@ -115,7 +115,7 @@ class Html
|
||||||
// tables, cells
|
// tables, cells
|
||||||
if (false !== strpos($val, '%')) {
|
if (false !== strpos($val, '%')) {
|
||||||
// e.g. <table width="100%"> or <td width="50%">
|
// e.g. <table width="100%"> or <td width="50%">
|
||||||
$styles['width'] = intval($val) * 50;
|
$styles['width'] = (int) $val * 50;
|
||||||
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
|
$styles['unit'] = \PhpOffice\PhpWord\SimpleType\TblWidth::PERCENT;
|
||||||
} else {
|
} else {
|
||||||
// e.g. <table width="250> where "250" = 250px (always pixels)
|
// e.g. <table width="250> where "250" = 250px (always pixels)
|
||||||
|
|
@ -125,7 +125,7 @@ class Html
|
||||||
break;
|
break;
|
||||||
case 'cellspacing':
|
case 'cellspacing':
|
||||||
// tables e.g. <table cellspacing="2">, where "2" = 2px (always pixels)
|
// tables e.g. <table cellspacing="2">, where "2" = 2px (always pixels)
|
||||||
$val = intval($val).'px';
|
$val = (int) $val . 'px';
|
||||||
$styles['cellSpacing'] = Converter::cssToTwip($val);
|
$styles['cellSpacing'] = Converter::cssToTwip($val);
|
||||||
break;
|
break;
|
||||||
case 'bgcolor':
|
case 'bgcolor':
|
||||||
|
|
@ -693,7 +693,7 @@ class Html
|
||||||
// This may be adjusted, if better ratio or formula found.
|
// This may be adjusted, if better ratio or formula found.
|
||||||
// BC change: up to ver. 0.17.0 was $size converted to points - Converter::cssToPoint($size)
|
// BC change: up to ver. 0.17.0 was $size converted to points - Converter::cssToPoint($size)
|
||||||
$size = Converter::cssToTwip($matches[1]);
|
$size = Converter::cssToTwip($matches[1]);
|
||||||
$size = intval($size / 2);
|
$size = (int) ($size / 2);
|
||||||
// valid variants may be e.g. borderSize, borderTopSize, borderLeftColor, etc ..
|
// valid variants may be e.g. borderSize, borderTopSize, borderLeftColor, etc ..
|
||||||
$styles["border{$which}Size"] = $size; // twips
|
$styles["border{$which}Size"] = $size; // twips
|
||||||
$styles["border{$which}Color"] = trim($matches[2], '#');
|
$styles["border{$which}Color"] = trim($matches[2], '#');
|
||||||
|
|
@ -871,9 +871,9 @@ class Html
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms a HTML/CSS alignment into a \PhpOffice\PhpWord\SimpleType\Jc
|
* Transforms a HTML/CSS vertical alignment
|
||||||
*
|
*
|
||||||
* @param string $cssAlignment
|
* @param string $alignment
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
protected static function mapAlignVertical($alignment)
|
protected static function mapAlignVertical($alignment)
|
||||||
|
|
@ -901,10 +901,10 @@ class Html
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map list style for ordered list
|
* Map list style for ordered list
|
||||||
*
|
*
|
||||||
* @param string $cssListType
|
* @param string $cssListType
|
||||||
*/
|
*/
|
||||||
protected static function mapListType($cssListType)
|
protected static function mapListType($cssListType)
|
||||||
{
|
{
|
||||||
switch ($cssListType) {
|
switch ($cssListType) {
|
||||||
|
|
@ -959,12 +959,12 @@ class Html
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render horizontal rule
|
* Render horizontal rule
|
||||||
* Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment
|
* Note: Word rule is not the same as HTML's <hr> since it does not support width and thus neither alignment
|
||||||
*
|
*
|
||||||
* @param \DOMNode $node
|
* @param \DOMNode $node
|
||||||
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
|
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element
|
||||||
*/
|
*/
|
||||||
protected static function parseHorizRule($node, $element)
|
protected static function parseHorizRule($node, $element)
|
||||||
{
|
{
|
||||||
$styles = self::parseInlineStyle($node);
|
$styles = self::parseInlineStyle($node);
|
||||||
|
|
@ -972,19 +972,19 @@ class Html
|
||||||
// <hr> is implemented as an empty paragraph - extending 100% inside the section
|
// <hr> is implemented as an empty paragraph - extending 100% inside the section
|
||||||
// Some properties may be controlled, e.g. <hr style="border-bottom: 3px #DDDDDD solid; margin-bottom: 0;">
|
// Some properties may be controlled, e.g. <hr style="border-bottom: 3px #DDDDDD solid; margin-bottom: 0;">
|
||||||
|
|
||||||
$fontStyle = $styles + ['size' => 3];
|
$fontStyle = $styles + array('size' => 3);
|
||||||
|
|
||||||
$paragraphStyle = $styles + [
|
$paragraphStyle = $styles + array(
|
||||||
'lineHeight' => 0.25, // multiply default line height - e.g. 1, 1.5 etc
|
'lineHeight' => 0.25, // multiply default line height - e.g. 1, 1.5 etc
|
||||||
'spacing' => 0, // twip
|
'spacing' => 0, // twip
|
||||||
'spaceBefore' => 120, // twip, 240/2 (default line height)
|
'spaceBefore' => 120, // twip, 240/2 (default line height)
|
||||||
'spaceAfter' => 120, // twip
|
'spaceAfter' => 120, // twip
|
||||||
'borderBottomSize' => empty($styles['line-height']) ? 1 : $styles['line-height'],
|
'borderBottomSize' => empty($styles['line-height']) ? 1 : $styles['line-height'],
|
||||||
'borderBottomColor' => empty($styles['color']) ? '000000' : $styles['color'],
|
'borderBottomColor' => empty($styles['color']) ? '000000' : $styles['color'],
|
||||||
'borderBottomStyle' => 'single', // same as "solid"
|
'borderBottomStyle' => 'single', // same as "solid"
|
||||||
];
|
);
|
||||||
|
|
||||||
$element->addText("", $fontStyle, $paragraphStyle);
|
$element->addText('', $fontStyle, $paragraphStyle);
|
||||||
|
|
||||||
// Notes: <hr/> cannot be:
|
// Notes: <hr/> cannot be:
|
||||||
// - table - throws error "cannot be inside textruns", e.g. lists
|
// - table - throws error "cannot be inside textruns", e.g. lists
|
||||||
|
|
|
||||||
|
|
@ -634,8 +634,8 @@ class HtmlTest extends AbstractWebServerEmbeddedTest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse widths in tables and cells, which also allows for controlling column width
|
* Parse widths in tables and cells, which also allows for controlling column width
|
||||||
*/
|
*/
|
||||||
public function testParseTableAndCellWidth()
|
public function testParseTableAndCellWidth()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
@ -703,14 +703,14 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test parsing background color for table rows and table cellspacing
|
* Test parsing background color for table rows and table cellspacing
|
||||||
*/
|
*/
|
||||||
public function testParseCellspacingRowBgColor()
|
public function testParseCellspacingRowBgColor()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection([
|
$section = $phpWord->addSection(array(
|
||||||
'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
|
'orientation' => \PhpOffice\PhpWord\Style\Section::ORIENTATION_LANDSCAPE,
|
||||||
]);
|
));
|
||||||
|
|
||||||
// borders & backgrounds are here just for better visual comparison
|
// borders & backgrounds are here just for better visual comparison
|
||||||
$html = <<<HTML
|
$html = <<<HTML
|
||||||
|
|
@ -744,8 +744,8 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse horizontal rule
|
* Parse horizontal rule
|
||||||
*/
|
*/
|
||||||
public function testParseHorizRule()
|
public function testParseHorizRule()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
@ -774,7 +774,7 @@ HTML;
|
||||||
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:pBdr/w:bottom';
|
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:pBdr/w:bottom';
|
||||||
$this->assertTrue($doc->elementExists($xpath));
|
$this->assertTrue($doc->elementExists($xpath));
|
||||||
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val'));
|
$this->assertEquals('single', $doc->getElement($xpath)->getAttribute('w:val'));
|
||||||
$this->assertEquals(intval(5 * 15 / 2), $doc->getElement($xpath)->getAttribute('w:sz'));
|
$this->assertEquals((int) (5 * 15 / 2), $doc->getElement($xpath)->getAttribute('w:sz'));
|
||||||
$this->assertEquals('lightblue', $doc->getElement($xpath)->getAttribute('w:color'));
|
$this->assertEquals('lightblue', $doc->getElement($xpath)->getAttribute('w:color'));
|
||||||
|
|
||||||
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:spacing';
|
$xpath = '/w:document/w:body/w:p[4]/w:pPr/w:spacing';
|
||||||
|
|
@ -785,8 +785,8 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse ordered list start & numbering style
|
* Parse ordered list start & numbering style
|
||||||
*/
|
*/
|
||||||
public function testParseOrderedList()
|
public function testParseOrderedList()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
@ -846,8 +846,8 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse ordered list start & numbering style
|
* Parse ordered list start & numbering style
|
||||||
*/
|
*/
|
||||||
public function testParseVerticalAlign()
|
public function testParseVerticalAlign()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
@ -886,8 +886,8 @@ HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix bug - don't decode double quotes inside double quoted string
|
* Fix bug - don't decode double quotes inside double quoted string
|
||||||
*/
|
*/
|
||||||
public function testDontDecodeAlreadyEncodedDoubleQuotes()
|
public function testDontDecodeAlreadyEncodedDoubleQuotes()
|
||||||
{
|
{
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
@ -900,6 +900,6 @@ HTML;
|
||||||
|
|
||||||
Html::addHtml($section, $html);
|
Html::addHtml($section, $html);
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
|
||||||
$this->assertTrue(is_object($doc));
|
$this->assertInternalType('object', $doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue