public function math2Img($str, $prop)
 {
     $img = "<img";
     $output = array();
     $prop["centerbaseline"] = "false";
     $prop["accessible"] = "true";
     $prop["metrics"] = "true";
     $src = $this->render->createImage($str, $prop, $output);
     $img .= " src=\"" . $src . "\"";
     $alt = com_wiris_system_PropertiesTools::getProperty($output, "alt", null);
     $width = com_wiris_system_PropertiesTools::getProperty($output, "width", null);
     $height = com_wiris_system_PropertiesTools::getProperty($output, "height", null);
     $baseline = com_wiris_system_PropertiesTools::getProperty($output, "baseline", null);
     $dpi = Std::parseFloat($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$WIRIS_DPI, "96"));
     if ($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null) !== null) {
         $json = com_wiris_util_json_JSon::decode($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null));
         $decodedHash = $json;
         if ($decodedHash->exists("dpi")) {
             $dpi = Std::parseFloat($decodedHash->get("dpi"));
         }
     }
     $mml = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$FILTER_OUTPUT_MATHML, "false") === "true";
     $f = 96 / $dpi;
     $dwidth = $f * Std::parseFloat($width);
     $dheight = $f * Std::parseFloat($height);
     $dbaseline = $f * Std::parseFloat($baseline);
     $alt = $this->html_entity_encode($alt);
     $img .= " class=\"Wirisformula\"";
     $img .= " alt=\"" . $alt . "\"";
     $img .= " width=\"" . _hx_string_rec($dwidth, "") . "\"";
     $img .= " height=\"" . _hx_string_rec($dheight, "") . "\"";
     $d = $dbaseline - $dheight;
     $img .= " style=\"vertical-align:" . _hx_string_rec($d, "") . "px\"";
     if ($mml) {
         $tag = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_MATHML_ATTRIBUTE, "data-mathml");
         $img .= " " . $tag . "=\"" . $this->save_xml_encode($str) . "\"";
     }
     $img .= "/>";
     return $img;
 }
 public function showImage($digest, $mml, $param)
 {
     if ($digest === null && $mml === null) {
         throw new HException("Missing parameters 'formula' or 'mml'.");
     }
     if ($digest !== null && $mml !== null) {
         throw new HException("Only one parameter 'formula' or 'mml' is valid.");
     }
     $atts = false;
     if ($digest === null && $mml !== null) {
         $digest = $this->computeDigest($mml, $param);
     }
     $formula = $this->plugin->getStorageAndCache()->decodeDigest($digest);
     if ($formula === null) {
         throw new HException("Formula associated to digest not found.");
     }
     if (StringTools::startsWith($formula, "<")) {
         throw new HException("Not implemented.");
     }
     $iniFile = com_wiris_util_sys_IniFile::newIniFileFromString($formula);
     $renderParams = $iniFile->getProperties();
     $i = null;
     $ss = $this->getEditorParametersList();
     if ($param !== null) {
         $_g1 = 0;
         $_g = $ss->length;
         while ($_g1 < $_g) {
             $i1 = $_g1++;
             $key = $ss[$i1];
             $value = com_wiris_system_PropertiesTools::getProperty($param, $key, null);
             if ($value !== null) {
                 $atts = true;
                 $renderParams->set($key, $value);
             }
             unset($value, $key, $i1);
         }
     }
     if ($atts) {
         if ($mml !== null) {
             $digest = $this->computeDigest($mml, com_wiris_system_PropertiesTools::toProperties($renderParams));
         } else {
             $digest = $this->computeDigest($renderParams->get("mml"), com_wiris_system_PropertiesTools::toProperties($renderParams));
         }
     }
     $store = $this->plugin->getStorageAndCache();
     $bs = null;
     $bs = $store->retreiveData($digest, $this->plugin->getConfiguration()->getProperty("wirisimageformat", "png"));
     if ($bs === null) {
         if ($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null) !== null) {
             $json = com_wiris_util_json_JSon::decode($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null));
             $decodedHash = $json;
             $keys = $decodedHash->keys();
             $notAllowedParams = _hx_explode(",", com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMETERS_NOTRENDER_LIST);
             while ($keys->hasNext()) {
                 $key = $keys->next();
                 if (!com_wiris_system_ArrayEx::contains($notAllowedParams, $key)) {
                     $renderParams->set($key, $decodedHash->get($key));
                 }
                 unset($key);
             }
         } else {
             $_g1 = 0;
             $_g = $ss->length;
             while ($_g1 < $_g) {
                 $i1 = $_g1++;
                 $key = $ss[$i1];
                 if (!$renderParams->exists($key)) {
                     $confKey = com_wiris_plugin_api_ConfigurationKeys::$imageConfigProperties->get($key);
                     if ($confKey !== null) {
                         $value = $this->plugin->getConfiguration()->getProperty($confKey, null);
                         if ($value !== null) {
                             $renderParams->set($key, $value);
                         }
                         unset($value);
                     }
                     unset($confKey);
                 }
                 unset($key, $i1);
             }
         }
         $prop = com_wiris_system_PropertiesTools::toProperties($renderParams);
         $iter = $renderParams->keys();
         $mml = $renderParams->get("mml");
         $b = $this->render($this->plugin->getConfiguration()->getProperty("wirisimageformat", "png"), $mml, null, $prop, null);
         $store->storeData($digest, $this->plugin->getConfiguration()->getProperty("wirisimageformat", "png"), $b->b);
         $bs = $b->b;
     }
     return $bs;
 }
Beispiel #3
0
 public function math2Img($str, $prop)
 {
     $img = "<img";
     $output = array();
     $prop["centerbaseline"] = "false";
     $prop["accessible"] = "true";
     $prop["metrics"] = "true";
     $src = null;
     $alt = null;
     $width = null;
     $height = null;
     $baseline = null;
     if ($this->plugin->getConfiguration()->getProperty("wirispluginperformance", "false") === "false") {
         $src = $this->render->createImage($str, $prop, $output);
         $img .= " src=\"" . $src . "\"";
         $alt = com_wiris_system_PropertiesTools::getProperty($output, "alt", null);
         $width = com_wiris_system_PropertiesTools::getProperty($output, "width", null);
         $height = com_wiris_system_PropertiesTools::getProperty($output, "height", null);
         $baseline = com_wiris_system_PropertiesTools::getProperty($output, "baseline", null);
     } else {
         $digest = $this->render->computeDigest($str, $prop);
         $json = com_wiris_util_json_JSon::decode($this->render->showImageJson($digest, com_wiris_system_PropertiesTools::getProperty($prop, "alt", null)));
         $hashImage = $json;
         if (_hx_equal($hashImage->get("status"), "warning")) {
             $this->render->showImage(null, $str, $prop);
         }
         $json = com_wiris_util_json_JSon::decode($this->render->showImageJson($digest, "en"));
         $hashImage = $json;
         if (_hx_equal($hashImage->get("status"), "ok")) {
             $result = $hashImage->get("result");
             $base64 = $result->get("pngBase64");
             $img .= " src=\"data:image/png;base64," . $base64 . "\"";
             if ($result->exists("alt")) {
                 $alt = $result->get("alt");
             } else {
                 $alt = $this->service->mathml2accessible($str, null, $prop);
             }
             $width = $result->get("width");
             $height = $result->get("height");
             $baseline = $result->get("baseline");
         } else {
             throw new HException("Image can't be rendererd");
         }
     }
     $dpi = Std::parseFloat($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$WIRIS_DPI, "96"));
     if ($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null) !== null) {
         $json = com_wiris_util_json_JSon::decode($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null));
         $decodedHash = $json;
         if ($decodedHash->exists("dpi")) {
             $dpi = Std::parseFloat($decodedHash->get("dpi"));
         }
     }
     $mml = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$FILTER_OUTPUT_MATHML, "false") === "true";
     $f = 96 / $dpi;
     $dwidth = $f * Std::parseFloat($width);
     $dheight = $f * Std::parseFloat($height);
     $dbaseline = $f * Std::parseFloat($baseline);
     $alt = $this->html_entity_encode($alt);
     $img .= " class=\"Wirisformula\"";
     $img .= " alt=\"" . $alt . "\"";
     $img .= " width=\"" . _hx_string_rec($dwidth, "") . "\"";
     $img .= " height=\"" . _hx_string_rec($dheight, "") . "\"";
     $d = $dbaseline - $dheight;
     $img .= " style=\"vertical-align:" . _hx_string_rec($d, "") . "px\"";
     if ($mml) {
         $tag = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_MATHML_ATTRIBUTE, "data-mathml");
         $img .= " " . $tag . "=\"" . $this->save_xml_encode($str) . "\"";
     }
     $img .= "/>";
     return $img;
 }