• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "xfa/fde/css/cfde_cssnumbervalue.h"
8 
CFDE_CSSNumberValue(FDE_CSSNumberType type,FX_FLOAT value)9 CFDE_CSSNumberValue::CFDE_CSSNumberValue(FDE_CSSNumberType type, FX_FLOAT value)
10     : CFDE_CSSValue(FDE_CSSPrimitiveType::Number), type_(type), value_(value) {
11   if (type_ == FDE_CSSNumberType::Number && FXSYS_fabs(value_) < 0.001f)
12     value_ = 0.0f;
13 }
14 
~CFDE_CSSNumberValue()15 CFDE_CSSNumberValue::~CFDE_CSSNumberValue() {}
16 
Apply(FX_FLOAT percentBase) const17 FX_FLOAT CFDE_CSSNumberValue::Apply(FX_FLOAT percentBase) const {
18   switch (type_) {
19     case FDE_CSSNumberType::Pixels:
20     case FDE_CSSNumberType::Number:
21       return value_ * 72 / 96;
22     case FDE_CSSNumberType::EMS:
23     case FDE_CSSNumberType::EXS:
24       return value_ * percentBase;
25     case FDE_CSSNumberType::Percent:
26       return value_ * percentBase / 100.0f;
27     case FDE_CSSNumberType::CentiMeters:
28       return value_ * 28.3464f;
29     case FDE_CSSNumberType::MilliMeters:
30       return value_ * 2.8346f;
31     case FDE_CSSNumberType::Inches:
32       return value_ * 72.0f;
33     case FDE_CSSNumberType::Picas:
34       return value_ / 12.0f;
35     case FDE_CSSNumberType::Points:
36       return value_;
37   }
38   return value_;
39 }
40