Added support for styling in lines

This commit is contained in:
Tim Otte 2020-09-29 12:13:41 +02:00
parent a53f7ff9c9
commit 3e612d2a94
3 changed files with 26 additions and 11 deletions

View File

@ -2097,6 +2097,9 @@ class ExtraFields
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
$value_key = price2num($value_arr); $value_key = price2num($value_arr);
} elseif (in_array($key_type, array('text'))) {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
$value_key = GETPOST($keysuffix."options_".$key.$keyprefix, 'alpha');
} else { } else {
if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
$value_key = GETPOST($keysuffix."options_".$key.$keyprefix); $value_key = GETPOST($keysuffix."options_".$key.$keyprefix);

View File

@ -231,14 +231,10 @@ class Segment implements IteratorAggregate, Countable
//throw new SegmentException("var $key not found in {$this->getName()}"); //throw new SegmentException("var $key not found in {$this->getName()}");
} }
$value=$this->odf->htmlToUTFAndPreOdf($value); $tag = $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT');
$value = $encode ? htmlspecialchars($value) : $value; $this->vars[$tag] = $this->odf->convertVarToOdf($value, $encode, $charset);
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
$value=$this->odf->preOdfToOdf($value);
$this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = $value;
return $this; return $this;
} }
/** /**

View File

@ -141,7 +141,23 @@ class Odf
//} //}
} }
$this->vars[$tag] = $this->convertVarToOdf($value, $encode, $charset);
return $this;
}
/**
* Replaces html tags in odt tags and returns a compatible string
* @param string $key Name of the variable within the template
* @param string $value Replacement value
* @param bool $encode If true, special XML characters are encoded
* @param string $charset Charset
* @return string
*/
public function convertVarToOdf($value, $encode = true, $charset = 'ISO-8859')
{
$value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value;
$convertedValue = $value;
// Check if the value includes html tags // Check if the value includes html tags
if ($this->_hasHtmlTag($value) === true) { if ($this->_hasHtmlTag($value) === true) {
@ -155,7 +171,7 @@ class Odf
'<style:style style:name="supText" style:family="text"><style:text-properties style:text-position="super 58%" /></style:style>' '<style:style style:name="supText" style:family="text"><style:text-properties style:text-position="super 58%" /></style:style>'
); );
$this->vars[$tag] = $this->_replaceHtmlWithOdtTag($this->_getDataFromHtml($value), $customStyles, $fontDeclarations); $convertedValue = $this->_replaceHtmlWithOdtTag($this->_getDataFromHtml($value), $customStyles, $fontDeclarations);
foreach ($customStyles as $key => $val) { foreach ($customStyles as $key => $val) {
array_push($automaticStyles, '<style:style style:name="customStyle' . $key . '" style:family="text">' . $val . '</style:style>'); array_push($automaticStyles, '<style:style style:name="customStyle' . $key . '" style:family="text">' . $val . '</style:style>');
@ -179,9 +195,9 @@ class Odf
} }
$this->contentXml = str_replace('</office:font-face-decls>', $fonts . '</office:font-face-decls>', $this->contentXml); $this->contentXml = str_replace('</office:font-face-decls>', $fonts . '</office:font-face-decls>', $this->contentXml);
} }
else $this->vars[$tag] = preg_replace('/(\r\n|\r|\n)/i', "<text:line-break/>", $value); else $convertedValue = preg_replace('/(\r\n|\r|\n)/i', "<text:line-break/>", $value);
return $this; return $convertedValue;
} }
/** /**