示例#1
0
文件: LineArea.cs 项目: nholik/Fo.Net
        private void addSpacedWord(string word, LinkSet ls, int startw,
                                   int spacew, TextState textState,
                                   bool addToPending)
        {
            /*
             * Split string based on four delimeters:
             * \u00A0 - Latin1 NBSP (Non breaking space)
             * \u202F - unknown reserved character according to Unicode Standard
             * \u3000 - CJK IDSP (Ideographic space)
             * \uFEFF - Arabic ZWN BSP (Zero width no break space)
             */
            StringTokenizer st = new StringTokenizer(word, "\u00A0\u202F\u3000\uFEFF", true);
            int extraw = 0;
            while (st.MoveNext())
            {
                string currentWord = (string)st.Current;

                if (currentWord.Length == 1
                    && (isNBSP(currentWord[0])))
                {
                    // Add an InlineSpace
                    int spaceWidth = getCharWidth(currentWord[0]);
                    if (spaceWidth > 0)
                    {
                        InlineSpace ispace = new InlineSpace(spaceWidth);
                        extraw += spaceWidth;
                        if (prevUlState)
                        {
                            ispace.setUnderlined(textState.getUnderlined());
                        }
                        if (prevOlState)
                        {
                            ispace.setOverlined(textState.getOverlined());
                        }
                        if (prevLTState)
                        {
                            ispace.setLineThrough(textState.getLineThrough());
                        }

                        if (addToPending)
                        {
                            pendingAreas.Add(ispace);
                            pendingWidth += spaceWidth;
                        }
                        else
                        {
                            addChild(ispace);
                        }
                    }
                }
                else
                {
                    WordArea ia = new WordArea(currentFontState, this.red,
                                               this.green, this.blue,
                                               currentWord,
                                               getWordWidth(currentWord));
                    ia.setYOffset(placementOffset);
                    ia.setUnderlined(textState.getUnderlined());
                    prevUlState = textState.getUnderlined();
                    ia.setOverlined(textState.getOverlined());
                    prevOlState = textState.getOverlined();
                    ia.setLineThrough(textState.getLineThrough());
                    prevLTState = textState.getLineThrough();
                    ia.setVerticalAlign(vAlign);

                    if (addToPending)
                    {
                        pendingAreas.Add(ia);
                        pendingWidth += getWordWidth(currentWord);
                    }
                    else
                    {
                        addChild(ia);
                    }
                    if (ls != null)
                    {
                        Rectangle lr = new Rectangle(startw + extraw, spacew,
                                                     ia.getContentWidth(),
                                                     fontState.FontSize);
                        ls.addRect(lr, this, ia);
                    }
                }
            }
        }
示例#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;
                        FonetDriver.ActiveDriver.FireFonetError(
                            "Unknown colour format. Must be #RGB or #RRGGBB");
                    }
                }
                catch (Exception)
                {
                    red = 0;
                    green = 0;
                    blue = 0;
                    FonetDriver.ActiveDriver.FireFonetError(
                        "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;
                        FonetDriver.ActiveDriver.FireFonetError(
                            "Unknown colour format. Must be #RGB or #RRGGBB");
                    }
                }

            }
            else if (colorValue.StartsWith("url("))
            {
                // refers to a gradient
                FonetDriver.ActiveDriver.FireFonetError(
                    "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;
                        FonetDriver.ActiveDriver.FireFonetWarning(
                            "Unknown colour name: " + colorValue + ".  Defaulting to black.");
                    }
                }
            }
        }