From 454ab87a354099fb96eee4721328d59f42ca0557 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 16 Jan 2018 21:20:46 +0000 Subject: Move StrokePath to the CXFA_Stroke class This CL moves the code to draw the stroke path to the stroke class. Change-Id: I76ae96e15a166d8bae19618c762d5ad923ed8d8a Reviewed-on: https://pdfium-review.googlesource.com/23030 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/cxfa_ffwidget.cpp | 37 ++++++++----------------------------- xfa/fxfa/parser/cxfa_stroke.cpp | 25 +++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_stroke.h | 4 ++++ 3 files changed, 37 insertions(+), 29 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 2642980dd1..8f7bda6d9e 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -532,31 +532,6 @@ void XFA_BOX_Fill(CXFA_Box* box, pGS->RestoreGraphState(); } -void XFA_BOX_StrokePath(CXFA_Stroke* stroke, - CXFA_GEPath* pPath, - CXFA_Graphics* pGS, - const CFX_Matrix& matrix) { - if (!stroke || !stroke->IsVisible()) - return; - - float fThickness = stroke->GetThickness(); - if (fThickness < 0.001f) - return; - - pGS->SaveGraphState(); - if (stroke->IsCorner() && fThickness > 2 * stroke->GetRadius()) - fThickness = 2 * stroke->GetRadius(); - - pGS->SetLineWidth(fThickness); - pGS->EnableActOnDash(); - pGS->SetLineCap(CFX_GraphStateData::LineCapButt); - XFA_StrokeTypeSetLineDash(pGS, stroke->GetStrokeType(), - XFA_AttributeEnum::Butt); - pGS->SetStrokeColor(CXFA_GEColor(stroke->GetColor())); - pGS->StrokePath(pPath, &matrix); - pGS->RestoreGraphState(); -} - void XFA_BOX_StrokeArc(CXFA_Box* box, CXFA_Graphics* pGS, CFX_RectF rtWidget, @@ -593,7 +568,8 @@ void XFA_BOX_StrokeArc(CXFA_Box* box, CXFA_GEPath arcPath; XFA_BOX_GetPath_Arc(box, rtWidget, arcPath, forceRound); - XFA_BOX_StrokePath(edge, &arcPath, pGS, matrix); + if (edge) + edge->Stroke(&arcPath, pGS, matrix); return; } pGS->SaveGraphState(); @@ -800,7 +776,8 @@ void XFA_BOX_Stroke_Rect(CXFA_Box* box, if ((i % 1) == 0 && stroke->GetRadius() < 0) { bool bEmpty = path.IsEmpty(); if (!bEmpty) { - XFA_BOX_StrokePath(stroke, &path, pGS, matrix); + if (stroke) + stroke->Stroke(&path, pGS, matrix); path.Clear(); } bStart = true; @@ -810,7 +787,8 @@ void XFA_BOX_Stroke_Rect(CXFA_Box* box, bStart = !stroke->SameStyles(strokes[(i + 1) % 8], 0); if (bStart) { - XFA_BOX_StrokePath(stroke, &path, pGS, matrix); + if (stroke) + stroke->Stroke(&path, pGS, matrix); path.Clear(); } } @@ -819,7 +797,8 @@ void XFA_BOX_Stroke_Rect(CXFA_Box* box, if (bClose) { path.Close(); } - XFA_BOX_StrokePath(strokes[7], &path, pGS, matrix); + if (strokes[7]) + strokes[7]->Stroke(&path, pGS, matrix); } } diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp index c9c7d73f49..45634b26e3 100644 --- a/xfa/fxfa/parser/cxfa_stroke.cpp +++ b/xfa/fxfa/parser/cxfa_stroke.cpp @@ -8,10 +8,12 @@ #include +#include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/parser/cxfa_color.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/xfa_utils.h" +#include "xfa/fxgraphics/cxfa_graphics.h" CXFA_Stroke::CXFA_Stroke(CXFA_Document* pDoc, XFA_PacketType ePacket, @@ -120,3 +122,26 @@ bool CXFA_Stroke::SameStyles(CXFA_Stroke* stroke, uint32_t dwFlags) { } return true; } + +void CXFA_Stroke::Stroke(CXFA_GEPath* pPath, + CXFA_Graphics* pGS, + const CFX_Matrix& matrix) { + if (!IsVisible()) + return; + + float fThickness = GetThickness(); + if (fThickness < 0.001f) + return; + + pGS->SaveGraphState(); + if (IsCorner() && fThickness > 2 * GetRadius()) + fThickness = 2 * GetRadius(); + + pGS->SetLineWidth(fThickness); + pGS->EnableActOnDash(); + pGS->SetLineCap(CFX_GraphStateData::LineCapButt); + XFA_StrokeTypeSetLineDash(pGS, GetStrokeType(), XFA_AttributeEnum::Butt); + pGS->SetStrokeColor(CXFA_GEColor(GetColor())); + pGS->StrokePath(pPath, &matrix); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/parser/cxfa_stroke.h b/xfa/fxfa/parser/cxfa_stroke.h index 42b7ec0c20..d3eeff1ed2 100644 --- a/xfa/fxfa/parser/cxfa_stroke.h +++ b/xfa/fxfa/parser/cxfa_stroke.h @@ -18,6 +18,8 @@ enum StrokeSameStyle { XFA_STROKE_SAMESTYLE_Corner = 2 }; +class CXFA_GEPath; +class CXFA_Graphics; class CXFA_Node; class CXFA_Stroke : public CXFA_Node { @@ -42,6 +44,8 @@ class CXFA_Stroke : public CXFA_Node { bool SameStyles(CXFA_Stroke* stroke, uint32_t dwFlags); + void Stroke(CXFA_GEPath* pPath, CXFA_Graphics* pGS, const CFX_Matrix& matrix); + protected: CXFA_Stroke(CXFA_Document* pDoc, XFA_PacketType ePacket, -- cgit v1.2.3