1 // Copyright 2017 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 "core/fxcrt/css/cfx_cssnumbervalue.h" 8 CFX_CSSNumberValue(CFX_CSSNumberType type,float value)9CFX_CSSNumberValue::CFX_CSSNumberValue(CFX_CSSNumberType type, float value) 10 : CFX_CSSValue(CFX_CSSPrimitiveType::Number), type_(type), value_(value) { 11 if (type_ == CFX_CSSNumberType::Number && fabs(value_) < 0.001f) 12 value_ = 0.0f; 13 } 14 ~CFX_CSSNumberValue()15CFX_CSSNumberValue::~CFX_CSSNumberValue() {} 16 Apply(float percentBase) const17float CFX_CSSNumberValue::Apply(float percentBase) const { 18 switch (type_) { 19 case CFX_CSSNumberType::Pixels: 20 case CFX_CSSNumberType::Number: 21 return value_ * 72 / 96; 22 case CFX_CSSNumberType::EMS: 23 case CFX_CSSNumberType::EXS: 24 return value_ * percentBase; 25 case CFX_CSSNumberType::Percent: 26 return value_ * percentBase / 100.0f; 27 case CFX_CSSNumberType::CentiMeters: 28 return value_ * 28.3464f; 29 case CFX_CSSNumberType::MilliMeters: 30 return value_ * 2.8346f; 31 case CFX_CSSNumberType::Inches: 32 return value_ * 72.0f; 33 case CFX_CSSNumberType::Picas: 34 return value_ / 12.0f; 35 case CFX_CSSNumberType::Points: 36 return value_; 37 } 38 return value_; 39 } 40