@@ -94,6 +94,7 @@ def __init__(self, edit_file_path=None, duplicate=False):
94
94
95
95
self .font_weight = 'normal'
96
96
self .font_style = 'normal'
97
+ self .font_size_pixel = 20
97
98
98
99
self .new_title_text = ""
99
100
self .sub_title_text = ""
@@ -279,8 +280,17 @@ def load_svg_template(self):
279
280
for i in range (0 , self .text_fields ):
280
281
if len (self .tspan_node [i ].childNodes ) > 0 :
281
282
text = self .tspan_node [i ].childNodes [0 ].data
283
+ ar = self .tspan_node [i ].attributes ["style" ].value .split (";" )
282
284
title_text .append (text )
283
285
286
+ # Set font size (for possible font dialog)
287
+ fs = self .find_in_list (ar , "font-size:" )
288
+ fs_value = ar [fs ][10 :]
289
+ if fs_value .endswith ("px" ):
290
+ self .qfont .setPixelSize (float (fs_value [:- 2 ]))
291
+ elif fs_value .endswith ("pt" ):
292
+ self .qfont .setPointSizeF (float (fs_value [:- 2 ]))
293
+
284
294
# Create Label
285
295
label = QLabel ()
286
296
label_line_text = _ ("Line %s:" ) % str (i + 1 )
@@ -414,6 +424,7 @@ def btnFont_clicked(self):
414
424
self .font_family = fontinfo .family ()
415
425
self .font_style = fontinfo .styleName ()
416
426
self .font_weight = fontinfo .weight ()
427
+ self .font_size_pixel = fontinfo .pixelSize ()
417
428
self .set_font_style ()
418
429
419
430
# Something changed, so update temp SVG
@@ -432,7 +443,7 @@ def update_font_color_button(self):
432
443
"""Updates the color shown on the font color button"""
433
444
434
445
# Loop through each TEXT element
435
- for node in self .text_node :
446
+ for node in self .text_node + self . tspan_node :
436
447
437
448
# Get the value in the style attribute
438
449
s = node .attributes ["style" ].value
@@ -449,6 +460,14 @@ def update_font_color_button(self):
449
460
# If the color was in an invalid format, try the next text element
450
461
log .debug ('Failed to parse {} as color value' .format (txt ))
451
462
463
+ # Look up color if needed
464
+ # Some colors are located in a different node
465
+ if color .startswith ("url(#" ) and self .xmldoc .getElementsByTagName ("defs" ).length == 1 :
466
+ color_ref_id = color [5 :- 1 ]
467
+ ref_color = self .get_ref_color (color_ref_id )
468
+ if ref_color :
469
+ color = ref_color
470
+
452
471
opacity = self .find_in_list (ar , "opacity:" )
453
472
454
473
try :
@@ -485,6 +504,31 @@ def update_font_color_button(self):
485
504
color .setAlphaF (opacity )
486
505
self .font_color_code = color
487
506
507
+ def get_ref_color (self , id ):
508
+ """Get the color value from a reference id (i.e. linearGradient3267)"""
509
+ found_color = ""
510
+ for ref_node in self .xmldoc .getElementsByTagName ("defs" )[0 ].childNodes :
511
+ if ref_node .attributes and "id" in ref_node .attributes :
512
+ ref_node_id = ref_node .attributes ["id" ].value
513
+ if id == ref_node_id :
514
+ # Found a matching color reference
515
+ if "xlink:href" in ref_node .attributes :
516
+ # look up color reference again
517
+ xlink_ref_id = ref_node .attributes ["xlink:href" ].value [1 :]
518
+ return self .get_ref_color (xlink_ref_id )
519
+ if "href" in ref_node .attributes :
520
+ # look up color reference again
521
+ xlink_ref_id = ref_node .attributes ["href" ].value [1 :]
522
+ return self .get_ref_color (xlink_ref_id )
523
+ elif ref_node .childNodes :
524
+ for stop_node in ref_node .childNodes :
525
+ if "stop" == stop_node .nodeName :
526
+ # get color from stop
527
+ ar = stop_node .attributes ["style" ].value .split (";" )
528
+ sc = self .find_in_list (ar , "stop-color:" )
529
+ return ar [sc ][11 :]
530
+ return found_color
531
+
488
532
def update_background_color_button (self ):
489
533
"""Updates the color shown on the background color button"""
490
534
@@ -545,9 +589,8 @@ def update_background_color_button(self):
545
589
546
590
def set_font_style (self ):
547
591
'''sets the font properties'''
548
-
549
592
# Loop through each TEXT element
550
- for text_child in self .text_node :
593
+ for text_child in self .text_node + self . tspan_node :
551
594
# set the style elements for the main text node
552
595
s = text_child .attributes ["style" ].value
553
596
# split the text node so we can access each part
@@ -558,40 +601,20 @@ def set_font_style(self):
558
601
# ignoring font-weight, as not sure what it represents in Qt.
559
602
fs = self .find_in_list (ar , "font-style:" )
560
603
ff = self .find_in_list (ar , "font-family:" )
604
+ fp = self .find_in_list (ar , "font-size:" )
561
605
if fs :
562
606
ar [fs ] = "font-style:" + self .font_style
563
607
if ff :
564
608
ar [ff ] = "font-family:" + self .font_family
609
+ if fp :
610
+ ar [fp ] = "font-size:%spx" % self .font_size_pixel
565
611
# rejoin the modified parts
566
612
t = ";"
567
613
self .title_style_string = t .join (ar )
568
614
569
615
# set the text node
570
616
text_child .setAttribute ("style" , self .title_style_string )
571
617
572
- # Loop through each TSPAN
573
- for tspan_child in self .tspan_node :
574
- # set the style elements for the main text node
575
- s = tspan_child .attributes ["style" ].value
576
- # split the text node so we can access each part
577
- ar = s .split (";" )
578
- # we need to find each element that we are changing, shouldn't assume
579
- # they are in the same position in any given template.
580
-
581
- # ignoring font-weight, as not sure what it represents in Qt.
582
- fs = self .find_in_list (ar , "font-style:" )
583
- ff = self .find_in_list (ar , "font-family:" )
584
- if fs :
585
- ar [fs ] = "font-style:" + self .font_style
586
- if ff :
587
- ar [ff ] = "font-family:" + self .font_family
588
- # rejoin the modified parts
589
- t = ";"
590
- self .title_style_string = t .join (ar )
591
-
592
- # set the text node
593
- tspan_child .setAttribute ("style" , self .title_style_string )
594
-
595
618
def set_bg_style (self , color , alpha ):
596
619
'''sets the background color'''
597
620
@@ -620,7 +643,7 @@ def set_bg_style(self, color, alpha):
620
643
def set_font_color_elements (self , color , alpha ):
621
644
622
645
# Loop through each TEXT element
623
- for text_child in self .text_node :
646
+ for text_child in self .text_node + self . tspan_node :
624
647
625
648
# SET TEXT PROPERTIES
626
649
s = text_child .attributes ["style" ].value
@@ -641,21 +664,6 @@ def set_font_color_elements(self, color, alpha):
641
664
t = ";"
642
665
text_child .setAttribute ("style" , t .join (ar ))
643
666
644
- # Loop through each TSPAN
645
- for tspan_child in self .tspan_node :
646
-
647
- # SET TSPAN PROPERTIES
648
- s = tspan_child .attributes ["style" ].value
649
- # split the text node so we can access each part
650
- ar = s .split (";" )
651
- fill = self .find_in_list (ar , "fill:" )
652
- if fill is None :
653
- ar .append ("fill:" + color )
654
- else :
655
- ar [fill ] = "fill:" + color
656
- t = ";"
657
- tspan_child .setAttribute ("style" , t .join (ar ))
658
-
659
667
def accept (self ):
660
668
app = get_app ()
661
669
_ = app ._tr
0 commit comments