OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium 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 #include "core/animation/FontWeightConversion.h" |
| 6 |
| 7 #include "platform/wtf/MathExtras.h" |
| 8 #include "platform/wtf/StdLibExtras.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 double fontWeightToDouble(FontWeight fontWeight) { |
| 13 switch (fontWeight) { |
| 14 case FontWeight100: |
| 15 return 100; |
| 16 case FontWeight200: |
| 17 return 200; |
| 18 case FontWeight300: |
| 19 return 300; |
| 20 case FontWeight400: |
| 21 return 400; |
| 22 case FontWeight500: |
| 23 return 500; |
| 24 case FontWeight600: |
| 25 return 600; |
| 26 case FontWeight700: |
| 27 return 700; |
| 28 case FontWeight800: |
| 29 return 800; |
| 30 case FontWeight900: |
| 31 return 900; |
| 32 default: |
| 33 NOTREACHED(); |
| 34 return 400; |
| 35 } |
| 36 } |
| 37 |
| 38 FontWeight doubleToFontWeight(double value) { |
| 39 static const FontWeight fontWeights[] = { |
| 40 FontWeight100, FontWeight200, FontWeight300, FontWeight400, FontWeight500, |
| 41 FontWeight600, FontWeight700, FontWeight800, FontWeight900, |
| 42 }; |
| 43 |
| 44 int index = round(value / 100 - 1); |
| 45 int clampedIndex = clampTo<int>(index, 0, WTF_ARRAY_LENGTH(fontWeights) - 1); |
| 46 return fontWeights[clampedIndex]; |
| 47 } |
| 48 |
| 49 } // namespace blink |
OLD | NEW |