Skip to content

Commit

Permalink
create subsets with character names
Browse files Browse the repository at this point in the history
make subsets and titles  public
  • Loading branch information
70ray committed Dec 4, 2024
1 parent d90fa4c commit 27a7904
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 42 deletions.
8 changes: 4 additions & 4 deletions SETUP/tests/unittests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]["?"]);
}
}

Expand Down
30 changes: 1 addition & 29 deletions api/v1_projects.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions pinc/CharSuites.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ class PickerSet
{
public string $name;
/** @var array<string, (string|null)[]> */
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;
Expand Down
9 changes: 4 additions & 5 deletions pinc/CharacterSelector.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CharacterSelector
$selector_string .= "<button type='button' id='$safe_code' class='selector_button' title='$title'>" . html_safe($code) . "</button>";
$row_string .= "<div class='$safe_code key-block'>\n";
foreach ($picker as $row) {
$row_string .= $this->draw_row(convert_codepoint_ranges_to_characters($row));
$row_string .= $this->draw_row($row);
}
$row_string .= "</div>\n";
}
Expand All @@ -55,13 +55,12 @@ class CharacterSelector
public function draw_row($chars)
{
$row = "<div class='table-row'>";

foreach ($chars as $character) {
foreach ($chars as $character => $title_string) {
$row .= "<div class='table-cell'>";
if (null == $character) {
if (null === $character) {
$row .= "<button type='button' class='picker invisible'></button>";
} 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"))) {
Expand Down
2 changes: 1 addition & 1 deletion tools/charsuites.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function output_pickerset(?PickerSet $pickerset, array $all_codepoints): void
echo "<table class='basic'>";
foreach ($coderows as $row) {
echo "<tr>";
$characters = convert_codepoint_ranges_to_characters($row);
$characters = array_keys($row);

Check failure on line 144 in tools/charsuites.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $array of function array_keys expects array, string given.
$picker_characters = array_merge($picker_characters, $characters);
output_characters_slice($characters);
echo "</tr>";
Expand Down

0 comments on commit 27a7904

Please sign in to comment.