public function processEntry($key, $value, GridFile $file)
 {
     foreach (str_split(preg_replace("/\n/", "", $value)) as $index => $char) {
         if ($char === "1") {
             $file->addPicture($index % $file->getWidth(), floor($index / $file->getWidth()));
         }
     }
 }
Пример #2
0
 public function processEntry($key, $value, GridFile $file)
 {
     $index = 0;
     $rows = array_map(function ($row) {
         return substr($row, 1, strlen($row) - 2);
     }, explode(",", substr($value, 1, strlen($value) - 2)));
     foreach ($rows as $row) {
         $file->addRow($row, ++$index);
     }
 }
Пример #3
0
 /**
  * @param GridFile $file
  *
  * @return AbstractReader
  * @throws MflParserException
  */
 private static function getReaderForFile(GridFile $file)
 {
     switch (strtolower($file->getExtension())) {
         case "mfl":
             return new MflReader($file);
         case "mfj":
             return new MfjReader($file);
     }
     throw new MflParserException(0, 0, "Can't find appropriate reader for extension {$file->getExtension()}");
 }
Пример #4
0
 public function processEntry($key, $value, GridFile $file)
 {
     if (preg_match("/^F[1-9]/", $value)) {
         $file->setForce(intval($value[1]));
     } else {
         if (preg_match("/Force [1-9]/", $value)) {
             $file->setForce(intval($value[strpos($value, "Force ") + strlen("Force ")]));
         } else {
             throw new MflParserException(0, 0, "Unable to detect grid level in '{$value}'");
         }
     }
 }
Пример #5
0
 public function processEntry($key, $value, GridFile $file)
 {
     $state = self::STATE_UKNOWN;
     $index = 0;
     $definition = "";
     foreach (str_split(trim($value)) as $char) {
         switch ($char) {
             case '[':
                 if ($state === self::STATE_UKNOWN) {
                     $state = self::STATE_BODY;
                 } else {
                     if ($state === self::STATE_BODY) {
                         $state = self::STATE_DEFINITION;
                     }
                 }
                 break;
             case ']':
                 if ($state === self::STATE_BODY) {
                     $state = self::STATE_UKNOWN;
                 } else {
                     if ($state === self::STATE_DEFINITION) {
                         $file->addDefinition(trim($definition), ++$index);
                         $definition = "";
                         $state = self::STATE_BODY;
                     }
                 }
                 break;
             case '"':
                 if ($state === self::STATE_DEFINITION) {
                     $state = self::STATE_DEFINITION_PART;
                 } else {
                     if ($state === self::STATE_DEFINITION_PART) {
                         $definition .= ord($char) !== 147 ? " " : "";
                         $state = self::STATE_DEFINITION;
                     }
                 }
                 break;
             default:
                 if ($state === self::STATE_DEFINITION_PART) {
                     $definition .= $char;
                 }
         }
     }
 }
 public function processEntry($key, $value, GridFile $file)
 {
     $row = substr($value, 1, strlen($value) - 2);
     $lbracket = strpos($row, "[");
     $rbracket = strpos($row, "]");
     while (false !== $lbracket && false !== $rbracket) {
         $coords = array_map(function ($d) {
             return intval($d);
         }, explode(",", substr($row, $lbracket + 1, $rbracket - $lbracket - 1)));
         if (sizeof($coords) === 4) {
             for ($x = $coords[1]; $x <= $coords[3]; $x++) {
                 for ($y = $coords[0]; $y <= $coords[2]; $y++) {
                     $file->addPicture($x - 1, $y - 1);
                 }
             }
         }
         $row = substr($row, $rbracket + 1);
         $lbracket = strpos($row, "[");
         $rbracket = strpos($row, "]");
     }
 }
Пример #7
0
 public function processEntry($key, $value, GridFile $file)
 {
     $file->setForce(intval(substr($value, 1, strlen($value) - 2)));
 }
Пример #8
0
 /**
  * @param $key
  * @param $value
  * @param GridFile $file
  */
 public function processEntry($key, $value, GridFile $file)
 {
     $file->addRow(preg_replace("/\n/", "", $value), $this->getRowIndex($key));
 }
Пример #9
0
 public function processEntry($key, $value, GridFile $file)
 {
     $file->addDefinition(preg_replace("/\n/", " ", preg_replace("/-\n/", "", $value)), $this->getDefinitionIndex($key));
 }
Пример #10
0
 public function processEntry($key, $value, GridFile $file)
 {
     $file->addDashes(intval(substr($key, strlen(self::PREFIX))), (int) $value);
 }
Пример #11
0
 private static function getWord(Arrow $arrow, GridFile $gridFile, $xStart, $yStart)
 {
     $word = "";
     $cell = $arrow->firstCell($xStart, $yStart);
     list($x, $y) = $cell;
     $value = $gridFile->getCell($x, $y);
     while ($x < $gridFile->getWidth() && $y < $gridFile->getHeight() && $value != strtolower($value)) {
         $word .= $value;
         $cell = $arrow->nextCell($x, $y);
         list($x, $y) = $cell;
         $value = $gridFile->getCell($x, $y);
     }
     return $word;
 }
Пример #12
0
 public function processEntry($key, $value, GridFile $file)
 {
     $file->addLevels($this->getLevels(preg_replace("/\n/", "", $value)));
 }