cxfa_data.cpp revision 4d3acf4ec42bf6e838f9060103aff98fbf170794
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_data.h" 8 9#include "core/fxcrt/fx_ext.h" 10#include "xfa/fxfa/parser/cxfa_measurement.h" 11#include "xfa/fxfa/parser/xfa_object.h" 12 13// Static. 14FX_ARGB CXFA_Data::ToColor(const CFX_WideStringC& wsValue) { 15 uint8_t r = 0, g = 0, b = 0; 16 if (wsValue.GetLength() == 0) 17 return 0xff000000; 18 19 int cc = 0; 20 const FX_WCHAR* str = wsValue.c_str(); 21 int len = wsValue.GetLength(); 22 while (FXSYS_iswspace(str[cc]) && cc < len) 23 cc++; 24 25 if (cc >= len) 26 return 0xff000000; 27 28 while (cc < len) { 29 if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc])) 30 break; 31 32 r = r * 10 + str[cc] - '0'; 33 cc++; 34 } 35 if (cc < len && str[cc] == ',') { 36 cc++; 37 while (FXSYS_iswspace(str[cc]) && cc < len) 38 cc++; 39 40 while (cc < len) { 41 if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc])) 42 break; 43 44 g = g * 10 + str[cc] - '0'; 45 cc++; 46 } 47 if (cc < len && str[cc] == ',') { 48 cc++; 49 while (FXSYS_iswspace(str[cc]) && cc < len) 50 cc++; 51 52 while (cc < len) { 53 if (str[cc] == ',' || !FXSYS_isDecimalDigit(str[cc])) 54 break; 55 56 b = b * 10 + str[cc] - '0'; 57 cc++; 58 } 59 } 60 } 61 return (0xff << 24) | (r << 16) | (g << 8) | b; 62} 63 64XFA_Element CXFA_Data::GetElementType() const { 65 return m_pNode ? m_pNode->GetElementType() : XFA_Element::Unknown; 66} 67 68bool CXFA_Data::TryMeasure(XFA_ATTRIBUTE eAttr, 69 FX_FLOAT& fValue, 70 bool bUseDefault) const { 71 CXFA_Measurement ms; 72 if (m_pNode->TryMeasure(eAttr, ms, bUseDefault)) { 73 fValue = ms.ToUnit(XFA_UNIT_Pt); 74 return true; 75 } 76 return false; 77} 78 79bool CXFA_Data::SetMeasure(XFA_ATTRIBUTE eAttr, FX_FLOAT fValue) { 80 CXFA_Measurement ms(fValue, XFA_UNIT_Pt); 81 return m_pNode->SetMeasure(eAttr, ms); 82} 83