File indexing completed on 2025-01-05 04:01:19

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 #include <array>
0009 #include "math/vector.hpp"
0010 #include "math/math.hpp"
0011 namespace glaxnimate::io::svg {
0012 
0013 /**
0014  * Compare:
0015  *  https://doc.qt.io/qt-5/qfont.html#Weight-enum
0016  *  https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#common_weight_name_mapping
0017  */
0018 struct WeightConverter
0019 {
0020     inline static constexpr const std::array<int, 9> qt = {
0021         00,
0022         12,
0023         25,
0024         50,
0025         57,
0026         63,
0027         75,
0028         81,
0029         87,
0030     };
0031     inline static constexpr const std::array<int, 9> css = {
0032         100,
0033         200,
0034         300,
0035         400,
0036         500,
0037         600,
0038         700,
0039         900,
0040         950,
0041     };
0042 
0043     static int convert(int old, const std::array<int, 9>& from, const std::array<int, 9>& to)
0044     {
0045         int index;
0046         for ( index = 0; index < 9; index++ )
0047         {
0048             if ( from[index] == old )
0049                 return to[index];
0050             else if ( from[index] > old )
0051                 break;
0052         }
0053 
0054         if ( index == 9 )
0055             index--;
0056 
0057         qreal t = (old - from[index]) / qreal(from[index+1] - from[index]);
0058         return qRound(math::lerp<qreal>(to[index], to[index+1], t));
0059     }
0060 
0061 };
0062 
0063 } // namespace glaxnimate::io::svg