• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "xfa/fxfa/parser/cxfa_fill.h"
8 
9 #include "xfa/fxfa/parser/xfa_object.h"
10 
CXFA_Fill(CXFA_Node * pNode)11 CXFA_Fill::CXFA_Fill(CXFA_Node* pNode) : CXFA_Data(pNode) {}
12 
~CXFA_Fill()13 CXFA_Fill::~CXFA_Fill() {}
14 
GetPresence()15 int32_t CXFA_Fill::GetPresence() {
16   return m_pNode->GetEnum(XFA_ATTRIBUTE_Presence);
17 }
18 
SetColor(FX_ARGB color)19 void CXFA_Fill::SetColor(FX_ARGB color) {
20   CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Color);
21   CFX_WideString wsColor;
22   int a, r, g, b;
23   ArgbDecode(color, a, r, g, b);
24   wsColor.Format(L"%d,%d,%d", r, g, b);
25   pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor);
26 }
27 
GetColor(bool bText)28 FX_ARGB CXFA_Fill::GetColor(bool bText) {
29   if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Color)) {
30     CFX_WideStringC wsColor;
31     if (pNode->TryCData(XFA_ATTRIBUTE_Value, wsColor, false))
32       return CXFA_Data::ToColor(wsColor);
33   }
34   if (bText)
35     return 0xFF000000;
36   return 0xFFFFFFFF;
37 }
38 
GetFillType()39 XFA_Element CXFA_Fill::GetFillType() {
40   CXFA_Node* pChild = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild);
41   while (pChild) {
42     XFA_Element eType = pChild->GetElementType();
43     if (eType != XFA_Element::Color && eType != XFA_Element::Extras)
44       return eType;
45 
46     pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
47   }
48   return XFA_Element::Solid;
49 }
50 
GetPattern(FX_ARGB & foreColor)51 int32_t CXFA_Fill::GetPattern(FX_ARGB& foreColor) {
52   CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Pattern);
53   if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color)) {
54     CFX_WideStringC wsColor;
55     pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, false);
56     foreColor = CXFA_Data::ToColor(wsColor);
57   } else {
58     foreColor = 0xFF000000;
59   }
60   return pNode->GetEnum(XFA_ATTRIBUTE_Type);
61 }
62 
GetStipple(FX_ARGB & stippleColor)63 int32_t CXFA_Fill::GetStipple(FX_ARGB& stippleColor) {
64   CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Stipple);
65   int32_t eAttr = 50;
66   pNode->TryInteger(XFA_ATTRIBUTE_Rate, eAttr);
67   if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color)) {
68     CFX_WideStringC wsColor;
69     pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, false);
70     stippleColor = CXFA_Data::ToColor(wsColor);
71   } else {
72     stippleColor = 0xFF000000;
73   }
74   return eAttr;
75 }
76 
GetLinear(FX_ARGB & endColor)77 int32_t CXFA_Fill::GetLinear(FX_ARGB& endColor) {
78   CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Linear);
79   XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_ToRight;
80   pNode->TryEnum(XFA_ATTRIBUTE_Type, eAttr);
81   if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color)) {
82     CFX_WideStringC wsColor;
83     pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, false);
84     endColor = CXFA_Data::ToColor(wsColor);
85   } else {
86     endColor = 0xFF000000;
87   }
88   return eAttr;
89 }
90 
GetRadial(FX_ARGB & endColor)91 int32_t CXFA_Fill::GetRadial(FX_ARGB& endColor) {
92   CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Radial);
93   XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_ToEdge;
94   pNode->TryEnum(XFA_ATTRIBUTE_Type, eAttr);
95   if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color)) {
96     CFX_WideStringC wsColor;
97     pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, false);
98     endColor = CXFA_Data::ToColor(wsColor);
99   } else {
100     endColor = 0xFF000000;
101   }
102   return eAttr;
103 }
104