From cce8e2f46d0fb64c2558c24a2aa33ac929dfdad6 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 7 Nov 2017 18:41:41 +0000 Subject: Rename CXFA_Box to CXFA_BoxData This CL renames CXFA_Box to CXFA_BoxData to make it clear it's part of the Data hierarchy. Change-Id: I5971eefb078f73228e2fcfc08d2025d800c319fb Reviewed-on: https://pdfium-review.googlesource.com/17975 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fxfa/cxfa_ffwidget.cpp | 93 +++++++++++---------- xfa/fxfa/cxfa_ffwidget.h | 4 +- xfa/fxfa/cxfa_widgetacc.h | 2 +- xfa/fxfa/parser/cxfa_arcdata.h | 6 +- xfa/fxfa/parser/cxfa_borderdata.h | 6 +- xfa/fxfa/parser/cxfa_box.cpp | 167 -------------------------------------- xfa/fxfa/parser/cxfa_box.h | 54 ------------ xfa/fxfa/parser/cxfa_boxdata.cpp | 167 ++++++++++++++++++++++++++++++++++++++ xfa/fxfa/parser/cxfa_boxdata.h | 54 ++++++++++++ xfa/fxfa/parser/cxfa_rectangle.h | 6 +- 10 files changed, 279 insertions(+), 280 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_box.cpp delete mode 100644 xfa/fxfa/parser/cxfa_box.h create mode 100644 xfa/fxfa/parser/cxfa_boxdata.cpp create mode 100644 xfa/fxfa/parser/cxfa_boxdata.h (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index dad1f01afd..cca04dac5e 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -38,24 +38,24 @@ namespace { -void XFA_BOX_GetPath_Arc(CXFA_Box box, +void XFA_BOX_GetPath_Arc(CXFA_BoxData boxData, CFX_RectF rtDraw, CXFA_Path& fillPath, uint32_t dwFlags) { float a, b; a = rtDraw.width / 2.0f; b = rtDraw.height / 2.0f; - if (box.IsCircular() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { + if (boxData.IsCircular() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) a = b = std::min(a, b); - } + CFX_PointF center = rtDraw.Center(); rtDraw.left = center.x - a; rtDraw.top = center.y - b; rtDraw.width = a + a; rtDraw.height = b + b; float startAngle = 0, sweepAngle = 360; - bool bStart = box.GetStartAngle(startAngle); - bool bEnd = box.GetSweepAngle(sweepAngle); + bool bStart = boxData.GetStartAngle(startAngle); + bool bEnd = boxData.GetSweepAngle(sweepAngle); if (!bStart && !bEnd) { fillPath.AddEllipse(rtDraw); return; @@ -65,8 +65,7 @@ void XFA_BOX_GetPath_Arc(CXFA_Box box, fillPath.AddArc(rtDraw.TopLeft(), rtDraw.Size(), startAngle, sweepAngle); } -void XFA_BOX_GetPath(CXFA_Box box, - const std::vector& strokes, +void XFA_BOX_GetPath(const std::vector& strokes, CFX_RectF rtWidget, CXFA_Path& path, int32_t nIndex, @@ -235,25 +234,25 @@ void XFA_BOX_GetPath(CXFA_Box box, } } -void XFA_BOX_GetFillPath(CXFA_Box box, +void XFA_BOX_GetFillPath(CXFA_BoxData boxData, const std::vector& strokes, CFX_RectF rtWidget, CXFA_Path& fillPath, uint16_t dwFlags) { - if (box.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { - CXFA_Edge edge = box.GetEdge(0); + if (boxData.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { + CXFA_Edge edge = boxData.GetEdge(0); float fThickness = edge.GetThickness(); if (fThickness < 0) { fThickness = 0; } float fHalf = fThickness / 2; - int32_t iHand = box.GetHand(); + int32_t iHand = boxData.GetHand(); if (iHand == XFA_ATTRIBUTEENUM_Left) { rtWidget.Inflate(fHalf, fHalf); } else if (iHand == XFA_ATTRIBUTEENUM_Right) { rtWidget.Deflate(fHalf, fHalf); } - XFA_BOX_GetPath_Arc(box, rtWidget, fillPath, dwFlags); + XFA_BOX_GetPath_Arc(boxData, rtWidget, fillPath, dwFlags); return; } bool bSameStyles = true; @@ -387,12 +386,12 @@ void XFA_BOX_GetFillPath(CXFA_Box box, } } -void XFA_BOX_Fill_Radial(CXFA_Box box, +void XFA_BOX_Fill_Radial(CXFA_BoxData boxData, CXFA_Graphics* pGS, CXFA_Path& fillPath, CFX_RectF rtFill, const CFX_Matrix& matrix) { - CXFA_Fill fill = box.GetFill(); + CXFA_Fill fill = boxData.GetFill(); FX_ARGB crStart, crEnd; crStart = fill.GetColor(); int32_t iType = fill.GetRadial(crEnd); @@ -410,12 +409,12 @@ void XFA_BOX_Fill_Radial(CXFA_Box box, pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); } -void XFA_BOX_Fill_Pattern(CXFA_Box box, +void XFA_BOX_Fill_Pattern(CXFA_BoxData boxData, CXFA_Graphics* pGS, CXFA_Path& fillPath, CFX_RectF rtFill, const CFX_Matrix& matrix) { - CXFA_Fill fill = box.GetFill(); + CXFA_Fill fill = boxData.GetFill(); FX_ARGB crStart, crEnd; crStart = fill.GetColor(); int32_t iType = fill.GetPattern(crEnd); @@ -445,12 +444,12 @@ void XFA_BOX_Fill_Pattern(CXFA_Box box, pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); } -void XFA_BOX_Fill_Linear(CXFA_Box box, +void XFA_BOX_Fill_Linear(CXFA_BoxData boxData, CXFA_Graphics* pGS, CXFA_Path& fillPath, CFX_RectF rtFill, const CFX_Matrix& matrix) { - CXFA_Fill fill = box.GetFill(); + CXFA_Fill fill = boxData.GetFill(); FX_ARGB crStart = fill.GetColor(); FX_ARGB crEnd; int32_t iType = fill.GetLinear(crEnd); @@ -481,31 +480,31 @@ void XFA_BOX_Fill_Linear(CXFA_Box box, pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); } -void XFA_BOX_Fill(CXFA_Box box, +void XFA_BOX_Fill(CXFA_BoxData boxData, const std::vector& strokes, CXFA_Graphics* pGS, const CFX_RectF& rtWidget, const CFX_Matrix& matrix, uint32_t dwFlags) { - CXFA_Fill fill = box.GetFill(); + CXFA_Fill fill = boxData.GetFill(); if (!fill || fill.GetPresence() != XFA_ATTRIBUTEENUM_Visible) return; pGS->SaveGraphState(); CXFA_Path fillPath; - XFA_BOX_GetFillPath(box, strokes, rtWidget, fillPath, + XFA_BOX_GetFillPath(boxData, strokes, rtWidget, fillPath, (dwFlags & XFA_DRAWBOX_ForceRound) != 0); fillPath.Close(); XFA_Element eType = fill.GetFillType(); switch (eType) { case XFA_Element::Radial: - XFA_BOX_Fill_Radial(box, pGS, fillPath, rtWidget, matrix); + XFA_BOX_Fill_Radial(boxData, pGS, fillPath, rtWidget, matrix); break; case XFA_Element::Pattern: - XFA_BOX_Fill_Pattern(box, pGS, fillPath, rtWidget, matrix); + XFA_BOX_Fill_Pattern(boxData, pGS, fillPath, rtWidget, matrix); break; case XFA_Element::Linear: - XFA_BOX_Fill_Linear(box, pGS, fillPath, rtWidget, matrix); + XFA_BOX_Fill_Linear(boxData, pGS, fillPath, rtWidget, matrix); break; default: { FX_ARGB cr; @@ -552,18 +551,18 @@ void XFA_BOX_StrokePath(CXFA_Stroke stroke, pGS->RestoreGraphState(); } -void XFA_BOX_StrokeArc(CXFA_Box box, +void XFA_BOX_StrokeArc(CXFA_BoxData boxData, CXFA_Graphics* pGS, CFX_RectF rtWidget, const CFX_Matrix& matrix, uint32_t dwFlags) { - CXFA_Edge edge = box.GetEdge(0); + CXFA_Edge edge = boxData.GetEdge(0); if (!edge || !edge.IsVisible()) { return; } bool bVisible = false; float fThickness = 0; - int32_t i3DType = box.Get3DStyle(bVisible, fThickness); + int32_t i3DType = boxData.Get3DStyle(bVisible, fThickness); if (i3DType) { if (bVisible && fThickness >= 0.001f) { dwFlags |= XFA_DRAWBOX_Lowered3D; @@ -573,7 +572,7 @@ void XFA_BOX_StrokeArc(CXFA_Box box, if (fHalf < 0) { fHalf = 0; } - int32_t iHand = box.GetHand(); + int32_t iHand = boxData.GetHand(); if (iHand == XFA_ATTRIBUTEENUM_Left) { rtWidget.Inflate(fHalf, fHalf); } else if (iHand == XFA_ATTRIBUTEENUM_Right) { @@ -585,7 +584,7 @@ void XFA_BOX_StrokeArc(CXFA_Box box, return; CXFA_Path arcPath; - XFA_BOX_GetPath_Arc(box, rtWidget, arcPath, dwFlags); + XFA_BOX_GetPath_Arc(boxData, rtWidget, arcPath, dwFlags); XFA_BOX_StrokePath(edge, &arcPath, pGS, matrix); return; } @@ -723,14 +722,14 @@ void XFA_BOX_Stroke_3DRect_Embossed(CXFA_Graphics* pGS, XFA_Draw3DRect(pGS, rtInner, fHalfWidth, matrix, 0xFF000000, 0xFF808080); } -void XFA_BOX_Stroke_Rect(CXFA_Box box, +void XFA_BOX_Stroke_Rect(CXFA_BoxData boxData, const std::vector& strokes, CXFA_Graphics* pGS, CFX_RectF rtWidget, const CFX_Matrix& matrix) { bool bVisible = false; float fThickness = 0; - int32_t i3DType = box.Get3DStyle(bVisible, fThickness); + int32_t i3DType = boxData.Get3DStyle(bVisible, fThickness); if (i3DType) { if (!bVisible || fThickness < 0.001f) { return; @@ -795,7 +794,7 @@ void XFA_BOX_Stroke_Rect(CXFA_Box box, bStart = true; continue; } - XFA_BOX_GetPath(box, strokes, rtWidget, path, i, bStart, !bSameStyles); + XFA_BOX_GetPath(strokes, rtWidget, path, i, bStart, !bSameStyles); CXFA_Stroke stroke2 = strokes[(i + 1) % 8]; bStart = !stroke.SameStyles(stroke2); if (bStart) { @@ -812,14 +811,14 @@ void XFA_BOX_Stroke_Rect(CXFA_Box box, } } -void XFA_BOX_Stroke(CXFA_Box box, +void XFA_BOX_Stroke(CXFA_BoxData boxData, const std::vector& strokes, CXFA_Graphics* pGS, CFX_RectF rtWidget, const CFX_Matrix& matrix, uint32_t dwFlags) { - if (box.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { - XFA_BOX_StrokeArc(box, pGS, rtWidget, matrix, dwFlags); + if (boxData.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { + XFA_BOX_StrokeArc(boxData, pGS, rtWidget, matrix, dwFlags); return; } bool bVisible = false; @@ -839,7 +838,7 @@ void XFA_BOX_Stroke(CXFA_Box box, fThickness = 0; } float fHalf = fThickness / 2; - int32_t iHand = box.GetHand(); + int32_t iHand = boxData.GetHand(); switch (i) { case 1: if (iHand == XFA_ATTRIBUTEENUM_Left) { @@ -875,28 +874,28 @@ void XFA_BOX_Stroke(CXFA_Box box, break; } } - XFA_BOX_Stroke_Rect(box, strokes, pGS, rtWidget, matrix); + XFA_BOX_Stroke_Rect(boxData, strokes, pGS, rtWidget, matrix); } -void XFA_DrawBox(CXFA_Box box, +void XFA_DrawBox(CXFA_BoxData boxData, CXFA_Graphics* pGS, const CFX_RectF& rtWidget, const CFX_Matrix& matrix, uint32_t dwFlags) { - if (!box || box.GetPresence() != XFA_ATTRIBUTEENUM_Visible) + if (!boxData || boxData.GetPresence() != XFA_ATTRIBUTEENUM_Visible) return; - XFA_Element eType = box.GetElementType(); + XFA_Element eType = boxData.GetElementType(); if (eType != XFA_Element::Arc && eType != XFA_Element::Border && eType != XFA_Element::Rectangle) { return; } std::vector strokes; if (!(dwFlags & XFA_DRAWBOX_ForceRound) && eType != XFA_Element::Arc) - box.GetStrokes(&strokes); + boxData.GetStrokes(&strokes); - XFA_BOX_Fill(box, strokes, pGS, rtWidget, matrix, dwFlags); - XFA_BOX_Stroke(box, strokes, pGS, rtWidget, matrix, dwFlags); + XFA_BOX_Fill(boxData, strokes, pGS, rtWidget, matrix, dwFlags); + XFA_BOX_Stroke(boxData, strokes, pGS, rtWidget, matrix, dwFlags); } bool IsFXCodecErrorStatus(FXCODEC_STATUS status) { @@ -1024,18 +1023,18 @@ bool CXFA_FFWidget::UpdateFWLData() { void CXFA_FFWidget::UpdateWidgetProperty() {} void CXFA_FFWidget::DrawBorder(CXFA_Graphics* pGS, - CXFA_Box box, + CXFA_BoxData boxData, const CFX_RectF& rtBorder, const CFX_Matrix& matrix) { - XFA_DrawBox(box, pGS, rtBorder, matrix, 0); + XFA_DrawBox(boxData, pGS, rtBorder, matrix, 0); } void CXFA_FFWidget::DrawBorderWithFlags(CXFA_Graphics* pGS, - CXFA_Box box, + CXFA_BoxData boxData, const CFX_RectF& rtBorder, const CFX_Matrix& matrix, uint32_t dwFlags) { - XFA_DrawBox(box, pGS, rtBorder, matrix, dwFlags); + XFA_DrawBox(boxData, pGS, rtBorder, matrix, dwFlags); } void CXFA_FFWidget::AddInvalidateRect() { diff --git a/xfa/fxfa/cxfa_ffwidget.h b/xfa/fxfa/cxfa_ffwidget.h index 77f6faf499..26cca1ee5b 100644 --- a/xfa/fxfa/cxfa_ffwidget.h +++ b/xfa/fxfa/cxfa_ffwidget.h @@ -167,11 +167,11 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { virtual bool PtInActiveRect(const CFX_PointF& point); void DrawBorder(CXFA_Graphics* pGS, - CXFA_Box box, + CXFA_BoxData boxData, const CFX_RectF& rtBorder, const CFX_Matrix& matrix); void DrawBorderWithFlags(CXFA_Graphics* pGS, - CXFA_Box box, + CXFA_BoxData boxData, const CFX_RectF& rtBorder, const CFX_Matrix& matrix, uint32_t dwFlags); diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index d1aa1df5c6..718dcf3a63 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -14,7 +14,7 @@ #include "core/fxcrt/retain_ptr.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/fx_dib.h" -#include "xfa/fxfa/parser/cxfa_box.h" +#include "xfa/fxfa/parser/cxfa_boxdata.h" #include "xfa/fxfa/parser/cxfa_event.h" #include "xfa/fxfa/parser/cxfa_image.h" #include "xfa/fxfa/parser/cxfa_margin.h" diff --git a/xfa/fxfa/parser/cxfa_arcdata.h b/xfa/fxfa/parser/cxfa_arcdata.h index 60c32bad4e..9c1272e9c6 100644 --- a/xfa/fxfa/parser/cxfa_arcdata.h +++ b/xfa/fxfa/parser/cxfa_arcdata.h @@ -7,13 +7,13 @@ #ifndef XFA_FXFA_PARSER_CXFA_ARCDATA_H_ #define XFA_FXFA_PARSER_CXFA_ARCDATA_H_ -#include "xfa/fxfa/parser/cxfa_box.h" +#include "xfa/fxfa/parser/cxfa_boxdata.h" class CXFA_Node; -class CXFA_ArcData : public CXFA_Box { +class CXFA_ArcData : public CXFA_BoxData { public: - explicit CXFA_ArcData(CXFA_Node* pNode) : CXFA_Box(pNode) {} + explicit CXFA_ArcData(CXFA_Node* pNode) : CXFA_BoxData(pNode) {} }; #endif // XFA_FXFA_PARSER_CXFA_ARCDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_borderdata.h b/xfa/fxfa/parser/cxfa_borderdata.h index 20e66562e5..aba7d3dd1a 100644 --- a/xfa/fxfa/parser/cxfa_borderdata.h +++ b/xfa/fxfa/parser/cxfa_borderdata.h @@ -7,13 +7,13 @@ #ifndef XFA_FXFA_PARSER_CXFA_BORDERDATA_H_ #define XFA_FXFA_PARSER_CXFA_BORDERDATA_H_ -#include "xfa/fxfa/parser/cxfa_box.h" +#include "xfa/fxfa/parser/cxfa_boxdata.h" class CXFA_Node; -class CXFA_BorderData : public CXFA_Box { +class CXFA_BorderData : public CXFA_BoxData { public: - explicit CXFA_BorderData(CXFA_Node* pNode) : CXFA_Box(pNode) {} + explicit CXFA_BorderData(CXFA_Node* pNode) : CXFA_BoxData(pNode) {} }; #endif // XFA_FXFA_PARSER_CXFA_BORDERDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp deleted file mode 100644 index c0ca723746..0000000000 --- a/xfa/fxfa/parser/cxfa_box.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/cxfa_box.h" - -#include "xfa/fxfa/parser/cxfa_corner.h" -#include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/cxfa_node.h" - -namespace { - -void GetStrokesInternal(CXFA_Node* pNode, - std::vector* strokes, - bool bNull) { - strokes->clear(); - if (!pNode) - return; - - strokes->resize(8); - int32_t i, j; - for (i = 0, j = 0; i < 4; i++) { - CXFA_Corner corner = CXFA_Corner( - pNode->JSNode()->GetProperty(i, XFA_Element::Corner, i == 0)); - if (corner || i == 0) { - (*strokes)[j] = corner; - } else if (!bNull) { - if (i == 1 || i == 2) - (*strokes)[j] = (*strokes)[0]; - else - (*strokes)[j] = (*strokes)[2]; - } - j++; - CXFA_Edge edge = - CXFA_Edge(pNode->JSNode()->GetProperty(i, XFA_Element::Edge, i == 0)); - if (edge || i == 0) { - (*strokes)[j] = edge; - } else if (!bNull) { - if (i == 1 || i == 2) - (*strokes)[j] = (*strokes)[1]; - else - (*strokes)[j] = (*strokes)[3]; - } - j++; - } -} - -static int32_t Style3D(const std::vector& strokes, - CXFA_Stroke& stroke) { - if (strokes.empty()) - return 0; - - stroke = strokes[0]; - for (size_t i = 1; i < strokes.size(); i++) { - CXFA_Stroke find = strokes[i]; - if (!find) - continue; - - if (!stroke) - stroke = find; - else if (stroke.GetStrokeType() != find.GetStrokeType()) - stroke = find; - break; - } - int32_t iType = stroke.GetStrokeType(); - if (iType == XFA_ATTRIBUTEENUM_Lowered || iType == XFA_ATTRIBUTEENUM_Raised || - iType == XFA_ATTRIBUTEENUM_Etched || - iType == XFA_ATTRIBUTEENUM_Embossed) { - return iType; - } - return 0; -} - -} // namespace - -int32_t CXFA_Box::GetHand() const { - if (!m_pNode) - return XFA_ATTRIBUTEENUM_Even; - return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_Hand); -} - -int32_t CXFA_Box::GetPresence() const { - if (!m_pNode) - return XFA_ATTRIBUTEENUM_Hidden; - return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_Presence); -} - -int32_t CXFA_Box::CountEdges() const { - if (!m_pNode) - return 0; - return m_pNode->CountChildren(XFA_Element::Edge, false); -} - -CXFA_Edge CXFA_Box::GetEdge(int32_t nIndex) const { - return CXFA_Edge(m_pNode ? m_pNode->JSNode()->GetProperty( - nIndex, XFA_Element::Edge, nIndex == 0) - : nullptr); -} - -void CXFA_Box::GetStrokes(std::vector* strokes) const { - GetStrokesInternal(m_pNode, strokes, false); -} - -bool CXFA_Box::IsCircular() const { - if (!m_pNode) - return false; - return m_pNode->JSNode()->GetBoolean(XFA_ATTRIBUTE_Circular); -} - -bool CXFA_Box::GetStartAngle(float& fStartAngle) const { - fStartAngle = 0; - if (!m_pNode) - return false; - - CXFA_Measurement ms; - bool bRet = - m_pNode->JSNode()->TryMeasure(XFA_ATTRIBUTE_StartAngle, ms, false); - if (bRet) - fStartAngle = ms.GetValue(); - - return bRet; -} - -bool CXFA_Box::GetSweepAngle(float& fSweepAngle) const { - fSweepAngle = 360; - if (!m_pNode) - return false; - - CXFA_Measurement ms; - bool bRet = - m_pNode->JSNode()->TryMeasure(XFA_ATTRIBUTE_SweepAngle, ms, false); - if (bRet) - fSweepAngle = ms.GetValue(); - - return bRet; -} - -CXFA_Fill CXFA_Box::GetFill(bool bModified) const { - if (!m_pNode) - return CXFA_Fill(nullptr); - - CXFA_Node* pFillNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Fill, bModified); - return CXFA_Fill(pFillNode); -} - -CXFA_Margin CXFA_Box::GetMargin() const { - return CXFA_Margin(m_pNode ? m_pNode->GetChild(0, XFA_Element::Margin, false) - : nullptr); -} - -int32_t CXFA_Box::Get3DStyle(bool& bVisible, float& fThickness) const { - if (IsArc()) - return 0; - - std::vector strokes; - GetStrokesInternal(m_pNode, &strokes, true); - CXFA_Stroke stroke(nullptr); - int32_t iType = Style3D(strokes, stroke); - if (iType) { - bVisible = stroke.IsVisible(); - fThickness = stroke.GetThickness(); - } - return iType; -} diff --git a/xfa/fxfa/parser/cxfa_box.h b/xfa/fxfa/parser/cxfa_box.h deleted file mode 100644 index d2b79fae56..0000000000 --- a/xfa/fxfa/parser/cxfa_box.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_CXFA_BOX_H_ -#define XFA_FXFA_PARSER_CXFA_BOX_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fxfa/parser/cxfa_data.h" -#include "xfa/fxfa/parser/cxfa_edge.h" -#include "xfa/fxfa/parser/cxfa_fill.h" -#include "xfa/fxfa/parser/cxfa_margin.h" - -class CXFA_Node; - -class CXFA_Box : public CXFA_Data { - public: - explicit CXFA_Box(CXFA_Node* pNode) : CXFA_Data(pNode) {} - - bool IsArc() const { return GetElementType() == XFA_Element::Arc; } - bool IsBorder() const { return GetElementType() == XFA_Element::Border; } - bool IsRectangle() const { - return GetElementType() == XFA_Element::Rectangle; - } - int32_t GetHand() const; - int32_t GetPresence() const; - int32_t CountEdges() const; - CXFA_Edge GetEdge(int32_t nIndex = 0) const; - void GetStrokes(std::vector* strokes) const; - bool IsCircular() const; - bool GetStartAngle(float& fStartAngle) const; - float GetStartAngle() const { - float fStartAngle; - GetStartAngle(fStartAngle); - return fStartAngle; - } - - bool GetSweepAngle(float& fSweepAngle) const; - float GetSweepAngle() const { - float fSweepAngle; - GetSweepAngle(fSweepAngle); - return fSweepAngle; - } - - CXFA_Fill GetFill(bool bModified = false) const; - CXFA_Margin GetMargin() const; - int32_t Get3DStyle(bool& bVisible, float& fThickness) const; -}; - -#endif // XFA_FXFA_PARSER_CXFA_BOX_H_ diff --git a/xfa/fxfa/parser/cxfa_boxdata.cpp b/xfa/fxfa/parser/cxfa_boxdata.cpp new file mode 100644 index 0000000000..c7a58a1c27 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_boxdata.cpp @@ -0,0 +1,167 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_boxdata.h" + +#include "xfa/fxfa/parser/cxfa_corner.h" +#include "xfa/fxfa/parser/cxfa_measurement.h" +#include "xfa/fxfa/parser/cxfa_node.h" + +namespace { + +void GetStrokesInternal(CXFA_Node* pNode, + std::vector* strokes, + bool bNull) { + strokes->clear(); + if (!pNode) + return; + + strokes->resize(8); + int32_t i, j; + for (i = 0, j = 0; i < 4; i++) { + CXFA_Corner corner = CXFA_Corner( + pNode->JSNode()->GetProperty(i, XFA_Element::Corner, i == 0)); + if (corner || i == 0) { + (*strokes)[j] = corner; + } else if (!bNull) { + if (i == 1 || i == 2) + (*strokes)[j] = (*strokes)[0]; + else + (*strokes)[j] = (*strokes)[2]; + } + j++; + CXFA_Edge edge = + CXFA_Edge(pNode->JSNode()->GetProperty(i, XFA_Element::Edge, i == 0)); + if (edge || i == 0) { + (*strokes)[j] = edge; + } else if (!bNull) { + if (i == 1 || i == 2) + (*strokes)[j] = (*strokes)[1]; + else + (*strokes)[j] = (*strokes)[3]; + } + j++; + } +} + +static int32_t Style3D(const std::vector& strokes, + CXFA_Stroke& stroke) { + if (strokes.empty()) + return 0; + + stroke = strokes[0]; + for (size_t i = 1; i < strokes.size(); i++) { + CXFA_Stroke find = strokes[i]; + if (!find) + continue; + + if (!stroke) + stroke = find; + else if (stroke.GetStrokeType() != find.GetStrokeType()) + stroke = find; + break; + } + int32_t iType = stroke.GetStrokeType(); + if (iType == XFA_ATTRIBUTEENUM_Lowered || iType == XFA_ATTRIBUTEENUM_Raised || + iType == XFA_ATTRIBUTEENUM_Etched || + iType == XFA_ATTRIBUTEENUM_Embossed) { + return iType; + } + return 0; +} + +} // namespace + +int32_t CXFA_BoxData::GetHand() const { + if (!m_pNode) + return XFA_ATTRIBUTEENUM_Even; + return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_Hand); +} + +int32_t CXFA_BoxData::GetPresence() const { + if (!m_pNode) + return XFA_ATTRIBUTEENUM_Hidden; + return m_pNode->JSNode()->GetEnum(XFA_ATTRIBUTE_Presence); +} + +int32_t CXFA_BoxData::CountEdges() const { + if (!m_pNode) + return 0; + return m_pNode->CountChildren(XFA_Element::Edge, false); +} + +CXFA_Edge CXFA_BoxData::GetEdge(int32_t nIndex) const { + return CXFA_Edge(m_pNode ? m_pNode->JSNode()->GetProperty( + nIndex, XFA_Element::Edge, nIndex == 0) + : nullptr); +} + +void CXFA_BoxData::GetStrokes(std::vector* strokes) const { + GetStrokesInternal(m_pNode, strokes, false); +} + +bool CXFA_BoxData::IsCircular() const { + if (!m_pNode) + return false; + return m_pNode->JSNode()->GetBoolean(XFA_ATTRIBUTE_Circular); +} + +bool CXFA_BoxData::GetStartAngle(float& fStartAngle) const { + fStartAngle = 0; + if (!m_pNode) + return false; + + CXFA_Measurement ms; + bool bRet = + m_pNode->JSNode()->TryMeasure(XFA_ATTRIBUTE_StartAngle, ms, false); + if (bRet) + fStartAngle = ms.GetValue(); + + return bRet; +} + +bool CXFA_BoxData::GetSweepAngle(float& fSweepAngle) const { + fSweepAngle = 360; + if (!m_pNode) + return false; + + CXFA_Measurement ms; + bool bRet = + m_pNode->JSNode()->TryMeasure(XFA_ATTRIBUTE_SweepAngle, ms, false); + if (bRet) + fSweepAngle = ms.GetValue(); + + return bRet; +} + +CXFA_Fill CXFA_BoxData::GetFill(bool bModified) const { + if (!m_pNode) + return CXFA_Fill(nullptr); + + CXFA_Node* pFillNode = + m_pNode->JSNode()->GetProperty(0, XFA_Element::Fill, bModified); + return CXFA_Fill(pFillNode); +} + +CXFA_Margin CXFA_BoxData::GetMargin() const { + return CXFA_Margin(m_pNode ? m_pNode->GetChild(0, XFA_Element::Margin, false) + : nullptr); +} + +int32_t CXFA_BoxData::Get3DStyle(bool& bVisible, float& fThickness) const { + if (IsArc()) + return 0; + + std::vector strokes; + GetStrokesInternal(m_pNode, &strokes, true); + CXFA_Stroke stroke(nullptr); + int32_t iType = Style3D(strokes, stroke); + if (iType) { + bVisible = stroke.IsVisible(); + fThickness = stroke.GetThickness(); + } + return iType; +} diff --git a/xfa/fxfa/parser/cxfa_boxdata.h b/xfa/fxfa/parser/cxfa_boxdata.h new file mode 100644 index 0000000000..b664479a28 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_boxdata.h @@ -0,0 +1,54 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_BOXDATA_H_ +#define XFA_FXFA_PARSER_CXFA_BOXDATA_H_ + +#include + +#include "core/fxcrt/fx_system.h" +#include "xfa/fxfa/parser/cxfa_data.h" +#include "xfa/fxfa/parser/cxfa_edge.h" +#include "xfa/fxfa/parser/cxfa_fill.h" +#include "xfa/fxfa/parser/cxfa_margin.h" + +class CXFA_Node; + +class CXFA_BoxData : public CXFA_Data { + public: + explicit CXFA_BoxData(CXFA_Node* pNode) : CXFA_Data(pNode) {} + + bool IsArc() const { return GetElementType() == XFA_Element::Arc; } + bool IsBorder() const { return GetElementType() == XFA_Element::Border; } + bool IsRectangle() const { + return GetElementType() == XFA_Element::Rectangle; + } + int32_t GetHand() const; + int32_t GetPresence() const; + int32_t CountEdges() const; + CXFA_Edge GetEdge(int32_t nIndex = 0) const; + void GetStrokes(std::vector* strokes) const; + bool IsCircular() const; + bool GetStartAngle(float& fStartAngle) const; + float GetStartAngle() const { + float fStartAngle; + GetStartAngle(fStartAngle); + return fStartAngle; + } + + bool GetSweepAngle(float& fSweepAngle) const; + float GetSweepAngle() const { + float fSweepAngle; + GetSweepAngle(fSweepAngle); + return fSweepAngle; + } + + CXFA_Fill GetFill(bool bModified = false) const; + CXFA_Margin GetMargin() const; + int32_t Get3DStyle(bool& bVisible, float& fThickness) const; +}; + +#endif // XFA_FXFA_PARSER_CXFA_BOXDATA_H_ diff --git a/xfa/fxfa/parser/cxfa_rectangle.h b/xfa/fxfa/parser/cxfa_rectangle.h index 8d18ace0de..07a4d7de70 100644 --- a/xfa/fxfa/parser/cxfa_rectangle.h +++ b/xfa/fxfa/parser/cxfa_rectangle.h @@ -7,13 +7,13 @@ #ifndef XFA_FXFA_PARSER_CXFA_RECTANGLE_H_ #define XFA_FXFA_PARSER_CXFA_RECTANGLE_H_ -#include "xfa/fxfa/parser/cxfa_box.h" +#include "xfa/fxfa/parser/cxfa_boxdata.h" class CXFA_Node; -class CXFA_Rectangle : public CXFA_Box { +class CXFA_Rectangle : public CXFA_BoxData { public: - explicit CXFA_Rectangle(CXFA_Node* pNode) : CXFA_Box(pNode) {} + explicit CXFA_Rectangle(CXFA_Node* pNode) : CXFA_BoxData(pNode) {} }; #endif // XFA_FXFA_PARSER_CXFA_RECTANGLE_H_ -- cgit v1.2.3