<commit_before>/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

using NPOI.SS.UserModel;
using System;
using Spreadsheet=NPOI.OpenXmlFormats.Spreadsheet;
using NPOI.OpenXmlFormats.Spreadsheet;
using NPOI.OpenXmlFormats.Dml;
using Dml = NPOI.OpenXmlFormats.Dml;
using NPOI.XSSF.Model;
using NPOI.Util;

namespace NPOI.XSSF.UserModel
{

    /**
     * Represents a font used in a workbook.
     *
     * @author <NAME>
     */
    public class XSSFFont : IFont
    {

        /**
         * By default, Microsoft Office Excel 2007 uses the Calibry font in font size 11
         */
        public const String DEFAULT_FONT_NAME = "Calibri";
        /**
         * By default, Microsoft Office Excel 2007 uses the Calibry font in font size 11
         */
        public const short DEFAULT_FONT_SIZE = 11;
        /**
         * Default font color is black
         * @see NPOI.SS.usermodel.IndexedColors#BLACK
         */
        public static short DEFAULT_FONT_COLOR = IndexedColors.Black.Index;

        private ThemesTable _themes;
        private CT_Font _ctFont;
        private short _index;

        /**
         * Create a new XSSFFont
         *
         * @param font the underlying CT_Font bean
         */
        public XSSFFont(CT_Font font)
        {
            _ctFont = font;
            _index = 0;
        }

        public XSSFFont(CT_Font font, int index)
        {
            _ctFont = font;
            _index = (short)index;
        }

        /**
         * Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
         */
        public XSSFFont()
        {
            this._ctFont = new CT_Font();
            FontName = DEFAULT_FONT_NAME;
            FontHeightInPoints =DEFAULT_FONT_SIZE;
        }

        /**
         * get the underlying CT_Font font
         */

        public CT_Font GetCTFont()
        {
            return _ctFont;
        }

        /**
         * get a bool value for the boldness to use.
         *
         * @return bool - bold
         */
        public bool IsBold
        {
            get
            {
                CT_BooleanProperty bold = _ctFont.SizeOfBArray() == 0 ? null : _ctFont.GetBArray(0);
                return (bold != null && bold.val);
            }
            set 
            {
                if (value)
                {
                    CT_BooleanProperty ctBold = _ctFont.SizeOfBArray() == 0 ? _ctFont.AddNewB() : _ctFont.GetBArray(0);
                    ctBold.val = value;
                }
                else
                {
                    _ctFont.SetBArray(null);
                }
            }
        }

        /**
         * get character-set to use.
         *
         * @return int - character-set (0-255)
         * @see NPOI.SS.usermodel.FontCharset
         */
        public short Charset
        {
            get
            {
                CT_IntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.GetCharsetArray(0);
                int val = charset == null ? FontCharset.ANSI.Value : FontCharset.ValueOf(charset.val).Value;
                return (short)val;
            }
            set
            {

            }
        }


        /**
         * get the indexed color value for the font
         * References a color defined in IndexedColors.
         *
         * @return short - indexed color to use
         * @see IndexedColors
         */
        public short Color
        {
            get
            {
                Spreadsheet.CT_Color color = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.GetColorArray(0);
                if (color == null) return IndexedColors.Black.Index;

                if (!color.indexedSpecified) return IndexedColors.Black.Index;
                long index = color.indexed;
                if (index == XSSFFont.DEFAULT_FONT_COLOR)
                {
                    return IndexedColors.Black.Index;
                }
                else if (index == IndexedColors.Red.Index)
                {
                    return IndexedColors.Red.Index;
                }
                else<commit_msg>Fix test case TestXSSFFont.TestRgbColor<commit_after>/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

using NPOI.SS.UserModel;
using System;
using Spreadsheet=NPOI.OpenXmlFormats.Spreadsheet;
using NPOI.OpenXmlFormats.Spreadsheet;
using NPOI.OpenXmlFormats.Dml;
using Dml = NPOI.OpenXmlFormats.Dml;
using NPOI.XSSF.Model;
using NPOI.Util;

namespace NPOI.XSSF.UserModel
{

    /**
     * Represents a font used in a workbook.
     *
     * @author <NAME>
     */
    public class XSSFFont : IFont
    {

        /**
         * By default, Microsoft Office Excel 2007 uses the Calibry font in font size 11
         */
        public const String DEFAULT_FONT_NAME = "Calibri";
        /**
         * By default, Microsoft Office Excel 2007 uses the Calibry font in font size 11
         */
        public const short DEFAULT_FONT_SIZE = 11;
        /**
         * Default font color is black
         * @see NPOI.SS.usermodel.IndexedColors#BLACK
         */
        public static short DEFAULT_FONT_COLOR = IndexedColors.Black.Index;

        private ThemesTable _themes;
        private CT_Font _ctFont;
        private short _index;

        /**
         * Create a new XSSFFont
         *
         * @param font the underlying CT_Font bean
         */
        public XSSFFont(CT_Font font)
        {
            _ctFont = font;
            _index = 0;
        }

        public XSSFFont(CT_Font font, int index)
        {
            _ctFont = font;
            _index = (short)index;
        }

        /**
         * Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
         */
        public XSSFFont()
        {
            this._ctFont = new CT_Font();
            FontName = DEFAULT_FONT_NAME;
            FontHeightInPoints =DEFAULT_FONT_SIZE;
        }

        /**
         * get the underlying CT_Font font
         */

        public CT_Font GetCTFont()
        {
            return _ctFont;
        }

        /**
         * get a bool value for the boldness to use.
         *
         * @return bool - bold
         */
        public bool IsBold
        {
            get
            {
                CT_BooleanProperty bold = _ctFont.SizeOfBArray() == 0 ? null : _ctFont.GetBArray(0);
                return (bold != null && bold.val);
            }
            set 
            {
                if (value)
                {
                    CT_BooleanProperty ctBold = _ctFont.SizeOfBArray() == 0 ? _ctFont.AddNewB() : _ctFont.GetBArray(0);
                    ctBold.val = value;
                }
                else
                {
                    _ctFont.SetBArray(null);
                }
            }
        }

        /**
         * get character-set to use.
         *
         * @return int - character-set (0-255)
         * @see NPOI.SS.usermodel.FontCharset
         */
        public short Charset
        {
            get
            {
                CT_IntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.GetCharsetArray(0);
                int val = charset == null ? FontCharset.ANSI.Value : FontCharset.ValueOf(charset.val).Value;
                return (short)val;
            }
            set
            {

            }
        }


        /**
         * get the indexed color value for the font
         * References a color defined in IndexedColors.
         *
         * @return short - indexed color to use
         * @see IndexedColors
         */
        public short Color
        {
            get
            {
                Spreadsheet.CT_Color color = _ctFont.sizeOfColorArray() == 0 ? null : _ctFont.GetColorArray(0);
                if (color == null) return IndexedColors.Black.Index;

                //if (!color.indexedSpecified) return IndexedColors.Black.Index;
                long index = color.indexed;
                if (index == XSSFFont.DEFAULT_FONT_COLOR)
                {
                    return IndexedColors.Black.Index;
                }
                else if (index == IndexedColors.Red.Index)
                {
                    return IndexedColors.Red.Index;
                }
                else
{'fraction_non_alphanumeric': 0.09904439577941469, 'fraction_numerical': 0.006171610591280112, 'mean_word_length': 1.5493529561025121, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7036715', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2625, 'n_words': 776}