Skip to content

Commit bcfd612

Browse files
authored
Rendering colored texts in schematic viewer (#70)
* add: rendering colored text in sch viewer * add: rendering colored property text in sch viewer
1 parent a85e81a commit bcfd612

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

‎src/kicad/common.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export class Font {
263263
P.atom("bold"),
264264
P.atom("italic"),
265265
P.pair("line_spacing", T.number),
266+
P.color(),
266267
),
267268
);
268269

‎src/viewers/schematic/painter.ts‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,14 @@ class TextPainter extends SchematicItemPainter {
317317
schtext.apply_at(t.at);
318318
schtext.apply_effects(t.effects);
319319

320-
schtext.attributes.color = this.dim_if_needed(this.theme.note);
320+
const font_color = t.effects.font.color;
321+
if (font_color.is_transparent_black) {
322+
// The color was not specified.
323+
const text_color = this.theme.note;
324+
schtext.attributes.color = this.dim_if_needed(text_color);
325+
} else {
326+
schtext.attributes.color = this.dim_if_needed(font_color);
327+
}
321328

322329
this.gfx.state.push();
323330
StrokeFont.default().draw(
@@ -347,22 +354,28 @@ class PropertyPainter extends SchematicItemPainter {
347354
color = this.theme.sheet_fields;
348355
}
349356

350-
switch (p.name) {
351-
case "Reference":
352-
color = this.theme.reference;
353-
break;
354-
case "Value":
355-
color = this.theme.value;
356-
break;
357-
case "Sheet name":
358-
color = this.theme.sheet_name;
359-
break;
360-
case "Sheet file":
361-
color = this.theme.sheet_filename;
362-
break;
363-
}
357+
const font_color = p.effects.font.color;
358+
if (font_color.is_transparent_black) {
359+
// The color was not specified.
360+
switch (p.name) {
361+
case "Reference":
362+
color = this.theme.reference;
363+
break;
364+
case "Value":
365+
color = this.theme.value;
366+
break;
367+
case "Sheet name":
368+
color = this.theme.sheet_name;
369+
break;
370+
case "Sheet file":
371+
color = this.theme.sheet_filename;
372+
break;
373+
}
364374

365-
color = this.dim_if_needed(color);
375+
color = this.dim_if_needed(color);
376+
} else {
377+
color = this.dim_if_needed(font_color);
378+
}
366379

367380
const parent = p.parent as schematic_items.SchematicSymbol;
368381
const transform = this.view_painter.current_symbol_transform;

0 commit comments

Comments
 (0)