Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only write stroke for non-default color #3949

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/svgdevicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void SvgDeviceContext::StartPage()
//"g.bounding-box{stroke:red; stroke-width:10} "
//"g.content-bounding-box{stroke:blue; stroke-width:10} "
"g.ending, g.fing, g.reh, g.tempo{font-weight:bold;} g.dir, g.dynam, "
"g.mNum{font-style:italic;} g.label{font-weight:normal;}");
"g.mNum{font-style:italic;} g.label{font-weight:normal;} path{stroke:currentColor}");
m_currentNode = m_svgNodeStack.back();
}

Expand Down Expand Up @@ -622,7 +622,9 @@ void SvgDeviceContext::DrawQuadBezierPath(Point bezier[3])
bezier[1].x, bezier[1].y, bezier[2].x, bezier[2].y)
.c_str();
pathChild.append_attribute("fill") = "none";
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
if (m_penStack.top().GetColor() != COLOR_NONE) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
pathChild.append_attribute("stroke-linecap") = "round";
pathChild.append_attribute("stroke-linejoin") = "round";
pathChild.append_attribute("stroke-width") = m_penStack.top().GetWidth();
Expand All @@ -638,7 +640,9 @@ void SvgDeviceContext::DrawCubicBezierPath(Point bezier[4])
)
.c_str();
pathChild.append_attribute("fill") = "none";
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
if (m_penStack.top().GetColor() != COLOR_NONE) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
pathChild.append_attribute("stroke-linecap") = "round";
pathChild.append_attribute("stroke-linejoin") = "round";
pathChild.append_attribute("stroke-width") = m_penStack.top().GetWidth();
Expand All @@ -656,7 +660,9 @@ void SvgDeviceContext::DrawCubicBezierPathFilled(Point bezier1[4], Point bezier2
.c_str();
// pathChild.append_attribute("fill") = "currentColor";
// pathChild.append_attribute("fill-opacity") = "1";
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
if (m_penStack.top().GetColor() != COLOR_NONE) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
pathChild.append_attribute("stroke-linecap") = "round";
pathChild.append_attribute("stroke-linejoin") = "round";
// pathChild.append_attribute("stroke-opacity") = "1";
Expand Down Expand Up @@ -692,7 +698,9 @@ void SvgDeviceContext::DrawEllipse(int x, int y, int width, int height)
}
if (currentPen.GetWidth() > 0) {
ellipseChild.append_attribute("stroke-width") = currentPen.GetWidth();
ellipseChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
if (currentPen.GetColor() != COLOR_NONE) {
ellipseChild.append_attribute("stroke") = this->GetColor(currentPen.GetColor()).c_str();
}
}

Expand Down Expand Up @@ -759,15 +767,19 @@ void SvgDeviceContext::DrawEllipticArc(int x, int y, int width, int height, doub
}
if (currentPen.GetWidth() > 0) {
pathChild.append_attribute("stroke-width") = currentPen.GetWidth();
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
if (currentPen.GetColor() != COLOR_NONE) {
pathChild.append_attribute("stroke") = this->GetColor(currentPen.GetColor()).c_str();
}
}

void SvgDeviceContext::DrawLine(int x1, int y1, int x2, int y2)
{
pugi::xml_node pathChild = AddChild("path");
pathChild.append_attribute("d") = StringFormat("M%d %d L%d %d", x1, y1, x2, y2).c_str();
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
if (m_penStack.top().GetColor() != COLOR_NONE) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
if (m_penStack.top().GetWidth() > 1) pathChild.append_attribute("stroke-width") = m_penStack.top().GetWidth();
this->AppendStrokeLineCap(pathChild, m_penStack.top());
this->AppendStrokeDashArray(pathChild, m_penStack.top());
Expand Down