Skip to content

Commit

Permalink
Rendering colored texts in schematic viewer (#70)
Browse files Browse the repository at this point in the history
* add: rendering colored text in sch viewer

* add: rendering colored property text in sch viewer
  • Loading branch information
XiangYyang committed Dec 13, 2023
1 parent a85e81a commit bcfd612
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/kicad/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class Font {
P.atom("bold"),
P.atom("italic"),
P.pair("line_spacing", T.number),
P.color(),
),
);

Expand Down
45 changes: 29 additions & 16 deletions src/viewers/schematic/painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,14 @@ class TextPainter extends SchematicItemPainter {
schtext.apply_at(t.at);
schtext.apply_effects(t.effects);

schtext.attributes.color = this.dim_if_needed(this.theme.note);
const font_color = t.effects.font.color;
if (font_color.is_transparent_black) {
// The color was not specified.
const text_color = this.theme.note;
schtext.attributes.color = this.dim_if_needed(text_color);
} else {
schtext.attributes.color = this.dim_if_needed(font_color);
}

this.gfx.state.push();
StrokeFont.default().draw(
Expand Down Expand Up @@ -347,22 +354,28 @@ class PropertyPainter extends SchematicItemPainter {
color = this.theme.sheet_fields;
}

switch (p.name) {
case "Reference":
color = this.theme.reference;
break;
case "Value":
color = this.theme.value;
break;
case "Sheet name":
color = this.theme.sheet_name;
break;
case "Sheet file":
color = this.theme.sheet_filename;
break;
}
const font_color = p.effects.font.color;
if (font_color.is_transparent_black) {
// The color was not specified.
switch (p.name) {
case "Reference":
color = this.theme.reference;
break;
case "Value":
color = this.theme.value;
break;
case "Sheet name":
color = this.theme.sheet_name;
break;
case "Sheet file":
color = this.theme.sheet_filename;
break;
}

color = this.dim_if_needed(color);
color = this.dim_if_needed(color);
} else {
color = this.dim_if_needed(font_color);
}

const parent = p.parent as schematic_items.SchematicSymbol;
const transform = this.view_painter.current_symbol_transform;
Expand Down

0 comments on commit bcfd612

Please sign in to comment.