Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfx_cssnumbervalue.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
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
9#include <math.h>
10
11CFX_CSSNumberValue::CFX_CSSNumberValue(Unit unit, float value)
12 : CFX_CSSValue(PrimitiveType::kNumber), unit_(unit), value_(value) {
13 if (unit_ == Unit::kNumber && fabs(value_) < 0.001f)
14 value_ = 0.0f;
15}
16
17CFX_CSSNumberValue::~CFX_CSSNumberValue() = default;
18
19float CFX_CSSNumberValue::Apply(float percentBase) const {
20 switch (unit_) {
21 case Unit::kPixels:
22 case Unit::kNumber:
23 return value_ * 72 / 96;
24 case Unit::kEMS:
25 case Unit::kEXS:
26 return value_ * percentBase;
27 case Unit::kPercent:
28 return value_ * percentBase / 100.0f;
30 return value_ * 28.3464f;
32 return value_ * 2.8346f;
33 case Unit::kInches:
34 return value_ * 72.0f;
35 case Unit::kPicas:
36 return value_ / 12.0f;
37 case Unit::kPoints:
38 return value_;
39 }
40 return value_;
41}
CFX_CSSNumberValue(Unit unit, float value)
float Apply(float percentBase) const
~CFX_CSSNumberValue() override
CFX_CSSValue(PrimitiveType type)