Ejemplo n.º 1
0
        private string FontLookup(string key)
        {
            string f = (string)triplets[key];

            if (f == null)
            {
                int    i = key.IndexOf(',');
                string s = "any" + key.Substring(i);
                f = (string)triplets[s];
                if (f == null)
                {
                    f = (string)triplets["any,normal,normal"];
                    if (f == null)
                    {
                        PdfCreatorBridge.Error("no default font defined by OutputConverter");
                    }
                    PdfCreatorBridge.Msg(
                        "Defaulted font to any,normal,normal");
                }
                PdfCreatorBridge.Warning(
                    "Unknown font " + key + " so defaulted font to any");
            }

            usedFonts[f] = fonts[f];
            return(f);
        }
Ejemplo n.º 2
0
        public ColorType(string value)
        {
            string colorValue = value.ToLower();

            if (colorValue.StartsWith("#"))
            {
                try
                {
                    if (colorValue.Length == 4)
                    {
                        // note: divide by 15 so F = FF = 1 and so on
                        red = Int32.Parse(
                            colorValue.Substring(1, 1), NumberStyles.HexNumber) / 15f;
                        green = Int32.Parse(
                            colorValue.Substring(2, 1), NumberStyles.HexNumber) / 15f;
                        blue = Int32.Parse(
                            colorValue.Substring(3, 1), NumberStyles.HexNumber) / 15f;
                    }
                    else if (colorValue.Length == 7)
                    {
                        // note: divide by 255 so FF = 1
                        red = Int32.Parse(
                            colorValue.Substring(1, 2), NumberStyles.HexNumber) / 255f;
                        green = Int32.Parse(
                            colorValue.Substring(3, 2), NumberStyles.HexNumber) / 255f;
                        blue = Int32.Parse(
                            colorValue.Substring(5, 2), NumberStyles.HexNumber) / 255f;
                    }
                    else
                    {
                        red   = 0;
                        green = 0;
                        blue  = 0;
                        PdfCreatorBridge.Error(
                            "Unknown colour format. Must be #RGB or #RRGGBB");
                    }
                }
                catch (Exception)
                {
                    red   = 0;
                    green = 0;
                    blue  = 0;
                    PdfCreatorBridge.Error(
                        "Unknown colour format. Must be #RGB or #RRGGBB");
                }
            }
            else if (colorValue.StartsWith("rgb("))
            {
                int poss = colorValue.IndexOf("(");
                int pose = colorValue.IndexOf(")");
                if (poss != -1 && pose != -1)
                {
                    colorValue = colorValue.Substring(poss + 1, pose);
                    StringTokenizer st = new StringTokenizer(colorValue, ",");
                    try
                    {
                        if (st.HasMoreTokens())
                        {
                            String str = st.NextToken().Trim();
                            if (str.EndsWith("%"))
                            {
                                this.Red =
                                    Int32.Parse(str.Substring(0, str.Length - 1))
                                    * 2.55f;
                            }
                            else
                            {
                                this.Red = Int32.Parse(str) / 255f;
                            }
                        }
                        if (st.HasMoreTokens())
                        {
                            String str = st.NextToken().Trim();
                            if (str.EndsWith("%"))
                            {
                                this.Green =
                                    Int32.Parse(str.Substring(0, str.Length - 1))
                                    * 2.55f;
                            }
                            else
                            {
                                this.Green = Int32.Parse(str) / 255f;
                            }
                        }
                        if (st.HasMoreTokens())
                        {
                            String str = st.NextToken().Trim();
                            if (str.EndsWith("%"))
                            {
                                this.Blue =
                                    Int32.Parse(str.Substring(0, str.Length - 1))
                                    * 2.55f;
                            }
                            else
                            {
                                this.Blue = Int32.Parse(str) / 255f;
                            }
                        }
                    }
                    catch
                    {
                        this.Red   = 0;
                        this.Green = 0;
                        this.Blue  = 0;
                        PdfCreatorBridge.Error(
                            "Unknown colour format. Must be #RGB or #RRGGBB");
                    }
                }
            }
            else if (colorValue.StartsWith("url("))
            {
                // refers to a gradient
                PdfCreatorBridge.Error(
                    "unsupported color format");
            }
            else
            {
                if (colorValue.Equals("transparent"))
                {
                    Red   = 0;
                    Green = 0;
                    Blue  = 0;
                    Alpha = 1;
                }
                else
                {
                    bool found = false;
                    for (int count = 0; count < names.Length; count++)
                    {
                        if (colorValue.Equals(names[count]))
                        {
                            Red   = vals[count, 0] / 255f;
                            Green = vals[count, 1] / 255f;
                            Blue  = vals[count, 2] / 255f;
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Red   = 0;
                        Green = 0;
                        Blue  = 0;
                        PdfCreatorBridge.Warning(
                            "Unknown colour name: " + colorValue + ".  Defaulting to black.");
                    }
                }
            }
        }