예제 #1
0
        /**
         *
         * org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to
         * org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter
         */
        private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr)
        {
            if (pr.sizeOfBArray() > 0)
            {
                rPr.b = (pr.GetBArray(0).val);
            }
            if (pr.sizeOfUArray() > 0)
            {
                ST_UnderlineValues u1 = pr.GetUArray(0).val;
                if (u1 == ST_UnderlineValues.single)
                {
                    rPr.u = (ST_TextUnderlineType.sng);
                }
                else if (u1 == ST_UnderlineValues.@double)
                {
                    rPr.u = (ST_TextUnderlineType.dbl);
                }
                else if (u1 == ST_UnderlineValues.none)
                {
                    rPr.u = (ST_TextUnderlineType.none);
                }
            }
            if (pr.sizeOfIArray() > 0)
            {
                rPr.i = (pr.GetIArray(0).val);
            }

            if (pr.sizeOfFamilyArray() > 0)
            {
                CT_TextFont rFont = rPr.AddNewLatin();
                rFont.typeface = (pr.GetRFontArray(0).val);
            }

            if (pr.sizeOfSzArray() > 0)
            {
                int sz = (int)(pr.GetSzArray(0).val * 100);
                rPr.sz = (sz);
            }

            if (pr.sizeOfColorArray() > 0)
            {
                CT_SolidColorFillProperties fill = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill();
                NPOI.OpenXmlFormats.Spreadsheet.CT_Color xlsColor = pr.GetColorArray(0);
                if (xlsColor.IsSetRgb())
                {
                    CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                    clr.val = (xlsColor.rgb);
                }
                else if (xlsColor.IsSetIndexed())
                {
                    HSSFColor indexed = HSSFColor.GetIndexHash()[(int)xlsColor.indexed] as HSSFColor;
                    if (indexed != null)
                    {
                        byte[]       rgb = indexed.RGB;
                        CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                        clr.val = (rgb);
                    }
                }
            }
        }
예제 #2
0
        private byte[] GetRGBOrARGB()
        {
            byte[] rgb = null;

            if (ctColor.indexedSpecified && ctColor.indexed > 0)
            {
                HSSFColor indexed = (HSSFColor)HSSFColor.GetIndexHash()[(int)ctColor.indexed];
                if (indexed != null)
                {
                    rgb    = new byte[3];
                    rgb[0] = (byte)indexed.GetTriplet()[0];
                    rgb[1] = (byte)indexed.GetTriplet()[1];
                    rgb[2] = (byte)indexed.GetTriplet()[2];
                    return(rgb);
                }
            }

            if (!ctColor.IsSetRgb())
            {
                // No colour is available, sorry
                return(null);
            }

            // Grab the colour
            rgb = ctColor.GetRgb();

            // Correct it as needed, and return
            return(rgb);
        }
        public static byte[] GetDefaultRGB(int index)
        {
            HSSFColor hssfColor = HSSFColor.GetIndexHash()[index];

            if (hssfColor == null)
            {
                return(null);
            }
            byte[] rgbShort = hssfColor.GetTriplet();
            return(rgbShort);
        }
예제 #4
0
        private void CompareToDefaults(ColorComparator c)
        {
            var         colors = HSSFColor.GetIndexHash();
            IEnumerator it     = colors.Keys.GetEnumerator();

            while (it.MoveNext())
            {
                int       index         = (int)it.Current;
                HSSFColor expectedColor = (HSSFColor)colors[index];
                HSSFColor paletteColor  = hssfPalette.GetColor((short)index);
                c.Compare(expectedColor, paletteColor);
            }
        }
예제 #5
0
 private byte[] GetRGBOrARGB()
 {
     if (this.ctColor.indexedSpecified && this.ctColor.indexed > 0U)
     {
         HSSFColor hssfColor = (HSSFColor)HSSFColor.GetIndexHash()[(object)(int)this.ctColor.indexed];
         if (hssfColor != null)
         {
             return new byte[3] {
                        (byte)hssfColor.GetTriplet()[0], (byte)hssfColor.GetTriplet()[1], (byte)hssfColor.GetTriplet()[2]
             }
         }
         ;
     }
     if (!this.ctColor.IsSetRgb())
     {
         return((byte[])null);
     }
     return(this.CorrectRGB(this.ctColor.GetRgb()));
 }
예제 #6
0
        public void TestDefaultPalette()
        {
            PaletteRecord palette = new PaletteRecord();

            //make sure all the HSSFColor constants match
            Dictionary <int, HSSFColor> colors = HSSFColor.GetIndexHash();

            foreach (KeyValuePair <int, HSSFColor> entry in colors)
            {
                int       index          = entry.Key;
                HSSFColor c              = entry.Value;
                byte[]    rgbTriplet     = c.GetTriplet();
                byte[]    paletteTriplet = palette.GetColor((short)index);
                String    msg            = "Expected HSSFColor constant to match PaletteRecord at index 0x"
                                           + NPOI.Util.StringUtil.ToHexString(c.Indexed);
                Assert.AreEqual(rgbTriplet[0], paletteTriplet[0] & 0xff, msg);
                Assert.AreEqual(rgbTriplet[1], paletteTriplet[1] & 0xff, msg);
                Assert.AreEqual(rgbTriplet[2], paletteTriplet[2] & 0xff, msg);
            }
        }
예제 #7
0
        public void TestDefaultPalette()
        {
            PaletteRecord palette = new PaletteRecord();

            //make sure all the HSSFColor constants match
            Hashtable   colors  = HSSFColor.GetIndexHash();
            IEnumerator indexes = colors.Keys.GetEnumerator();

            while (indexes.MoveNext())
            {
                int       index          = (int)indexes.Current;
                HSSFColor c              = (HSSFColor)colors[index];
                short[]   rgbTriplet     = c.GetTriplet();
                byte[]    paletteTriplet = palette.GetColor((short)index);
                String    msg            = "Expected HSSFColor constant to match PaletteRecord at index 0x"
                                           + NPOI.Util.StringUtil.ToHexString(c.GetIndex());
                Assert.AreEqual(rgbTriplet[0], paletteTriplet[0] & 0xff, msg);
                Assert.AreEqual(rgbTriplet[1], paletteTriplet[1] & 0xff, msg);
                Assert.AreEqual(rgbTriplet[2], paletteTriplet[2] & 0xff, msg);
            }
        }
예제 #8
0
        protected byte[] GetRGBOrARGB()
        {
            if (IsIndexed && Index > 0)
            {
                int       indexNum  = Index;
                var       hashIndex = HSSFColor.GetIndexHash();
                HSSFColor indexed   = null;
                if (hashIndex.ContainsKey(indexNum))
                {
                    indexed = hashIndex[indexNum];
                }
                if (indexed != null)
                {
                    byte[] rgb = new byte[3];
                    rgb[0] = (byte)indexed.GetTriplet()[0];
                    rgb[1] = (byte)indexed.GetTriplet()[1];
                    rgb[2] = (byte)indexed.GetTriplet()[2];
                    return(rgb);
                }
            }

            // Grab the colour
            return(StoredRBG);
        }
        static CellFormatPart()
        {
            NAMED_COLORS = new Dictionary <String, Color>(CASE_INSENSITIVE_ORDER);

            Hashtable colors = HSSFColor.GetIndexHash();

            foreach (object v in colors.Values)
            {
                HSSFColor hc   = (HSSFColor)v;
                Type      type = hc.GetType();
                String    name = type.Name;
                if (name.Equals(name.ToUpper()))
                {
                    short[] rgb = hc.GetTriplet();
                    Color   c   = Color.FromArgb(rgb[0], rgb[1], rgb[2]);
                    if (!NAMED_COLORS.ContainsKey(name))
                    {
                        NAMED_COLORS.Add(name, c);
                    }
                    if (name.IndexOf('_') > 0)
                    {
                        if (!NAMED_COLORS.ContainsKey(name.Replace('_', ' ')))
                        {
                            NAMED_COLORS.Add(name.Replace('_', ' '), c);
                        }
                    }
                    if (name.IndexOf("_PERCENT") > 0)
                    {
                        if (!NAMED_COLORS.ContainsKey(name.Replace("_PERCENT", "%").Replace('_', ' ')))
                        {
                            NAMED_COLORS.Add(name.Replace("_PERCENT", "%").Replace('_', ' '), c);
                        }
                    }
                }
            }
            // A condition specification
            String condition = "([<>=]=?|!=|<>)    # The operator\n" +
                               "  \\s*([0-9]+(?:\\.[0-9]*)?)\\s*  # The constant to test against\n";

            String color =
                "\\[(black|blue|cyan|green|magenta|red|white|yellow|color [0-9]+)\\]";

            // A number specification
            // Note: careful that in something like ##, that the trailing comma is not caught up in the integer part

            // A part of a specification
            String part = "\\\\.                 # Quoted single character\n" +
                          "|\"([^\\\\\"]|\\\\.)*\"         # Quoted string of characters (handles escaped quotes like \\\") \n" +
                          "|_.                             # Space as wide as a given character\n" +
                          "|\\*.                           # Repeating fill character\n" +
                          "|@                              # Text: cell text\n" +
                          "|([0?\\#](?:[0?\\#,]*))         # Number: digit + other digits and commas\n" +
                          "|e[-+]                          # Number: Scientific: Exponent\n" +
                          "|m{1,5}                         # Date: month or minute spec\n" +
                          "|d{1,4}                         # Date: day/date spec\n" +
                          "|y{2,4}                         # Date: year spec\n" +
                          "|h{1,2}                         # Date: hour spec\n" +
                          "|s{1,2}                         # Date: second spec\n" +
                          "|am?/pm?                        # Date: am/pm spec\n" +
                          "|\\[h{1,2}\\]                   # Elapsed time: hour spec\n" +
                          "|\\[m{1,2}\\]                   # Elapsed time: minute spec\n" +
                          "|\\[s{1,2}\\]                   # Elapsed time: second spec\n" +
                          "|[^;]                           # A character\n" + "";

            String format = "(?:" + color + ")?                  # Text color\n" +
                            "(?:\\[" + condition + "\\])?                # Condition\n" +
                            "((?:" + part + ")+)                        # Format spec\n";

            RegexOptions flags = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled;

            COLOR_PAT         = new Regex(color, flags);
            CONDITION_PAT     = new Regex(condition, flags);
            SPECIFICATION_PAT = new Regex(part, flags);
            FORMAT_PAT        = new Regex(format, flags);

            // Calculate the group numbers of important groups.  (They shift around
            // when the pattern is Changed; this way we figure out the numbers by
            // experimentation.)

            COLOR_GROUP = FindGroup(FORMAT_PAT, "[Blue]@", "Blue");
            CONDITION_OPERATOR_GROUP = FindGroup(FORMAT_PAT, "[>=1]@", ">=");
            CONDITION_VALUE_GROUP    = FindGroup(FORMAT_PAT, "[>=1]@", "1");
            SPECIFICATION_GROUP      = FindGroup(FORMAT_PAT, "[Blue][>1]\\a ?", "\\a ?");
        }
예제 #10
0
        /**
         * org.Openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to
         * org.Openxmlformats.schemas.Drawingml.x2006.main.CTFont adapter
         */
        private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr)
        {
            if (pr.SizeOfBArray() > 0)
            {
                rPr.b = (/*setter*/ pr.GetBArray(0).val);
            }
            if (pr.SizeOfUArray() > 0)
            {
                ST_UnderlineValues u1 = pr.GetUArray(0).val;
                if (u1 == ST_UnderlineValues.single)
                {
                    rPr.u = (/*setter*/ ST_TextUnderlineType.sng);
                }
                else if (u1 == ST_UnderlineValues.@double)
                {
                    rPr.u = (/*setter*/ ST_TextUnderlineType.dbl);
                }
                else if (u1 == ST_UnderlineValues.none)
                {
                    rPr.u = (/*setter*/ ST_TextUnderlineType.none);
                }
            }
            if (pr.SizeOfIArray() > 0)
            {
                rPr.i = (/*setter*/ pr.GetIArray(0).val);
            }

            if (pr.SizeOfRFontArray() > 0)
            {
                CT_TextFont rFont = rPr.IsSetLatin() ? rPr.latin : rPr.AddNewLatin();
                rFont.typeface = (/*setter*/ pr.GetRFontArray(0).val);
            }

            if (pr.SizeOfSzArray() > 0)
            {
                int sz = (int)(pr.GetSzArray(0).val * 100);
                rPr.sz = (/*setter*/ sz);
            }

            if (pr.SizeOfColorArray() > 0)
            {
                CT_SolidColorFillProperties fill = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill();
                NPOI.OpenXmlFormats.Spreadsheet.CT_Color xlsColor = pr.GetColorArray(0);
                if (xlsColor.IsSetRgb())
                {
                    CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                    clr.val = (/*setter*/ xlsColor.rgb);
                }
                else if (xlsColor.IsSetIndexed())
                {
                    HSSFColor indexed = (HSSFColor)HSSFColor.GetIndexHash()[((int)xlsColor.indexed)];
                    if (indexed != null)
                    {
                        byte[] rgb = new byte[3];
                        rgb[0] = (byte)indexed.GetTriplet()[0];
                        rgb[1] = (byte)indexed.GetTriplet()[1];
                        rgb[2] = (byte)indexed.GetTriplet()[2];
                        CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                        clr.val = (/*setter*/ rgb);
                    }
                }
            }
        }
예제 #11
0
        private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr)
        {
            if (pr.sizeOfBArray() > 0)
            {
                rPr.b = pr.GetBArray(0).val;
            }
            if (pr.sizeOfUArray() > 0)
            {
                switch (pr.GetUArray(0).val)
                {
                case ST_UnderlineValues.none:
                    rPr.u = ST_TextUnderlineType.none;
                    break;

                case ST_UnderlineValues.single:
                    rPr.u = ST_TextUnderlineType.sng;
                    break;

                case ST_UnderlineValues.@double:
                    rPr.u = ST_TextUnderlineType.dbl;
                    break;
                }
            }
            if (pr.sizeOfIArray() > 0)
            {
                rPr.i = pr.GetIArray(0).val;
            }
            if (pr.sizeOfFamilyArray() > 0)
            {
                rPr.AddNewLatin().typeface = pr.GetRFontArray(0).val;
            }
            if (pr.sizeOfSzArray() > 0)
            {
                int num = (int)(pr.GetSzArray(0).val * 100.0);
                rPr.sz = num;
            }
            if (pr.sizeOfColorArray() <= 0)
            {
                return;
            }
            CT_SolidColorFillProperties colorFillProperties = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill();

            NPOI.OpenXmlFormats.Spreadsheet.CT_Color colorArray = pr.GetColorArray(0);
            if (colorArray.IsSetRgb())
            {
                (colorFillProperties.IsSetSrgbClr() ? colorFillProperties.srgbClr : colorFillProperties.AddNewSrgbClr()).val = colorArray.rgb;
            }
            else
            {
                if (!colorArray.IsSetIndexed())
                {
                    return;
                }
                HSSFColor hssfColor = HSSFColor.GetIndexHash()[(object)(int)colorArray.indexed] as HSSFColor;
                if (hssfColor == null)
                {
                    return;
                }
                byte[] numArray = new byte[3] {
                    (byte)hssfColor.GetTriplet()[0], (byte)hssfColor.GetTriplet()[1], (byte)hssfColor.GetTriplet()[2]
                };
                (colorFillProperties.IsSetSrgbClr() ? colorFillProperties.srgbClr : colorFillProperties.AddNewSrgbClr()).val = numArray;
            }
        }