diff --git a/SETUP/tests/unittests/ApiTest.php b/SETUP/tests/unittests/ApiTest.php index 61ccb3127..5fe629184 100644 --- a/SETUP/tests/unittests/ApiTest.php +++ b/SETUP/tests/unittests/ApiTest.php @@ -700,10 +700,10 @@ public function test_pickersets() $router = ApiRouter::get_router(); $_SERVER["REQUEST_METHOD"] = "GET"; $response = $router->route($path, $query_params); - $this->assertEquals("basic-latin", $response[0]["name"]); - $this->assertEquals("!", $response[0]["subsets"][3]["name"]); - $this->assertEquals("Punctuation", $response[0]["subsets"][3]["title"]); - $this->assertEquals(["0", "DIGIT ZERO"], $response[0]["subsets"][5]["rows"][0][0]); + $this->assertEquals("basic-latin", $response[0]->name); + $this->assertEquals("!", array_keys($response[0]->get_subsets())[3]); + $this->assertEquals("Punctuation", $response[0]->get_title("!")); + $this->assertEquals("QUESTION MARK", $response[0]->get_subsets()["!"][0]["?"]); } } diff --git a/api/v1_projects.inc b/api/v1_projects.inc index 298c3e2a9..1ab80a6ff 100644 --- a/api/v1_projects.inc +++ b/api/v1_projects.inc @@ -801,36 +801,8 @@ function api_v1_project_validatetext($method, $data, array $query_params) function api_v1_project_pickersets($method, $data, $query_params) { - // expand the character ranges so that each character can have its name $project = $data[":projectid"]; - return expand_pickersets($project->get_pickersets()); -} - -function expand_pickersets($pickersets) -{ - $expanded_pickersets = []; - foreach ($pickersets as $pickerset) { - $expanded_subsets = []; - foreach ($pickerset->get_subsets() as $subset_name => $codepoint_rows) { - $expanded_rows = []; - foreach ($codepoint_rows as $row) { - $chars = convert_codepoint_ranges_to_characters($row); - $char_titles = []; - foreach ($chars as $char) { - if (null == $char) { - $char_title = [null, null]; - } else { - $char_title = [$char, utf8_character_name($char)]; - } - $char_titles[] = $char_title; - } - $expanded_rows[] = $char_titles; - } - $expanded_subsets[] = ["name" => $subset_name, "title" => $pickerset->get_title($subset_name), "rows" => $expanded_rows]; - } - $expanded_pickersets[] = ["name" => $pickerset->name, "subsets" => $expanded_subsets]; - } - return $expanded_pickersets; + return $project->get_pickersets(); } function api_v1_project_page(string $method, array $data, array $query_params) diff --git a/pinc/CharSuites.inc b/pinc/CharSuites.inc index 3b904d632..0b3fe731e 100644 --- a/pinc/CharSuites.inc +++ b/pinc/CharSuites.inc @@ -9,14 +9,27 @@ class PickerSet { public string $name; /** @var array */ - private array $subsets; + public array $subsets; /** @var string[] */ - private array $titles; + public array $titles; /** @param $codepoints (string|null)[] */ public function add_subset(string $name, array $codepoints, ?string $title = null) { - $this->subsets[$name] = $codepoints; + $char_name_rows = []; + foreach ($codepoints as $codepoint_row) { + $chars = convert_codepoint_ranges_to_characters($codepoint_row); + $char_name_row = []; + foreach ($chars as $char) { + if (null == $char) { + $char_name_row[null] = null; + } else { + $char_name_row[$char] = utf8_character_name($char); + } + } + $char_name_rows[] = $char_name_row; + } + $this->subsets[$name] = $char_name_rows; if ($title) { $this->titles[$name] = $title; diff --git a/pinc/CharacterSelector.inc b/pinc/CharacterSelector.inc index daafc20b6..c603ad9bc 100644 --- a/pinc/CharacterSelector.inc +++ b/pinc/CharacterSelector.inc @@ -40,7 +40,7 @@ class CharacterSelector $selector_string .= ""; $row_string .= "
\n"; foreach ($picker as $row) { - $row_string .= $this->draw_row(convert_codepoint_ranges_to_characters($row)); + $row_string .= $this->draw_row($row); } $row_string .= "
\n"; } @@ -55,13 +55,12 @@ class CharacterSelector public function draw_row($chars) { $row = "
"; - - foreach ($chars as $character) { + foreach ($chars as $character => $title_string) { $row .= "
"; - if (null == $character) { + if (null === $character) { $row .= ""; } else { - $title_string = attr_safe(utf8_character_name($character)); + $title_string = attr_safe($title_string); // to ensure the accents for Greek capital letters are visible, add a text indent. // see also similar code in tools/proofers/character_selector.js if (startswith($title_string, "GREEK CAPITAL") && (str_contains($title_string, "OXIA") || str_contains($title_string, "VARIA"))) { diff --git a/tools/charsuites.php b/tools/charsuites.php index 38c71f9fa..0620ccced 100644 --- a/tools/charsuites.php +++ b/tools/charsuites.php @@ -141,7 +141,7 @@ function output_pickerset(?PickerSet $pickerset, array $all_codepoints): void echo ""; foreach ($coderows as $row) { echo ""; - $characters = convert_codepoint_ranges_to_characters($row); + $characters = array_keys($row); $picker_characters = array_merge($picker_characters, $characters); output_characters_slice($characters); echo "";