« tools/lib/Term/Fabulous/Screenshot/Screen.pm
↑ Summary
blib/lib/Term/Fabulous/Render/Rectangle.pm »
| 1 | package Term::Fabulous::Screenshot::Scene; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.32; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Object::Pad 0.825; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | class Term::Fabulous::Screenshot::Scene :strict(params) { | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Term::Fabulous::Screenshot::BoxDrawing qw(is_drawn_glyph glyph_shapes); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # Characters every monospace font has, one cell wide: text of these is | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # drawn in runs. Anything else (symbols, CJK, emoji, clusters with | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # combining marks) is drawn one cell at a time, centered in its cells, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # so a fallback font with other widths cannot shift the line. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant RUN_CHARACTER => qr/\A[\x21-\x7E\xA1-\x{17F}\x{370}-\x{3FF}\x{400}-\x{4FF}]\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use constant DIM_FACTOR => 0.5; # how far dim text moves towards the background | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # The width of a title character in units of the title's font size (a | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # monospace font), and the room kept free between buttons and title. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use constant TITLE_CHARACTER_WIDTH => 0.6; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use constant TITLE_BUTTON_GAP => 12; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | field $screen :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
screen: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | field $theme :param :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
theme: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | field $title :param :reader = ''; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | field $scale :param :reader = 1; # image units per theme unit | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
title: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # The parts of the picture, in image units, back to front. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | field $layout :reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
layout: not called CC=1 SCAR=2.0
Subroutine
scale: not called CC=1 SCAR=2.0
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | field $shown_title :reader; # the title as it fits between the window buttons | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shown_title: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | field @backgrounds :reader; # { x, y, width, height, color } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
backgrounds: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | field @shapes :reader; # { type => 'rect', x, y, width, height, color }, { type => 'polyline', points, width, color } or { type => 'circle', cx, cy, r, color } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shapes: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | field @texts :reader; # { x, y, width, glyphs => [ [ x, glyph ] ], text, color, bold, italic, anchor } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
texts: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | field @lines :reader; # decorations (underline, strikeout, overline): { x, y, width, height, color } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lines: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | field @pictures :reader; # sixel pictures over all of these: { x, y, width, height, png } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pictures: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | ADJUST { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | croak "Term::Fabulous::Screenshot::Scene: the scale must be a positive whole number, got '$scale'" unless $scale =~ /\A[1-9][0-9]*\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | $layout = { %{ $theme->layout( $screen->columns, $screen->rows ) } }; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | $layout->{$_} *= $scale foreach keys %$layout; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | $shown_title = $self->_fitting_title; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | foreach my $y ( 0 .. $screen->rows - 1 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | my @cells = map { $self->_resolve($_) } $screen->row($y); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | push @backgrounds, $self->_background_runs( $y, \@cells ); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | push @shapes, $self->_cell_shapes( $y, $_ ) foreach grep { is_drawn_glyph( $_->{glyph} ) } @cells; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | push @texts, $self->_text_runs( $y, \@cells ); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | push @lines, $self->_decorations( $y, $_ ) foreach @cells; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | @backgrounds = _merge_rects(@backgrounds); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | @shapes = ( _merge_rects( grep { $_->{type} eq 'rect' } @shapes ), grep { $_->{type} ne 'rect' } @shapes ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | @lines = _merge_rects(@lines); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | @pictures = map { $self->_picture($_) } $screen->pictures; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # The title, shortened with '...' when it is wider than the room the | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # window buttons leave; the same room is kept free on the right, so a | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # centered title stays centered. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | method _fitting_title () { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fitting_title: not called CC=3 SCAR=23.3
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $reserved = ( @{ $theme->button_colors } * $theme->button_spacing + $theme->button_radius + TITLE_BUTTON_GAP ) * $scale; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $room = $layout->{window_width} - 2 * $reserved; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $fitting = int( $room / ( $theme->title_font_size * $scale * TITLE_CHARACTER_WIDTH ) ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return $title if length($title) <= $fitting; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return '' if $fitting < 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return substr( $title, 0, $fitting - 3 ) . '...'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | method cell_width () { return $theme->cell_width * $scale } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cell_width: not called CC=1 SCAR=4.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | method cell_height () { return $theme->cell_height * $scale } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cell_height: not called CC=1 SCAR=4.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | method font_size () { return $theme->font_size * $scale } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
font_size: not called CC=1 SCAR=4.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # The final colors of a cell: defaults filled in, reverse video applied, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # dim text mixed towards the background (half opaque), invisible text | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # dropped. Blink has no picture; it is ignored. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | method _resolve ($cell) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $styles = $cell->{styles}; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $fg = $cell->{fg} // $theme->default_foreground; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cell->{"fg"} // $theme->default_foreground
MC/DC0%0/2
$cell->{"fg"} // $theme->default_foreground
$cell->{"fg"}
$theme->default_foreground
Truth table0%0/3
A // B
A= $cell->{"fg"}B= $theme->default_foreground
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $bg = $cell->{bg} // $theme->default_background; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cell->{"bg"} // $theme->default_background
MC/DC0%0/2
$cell->{"bg"} // $theme->default_background
$cell->{"bg"}
$theme->default_background
Truth table0%0/3
A // B
A= $cell->{"bg"}B= $theme->default_background
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | ( $fg, $bg ) = ( $bg, $fg ) if $styles->{reverse}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $fg = mix_colors( $bg, $fg, 1 - DIM_FACTOR ) if $styles->{dim}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $glyph = $styles->{invisible} ? ' ' : $cell->{glyph}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return { %$cell, glyph => $glyph, fg => $fg, bg => $bg }; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | method _cell_x ($column) { return $layout->{terminal_x} + $column * $self->cell_width } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell_x: not called CC=1 SCAR=4.6
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | method _cell_y ($row) { return $layout->{terminal_y} + $row * $self->cell_height } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell_y: not called CC=1 SCAR=4.6
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Background rectangles for every run of cells with the same color, except | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # the terminal's default background, which the window already shows. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | method _background_runs ( $y, $cells ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_background_runs: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my @runs; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | foreach my $cell (@$cells) { | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | next if $cell->{bg} == $theme->default_background; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $x = $self->_cell_x( $cell->{x} ); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $width = $cell->{columns} * $self->cell_width; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( @runs && $runs[-1]{color} == $cell->{bg} && $runs[-1]{x} + $runs[-1]{width} == $x ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@runs and $runs[-1]{"color"} == $cell->{"bg"} and $runs[-1]{"x"} + $runs[-1]{"width"} == $x
@runs and $runs[-1]{"color"} == $cell->{"bg"}
MC/DC0%0/3
@runs and $runs[-1]{"color"} == $cell->{"bg"} and $runs[-1]{"x"} + $runs[-1]{"width"} == $x
@runs
$runs[-1]{"color"} == $cell->{"bg"}
$runs[-1]{"x"} + $runs[-1]{"width"} == $x
Truth table0%0/4
A and B and C
A= @runsB= $runs[-1]{"color"} == $cell->{"bg"}C= $runs[-1]{"x"} + $runs[-1]{"width"} == $x
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $runs[-1]{width} += $width; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | push @runs, { x => $x, y => $self->_cell_y($y), width => $width, height => $self->cell_height, color => $cell->{bg} }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return @runs; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | method _cell_shapes ( $y, $cell ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cell_shapes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ( $left, $top ) = ( $self->_cell_x( $cell->{x} ), $self->_cell_y($y) ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my @cell_shapes = glyph_shapes( $cell->{glyph}, $self->cell_width, $self->cell_height, $theme->line_thickness * $scale ); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return map { _placed_shape( $_, $left, $top, $cell ) } @cell_shapes; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub _placed_shape ( $shape, $left, $top, $cell ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_placed_shape: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( $shape->{type} eq 'rect' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | type => 'rect', | ||||||||||||||||||||||||||||||||||||||||||
| 119 | x => $left + $shape->{x}, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | y => $top + $shape->{y}, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | width => $shape->{width}, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | height => $shape->{height}, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | color => mix_colors( $cell->{bg}, $cell->{fg}, $shape->{coverage} ), | |||||||||||||||||||||||||||||||||||||||||
| 124 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ( $shape->{type} eq 'circle' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | return { type => 'circle', cx => $left + $shape->{cx}, cy => $top + $shape->{cy}, r => $shape->{r}, color => $cell->{fg} }; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my @points = @{ $shape->{points} }; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $points[$_] += $_ % 2 ? $top : $left foreach 0 .. $#points; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return { type => 'polyline', points => \@points, width => $shape->{width}, color => $cell->{fg} }; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Text in runs of cells with the same color and weight, spaces included | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # between them; other glyphs one per run, centered in their cells. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | method _text_runs ( $y, $cells ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text_runs: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $baseline = $self->_cell_y($y) + $theme->baseline * $scale; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my ( @runs, $open ); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | foreach my $cell (@$cells) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $glyph = $cell->{glyph}; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( is_drawn_glyph($glyph) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | undef $open; # a run cannot skip a cell | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my $style = join ',', $cell->{fg}, $cell->{styles}{bold} ? 1 : 0, $cell->{styles}{italic} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $x = $self->_cell_x( $cell->{x} ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( $glyph eq ' ' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | push @{ $open->{pending_spaces} }, $x if $open; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( $glyph !~ RUN_CHARACTER ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | undef $open; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | push @runs, $self->_run( $cell, $x, $baseline, 'middle' ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ( $open && $open->{style} eq $style ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$open and $open->{"style"} eq $style
MC/DC0%0/2
$open and $open->{"style"} eq $style
$open
$open->{"style"} eq $style
Truth table0%0/3
A and B
A= $openB= $open->{"style"} eq $style
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | push @{ $open->{glyphs} }, map { [ $_, ' ' ] } @{ delete $open->{pending_spaces} // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $open->{"pending_spaces"} // []
MC/DC0%0/1
delete $open->{"pending_spaces"} // []
delete $open->{"pending_spaces"}
Truth table0%0/2
A
A= delete $open->{"pending_spaces"}
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | push @{ $open->{glyphs} }, [ $x, $glyph ]; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $open->{width} = $x + $self->cell_width - $open->{x}; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $open = $self->_run( $cell, $x, $baseline, 'start' ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $open->{style} = $style; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | push @runs, $open; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | foreach my $run (@runs) { | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | delete @$run{qw(style pending_spaces)}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $run->{text} = join '', map { $_->[1] } @{ $run->{glyphs} }; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return @runs; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | method _run ( $cell, $x, $baseline, $anchor ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | x => $x, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | y => $baseline, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | width => $cell->{columns} * $self->cell_width, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | glyphs => [ [ $x, $cell->{glyph} ] ], | ||||||||||||||||||||||||||||||||||||||||||
| 180 | color => $cell->{fg}, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | bold => $cell->{styles}{bold} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | italic => $cell->{styles}{italic} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | anchor => $anchor, | ||||||||||||||||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | method _decorations ( $y, $cell ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decorations: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $styles = $cell->{styles}; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my ( $left, $top ) = ( $self->_cell_x( $cell->{x} ), $self->_cell_y($y) ); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $width = $cell->{columns} * $self->cell_width; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $thickness = $theme->line_thickness * $scale; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $underline = $top + ( $theme->baseline + 1 ) * $scale; # a second line fits below it in the cell | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my @offsets; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | push @offsets, $underline if $styles->{underline} || $styles->{double_underline}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$styles->{"underline"} or $styles->{"double_underline"}
MC/DC0%0/2
$styles->{"underline"} or $styles->{"double_underline"}
$styles->{"underline"}
$styles->{"double_underline"}
Truth table0%0/3
A or B
A= $styles->{"underline"}B= $styles->{"double_underline"}
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | push @offsets, $underline + 2 * $thickness if $styles->{double_underline}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | push @offsets, $top + int( $self->cell_height * 0.55 ) if $styles->{strikeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | push @offsets, $top if $styles->{overline}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return map { { x => $left, y => $_, width => $width, height => $thickness, color => $cell->{fg} } } @offsets; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | method _picture ($picture) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_picture: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | x => $self->_cell_x( $picture->{x} ), | ||||||||||||||||||||||||||||||||||||||||||
| 205 | y => $self->_cell_y( $picture->{y} ), | ||||||||||||||||||||||||||||||||||||||||||
| 206 | width => $picture->{columns} * $self->cell_width, | ||||||||||||||||||||||||||||||||||||||||||
| 207 | height => $picture->{rows} * $self->cell_height, | ||||||||||||||||||||||||||||||||||||||||||
| 208 | png => $picture->{png}, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | } | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | # Joins rectangles of one color that continue each other, first along | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # rows, then down columns; the picture stays the same with fewer shapes. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub _merge_rects (@rects) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_rects: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my @merged = _merge_along( \@rects, 'x', 'width', 'y', 'height' ); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return _merge_along( \@merged, 'y', 'height', 'x', 'width' ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub _merge_along ( $rects, $position, $length, $cross_position, $cross_length ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_along: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my %group; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | foreach my $rect (@$rects) { | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $key = join ',', $rect->{color}, $rect->{$cross_position}, $rect->{$cross_length}; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | push @{ $group{$key} }, $rect; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | foreach my $key ( sort keys %group ) { | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my @sorted = sort { $a->{$position} <=> $b->{$position} } @{ $group{$key} }; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my @joined = ( { %{ shift @sorted } } ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | foreach my $rect (@sorted) { | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $last = $joined[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ( $rect->{$position} <= $last->{$position} + $last->{$length} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $end = $rect->{$position} + $rect->{$length}; | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $last->{$length} = $end - $last->{$position} if $end > $last->{$position} + $last->{$length}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | push @joined, {%$rect}; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | push @result, @joined; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my @sorted = sort { $a->{y} <=> $b->{y} || $a->{x} <=> $b->{x} || $a->{color} <=> $b->{color} } @result; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$Term::Fabulous::Screenshot::Scene::a->{'y'} <=> $Term::Fabulous::Screenshot::Scene::b->{'y'} || $Term::Fabulous::Screenshot::Scene::a->{'x'} <=> $Term::Fabulous::Screenshot::Scene::b->{'x'} || $Term::Fabulous::Screenshot::Scene::a->{'color'} <=> $Term::Fabulous::Screenshot::Scene::b->{'color'}
$Term::Fabulous::Screenshot::Scene::a->{"y"} <=> $Term::Fabulous::Screenshot::Scene::b->{"y"} or $Term::Fabulous::Screenshot::Scene::a->{"x"} <=> $Term::Fabulous::Screenshot::Scene::b->{"x"}
MC/DC0%0/3
$Term::Fabulous::Screenshot::Scene::a->{'y'} <=> $Term::Fabulous::Screenshot::Scene::b->{'y'} || $Term::Fabulous::Screenshot::Scene::a->{'x'} <=> $Term::Fabulous::Screenshot::Scene::b->{'x'} || $Term::Fabulous::Screenshot::Scene::a->{'color'} <=> $Term::Fabulous::Screenshot::Scene::b->{'color'}
$Term::Fabulous::Screenshot::Scene::a->{"y"} <=> $Term::Fabulous::Screenshot::Scene::b->{"y"}
$Term::Fabulous::Screenshot::Scene::a->{"x"} <=> $Term::Fabulous::Screenshot::Scene::b->{"x"}
$Term::Fabulous::Screenshot::Scene::a->{'color'} <=> $Term::Fabulous::Screenshot::Scene::b->{'color'}
Truth table0%0/4
A or B || C
A= $Term::Fabulous::Screenshot::Scene::a->{"y"} <=> $Term::Fabulous::Screenshot::Scene::b->{"y"}B= $Term::Fabulous::Screenshot::Scene::a->{"x"} <=> $Term::Fabulous::Screenshot::Scene::b->{"x"}C= $Term::Fabulous::Screenshot::Scene::a->{'color'} <=> $Term::Fabulous::Screenshot::Scene::b->{'color'}
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return @sorted; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | # $over mixed over $under: 0 is $under, 1 is $over. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub mix_colors ( $under, $over, $amount ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mix_colors: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | return $over if $amount >= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return $under if $amount <= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $mixed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | foreach my $shift ( 16, 8, 0 ) { | |||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my ( $low, $high ) = ( ( $under >> $shift ) & 0xFF, ( $over >> $shift ) & 0xFF ); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $mixed |= int( $low + ( $high - $low ) * $amount + 0.5 ) << $shift; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return $mixed; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | __END__ | ||||||||||||||||||||||||||||||||||||||||||