Skip to content
Closed
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
6 changes: 5 additions & 1 deletion src/PhpWord/Writer/RTF/Element/TextBreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function write()
$parentWriter = $this->parentWriter;
$parentWriter->setLastParagraphStyle();

return '\pard\par' . PHP_EOL;
if ($this->withoutP) {
return '\line' . PHP_EOL;
} else {
return '\pard\par' . PHP_EOL;
}
}
}
71 changes: 66 additions & 5 deletions src/PhpWord/Writer/RTF/Style/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Font extends AbstractStyle
*/
private $colorIndex = 0;

/**
* @var int Font lang index
*/
private $langIndex = 0;

/**
* Write style.
*
Expand All @@ -50,20 +55,67 @@ public function write()
}

$content = '';
$content .= $this->getValueIf($style->isRTL(), '\rtlch');
$content .= '\cf' . $this->colorIndex;

// Font Name
$content .= '\f' . $this->nameIndex;

$size = $style->getSize();
$content .= $this->getValueIf(is_numeric($size), '\fs' . round($size * 2));
// Basic - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
$content .= $this->getValueIf($style->getName() !== null, '\f' . $this->nameIndex); // Doesn't work; fonts not implemented.
$content .= $this->getValueIf($style->getSize() !== null, '\fs' . round($style->getSize() * 2));
$content .= $this->getValueIf($style->getColor() !== null, '\cf' . $this->colorIndex); // Doesn't work; coloring not implemented.
// Hint (font content type) not implemented.

// Underline Keywords
$underlines = [
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DASH => '\uldash',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHHEAVY => '\ulth',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONG => '\ulldash',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DASHLONGHEAVY => '\ulthldash',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOUBLE => '\uldb',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASH => '\uldashd',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDASHHEAVY => '\ulthdashd',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASH => '\uldashdd',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTDOTDASHHEAVY => '\ulthdashdd',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTED => '\uld',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_DOTTEDHEAVY => '\ulthd',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_HEAVY => '\ulth',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE => '\ul',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVY => '\ulwave',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYDOUBLE => '\ululdbwave',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_WAVYHEAVY => '\ulhwave',
\PhpOffice\PhpWord\Style\Font::UNDERLINE_WORDS => '\ulw',
];

// Style - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
$content .= $this->getValueIf($style->isBold(), '\b');
$content .= $this->getValueIf($style->isItalic(), '\i');
$content .= $this->getValueIf($style->getUnderline() != FontStyle::UNDERLINE_NONE, '\ul');
if (isset($underlines[$style->getUnderline()])) { $content .= $underlines[$style->getUnderline()]; }
$content .= $this->getValueIf($style->isStrikethrough(), '\strike');
$content .= $this->getValueIf($style->isDoubleStrikethrough(), '\striked1');
$content .= $this->getValueIf($style->isSuperScript(), '\super');
$content .= $this->getValueIf($style->isSubScript(), '\sub');
$content .= $this->getValueIf($style->isSmallCaps(), '\scaps');
$content .= $this->getValueIf($style->isAllCaps(), '\caps');
$content .= $this->getValueIf($style->getFgColor() !== null, '\highlight' . $this->colorIndex); // Doesn't work; coloring not implemented.
$content .= $this->getValueIf($style->isHidden(), '\v');

// Spacing - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
$content .= $this->getValueIf($style->getScale() !== null, '\charscalex' . $style->getScale());
$content .= $this->getValueIf($style->getSpacing() !== null, '\expnd' . $style->getSpacing());
$content .= $this->getValueIf($style->getKerning() !== null, '\kerning' . $style->getKerning() * 2);
$content .= $this->getValueIf($style->getPosition() !== null, '\up' . $style->getPosition());

// General - same order as array found in PhpOffice\PhpWord\Style\Font\getStyleValues
// Paragraph not implemented.
$content .= $this->getValueIf($style->isRTL(), '\rtlch');
$content .= $this->getValueIf($style->getShading() !== null, '\chcfpat' . $this->colorIndex); // Doesn't work; coloring not implemented.
$content .= $this->getValueIf($style->getLang() !== null, '\lang' . $this->langIndex); // Doesn't work; language not implemented.
// Whitespace and fallbackFont are HTML specific

// Other items not in included in array found in PhpOffice\PhpWord\Style\Font\getStyleValues
$content .= $this->getValueIf($style->isNoProof(), '\noproof');
$content .= $this->getValueIf($style->getBgColor() !== null, '\cb' . $this->colorIndex); // Doesn't work; coloring not implemented.

return $content . ' ';
}

Expand All @@ -86,4 +138,13 @@ public function setColorIndex($value = 0): void
{
$this->colorIndex = $value;
}
/**
* Set font lang index.
*
* @param int $value
*/
public function setLangIndex($value = 0): void
{
$this->langIndex = $value;
}
}
9 changes: 9 additions & 0 deletions src/PhpWord/Writer/RTF/Style/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public function write()
$content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight()));
$content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter()));
$content .= $this->getValueIf($style->getPageNumberingStart() !== null, '\pgnstarts' . $style->getPageNumberingStart() . '\pgnrestart');

// Vertical Align
$verticalAlign = [
\PhpOffice\PhpWord\SimpleType\VerticalJc::TOP => '\vertalt',
\PhpOffice\PhpWord\SimpleType\VerticalJc::CENTER => '\vertalc',
\PhpOffice\PhpWord\SimpleType\VerticalJc::BOTH => '\vertalj',
\PhpOffice\PhpWord\SimpleType\VerticalJc::BOTTOM => '\vertalb',
];
if (isset($verticalAlign[$style->getVAlign()])) { $content .= $verticalAlign[$style->getVAlign()]; }
$content .= ' ';

// Borders
Expand Down
15 changes: 13 additions & 2 deletions src/PhpWord/Writer/RTF/Style/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ public function write()
\PhpOffice\PhpWord\Style\Tab::TAB_STOP_RIGHT => '\tqr',
\PhpOffice\PhpWord\Style\Tab::TAB_STOP_CENTER => '\tqc',
\PhpOffice\PhpWord\Style\Tab::TAB_STOP_DECIMAL => '\tqdec',
\PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT => '\tldot',
\PhpOffice\PhpWord\Style\Tab::TAB_LEADER_HYPHEN => '\tlhyph',
\PhpOffice\PhpWord\Style\Tab::TAB_LEADER_UNDERSCORE => '\tlul',
\PhpOffice\PhpWord\Style\Tab::TAB_LEADER_HEAVY => '\tlth',
\PhpOffice\PhpWord\Style\Tab::TAB_LEADER_MIDDLEDOT => '\tlmdot',
];
$content = '';
if (isset($tabs[$style->getType()])) {
$content .= $tabs[$style->getType()];
}
$content .= '\tx' . round($style->getPosition());

if (isset($tabs[$style->getLeader()])) {
$content .= $tabs[$style->getLeader()];
}
if ($style->getType() == \PhpOffice\PhpWord\Style\Tab::TAB_STOP_BAR) {
$content .= '\tb' . round($style->getPosition());
} else {
$content .= '\tx' . round($style->getPosition());
}
return $content;
}
}
Loading