chinese display support

This commit is contained in:
wen huxian 2024-04-04 16:55:44 +08:00
parent da03517de1
commit 16cd66f3e2

20
h-m-m
View file

@ -796,13 +796,13 @@ function calculate_x_and_lh(&$mm, $id)
$mm['nodes'][$id]['w'] = 0; $mm['nodes'][$id]['w'] = 0;
foreach ($lines as $line) foreach ($lines as $line)
$mm['nodes'][$id]['w'] = $mm['nodes'][$id]['w'] =
max($mm['nodes'][$id]['w'], trim(mb_strlen($line))); max($mm['nodes'][$id]['w'], trim(mb_strwidth($line)));
$mm['nodes'][$id]['lh'] = count($lines); $mm['nodes'][$id]['lh'] = count($lines);
} }
else else
{ {
$mm['nodes'][$id]['w'] = mb_strlen(trim($node['title'])); $mm['nodes'][$id]['w'] = mb_strwidth(trim($node['title']));
$mm['nodes'][$id]['lh'] = 1; $mm['nodes'][$id]['lh'] = 1;
} }
@ -1263,7 +1263,7 @@ function add_content_to_the_map(&$mm, $id)
$num_lines = count($lines); $num_lines = count($lines);
for ( $i=0 ; $i<$num_lines ; $i++ ) for ( $i=0 ; $i<$num_lines ; $i++ )
mmput mmputcontent
( (
$mm, $mm,
$node['x'], $node['x'],
@ -1321,7 +1321,7 @@ function build_map(&$mm)
// resetting the map, 2/2 // resetting the map, 2/2
$height = max($mm['map_bottom'],$mm['terminal_height']); $height = max($mm['map_bottom'],$mm['terminal_height']);
$blank = str_repeat(' ', $mm['map_width']+$mm['terminal_width']); $blank = str_repeat(' ', max($mm['map_width'],$mm['terminal_width']));
for ($i=$mm['map_top'] ; $i<=$height ; $i++) for ($i=$mm['map_top'] ; $i<=$height ; $i++)
$mm['map'][$i] = $blank; $mm['map'][$i] = $blank;
@ -1883,7 +1883,7 @@ function magic_readline(&$mm, $title)
function show_line(&$mm, $title, $cursor, $shift) function show_line(&$mm, $title, $cursor, $shift)
{ {
$output = mb_substr($title,$shift,$mm['terminal_width']-1); $output = mb_substr($title,$shift,$mm['terminal_width']-1);
$output .= str_repeat( ' ' ,$mm['terminal_width'] - mb_strlen($output) ); $output .= str_repeat( ' ' ,$mm['terminal_width'] - mb_strwidth($output) );
// showing the cursor // showing the cursor
$output = $output =
@ -3512,6 +3512,16 @@ function mmput(&$mm,$x,$y,$s)
. mb_substr( $mm['map'][$y], $x + mb_strlen($s) ); . mb_substr( $mm['map'][$y], $x + mb_strlen($s) );
} }
function mmputcontent(&$mm,$x,$y,$s)
{
$y = round($y);
$mm['map'][$y]
= mb_substr( $mm['map'][$y], 0, $x)
. $s
. mb_substr( $mm['map'][$y], $x + mb_strwidth($s) );
}
// }}} // }}}
// {{{ rank // {{{ rank