Finally i get how to make less labels for this case
Open lines layer in python gdal bindings
Make a grid (raster) in memory
For each pixel: store labels from all lines intersecting with pixel
-- if there is two lines and route refs are same, then store one route ref ( 3> 3< --> 3)
-- ??? make line beetwen pixels with same texts. Simplify and smooth line.
these line will be not connected, and with jagged shape, but it will be transparent, and used only for labels rendering
Tram lines generally stored in OSM as two parallel lines. This is produces two separate line of labels, see https://commons.wikimedia.org/wiki/File:Kaliningrad_tram_map_2022-12.svg
Finally i get how to make less labels for this case