Skip to content

Commit 912e77e

Browse files
committed
Revert rasterized rendering of vertical half-lines
1 parent 9940fbf commit 912e77e

4 files changed

Lines changed: 31 additions & 63 deletions

File tree

lib/asciinema_web/controllers/recording_svg.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ defmodule AsciinemaWeb.RecordingSVG do
6969
end
7070

7171
# Bump when SVG rendering output can change without recording data changes.
72-
@svg_renderer_salt 3
72+
@svg_renderer_salt 4
7373

7474
def svg_cache_key(asciicast) do
7575
key =
@@ -311,12 +311,9 @@ defmodule AsciinemaWeb.RecordingSVG do
311311
defp mosaic_block?(char) do
312312
cp = codepoint(char)
313313

314-
# block elements || box drawing vertical lines || black square || sextants
314+
# block elements || heavy box drawing verticals || black square || sextants
315315
(cp >= 0x2580 and cp <= 0x259F) ||
316-
cp == 0x2502 ||
317316
cp == 0x2503 ||
318-
cp == 0x2575 ||
319-
cp == 0x2577 ||
320317
cp == 0x2579 ||
321318
cp == 0x257B ||
322319
cp == 0x25A0 ||

native/svg_raster/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,9 @@ fn draw_mosaic_block(
159159
let half_y = CELL_Y_RES / 2;
160160

161161
match cp {
162-
// box drawings light vertical (https://symbl.cc/en/2502/)
163-
0x2502 => fill_cell_rect(pixels, img_w, origin, (4, 0, 5, CELL_Y_RES), color),
164-
165162
// box drawings heavy vertical (https://symbl.cc/en/2503/)
166163
0x2503 => fill_cell_rect(pixels, img_w, origin, (3, 0, 5, CELL_Y_RES), color),
167164

168-
// box drawings light up (https://symbl.cc/en/2575/)
169-
0x2575 => fill_cell_rect(pixels, img_w, origin, (4, 0, 5, half_y), color),
170-
171-
// box drawings light down (https://symbl.cc/en/2577/)
172-
0x2577 => fill_cell_rect(pixels, img_w, origin, (4, half_y, 5, CELL_Y_RES), color),
173-
174165
// box drawings heavy up (https://symbl.cc/en/2579/)
175166
0x2579 => fill_cell_rect(pixels, img_w, origin, (3, 0, 5, half_y), color),
176167

test/asciinema/svg_raster_test.exs

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,39 @@ defmodule Asciinema.SvgRasterTest do
2424
assert rgb_at(decoded, 8, 12) == {4, 5, 6}
2525
end
2626

27-
test "renders representative glyphs grouped by rasterized groups" do
27+
test "renders representative glyphs supported by rasterized groups" do
2828
fg = {240, 16, 32}
2929
bg = {1, 2, 3}
3030

31-
# 0: █, 1: , 2: , 3: , 4: ╷, 5: ╹, 6: ╻, 7: ■, 8: 🬀
31+
# 0: █, 1: , 2: , 3: , 4: ■, 5: 🬀
3232
mosaic_blocks = [
3333
{0, 0, 0x2588, fg},
34-
{0, 1, 0x2502, fg},
35-
{0, 2, 0x2503, fg},
36-
{0, 3, 0x2575, fg},
37-
{0, 4, 0x2577, fg},
38-
{0, 5, 0x2579, fg},
39-
{0, 6, 0x257B, fg},
40-
{0, 7, 0x25A0, fg},
41-
{0, 8, 0x1FB00, fg}
34+
{0, 1, 0x2503, fg},
35+
{0, 2, 0x2579, fg},
36+
{0, 3, 0x257B, fg},
37+
{0, 4, 0x25A0, fg},
38+
{0, 5, 0x1FB00, fg}
4239
]
4340

44-
png = SvgRaster.render_png(9, 1, bg, [], mosaic_blocks)
41+
png = SvgRaster.render_png(6, 1, bg, [], mosaic_blocks)
4542
decoded = decode_png(png)
4643

4744
# block elements
4845
assert cell_contains_color?(decoded, 0, 0, fg)
4946

50-
# box verticals
47+
# heavy box verticals
5148
assert cell_contains_color?(decoded, 1, 0, fg)
5249
assert cell_contains_color?(decoded, 2, 0, fg)
5350
assert cell_contains_color?(decoded, 3, 0, fg)
54-
assert cell_contains_color?(decoded, 4, 0, fg)
55-
assert cell_contains_color?(decoded, 5, 0, fg)
56-
assert cell_contains_color?(decoded, 6, 0, fg)
5751

5852
# black square
59-
assert cell_contains_color?(decoded, 7, 0, fg)
53+
assert cell_contains_color?(decoded, 4, 0, fg)
6054

6155
# sextants
62-
assert cell_contains_color?(decoded, 8, 0, fg)
56+
assert cell_contains_color?(decoded, 5, 0, fg)
6357
end
6458

65-
test "renders box drawing vertical lines with light/heavy widths" do
59+
test "renders heavy box drawing vertical lines on raster layer" do
6660
png =
6761
SvgRaster.render_png(
6862
2,
@@ -74,17 +68,13 @@ defmodule Asciinema.SvgRasterTest do
7468

7569
decoded = decode_png(png)
7670

77-
# light line: x + 4, width 1
78-
assert rgb_at(decoded, 4, 12) == {240, 16, 32}
79-
assert rgb_at(decoded, 3, 12) == {1, 2, 3}
80-
8171
# heavy line: x + 3, width 2
8272
assert rgb_at(decoded, 11, 12) == {240, 16, 32}
8373
assert rgb_at(decoded, 12, 12) == {240, 16, 32}
8474
assert rgb_at(decoded, 10, 12) == {1, 2, 3}
8575
end
8676

87-
test "renders box drawing vertical half-lines with direction and light/heavy widths" do
77+
test "renders heavy box drawing vertical half-lines on raster layer" do
8878
png =
8979
SvgRaster.render_png(
9080
4,
@@ -101,16 +91,6 @@ defmodule Asciinema.SvgRasterTest do
10191

10292
decoded = decode_png(png)
10393

104-
# light up (top half only)
105-
assert rgb_at(decoded, 4, 5) == {240, 16, 32}
106-
assert rgb_at(decoded, 4, 18) == {1, 2, 3}
107-
assert rgb_at(decoded, 3, 5) == {1, 2, 3}
108-
109-
# light down (bottom half only)
110-
assert rgb_at(decoded, 12, 5) == {1, 2, 3}
111-
assert rgb_at(decoded, 12, 18) == {240, 16, 32}
112-
assert rgb_at(decoded, 11, 18) == {1, 2, 3}
113-
11494
# heavy up (top half only)
11595
assert rgb_at(decoded, 19, 5) == {240, 16, 32}
11696
assert rgb_at(decoded, 20, 5) == {240, 16, 32}

test/asciinema_web/controllers/recording_svg_test.exs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule AsciinemaWeb.RecordingSvgTest do
6666
assert rgb_at(png, 23, 23) == {17, 34, 51}
6767
end
6868

69-
test "routes representative rasterized glyph groups to embedded PNG layer" do
69+
test "routes only supported rasterized glyph groups to embedded PNG layer" do
7070
fg = {255, 85, 0}
7171
sextant_ul = <<0x1FB00::utf8>>
7272
line = "█│┃╵╷╹╻■" <> sextant_ul
@@ -85,17 +85,17 @@ defmodule AsciinemaWeb.RecordingSvgTest do
8585
refute svg =~ "█"
8686
assert cell_contains_color?(png, 0, 0, fg)
8787

88-
# box verticals
89-
refute svg =~ "│"
88+
# light verticals stay in text, heavy ones are rasterized
89+
assert svg =~ "│"
9090
refute svg =~ "┃"
91-
refute svg =~ "╵"
92-
refute svg =~ "╷"
91+
assert svg =~ "╵"
92+
assert svg =~ "╷"
9393
refute svg =~ "╹"
9494
refute svg =~ "╻"
95-
assert cell_contains_color?(png, 1, 0, fg)
95+
refute cell_contains_color?(png, 1, 0, fg)
9696
assert cell_contains_color?(png, 2, 0, fg)
97-
assert cell_contains_color?(png, 3, 0, fg)
98-
assert cell_contains_color?(png, 4, 0, fg)
97+
refute cell_contains_color?(png, 3, 0, fg)
98+
refute cell_contains_color?(png, 4, 0, fg)
9999
assert cell_contains_color?(png, 5, 0, fg)
100100
assert cell_contains_color?(png, 6, 0, fg)
101101

@@ -142,7 +142,7 @@ defmodule AsciinemaWeb.RecordingSvgTest do
142142
assert rgb_at(png, 8, 12) == {51, 102, 204}
143143
end
144144

145-
test "renders box drawing vertical lines in mosaic layer and excludes them from text layer" do
145+
test "renders heavy box drawing vertical lines in mosaic layer" do
146146
asciicast =
147147
build(:asciicast,
148148
term_cols: 2,
@@ -153,13 +153,13 @@ defmodule AsciinemaWeb.RecordingSvgTest do
153153
svg = render_full(asciicast)
154154
png = decode_embedded_png(svg)
155155

156-
refute svg =~ "│"
156+
assert svg =~ "│"
157157
refute svg =~ "┃"
158-
assert cell_contains_color?(png, 0, 0, {255, 85, 0})
158+
refute cell_contains_color?(png, 0, 0, {255, 85, 0})
159159
assert cell_contains_color?(png, 1, 0, {255, 85, 0})
160160
end
161161

162-
test "renders box drawing vertical half-lines in mosaic layer and excludes them from text layer" do
162+
test "renders heavy box drawing vertical half-lines in mosaic layer" do
163163
half_lines = <<0x2575::utf8, 0x2577::utf8, 0x2579::utf8, 0x257B::utf8>>
164164

165165
asciicast =
@@ -172,12 +172,12 @@ defmodule AsciinemaWeb.RecordingSvgTest do
172172
svg = render_full(asciicast)
173173
png = decode_embedded_png(svg)
174174

175-
refute svg =~ <<0x2575::utf8>>
176-
refute svg =~ <<0x2577::utf8>>
175+
assert svg =~ <<0x2575::utf8>>
176+
assert svg =~ <<0x2577::utf8>>
177177
refute svg =~ <<0x2579::utf8>>
178178
refute svg =~ <<0x257B::utf8>>
179-
assert cell_contains_color?(png, 0, 0, {255, 85, 0})
180-
assert cell_contains_color?(png, 1, 0, {255, 85, 0})
179+
refute cell_contains_color?(png, 0, 0, {255, 85, 0})
180+
refute cell_contains_color?(png, 1, 0, {255, 85, 0})
181181
assert cell_contains_color?(png, 2, 0, {255, 85, 0})
182182
assert cell_contains_color?(png, 3, 0, {255, 85, 0})
183183
end

0 commit comments

Comments
 (0)