From af7e7b76bcac4da309626861ef9f9c012f1145df Mon Sep 17 00:00:00 2001 From: QinQing Date: Mon, 4 Dec 2023 21:38:29 +0800 Subject: [PATCH] FIXED: The width of dnd's overlay is wrong CHANGED: remove is_nonspacing function --- lib/App/Asciio/GTK/Asciio/DnD.pm | 3 ++- lib/App/Asciio/String.pm | 10 ---------- lib/App/Asciio/ZBuffer.pm | 6 ++++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/App/Asciio/GTK/Asciio/DnD.pm b/lib/App/Asciio/GTK/Asciio/DnD.pm index 060d8cd1..92b260a8 100644 --- a/lib/App/Asciio/GTK/Asciio/DnD.pm +++ b/lib/App/Asciio/GTK/Asciio/DnD.pm @@ -15,6 +15,7 @@ use Sereal qw( use Sereal::Encoder qw(SRL_SNAPPY SRL_ZLIB SRL_ZSTD) ; use App::Asciio::Actions::Clipboard ; +use App::Asciio::String ; #-------------------------------------------------------------------------- @@ -80,7 +81,7 @@ my $text = $self->transform_elements_to_ascii_buffer_aligned_left($self->get_sel my $lines = $text =~ tr /\n/\n/ ; my ($character_width, $character_height) = $self->get_character_size() ; -my ($width, $height) = (length($text) * $character_width, $character_height * $lines) ; +my ($width, $height) = (max(map { unicode_length $_ } split('\n', $text)) * $character_width, $character_height * $lines) ; my $surface = Cairo::ImageSurface->create('argb32', $width, $height) ; my $gc = Cairo::Context->create($surface) ; my $layout = Pango::Cairo::create_layout($gc) ; diff --git a/lib/App/Asciio/String.pm b/lib/App/Asciio/String.pm index 804df9d2..459422e6 100644 --- a/lib/App/Asciio/String.pm +++ b/lib/App/Asciio/String.pm @@ -6,7 +6,6 @@ require Exporter ; @EXPORT = qw( unicode_length make_vertical_text - is_nonspacing_char ) ; #----------------------------------------------------------------------------- @@ -20,15 +19,6 @@ use App::Asciio::Markup ; use Memoize ; memoize('unicode_length') ; -memoize('is_nonspacing_char') ; - -#----------------------------------------------------------------------------- - -sub is_nonspacing_char -{ -my ($character) = @_ ; -return $character =~ /\p{gc:Mn}/ ; -} #----------------------------------------------------------------------------- diff --git a/lib/App/Asciio/ZBuffer.pm b/lib/App/Asciio/ZBuffer.pm index 01b9ad40..dcdb5309 100644 --- a/lib/App/Asciio/ZBuffer.pm +++ b/lib/App/Asciio/ZBuffer.pm @@ -75,7 +75,9 @@ for my $strip (@{$element->get_stripes}) my $Y = $element->{Y} + $strip->{Y_OFFSET} + $line_index ; my $X = $element->{X} + $strip->{X_OFFSET} + $character_index ; - if(is_nonspacing_char($char)) + my $character_length = unicode_length($char) ; + + if($character_length == 0) { $glyphs[$#glyphs][1] .= $char if @glyphs ; } @@ -84,7 +86,7 @@ for my $strip (@{$element->get_stripes}) push @glyphs, [ "$Y;$X", $char] ; } - $character_index += unicode_length($char); + $character_index += $character_length; } $line_index++ ;