Skip to content

Commit

Permalink
4.12.0 stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
mcagigas-at-wiris authored Feb 1, 2018
1 parent dd05683 commit 7994817
Show file tree
Hide file tree
Showing 18 changed files with 271 additions and 37 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.11.0.1383
4.12.0.1384
12 changes: 10 additions & 2 deletions classes/accessprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
global $CFG;

require_once($CFG->dirroot . '/lib/moodlelib.php');
require_once($CFG->dirroot . '/filter/wiris/integration/lib/com/wiris/plugin/api/AccessProvider.interface.php');
require_once($CFG->dirroot . '/filter/wiris/integration/lib/com/wiris/util/sys/AccessProvider.interface.php');

class filter_wiris_accessprovider implements com_wiris_plugin_api_AccessProvider {
class filter_wiris_accessprovider implements com_wiris_util_sys_AccessProvider {
/**
* This method is called before all service. We use it as a wrapper to call
* Moodle require_login() method. Any WIRIS service can't be called without a
Expand All @@ -47,4 +47,12 @@ function requireAccess() {
// user is logged.
return true;
}

/**
* Not implemented.
*/
// @codingStandardsIgnoreStart
function isEnabled() {
// @codingStandardsIgnoreEnd
}
}
2 changes: 1 addition & 1 deletion integration/lib/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.11.0.1383
4.12.0.1384

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

interface com_wiris_plugin_api_ImageFormatController {
function scalateMetrics($dpi, $metrics);
function getMetrics($bytes, &$output);
function getContentType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
class com_wiris_plugin_impl_ImageFormatControllerPng implements com_wiris_plugin_api_ImageFormatController{
public function __construct() {
}
public function scalateMetrics($dpi, $metrics) {
$f = 96 / $dpi;
$metrics->set("width", intval($f * $metrics->get("width")));
$metrics->set("height", intval($f * $metrics->get("height")));
$metrics->set("baseline", intval($f * $metrics->get("baseline")));
}
public function getMetrics($bytes, &$output) {
$output = $output;
$width = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class com_wiris_plugin_impl_ImageFormatControllerSvg implements com_wiris_plugin_api_ImageFormatController{
public function __construct() {
}
public function scalateMetrics($dpi, $metrics) {
}
public function getMetrics($bytes, &$output) {
$svg = $bytes->toString();
$svgRoot = _hx_substr($svg, 0, _hx_index_of($svg, ">", null));
Expand Down
2 changes: 1 addition & 1 deletion integration/lib/com/wiris/plugin/impl/TestImpl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function createTableRow($testName, $reportText, $solutionLink, $condition
return $output;
}
public function getTestPage() {
$random = "" . _hx_string_rec(Math::floor(Math::random() * 9999), "");
$random = "" . _hx_string_rec(intval(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;
$this->conf = $this->plugin->getConfiguration();
Expand Down
17 changes: 10 additions & 7 deletions integration/lib/com/wiris/plugin/impl/TextFilter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ public function math2Img($str, $prop) {
}
$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);
$imageFormatController = $this->plugin->getImageFormatController();
$metricsHash = new Hash();
$metricsHash->set("width", Std::parseInt($width));
$metricsHash->set("height", Std::parseInt($height));
$metricsHash->set("baseline", Std::parseInt($baseline));
$imageFormatController->scalateMetrics($dpi, $metricsHash);
$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\"";
$img .= " width=\"" . _hx_string_rec($metricsHash->get("width"), "") . "\"";
$img .= " height=\"" . _hx_string_rec($metricsHash->get("height"), "") . "\"";
$verticalAlign = $metricsHash->get("baseline") - $metricsHash->get("height");
$img .= " style=\"vertical-align:" . _hx_string_rec($verticalAlign, "") . "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) . "'";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

interface com_wiris_plugin_provider_PhpAccessProvider extends com_wiris_plugin_api_AccessProvider{
interface com_wiris_plugin_provider_PhpAccessProvider extends com_wiris_util_sys_AccessProvider{
function setInitObject();
}
4 changes: 2 additions & 2 deletions integration/lib/com/wiris/system/TypeTools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ static function floatToString($value) {
return "" . _hx_string_rec($value, "");
}
static function isFloating($str) {
$pattern = new EReg("^(\\d|\\d\\.|\\.\\d)", "");
$pattern = new EReg("^[+-]?\\d*\\.?\\d+([eE][+-]?\\d+)?\$", "");
return $pattern->match($str);
}
static function isInteger($str) {
$pattern = new EReg("^(\\d)", "");
$pattern = new EReg("^[+-]?\\d+\$", "");
return $pattern->match($str);
}
static function isIdentifierPart($c) {
Expand Down
39 changes: 26 additions & 13 deletions integration/lib/com/wiris/util/json/JSon.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ public function encodeString($sb, $s) {
$sb->add($s);
$sb->add("\"");
}
public function encodeArrayInt($sb, $v) {
$v2 = new _hx_array(array());
$i = 0;
while($i < $v->length) {
$v2->push($v[$i]);
++$i;
}
$this->encodeArray($sb, $v2);
}
public function encodeArray($sb, $v) {
$newLines = $this->addNewLines && com_wiris_util_json_JSon::getDepth($v) > 2;
$this->depth++;
Expand Down Expand Up @@ -300,25 +309,29 @@ public function encodeImpl($sb, $o) {
if(com_wiris_system_TypeTools::isArray($o)) {
$this->encodeArray($sb, $o);
} else {
if(Std::is($o, _hx_qtype("String"))) {
$this->encodeString($sb, $o);
if(Std::is($o, _hx_qtype("Array"))) {
$this->encodeArrayInt($sb, $o);
} else {
if(Std::is($o, _hx_qtype("Int"))) {
$this->encodeInteger($sb, $o);
if(Std::is($o, _hx_qtype("String"))) {
$this->encodeString($sb, $o);
} else {
if(Std::is($o, _hx_qtype("haxe.Int64"))) {
$this->encodeLong($sb, $o);
if(Std::is($o, _hx_qtype("Int"))) {
$this->encodeInteger($sb, $o);
} else {
if(Std::is($o, _hx_qtype("com.wiris.util.json.JSonIntegerFormat"))) {
$this->encodeIntegerFormat($sb, $o);
if(Std::is($o, _hx_qtype("haxe.Int64"))) {
$this->encodeLong($sb, $o);
} else {
if(Std::is($o, _hx_qtype("Bool"))) {
$this->encodeBoolean($sb, $o);
if(Std::is($o, _hx_qtype("com.wiris.util.json.JSonIntegerFormat"))) {
$this->encodeIntegerFormat($sb, $o);
} else {
if(Std::is($o, _hx_qtype("Float"))) {
$this->encodeFloat($sb, $o);
if(Std::is($o, _hx_qtype("Bool"))) {
$this->encodeBoolean($sb, $o);
} else {
throw new HException("Impossible to convert to json object of type " . Std::string(Type::getClass($o)));
if(Std::is($o, _hx_qtype("Float"))) {
$this->encodeFloat($sb, $o);
} else {
throw new HException("Impossible to convert to json object of type " . Std::string(Type::getClass($o)));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

interface com_wiris_util_sys_AccessProvider {
function isEnabled();
function requireAccess();
}
195 changes: 195 additions & 0 deletions integration/lib/com/wiris/util/type/Arrays.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php

class com_wiris_util_type_Arrays {
public function __construct() {
}
static function newIntArray($length, $initValue) {
$data = new _hx_array(array());
--$length;
while($length >= 0) {
$data[$length] = $initValue;
--$length;
}
return $data;
}
static function indexOfElement($array, $element) {
$i = 0;
$n = $array->length;
while($i < $n) {
if($array[$i] !== null && $array[$i] == $element) {
return $i;
}
++$i;
}
return -1;
}
static function fromIterator($iterator) {
$array = new _hx_array(array());
while($iterator->hasNext()) {
$array->push($iterator->next());
}
return $array;
}
static function fromCSV($s) {
$words = _hx_explode(",", $s);
$i = 0;
while($i < $words->length) {
$w = trim($words[$i]);
if(strlen($w) > 0) {
$words[$i] = $w;
++$i;
} else {
$words->splice($i, 1);
}
unset($w);
}
return $words;
}
static function contains($array, $element) {
return com_wiris_util_type_Arrays::indexOfElement($array, $element) >= 0;
}
static function indexOfElementArray($array, $element) {
$i = null;
{
$_g1 = 0; $_g = $array->length;
while($_g1 < $_g) {
$i1 = $_g1++;
if($array[$i1] !== null && _hx_equal($array[$i1], $element)) {
return $i1;
}
unset($i1);
}
}
return -1;
}
static function indexOfElementInt($array, $element) {
$i = null;
{
$_g1 = 0; $_g = $array->length;
while($_g1 < $_g) {
$i1 = $_g1++;
if($array[$i1] === $element) {
return $i1;
}
unset($i1);
}
}
return -1;
}
static function containsArray($array, $element) {
return com_wiris_util_type_Arrays::indexOfElementArray($array, $element) >= 0;
}
static function containsInt($array, $element) {
return com_wiris_util_type_Arrays::indexOfElementInt($array, $element) >= 0;
}
static function clear($a) {
$i = $a->length - 1;
while($i >= 0) {
$a->remove($a[$i]);
$i--;
}
}
static function sort($elements, $comparator) {
com_wiris_util_type_Arrays::quicksort($elements, 0, $elements->length - 1, $comparator);
}
static function insertSorted($a, $e) {
com_wiris_util_type_Arrays::insertSortedImpl($a, $e, false);
}
static function insertSortedSet($a, $e) {
com_wiris_util_type_Arrays::insertSortedImpl($a, $e, true);
}
static function insertSortedImpl($a, $e, $set) {
$imin = 0;
$imax = $a->length;
while($imin < $imax) {
$imid = intval(($imax + $imin) / 2);
$cmp = Reflect::compare($a[$imid], $e);
if($cmp === 0) {
if($set) {
return;
} else {
$imin = $imid;
$imax = $imid;
}
} else {
if($cmp < 0) {
$imin = $imid + 1;
} else {
$imax = $imid;
}
}
unset($imid,$cmp);
}
$a->insert($imin, $e);
}
static function binarySearch($array, $key) {
$imin = 0;
$imax = $array->length;
while($imin < $imax) {
$imid = intval(($imin + $imax) / 2);
$cmp = Reflect::compare($array[$imid], $key);
if($cmp === 0) {
return $imid;
} else {
if($cmp < 0) {
$imin = $imid + 1;
} else {
$imax = $imid;
}
}
unset($imid,$cmp);
}
return -1;
}
static function copyArray($a) {
$b = new _hx_array(array());
$i = $a->iterator();
while($i->hasNext()) {
$b->push($i->next());
}
return $b;
}
static function addAll($baseArray, $additionArray) {
$i = $additionArray->iterator();
while($i->hasNext()) {
$baseArray->push($i->next());
}
}
static function quicksort($elements, $lower, $higher, $comparator) {
if($lower < $higher) {
$p = com_wiris_util_type_Arrays::partition($elements, $lower, $higher, $comparator);
com_wiris_util_type_Arrays::quicksort($elements, $lower, $p - 1, $comparator);
com_wiris_util_type_Arrays::quicksort($elements, $p + 1, $higher, $comparator);
}
}
static function partition($elements, $lower, $higher, $comparator) {
$pivot = $elements[$higher];
$i = $lower - 1;
$j = $lower;
while($j < $higher) {
if($comparator->compare($pivot, $elements[$j]) > 0) {
$i++;
if($i !== $j) {
$swapper = $elements[$i];
$elements[$i] = $elements[$j];
$elements[$j] = $swapper;
unset($swapper);
}
}
$j++;
}
if($comparator->compare($elements[$i + 1], $elements[$higher]) > 0) {
$finalSwap = $elements[$i + 1];
$elements[$i + 1] = $elements[$higher];
$elements[$higher] = $finalSwap;
}
return $i + 1;
}
static function firstElement($elements) {
return $elements[0];
}
static function lastElement($elements) {
return $elements[$elements->length - 1];
}
function __toString() { return 'com.wiris.util.type.Arrays'; }
}
5 changes: 5 additions & 0 deletions integration/lib/com/wiris/util/type/Comparator.interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

interface com_wiris_util_type_Comparator {
function compare($a, $b);
}
Loading

0 comments on commit 7994817

Please sign in to comment.