本文整理汇总了PHP中TCPDF_FONTS::UTF8StringToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP TCPDF_FONTS::UTF8StringToArray方法的具体用法?PHP TCPDF_FONTS::UTF8StringToArray怎么用?PHP TCPDF_FONTS::UTF8StringToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPDF_FONTS
的用法示例。
在下文中一共展示了TCPDF_FONTS::UTF8StringToArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hyphenateText
/**
* Returns text with soft hyphens.
* @param $text (string) text to process
* @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
* @param $dictionary (array) Array of words to be returned without applying the hyphenation algoritm.
* @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
* @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
* @param $charmin (int) Minimum word length to apply the hyphenation algoritm.
* @param $charmax (int) Maximum length of broken piece of word.
* @return array text with soft hyphens
* @author Nicola Asuni
* @since 4.9.012 (2010-04-12)
* @public
*/
public function hyphenateText($text, $patterns, $dictionary = array(), $leftmin = 1, $rightmin = 2, $charmin = 1, $charmax = 8)
{
$text = $this->unhtmlentities($text);
$word = array();
// last word
$txtarr = array();
// text to be returned
$intag = false;
// true if we are inside an HTML tag
if (!is_array($patterns)) {
$patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
}
// get array of characters
$unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
// for each char
foreach ($unichars as $char) {
if (!$intag and TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
// letter character
$word[] = $char;
} else {
// other type of character
if (!TCPDF_STATIC::empty_string($word)) {
// hypenate the word
$txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
$word = array();
}
$txtarr[] = $char;
if (chr($char) == '<') {
// we are inside an HTML tag
$intag = true;
} elseif ($intag and chr($char) == '>') {
// end of HTML tag
$intag = false;
}
}
}
if (!TCPDF_STATIC::empty_string($word)) {
// hypenate the word
$txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
}
// convert char array to string and return
return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
}
示例2: hyphenateText
/**
* Returns text with soft hyphens.
* @param $text (string) text to process
* @param $patterns (mixed) Array of hypenation patterns or a TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
* @param $dictionary (array) Array of words to be returned without applying the hyphenation algorithm.
* @param $leftmin (int) Minimum number of character to leave on the left of the word without applying the hyphens.
* @param $rightmin (int) Minimum number of character to leave on the right of the word without applying the hyphens.
* @param $charmin (int) Minimum word length to apply the hyphenation algorithm.
* @param $charmax (int) Maximum length of broken piece of word.
* @return array text with soft hyphens
* @author Nicola Asuni
* @since 4.9.012 (2010-04-12)
* @public
*/
public function hyphenateText($text, $patterns, $dictionary = array(), $leftmin = 1, $rightmin = 2, $charmin = 1, $charmax = 8)
{
$text = $this->unhtmlentities($text);
$word = array();
// last word
$txtarr = array();
// text to be returned
$intag = false;
// true if we are inside an HTML tag
$skip = false;
// true to skip hyphenation
if (!is_array($patterns)) {
$patterns = TCPDF_STATIC::getHyphenPatternsFromTEX($patterns);
}
// get array of characters
$unichars = TCPDF_FONTS::UTF8StringToArray($text, $this->isunicode, $this->CurrentFont);
// for each char
foreach ($unichars as $char) {
if (!$intag and !$skip and TCPDF_FONT_DATA::$uni_type[$char] == 'L') {
// letter character
$word[] = $char;
} else {
// other type of character
if (!TCPDF_STATIC::empty_string($word)) {
// hypenate the word
$txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
$word = array();
}
$txtarr[] = $char;
if (chr($char) == '<') {
// we are inside an HTML tag
$intag = true;
} elseif ($intag and chr($char) == '>') {
// end of HTML tag
$intag = false;
// check for style tag
$expected = array(115, 116, 121, 108, 101);
// = 'style'
$current = array_slice($txtarr, -6, 5);
// last 5 chars
$compare = array_diff($expected, $current);
if (empty($compare)) {
// check if it is a closing tag
$expected = array(47);
// = '/'
$current = array_slice($txtarr, -7, 1);
$compare = array_diff($expected, $current);
if (empty($compare)) {
// closing style tag
$skip = false;
} else {
// opening style tag
$skip = true;
}
}
}
}
}
if (!TCPDF_STATIC::empty_string($word)) {
// hypenate the word
$txtarr = array_merge($txtarr, $this->hyphenateWord($word, $patterns, $dictionary, $leftmin, $rightmin, $charmin, $charmax));
}
// convert char array to string and return
return TCPDF_FONTS::UTF8ArrSubString($txtarr, '', '', $this->isunicode);
}