Exemple #1
0
 /**
  * Extract data from a JPEG image
  *
  * @param string $data Image raw data
  *
  * @return array Image raw data array
  */
 public function getData($data)
 {
     $data['filter'] = 'DCTDecode';
     $data['data'] = $data['raw'];
     $byte = new Byte($data['raw']);
     // extract embedded ICC profile (if any)
     $icc = array();
     $offset = 0;
     while (($pos = strpos($data['raw'], 'ICC_PROFILE' . "", $offset)) !== false) {
         // get ICC sequence length
         $length = $byte->getUShort($pos - 2) - 16;
         // marker sequence number
         $msn = max(1, ord($data['raw'][$pos + 12]));
         // number of markers (total of APP2 used)
         //$nom = max(1, ord($data['raw'][($pos + 13)]));
         // get sequence segment
         $icc[$msn - 1] = substr($data['raw'], $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 (substr($icc, 36, 4) == 'acsp') {
             // valid ICC profile
             $data['icc'] = $icc;
         }
     }
     return $data;
 }
 /**
  * Get maxp data
  */
 protected function getMaxpData()
 {
     $this->offset = $this->fdt['table']['maxp']['offset'];
     $this->offset += 4;
     // skip Table version number
     // get the the number of glyphs in the font.
     $this->fdt['numGlyphs'] = $this->fbyte->getUShort($this->offset);
 }
 /**
  * Add composite glyphs
  *
  * @param array $new_sga
  * @param int   $key
  *
  * @return array
  */
 protected function findCompositeGlyphs($new_sga, $key)
 {
     if (isset($this->fdt['indexToLoc'][$key])) {
         $this->offset = $this->fdt['table']['glyf']['offset'] + $this->fdt['indexToLoc'][$key];
         $numberOfContours = $this->fbyte->getShort($this->offset);
         $this->offset += 2;
         if ($numberOfContours < 0) {
             // composite glyph
             $this->offset += 8;
             // skip xMin, yMin, xMax, yMax
             do {
                 $flags = $this->fbyte->getUShort($this->offset);
                 $this->offset += 2;
                 $glyphIndex = $this->fbyte->getUShort($this->offset);
                 $this->offset += 2;
                 if (!isset($this->subglyphs[$glyphIndex])) {
                     // add missing glyphs
                     $new_sga[$glyphIndex] = true;
                 }
                 // skip some bytes by case
                 if ($flags & 1) {
                     $this->offset += 4;
                 } else {
                     $this->offset += 2;
                 }
                 if ($flags & 8) {
                     $this->offset += 2;
                 } elseif ($flags & 64) {
                     $this->offset += 4;
                 } elseif ($flags & 128) {
                     $this->offset += 8;
                 }
             } while ($flags & 32);
         }
     }
     return $new_sga;
 }