作者:hcvcastr
项目:px
/**
* Write font faces declaration
*/
protected function writeFontFaces(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('office:font-face-decls');
$fontTable = array();
$styles = Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $style) {
// Font
if ($style instanceof Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $fontTable)) {
$fontTable[] = $name;
// style:font-face
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', $name);
$xmlWriter->writeAttribute('svg:font-family', $name);
$xmlWriter->endElement();
}
}
}
}
if (!in_array(Settings::getDefaultFontName(), $fontTable)) {
$xmlWriter->startElement('style:font-face');
$xmlWriter->writeAttribute('style:name', Settings::getDefaultFontName());
$xmlWriter->writeAttribute('svg:font-family', Settings::getDefaultFontName());
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
作者:hcvcastr
项目:px
/**
* Write content types element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param array $parts
* @param boolean $isDefault
*/
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
{
foreach ($parts as $partName => $contentType) {
$partType = $isDefault ? 'Default' : 'Override';
$partAttribute = $isDefault ? 'Extension' : 'PartName';
$xmlWriter->startElement($partType);
$xmlWriter->writeAttribute($partAttribute, $partName);
$xmlWriter->writeAttribute('ContentType', $contentType);
$xmlWriter->endElement();
}
}
作者:hcvcastr
项目:px
/**
* Test empty styles
*/
public function testEmptyStyles()
{
$styles = array('Font', 'Paragraph', 'Image', 'Section', 'Table');
foreach ($styles as $style) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Style\\' . $style;
$xmlWriter = new XMLWriter();
$object = new $objectClass($xmlWriter);
$object->write();
$this->assertEquals('', $xmlWriter->getData());
}
}
作者:doit0
项目:relProjec
/**
* Test method exceptions
*/
public function testMethodExceptions()
{
$styles = array('Frame' => 'writeAlignment', 'Line' => 'writeStroke', 'TextBox' => 'writeBorder');
foreach ($styles as $style => $method) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Style\\' . $style;
$xmlWriter = new XMLWriter();
$object = new $objectClass($xmlWriter);
$object->{$method}();
$this->assertEquals('', $xmlWriter->getData());
}
}
作者:productioncompiler
项目:PHPWor
/**
* Test unmatched element
*/
public function testUnmatchedElements()
{
$elements = array('CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC', 'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT');
foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $element;
$xmlWriter = new XMLWriter();
$newElement = new \PhpOffice\PhpWord\Element\PageBreak();
$object = new $objectClass($xmlWriter, $newElement);
$object->write();
$this->assertEquals('', $xmlWriter->getData());
}
}
作者:HaiLeade
项目:quiz
/**
* Test unmatched elements
*/
public function testUnmatchedElements()
{
$elements = array('Image', 'Link', 'Table', 'Text', 'Title');
foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $element;
$xmlWriter = new XMLWriter();
$newElement = new \PhpOffice\PhpWord\Element\PageBreak();
$object = new $objectClass($xmlWriter, $newElement);
$object->write();
$this->assertEquals('', $xmlWriter->getData());
}
}
作者:kaantun
项目:MYK-BO
/**
* Write content types element
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter XML Writer
* @param array $parts
* @param boolean $isDefault
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault)
{
foreach ($parts as $partName => $contentType) {
if ($partName != '' && $contentType != '') {
$partType = $isDefault ? 'Default' : 'Override';
$partAttribute = $isDefault ? 'Extension' : 'PartName';
$xmlWriter->startElement($partType);
$xmlWriter->writeAttribute($partAttribute, $partName);
$xmlWriter->writeAttribute('ContentType', $contentType);
$xmlWriter->endElement();
} else {
throw new Exception("Invalid parameters passed.");
}
}
}
作者:hcvcastr
项目:px
/**
* Write watermark element
*/
private function writeWatermark(XMLWriter $xmlWriter, ImageElement $element)
{
$rId = $element->getRelationId();
$style = $element->getStyle();
$style->setPositioning('absolute');
$styleWriter = new ImageStyleWriter($xmlWriter, $style);
$xmlWriter->startElement('w:p');
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:pict');
$xmlWriter->startElement('v:shape');
$xmlWriter->writeAttribute('type', '#_x0000_t75');
$styleWriter->write();
$xmlWriter->startElement('v:imagedata');
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->writeAttribute('o:title', '');
$xmlWriter->endElement();
// v:imagedata
$xmlWriter->endElement();
// v:shape
$xmlWriter->endElement();
// w:pict
$xmlWriter->endElement();
// w:r
$xmlWriter->endElement();
// w:p
}
作者:kaantun
项目:MYK-BO
/**
* Write indivual setting, recursive to any child settings
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $settingKey
* @param array|string $settingValue
*/
protected function writeSetting($xmlWriter, $settingKey, $settingValue)
{
if ($settingValue == '') {
$xmlWriter->writeElement($settingKey);
} else {
$xmlWriter->startElement($settingKey);
foreach ($settingValue as $childKey => $childValue) {
if ($childKey == '@attributes') {
foreach ($childValue as $key => $val) {
$xmlWriter->writeAttribute($key, $val);
}
} else {
$this->writeSetting($xmlWriter, $childKey, $childValue);
}
}
$xmlWriter->endElement();
}
}
作者:doit0
项目:relProjec
/**
* Write side.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $side
* @param int $width
* @param string $color
* @return void
*/
private function writeSide(XMLWriter $xmlWriter, $side, $width, $color = null)
{
$xmlWriter->startElement('w:' . $side);
if (!empty($this->colors)) {
if ($color === null && !empty($this->attributes)) {
if (isset($this->attributes['defaultColor'])) {
$color = $this->attributes['defaultColor'];
}
}
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $width);
$xmlWriter->writeAttribute('w:color', $color);
if (!empty($this->attributes)) {
if (isset($this->attributes['space'])) {
$xmlWriter->writeAttribute('w:space', $this->attributes['space']);
}
}
} else {
$xmlWriter->writeAttribute('w:w', $width);
$xmlWriter->writeAttribute('w:type', 'dxa');
}
$xmlWriter->endElement();
}
作者:Senasu
项目:PHPWor
/**
* Write alignment.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Frame $style
* @param string $wrap
* @return void
*/
private function writeWrap(XMLWriter $xmlWriter, FrameStyle $style, $wrap)
{
if ($wrap !== null) {
$xmlWriter->startElement('w10:wrap');
$xmlWriter->writeAttribute('type', $wrap);
$relativePositions = array(FrameStyle::POS_RELTO_MARGIN => 'margin', FrameStyle::POS_RELTO_PAGE => 'page', FrameStyle::POS_RELTO_TMARGIN => 'margin', FrameStyle::POS_RELTO_BMARGIN => 'page', FrameStyle::POS_RELTO_LMARGIN => 'margin', FrameStyle::POS_RELTO_RMARGIN => 'page');
$pos = $style->getPos();
$hPos = $style->getHPosRelTo();
$vPos = $style->getVPosRelTo();
if ($pos == FrameStyle::POS_ABSOLUTE) {
$xmlWriter->writeAttribute('anchorx', "page");
$xmlWriter->writeAttribute('anchory', "page");
} elseif ($pos == FrameStyle::POS_RELATIVE) {
if (isset($relativePositions[$hPos])) {
$xmlWriter->writeAttribute('anchorx', $relativePositions[$hPos]);
}
if (isset($relativePositions[$vPos])) {
$xmlWriter->writeAttribute('anchory', $relativePositions[$vPos]);
}
}
$xmlWriter->endElement();
// w10:wrap
}
}
作者:doit0
项目:relProjec
/**
* Write shape
*
* @link http://www.datypic.com/sc/ooxml/t-a_CT_ShapeProperties.html
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param bool $line
* @return void
*/
private function writeShape(XMLWriter $xmlWriter, $line = false)
{
$xmlWriter->startElement('c:spPr');
$xmlWriter->startElement('a:ln');
if ($line === true) {
$xmlWriter->writeElement('a:solidFill');
} else {
$xmlWriter->writeElement('a:noFill');
}
$xmlWriter->endElement();
// a:ln
$xmlWriter->endElement();
// c:spPr
}
作者:brunodebarro
项目:phpwor
/**
* Write shading.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Style\Table $style
* @return void
*/
private function writeShading(XMLWriter $xmlWriter, TableStyle $style)
{
if (null !== $style->getShading()) {
$xmlWriter->startElement('w:tcPr');
$styleWriter = new Shading($xmlWriter, $style->getShading());
$styleWriter->write();
$xmlWriter->endElement();
}
}
作者:kaantun
项目:MYK-BO
/**
* Write default font and other default styles
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param array $styles
*/
private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles)
{
$fontName = $phpWord->getDefaultFontName();
$fontSize = $phpWord->getDefaultFontSize();
// Default font
$xmlWriter->startElement('w:docDefaults');
$xmlWriter->startElement('w:rPrDefault');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:rFonts');
$xmlWriter->writeAttribute('w:ascii', $fontName);
$xmlWriter->writeAttribute('w:hAnsi', $fontName);
$xmlWriter->writeAttribute('w:eastAsia', $fontName);
$xmlWriter->writeAttribute('w:cs', $fontName);
$xmlWriter->endElement();
// w:rFonts
$xmlWriter->startElement('w:sz');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement();
// w:sz
$xmlWriter->startElement('w:szCs');
$xmlWriter->writeAttribute('w:val', $fontSize * 2);
$xmlWriter->endElement();
// w:szCs
$xmlWriter->endElement();
// w:rPr
$xmlWriter->endElement();
// w:rPrDefault
$xmlWriter->endElement();
// w:docDefaults
// Normal style
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'paragraph');
$xmlWriter->writeAttribute('w:default', '1');
$xmlWriter->writeAttribute('w:styleId', 'Normal');
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement();
// w:name
if (array_key_exists('Normal', $styles)) {
$styleWriter = new ParagraphStyleWriter($xmlWriter, $styles['Normal']);
$styleWriter->write();
}
$xmlWriter->endElement();
// w:style
// FootnoteReference style
if (!array_key_exists('FootnoteReference', $styles)) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'character');
$xmlWriter->writeAttribute('w:styleId', 'FootnoteReference');
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', 'Footnote Reference');
$xmlWriter->endElement();
// w:name
$xmlWriter->writeElement('w:semiHidden');
$xmlWriter->writeElement('w:unhideWhenUsed');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:vertAlign');
$xmlWriter->writeAttribute('w:val', 'superscript');
$xmlWriter->endElement();
// w:vertAlign
$xmlWriter->endElement();
// w:rPr
$xmlWriter->endElement();
// w:style
}
}
作者:doit0
项目:relProjec
/**
* Write end section.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Section $section
* @return void
*/
private function writeSectionSettings(XMLWriter $xmlWriter, Section $section)
{
$xmlWriter->startElement('w:sectPr');
// Header reference
foreach ($section->getHeaders() as $header) {
$rId = $header->getRelationId();
$xmlWriter->startElement('w:headerReference');
$xmlWriter->writeAttribute('w:type', $header->getType());
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
// Footer reference
foreach ($section->getFooters() as $footer) {
$rId = $footer->getRelationId();
$xmlWriter->startElement('w:footerReference');
$xmlWriter->writeAttribute('w:type', $footer->getType());
$xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$xmlWriter->endElement();
}
// Different first page
if ($section->hasDifferentFirstPage()) {
$xmlWriter->startElement('w:titlePg');
$xmlWriter->endElement();
}
// Section settings
$styleWriter = new SectionStyleWriter($xmlWriter, $section->getStyle());
$styleWriter->write();
$xmlWriter->endElement();
// w:sectPr
}
作者:Senasu
项目:PHPWor
/**
* Write individual property
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $property
* @param string $value
* @return void
*
* @todo Handle other `$type`: double|date|dateTime|duration|boolean (4th arguments)
*/
private function writeCustomProperty(XMLWriter $xmlWriter, $property, $value)
{
$xmlWriter->startElement('meta:user-defined');
$xmlWriter->writeAttribute('meta:name', $property);
// if ($type !== null) {
// $xmlWriter->writeAttribute('meta:value-type', $type);
// }
$xmlWriter->writeRaw($value);
$xmlWriter->endElement();
// meta:user-defined
}
作者:FabianoFari
项目:ULA_fron
/**
* Write table style
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $styleName
* @param \PhpOffice\PhpWord\Style\Table $style
*/
private function writeTableStyle(XMLWriter $xmlWriter, $styleName, TableStyle $style)
{
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1');
$xmlWriter->writeAttribute('w:styleId', $styleName);
$xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', $styleName);
$xmlWriter->endElement();
$xmlWriter->startElement('w:uiPriority');
$xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement();
$styleWriter = new TableStyleWriter($xmlWriter, $style);
$styleWriter->write();
$xmlWriter->endElement();
// w:style
}
作者:Senasu
项目:PHPWor
/**
* Write cell.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Cell $cell
* @return void
*/
private function writeCell(XMLWriter $xmlWriter, CellElement $cell)
{
$xmlWriter->startElement('w:tc');
// Write style
$cellStyle = $cell->getStyle();
if ($cellStyle instanceof CellStyle) {
$styleWriter = new CellStyleWriter($xmlWriter, $cellStyle);
$styleWriter->setWidth($cell->getWidth());
$styleWriter->write();
}
// Write content
$containerWriter = new Container($xmlWriter, $cell);
$containerWriter->write();
$xmlWriter->endElement();
// w:tc
}
作者:kaantun
项目:MYK-BO
/**
* Write note item
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param \PhpOffice\PhpWord\Element\Footnote|\PhpOffice\PhpWord\Element\Endnote $element
*/
protected function writeNote(XMLWriter $xmlWriter, $element)
{
$xmlWriter->startElement($this->elementNode);
$xmlWriter->writeAttribute('w:id', $element->getRelationId());
$xmlWriter->startElement('w:p');
// Paragraph style
$styleWriter = new ParagraphStyleWriter($xmlWriter, $element->getParagraphStyle());
$styleWriter->setIsInline(true);
$styleWriter->write();
// Reference symbol
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:rPr');
$xmlWriter->startElement('w:rStyle');
$xmlWriter->writeAttribute('w:val', $this->refStyle);
$xmlWriter->endElement();
// w:rStyle
$xmlWriter->endElement();
// w:rPr
$xmlWriter->writeElement($this->refNode);
$xmlWriter->endElement();
// w:r
// Empty space after refence symbol
$xmlWriter->startElement('w:r');
$xmlWriter->startElement('w:t');
$xmlWriter->writeAttribute('xml:space', 'preserve');
$xmlWriter->writeRaw(' ');
$xmlWriter->endElement();
// w:t
$xmlWriter->endElement();
// w:r
$this->writeContainerElements($xmlWriter, $element);
$xmlWriter->endElement();
// w:p
$xmlWriter->endElement();
// $this->elementNode
}
作者:nhatlang1
项目:elearningON
/**
* Write numbering.
*
* @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param array $numbering
* @return void
*/
private function writeNumbering(XMLWriter $xmlWriter, $numbering)
{
$numStyle = $numbering['style'];
$numLevel = $numbering['level'];
/** @var \PhpOffice\PhpWord\Style\Numbering $numbering */
$numbering = Style::getStyle($numStyle);
if ($numStyle !== null && $numbering !== null) {
$xmlWriter->startElement('w:numPr');
$xmlWriter->startElement('w:numId');
$xmlWriter->writeAttribute('w:val', $numbering->getIndex());
$xmlWriter->endElement(); // w:numId
$xmlWriter->startElement('w:ilvl');
$xmlWriter->writeAttribute('w:val', $numLevel);
$xmlWriter->endElement(); // w:ilvl
$xmlWriter->endElement(); // w:numPr
$xmlWriter->startElement('w:outlineLvl');
$xmlWriter->writeAttribute('w:val', $numLevel);
$xmlWriter->endElement(); // w:outlineLvl
}
}