14
14
from qtpy .QtCore import QBuffer , QByteArray
15
15
from qtpy .QtGui import QColor , QIcon , QImage , QPainter , QPixmap
16
16
from qtpy .QtWidgets import QStyle , QWidget
17
- from qtpy .QtSvg import QSvgRenderer
18
17
19
18
# Local imports
20
19
from spyder .config .manager import CONF
@@ -507,8 +506,9 @@ def _process_svg_icon(self, icon_path, resample):
507
506
508
507
# Process each size to ensure proper scaling on all displays
509
508
for size in sizes :
510
- # Create the base pixmap for this size
511
- pixmap = self ._render_colored_svg (
509
+ # Create the base pixmap for this size using SVGColorize
510
+ svg_colorizer = SVGColorize (icon_path )
511
+ pixmap = svg_colorizer .render_colored_svg (
512
512
paths , size , width , height , viewbox
513
513
)
514
514
@@ -528,91 +528,6 @@ def _process_svg_icon(self, icon_path, resample):
528
528
# Any error, fall back to regular processing
529
529
return self ._process_regular_icon (icon_path , resample )
530
530
531
- def _render_colored_svg (self , paths , size , width , height , viewbox = None ):
532
- """
533
- Render colored SVG paths to a pixmap.
534
-
535
- Parameters
536
- ----------
537
- paths : list
538
- List of path dictionaries with 'path_data' and 'color'
539
- size : int
540
- Size of the pixmap to create (used as the maximum dimension)
541
- width : int
542
- Original SVG width
543
- height : int
544
- Original SVG height
545
- viewbox : str or None
546
- SVG viewBox attribute if available
547
-
548
- Returns
549
- -------
550
- QPixmap
551
- A pixmap with all paths rendered with their respective colors
552
- """
553
-
554
- # Calculate proper dimensions preserving aspect ratio
555
- aspect_ratio = width / height
556
- if width > height :
557
- # Width is larger, use size as width
558
- pixmap_width = size
559
- pixmap_height = int (size / aspect_ratio )
560
- else :
561
- # Height is larger or equal, use size as height
562
- pixmap_height = size
563
- pixmap_width = int (size * aspect_ratio )
564
-
565
- # Create transparent pixmap for the icon with proper aspect ratio
566
- pixmap = QPixmap (pixmap_width , pixmap_height )
567
- pixmap .fill (QColor (0 , 0 , 0 , 0 )) # Transparent
568
-
569
- # Painter for compositing all parts
570
- painter = QPainter (pixmap )
571
- painter .setRenderHint (QPainter .Antialiasing )
572
-
573
- # Process each path
574
- for path_data in paths :
575
- path_d = path_data .get ('path_data' , '' )
576
- color = QColor (path_data .get ('color' , self .MAIN_FG_COLOR ))
577
-
578
- if not path_d :
579
- continue
580
-
581
- # Create a temporary SVG with just this path
582
- svg_template = (
583
- f'<svg xmlns="http://www.w3.org/2000/svg" '
584
- f'width="{ width } " height="{ height } "'
585
- )
586
-
587
- # Add viewBox if available
588
- if viewbox :
589
- svg_template += f' viewBox="{ viewbox } "'
590
-
591
- svg_template += f'><path d="{ path_d } "/></svg>'
592
-
593
- # Render the path and apply color
594
- temp_bytes = QByteArray (svg_template .encode ('utf-8' ))
595
- temp_pixmap = QPixmap (pixmap_width , pixmap_height )
596
- temp_pixmap .fill (QColor (0 , 0 , 0 , 0 )) # Transparent
597
-
598
- # Render the path
599
- temp_renderer = QSvgRenderer (temp_bytes )
600
- temp_painter = QPainter (temp_pixmap )
601
- temp_renderer .render (temp_painter )
602
- temp_painter .end ()
603
-
604
- # Apply color to the path
605
- temp_painter = QPainter (temp_pixmap )
606
- temp_painter .setCompositionMode (QPainter .CompositionMode_SourceIn )
607
- temp_painter .fillRect (temp_pixmap .rect (), color )
608
- temp_painter .end ()
609
-
610
- # Composite this path onto the main pixmap
611
- painter .drawPixmap (0 , 0 , temp_pixmap )
612
-
613
- # Finish compositing
614
- painter .end ()
615
- return pixmap
616
531
617
532
def _create_disabled_pixmap (self , source_pixmap ):
618
533
"""
0 commit comments