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; }
static function compare($a, $b, $eps) { if (com_wiris_system_TypeTools::isHash($a)) { $isBHash = com_wiris_system_TypeTools::isHash($b); if (!$isBHash) { return false; } $ha = $a; $hb = $b; $it = $ha->keys(); while ($it->hasNext()) { $key = $it->next(); if (!$hb->exists($key) || !com_wiris_util_json_JSon::compare($ha->get($key), $hb->get($key), $eps)) { return false; } unset($key); } return true; } else { if (com_wiris_system_TypeTools::isArray($a)) { $isBArray = com_wiris_system_TypeTools::isArray($b); if (!$isBArray) { return false; } $aa = $a; $ab = $b; if ($aa->length !== $ab->length) { return false; } $i = null; $_g1 = 0; $_g = $aa->length; while ($_g1 < $_g) { $i1 = $_g1++; if (!com_wiris_util_json_JSon::compare($aa[$i1], $ab[$i1], $eps)) { return false; } unset($i1); } return true; } else { if (Std::is($a, _hx_qtype("String"))) { if (!Std::is($b, _hx_qtype("String"))) { return false; } return _hx_equal($a, $b); } else { if (Std::is($a, _hx_qtype("Int"))) { if (!Std::is($b, _hx_qtype("Int"))) { return false; } return _hx_equal($a, $b); } else { if (Std::is($a, _hx_qtype("haxe.Int64"))) { $isBLong = Std::is($b, _hx_qtype("haxe.Int64")); if (!$isBLong) { return false; } return _hx_equal($a, $b); } else { if (Std::is($a, _hx_qtype("com.wiris.util.json.JSonIntegerFormat"))) { if (!Std::is($b, _hx_qtype("com.wiris.util.json.JSonIntegerFormat"))) { return false; } $ja = $a; $jb = $b; return $ja->toString() === $jb->toString(); } else { if (Std::is($a, _hx_qtype("Bool"))) { if (!Std::is($b, _hx_qtype("Bool"))) { return false; } return _hx_equal($a, $b); } else { if (Std::is($a, _hx_qtype("Float"))) { if (!Std::is($b, _hx_qtype("Float"))) { return false; } $da = com_wiris_util_json_JSon::getFloat($a); $db = com_wiris_util_json_JSon::getFloat($b); return $da >= $db - $eps && $da <= $db + $eps; } } } } } } } } return true; }
static function getDepth($o) { if (com_wiris_system_TypeTools::isHash($o)) { $h = $o; $m = 0; if ($h->exists("_left_") || $h->exists("_right_")) { if ($h->exists("_left_")) { $m = com_wiris_common_WInteger::max(com_wiris_util_json_JSon::getDepth($h->get("_left_")), $m); } if ($h->exists("_right_")) { $m = com_wiris_common_WInteger::max(com_wiris_util_json_JSon::getDepth($h->get("_right_")), $m); } return $m; } $iter = $h->keys(); while ($iter->hasNext()) { $key = $iter->next(); $m = com_wiris_common_WInteger::max(com_wiris_util_json_JSon::getDepth($h->get($key)), $m); unset($key); } return $m + 2; } else { if (com_wiris_system_TypeTools::isArray($o)) { $a = $o; $i = null; $m = 0; $_g1 = 0; $_g = $a->length; while ($_g1 < $_g) { $i1 = $_g1++; $m = com_wiris_common_WInteger::max(com_wiris_util_json_JSon::getDepth($a[$i1]), $m); unset($i1); } return $m + 1; } else { return 1; } } }
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; }