public function render($format, $mml, $latex, $properties, $outProperties)
 {
     $servicesClass = Type::resolveClass("com.wiris.editor.services.PublicServices");
     $getInstance = Reflect::field($servicesClass, "getInstance");
     $publicServices = Reflect::callMethod($servicesClass, $getInstance, null);
     $args = new _hx_array(array());
     $args->push($mml);
     $args->push($latex);
     $args->push($properties);
     $args->push($outProperties);
     try {
         if (_hx_index_of($format, "png", null) !== -1) {
             $renderPngMethod = Reflect::field($publicServices, "renderPng");
             $pngObject = Reflect::callMethod($publicServices, $renderPngMethod, $args);
             $pngBytes = $pngObject;
             return haxe_io_Bytes::ofData($pngBytes);
         } else {
             if (_hx_index_of($format, "svg", null) !== -1) {
                 $renderSvgMethod = Reflect::field($publicServices, "renderSvg");
                 $svgObject = Reflect::callMethod($publicServices, $renderSvgMethod, $args);
                 $svgString = $svgObject;
                 return haxe_io_Bytes::ofString($svgString);
             } else {
                 throw new HException("Unexpected image format.");
             }
         }
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $e = $_ex_;
         throw new HException($e->getMessage());
     }
 }
 public function storeData($digest, $service, $stream)
 {
     $formula = $this->getAndCheckFolder(com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER);
     $parent = $this->getFolderStore($formula, $digest);
     $parent->mkdirs();
     $store = $this->getFileStoreWithParent($parent, $digest, $this->getExtension($service));
     $store->writeBinary(haxe_io_Bytes::ofData($stream));
 }
 public function getMetricsFromBytes($bs, &$output)
 {
     $output = $output;
     $width = 0;
     $height = 0;
     $dpi = 0;
     $baseline = 0;
     $bys = haxe_io_Bytes::ofData($bs);
     $bi = new haxe_io_BytesInput($bys, null, null);
     $n = $bys->length;
     $alloc = 10;
     $b = haxe_io_Bytes::alloc($alloc);
     $bi->readBytes($b, 0, 8);
     $n -= 8;
     while ($n > 0) {
         $len = com_wiris_system_InputEx::readInt32_($bi);
         $typ = com_wiris_system_InputEx::readInt32_($bi);
         if ($typ === 1229472850) {
             $width = com_wiris_system_InputEx::readInt32_($bi);
             $height = com_wiris_system_InputEx::readInt32_($bi);
             com_wiris_system_InputEx::readInt32_($bi);
             $bi->readByte();
         } else {
             if ($typ === 1650545477) {
                 $baseline = com_wiris_system_InputEx::readInt32_($bi);
             } else {
                 if ($typ === 1883789683) {
                     $dpi = com_wiris_system_InputEx::readInt32_($bi);
                     $dpi = Math::round($dpi / 39.37);
                     com_wiris_system_InputEx::readInt32_($bi);
                     $bi->readByte();
                 } else {
                     if ($len > $alloc) {
                         $alloc = $len;
                         $b = haxe_io_Bytes::alloc($alloc);
                     }
                     $bi->readBytes($b, 0, $len);
                 }
             }
         }
         com_wiris_system_InputEx::readInt32_($bi);
         $n -= $len + 12;
         unset($typ, $len);
     }
     $r = null;
     if ($output !== null) {
         $output["width"] = "" . _hx_string_rec($width, "");
         $output["height"] = "" . _hx_string_rec($height, "");
         $output["baseline"] = "" . _hx_string_rec($baseline, "");
         if ($dpi !== 96) {
             $output["dpi"] = "" . _hx_string_rec($dpi, "");
         }
         $r = "";
     } else {
         $r = "&cw=" . _hx_string_rec($width, "") . "&ch=" . _hx_string_rec($height, "") . "&cb=" . _hx_string_rec($baseline, "");
         if ($dpi !== 96) {
             $r = $r . "&dpi=" . _hx_string_rec($dpi, "");
         }
     }
     return $r;
 }
Exemple #4
0
 public function getTestPage()
 {
     $random = "" . _hx_string_rec(Math::floor(Math::random() * 9999), "");
     $mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><msqrt><mn>" . $random . "</mn></msqrt></mrow></math>";
     $testName = null;
     $reportText = null;
     $solutionLink = null;
     $condition = null;
     $output = "";
     $output .= "<html><head>\r\n";
     $output .= "<title>WIRIS plugin test page</title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /><style type=\"text/css\">/*<!--*/html {font-family: sans-serif;}h2 {margin-left: 1em;}h3 {margin-left: 2em;}p {margin-left: 3em;}p.concrete {margin-left: 4em;}.ok {font-weight: bold;color: #0c0;}.error {font-weight: bold;color: #f00;}/*-->*/</style><style type=\"text/css\">body{font-family: Arial;}span{font-weight: bold;}span.ok {color: #009900;}span.error {color: #dd0000;}table, th, td, tr {border: solid 1px #000000;border-collapse:collapse;padding: 5px;}th{background-color: #eeeeee;}img{border:none;}</style>\r\n";
     $output .= "<script src=\"../core/WIRISplugins.js?viewer=image\" ></script>\r\n";
     $output .= "</head><body><h1>WIRIS plugin test page</h1>\r\n";
     $output .= "<table><tr><th>Test</th><th>Report</th><th>Status</th></tr>\r\n";
     $testName = "WIRIS plugin version";
     try {
         $s = com_wiris_system_Storage::newResourceStorage("VERSION")->read();
         $reportText = "<b>" . $s . "</b>";
         $solutionLink = "";
         $condition = true;
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $ex = $_ex_;
         $reportText = "Missing version";
         $solutionLink = "";
         $condition = false;
     }
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Creating and storing data";
     $solutionLink = "";
     $param = array();
     $outp = array();
     $imageUrl = $this->plugin->newRender()->createImage($mml, $param, $outp);
     $reportText = "<a href=\"" . $imageUrl . "\" />" . $imageUrl . "</a>";
     $condition = true;
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Retrieving data";
     $solutionLink = "";
     $reportText = "<img src=\"" . $imageUrl . "\" />";
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "JavaScript MathML filter";
     $solutionLink = "";
     $reportText = $mml;
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Host platform";
     $solutionLink = "";
     $platform = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$HOST_PLATFORM, "failed");
     $reportText = $platform;
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Filter test";
     $solutionLink = "";
     $condition = true;
     $p = null;
     $p = array();
     $p["savemode"] = "safeXml";
     $s2 = str_replace("<", com_wiris_plugin_impl_TestImpl_0($this, $condition, $ex, $imageUrl, $mml, $outp, $output, $p, $param, $platform, $random, $reportText, $solutionLink, $testName), $mml);
     $s2 = str_replace(">", com_wiris_plugin_impl_TestImpl_1($this, $condition, $ex, $imageUrl, $mml, $outp, $output, $p, $param, $platform, $random, $reportText, $s2, $solutionLink, $testName), $s2);
     $s2 = str_replace("\"", com_wiris_plugin_impl_TestImpl_2($this, $condition, $ex, $imageUrl, $mml, $outp, $output, $p, $param, $platform, $random, $reportText, $s2, $solutionLink, $testName), $s2);
     $reportText = $this->plugin->newTextService()->filter("square root: " . $s2, $p);
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Connecting to www.wiris.net";
     $solutionLink = "";
     $condition = true;
     try {
         $h = new com_wiris_plugin_impl_HttpImpl("http://www.wiris.net", null);
         $h->request(true);
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $ex2 = $_ex_;
         $condition = false;
     }
     $reportText = "Checking if WIRIS server is reachable";
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     if (Type::resolveClass("com.wiris.editor.services.PublicServices") !== null) {
         $condition = true;
         $testName = "Testing integrated services";
         $reportText = "WIRIS Services installed";
         $solutionLink = "";
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $isLicensed = $this->plugin->isEditorLicensed();
         $condition = false;
         $testName = "WIRIS editor license";
         $reportText = "Checking WIRIS editor valid license";
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $isLicensed);
     } else {
         $reportText = "WIRIS Services not installed";
     }
     $debug = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$DEBUG, "false") === "true";
     if ($debug) {
         $testName = "Font family";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$FONT_FAMILY, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Configuration file";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_PATH, "") . "\\configuration.ini";
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Cache path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Formula path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$FORMULA_FOLDER, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Integration path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$INTEGRATION_PATH, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Context path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONTEXT_PATH, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "default-configuration.ini load";
         $solutionLink = "";
         $defaultConfiguration = com_wiris_system_Storage::newResourceStorage("default-configuration.ini")->read();
         $condition = $defaultConfiguration !== null && strlen($defaultConfiguration) > 0;
         if ($condition) {
             $reportText = "Length: " . _hx_string_rec(strlen($defaultConfiguration), "");
         } else {
             $reportText = "Not found!";
         }
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "cas.png load";
         $solutionLink = "";
         $casPng = com_wiris_system_Storage::newResourceStorage("cas.png")->readBinary();
         $casPngLength = 0;
         if ($casPng !== null) {
             $casPngLength = haxe_io_Bytes::ofData($casPng)->length;
             $condition = $casPngLength > 0;
         } else {
             $condition = false;
         }
         if ($condition) {
             $reportText = "Length: " . _hx_string_rec($casPngLength, "");
         } else {
             $reportText = "Not found!";
         }
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     }
     $output .= "<div id=\"haxe:trace\"></div>";
     return $output;
 }
 public function createImage($mml, $param, &$output)
 {
     $output = $output;
     if ($mml === null) {
         throw new HException("Missing parameter 'mml'.");
     }
     $digest = $this->computeDigest($mml, $param);
     $contextPath = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONTEXT_PATH, "/");
     $showImagePath = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$SHOWIMAGE_PATH, null);
     $saveMode = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$SAVE_MODE, "xml");
     $s = "";
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "metrics", "false") === "true") {
         $s = $this->getMetrics($digest, $output);
     }
     $a = "";
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "accessible", "false") === "true") {
         $lang = com_wiris_system_PropertiesTools::getProperty($param, "lang", "en");
         $text = $this->safeMath2Accessible($mml, $lang, $param);
         if ($output === null) {
             $a = "&text=" . rawurlencode($text);
         } else {
             $output["alt"] = $text;
         }
     }
     $rparam = "";
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "refererquery", null) !== null) {
         $refererquery = com_wiris_system_PropertiesTools::getProperty($param, "refererquery", null);
         $rparam = "&refererquery=" . $refererquery;
     }
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "base64", null) !== null || $saveMode === "base64") {
         $bs = $this->showImage($digest, null, $param);
         $by = haxe_io_Bytes::ofData($bs);
         $b64 = _hx_deref(new com_wiris_system_Base64())->encodeBytes($by);
         return "data:image/png;base64," . $b64->toString();
     } else {
         return com_wiris_plugin_impl_RenderImpl::concatPath($contextPath, $showImagePath) . rawurlencode($digest) . $s . $a . $rparam;
     }
 }
 public function writeBinary($bs)
 {
     $bytes = haxe_io_Bytes::ofData($bs);
     $fo = sys_io_File::write($this->location, true);
     $fo->writeBytes($bytes, 0, $bytes->length);
 }
 public function storeData($digest, $service, $stream)
 {
     $formula = $this->getAndCheckFolder(com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER);
     $store = com_wiris_util_sys_Store::newStoreWithParent(com_wiris_util_sys_Store::newStore($formula), $digest . $this->getExtension($service));
     $store->writeBinary(haxe_io_Bytes::ofData($stream));
 }
Exemple #8
0
 static function fromBytes($s)
 {
     $bs = haxe_io_Bytes::ofData($s);
     return $bs->toString();
 }