本文整理匯總了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);
}