Skip to content

Commit

Permalink
Set default opacity to -1.0 and add check method (item for color)
Browse files Browse the repository at this point in the history
* Test suite evaluated locally
  • Loading branch information
lpugin committed Feb 11, 2025
1 parent 5d47958 commit 8243030
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
8 changes: 6 additions & 2 deletions include/vrv/devicecontextbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Pen {
, m_gapLength(0)
, m_lineCap(LINECAP_DEFAULT)
, m_lineJoin(LINEJOIN_DEFAULT)
, m_opacity(1.0)
, m_opacity(-1.0)
, m_color(COLOR_NONE)
{
}
Expand All @@ -82,6 +82,7 @@ class Pen {

int GetColor() const { return m_color; }
void SetColor(int color) { m_color = color; }
bool HasColor() const { return (m_color != COLOR_NONE); }
int GetWidth() const { return m_width; }
void SetWidth(int width) { m_width = width; }
int GetDashLength() const { return m_dashLength; }
Expand All @@ -96,6 +97,7 @@ class Pen {
void SetStyle(PenStyle style) { m_style = style; }
float GetOpacity() const { return m_opacity; }
void SetOpacity(float opacity) { m_opacity = opacity; }
bool HasOpacity() const { return (m_opacity != -1.0); }

private:
int m_width;
Expand All @@ -109,13 +111,15 @@ class Pen {

class Brush {
public:
Brush() : m_opacity(1.0), m_color(COLOR_NONE) {}
Brush() : m_opacity(-1.0), m_color(COLOR_NONE) {}
Brush(float opacity, int color) : m_opacity(opacity), m_color(color) {}

int GetColor() const { return m_color; }
void SetColor(int color) { m_color = color; }
bool HasColor() const { return (m_color != COLOR_NONE); }
float GetOpacity() const { return m_opacity; }
void SetOpacity(float opacity) { m_opacity = opacity; }
bool HasOpacity() const { return (m_opacity != -1.0); }

private:
float m_opacity;
Expand Down
34 changes: 17 additions & 17 deletions src/svgdevicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ 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";
if (m_penStack.top().GetColor() != COLOR_NONE) {
if (m_penStack.top().HasColor()) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
pathChild.append_attribute("stroke-linecap") = "round";
Expand All @@ -640,7 +640,7 @@ void SvgDeviceContext::DrawCubicBezierPath(Point bezier[4])
)
.c_str();
pathChild.append_attribute("fill") = "none";
if (m_penStack.top().GetColor() != COLOR_NONE) {
if (m_penStack.top().HasColor()) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
pathChild.append_attribute("stroke-linecap") = "round";
Expand All @@ -660,7 +660,7 @@ void SvgDeviceContext::DrawCubicBezierPathFilled(Point bezier1[4], Point bezier2
.c_str();
// pathChild.append_attribute("fill") = "currentColor";
// pathChild.append_attribute("fill-opacity") = "1";
if (m_penStack.top().GetColor() != COLOR_NONE) {
if (m_penStack.top().HasColor()) {
pathChild.append_attribute("stroke") = this->GetColor(m_penStack.top().GetColor()).c_str();
}
pathChild.append_attribute("stroke-linecap") = "round";
Expand Down Expand Up @@ -690,16 +690,16 @@ void SvgDeviceContext::DrawEllipse(int x, int y, int width, int height)
ellipseChild.append_attribute("cy") = y + rh;
ellipseChild.append_attribute("rx") = rw;
ellipseChild.append_attribute("ry") = rh;
if (currentBrush.GetOpacity() != 1.0) {
if (currentBrush.HasOpacity()) {
ellipseChild.append_attribute("fill-opacity") = currentBrush.GetOpacity();
}
if (currentPen.GetOpacity() != 1.0) {
if (currentPen.HasOpacity()) {
ellipseChild.append_attribute("stroke-opacity") = currentPen.GetOpacity();
}
if (currentPen.GetWidth() > 0) {
ellipseChild.append_attribute("stroke-width") = currentPen.GetWidth();
}
if (currentPen.GetColor() != COLOR_NONE) {
if (currentPen.HasColor()) {
ellipseChild.append_attribute("stroke") = this->GetColor(currentPen.GetColor()).c_str();
}
}
Expand Down Expand Up @@ -759,16 +759,16 @@ void SvgDeviceContext::DrawEllipticArc(int x, int y, int width, int height, doub
"M%d %d A%d %d 0.0 %d %d %d %d", int(xs), int(ys), abs(int(rx)), abs(int(ry)), fArc, fSweep, int(xe), int(ye))
.c_str();
// pathChild.append_attribute("fill") = "currentColor";
if (currentBrush.GetOpacity() != 1.0) {
if (currentBrush.HasOpacity()) {
pathChild.append_attribute("fill-opacity") = currentBrush.GetOpacity();
}
if (currentPen.GetOpacity() != 1.0) {
if (currentPen.HasOpacity()) {
pathChild.append_attribute("stroke-opacity") = currentPen.GetOpacity();
}
if (currentPen.GetWidth() > 0) {
pathChild.append_attribute("stroke-width") = currentPen.GetWidth();
}
if (currentPen.GetColor() != COLOR_NONE) {
if (currentPen.HasColor()) {
pathChild.append_attribute("stroke") = this->GetColor(currentPen.GetColor()).c_str();
}
}
Expand All @@ -777,7 +777,7 @@ 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();
if (m_penStack.top().GetColor() != COLOR_NONE) {
if (m_penStack.top().HasColor()) {
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();
Expand All @@ -798,7 +798,7 @@ void SvgDeviceContext::DrawPolyline(int n, Point points[], bool close)
if (currentPen.GetWidth() > 1) {
polylineChild.append_attribute("stroke-width") = currentPen.GetWidth();
}
if (currentPen.GetOpacity() != 1.0) {
if (currentPen.HasOpacity()) {
polylineChild.append_attribute("stroke-opacity") = currentPen.GetOpacity();
}

Expand Down Expand Up @@ -831,17 +831,17 @@ void SvgDeviceContext::DrawPolygon(int n, Point points[])
if (currentPen.GetWidth() > 1) {
polygonChild.append_attribute("stroke-width") = currentPen.GetWidth();
}
if (currentPen.GetOpacity() != 1.0) {
if (currentPen.HasOpacity()) {
polygonChild.append_attribute("stroke-opacity") = currentPen.GetOpacity();
}

this->AppendStrokeLineJoin(polygonChild, currentPen);
this->AppendStrokeDashArray(polygonChild, currentPen);

if (currentBrush.GetColor() != COLOR_NONE) {
if (currentBrush.HasColor()) {
polygonChild.append_attribute("fill") = this->GetColor(currentBrush.GetColor()).c_str();
}
if (currentBrush.GetOpacity() != 1.0) {
if (currentBrush.HasOpacity()) {
polygonChild.append_attribute("fill-opacity") = currentBrush.GetOpacity();
}

Expand Down Expand Up @@ -869,17 +869,17 @@ void SvgDeviceContext::DrawRoundedRectangle(int x, int y, int width, int height,
if (currentPen.GetWidth() > 1) {
rectChild.append_attribute("stroke-width") = currentPen.GetWidth();
}
if (currentPen.GetOpacity() != 1.0) {
if (currentPen.HasOpacity()) {
rectChild.append_attribute("stroke-opacity") = currentPen.GetOpacity();
}
}

if (m_brushStack.size()) {
Brush currentBrush = m_brushStack.top();
if (currentBrush.GetColor() != COLOR_NONE) {
if (currentBrush.HasColor()) {
rectChild.append_attribute("fill") = this->GetColor(currentBrush.GetColor()).c_str();
}
if (currentBrush.GetOpacity() != 1.0) {
if (currentBrush.HasOpacity()) {
rectChild.append_attribute("fill-opacity") = currentBrush.GetOpacity();
}
}
Expand Down

0 comments on commit 8243030

Please sign in to comment.