当前位置: 首页>>代码示例>>PHP>>正文


PHP TCPDF_STATIC::_getUSHORT方法代码示例

本文整理汇总了PHP中TCPDF_STATIC::_getUSHORT方法的典型用法代码示例。如果您正苦于以下问题:PHP TCPDF_STATIC::_getUSHORT方法的具体用法?PHP TCPDF_STATIC::_getUSHORT怎么用?PHP TCPDF_STATIC::_getUSHORT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPDF_STATIC的用法示例。


在下文中一共展示了TCPDF_STATIC::_getUSHORT方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _parsejpeg

 /**
  * Extract info from a JPEG file without using the GD library.
  * @param $file (string) image file to parse
  * @return array structure containing the image data
  * @public static
  */
 public static function _parsejpeg($file)
 {
     $a = getimagesize($file);
     if (empty($a)) {
         //Missing or incorrect image file
         return false;
     }
     if ($a[2] != 2) {
         // Not a JPEG file
         return false;
     }
     // bits per pixel
     $bpc = isset($a['bits']) ? intval($a['bits']) : 8;
     // number of image channels
     if (!isset($a['channels'])) {
         $channels = 3;
     } else {
         $channels = intval($a['channels']);
     }
     // default colour space
     switch ($channels) {
         case 1:
             $colspace = 'DeviceGray';
             break;
         case 3:
             $colspace = 'DeviceRGB';
             break;
         case 4:
             $colspace = 'DeviceCMYK';
             break;
         default:
             $channels = 3;
             $colspace = 'DeviceRGB';
             break;
     }
     // get file content
     $data = file_get_contents($file);
     // check for embedded ICC profile
     $icc = array();
     $offset = 0;
     while (($pos = strpos($data, "ICC_PROFILE", $offset)) !== false) {
         // get ICC sequence length
         $length = TCPDF_STATIC::_getUSHORT($data, $pos - 2) - 16;
         // marker sequence number
         $msn = max(1, ord($data[$pos + 12]));
         // number of markers (total of APP2 used)
         $nom = max(1, ord($data[$pos + 13]));
         // get sequence segment
         $icc[$msn - 1] = substr($data, $pos + 14, $length);
         // move forward to next sequence
         $offset = $pos + 14 + $length;
     }
     // order and compact ICC segments
     if (count($icc) > 0) {
         ksort($icc);
         $icc = implode('', $icc);
         if (ord($icc[36]) != 0x61 or ord($icc[37]) != 0x63 or ord($icc[38]) != 0x73 or ord($icc[39]) != 0x70) {
             // invalid ICC profile
             $icc = false;
         }
     } else {
         $icc = false;
     }
     return array('w' => $a[0], 'h' => $a[1], 'ch' => $channels, 'icc' => $icc, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data);
 }
开发者ID:amirjuve,项目名称:php,代码行数:71,代码来源:tcpdf_images.php

示例2: _getTrueTypeFontSubset

	/**
	 * Returns a subset of the TrueType font data without the unused glyphs.
	 * @param $font (string) TrueType font data.
	 * @param $subsetchars (array) Array of used characters (the glyphs to keep).
	 * @return (string) A subset of TrueType font data without the unused glyphs.
	 * @author Nicola Asuni
	 * @since 5.2.000 (2010-06-02)
	 * @public static
	 */
	public static function _getTrueTypeFontSubset($font, $subsetchars) {
		ksort($subsetchars);
		$offset = 0; // offset position of the font data
		if (TCPDF_STATIC::_getULONG($font, $offset) != 0x10000) {
			// sfnt version must be 0x00010000 for TrueType version 1.0.
			return $font;
		}
		$offset += 4;
		// get number of tables
		$numTables = TCPDF_STATIC::_getUSHORT($font, $offset);
		$offset += 2;
		// skip searchRange, entrySelector and rangeShift
		$offset += 6;
		// tables array
		$table = array();
		// for each table
		for ($i = 0; $i < $numTables; ++$i) {
			// get table info
			$tag = substr($font, $offset, 4);
			$offset += 4;
			$table[$tag] = array();
			$table[$tag]['checkSum'] = TCPDF_STATIC::_getULONG($font, $offset);
			$offset += 4;
			$table[$tag]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
			$offset += 4;
			$table[$tag]['length'] = TCPDF_STATIC::_getULONG($font, $offset);
			$offset += 4;
		}
		// check magicNumber
		$offset = $table['head']['offset'] + 12;
		if (TCPDF_STATIC::_getULONG($font, $offset) != 0x5F0F3CF5) {
			// magicNumber must be 0x5F0F3CF5
			return $font;
		}
		$offset += 4;
		// get offset mode (indexToLocFormat : 0 = short, 1 = long)
		$offset = $table['head']['offset'] + 50;
		$short_offset = (TCPDF_STATIC::_getSHORT($font, $offset) == 0);
		$offset += 2;
		// get the offsets to the locations of the glyphs in the font, relative to the beginning of the glyphData table
		$indexToLoc = array();
		$offset = $table['loca']['offset'];
		if ($short_offset) {
			// short version
			$tot_num_glyphs = floor($table['loca']['length'] / 2); // numGlyphs + 1
			for ($i = 0; $i < $tot_num_glyphs; ++$i) {
				$indexToLoc[$i] = TCPDF_STATIC::_getUSHORT($font, $offset) * 2;
				$offset += 2;
			}
		} else {
			// long version
			$tot_num_glyphs = ($table['loca']['length'] / 4); // numGlyphs + 1
			for ($i = 0; $i < $tot_num_glyphs; ++$i) {
				$indexToLoc[$i] = TCPDF_STATIC::_getULONG($font, $offset);
				$offset += 4;
			}
		}
		// get glyphs indexes of chars from cmap table
		$subsetglyphs = array(); // glyph IDs on key
		$subsetglyphs[0] = true; // character codes that do not correspond to any glyph in the font should be mapped to glyph index 0
		$offset = $table['cmap']['offset'] + 2;
		$numEncodingTables = TCPDF_STATIC::_getUSHORT($font, $offset);
		$offset += 2;
		$encodingTables = array();
		for ($i = 0; $i < $numEncodingTables; ++$i) {
			$encodingTables[$i]['platformID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
			$offset += 2;
			$encodingTables[$i]['encodingID'] = TCPDF_STATIC::_getUSHORT($font, $offset);
			$offset += 2;
			$encodingTables[$i]['offset'] = TCPDF_STATIC::_getULONG($font, $offset);
			$offset += 4;
		}
		foreach ($encodingTables as $enctable) {
			// get all platforms and encodings
			$offset = $table['cmap']['offset'] + $enctable['offset'];
			$format = TCPDF_STATIC::_getUSHORT($font, $offset);
			$offset += 2;
			switch ($format) {
				case 0: { // Format 0: Byte encoding table
					$offset += 4; // skip length and version/language
					for ($c = 0; $c < 256; ++$c) {
						if (isset($subsetchars[$c])) {
							$g = TCPDF_STATIC::_getBYTE($font, $offset);
							$subsetglyphs[$g] = true;
						}
						++$offset;
					}
					break;
				}
				case 2: { // Format 2: High-byte mapping through table
					$offset += 4; // skip length and version/language
//.........这里部分代码省略.........
开发者ID:elcharlygraf,项目名称:Encuesta-YiiFramework,代码行数:101,代码来源:tcpdf_fonts.php


注:本文中的TCPDF_STATIC::_getUSHORT方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。