Example #1
0
        public int ReadInteger(string section, string ident, int defaultValue)
        {
            string intStr = ReadString(section, ident, "");

            if (!string.IsNullOrEmpty(intStr))
            {
                if (intStr.Length > 2 && intStr[0] == '0' && (intStr[1] == 'X' || intStr[1] == 'x'))
                {
                    intStr = intStr.Substring(2);
                    return(Convert.ToInt32(intStr, 16));
                }
            }
            return(SysUtils.ParseInt(intStr, defaultValue));
        }
Example #2
0
        public void ParseText(List <BBTextChunk> chunksList, string text)
        {
            fChunks = chunksList;
            fChunks.Clear();

            float              lastFontSize = fDefaultFontSize;
            BBTextChunk        lastChunk    = null;
            Stack <SizeChange> stackSizes   = new Stack <SizeChange>();

            //lastChunk = SetChunkFontSize(0, lastChunk, fDefaultFontSize);

            if (string.IsNullOrEmpty(text))
            {
                text      = EMPTY_CHUNK;
                lastChunk = SetChunkText(0, lastChunk, text);
                return;
            }

            StringTokenizer strTok = new StringTokenizer(text);

            strTok.IgnoreWhiteSpace  = false;
            strTok.RecognizeDecimals = false;

            Token tok = strTok.Next();

            while (tok.Kind != TokenKind.EOF)
            {
                if (tok.Kind == TokenKind.Symbol && tok.Value == "[")
                {
                    string temp = tok.Value;
                    tok = strTok.Next();

                    bool closedTag;
                    if (tok.Kind == TokenKind.Symbol && tok.Value == "/")
                    {
                        closedTag = true;
                        temp     += tok.Value;
                        tok       = strTok.Next();
                    }
                    else
                    {
                        closedTag = false;
                    }

                    if (tok.Kind != TokenKind.Word)
                    {
                        // not tag
                        lastChunk = SetChunkText(tok.Line, lastChunk, temp + tok.Value);
                    }
                    else
                    {
                        string tag = tok.Value;
                        //bool skipTag = false;

                        if (tag == "color")
                        {
                            // [color="{red|#ff0000}"][/color]
                            IColor color = fTextColor;
                            if (!closedTag)
                            {
                                tok = strTok.Next();
                                if (tok.Kind == TokenKind.Symbol && tok.Value == "=")
                                {
                                    tok = strTok.Next();
                                    if (tok.Kind == TokenKind.Word)
                                    {
                                        color     = fGfxProvider.CreateColor(tok.Value);
                                        lastChunk = SetChunkColor(tok.Line, lastChunk, color);
                                    }
                                }
                            }
                            else
                            {
                                // TODO: colorStack
                                color     = fTextColor;
                                lastChunk = SetChunkColor(tok.Line, lastChunk, color);
                            }
                        }
                        else if (tag == "size")
                        {
                            // [size={+/-x}][/size]
                            if (!closedTag)
                            {
                                tok = strTok.Next();
                                if (tok.Kind == TokenKind.Symbol && tok.Value == "=")
                                {
                                    tok = strTok.Next();
                                    int factor = 0;
                                    if (tok.Kind == TokenKind.Symbol)
                                    {
                                        if (tok.Value == "+")
                                        {
                                            factor = +1;
                                        }
                                        else if (tok.Value == "-")
                                        {
                                            factor = -1;
                                        }
                                        tok = strTok.Next();
                                    }
                                    if (tok.Kind == TokenKind.Number)
                                    {
                                        float newSize = lastFontSize + factor * SysUtils.ParseInt(tok.Value, 0);
                                        stackSizes.Push(new SizeChange(lastFontSize, newSize));
                                        lastChunk    = SetChunkFontSize(tok.Line, lastChunk, newSize);
                                        lastFontSize = newSize;
                                    }
                                }
                            }
                            else
                            {
                                if (stackSizes.Count > 0)
                                {
                                    SizeChange sizeChange = stackSizes.Pop();
                                    lastChunk    = SetChunkFontSize(tok.Line, lastChunk, sizeChange.PrevSize);
                                    lastFontSize = sizeChange.PrevSize;
                                }
                            }
                        }
                        else if (tag == "b")
                        {
                            // [b][/b]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Bold, !closedTag);
                        }
                        else if (tag == "i")
                        {
                            // [i][/i]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Italic, !closedTag);
                        }
                        else if (tag == "s")
                        {
                            // [s][/s]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Strikeout, !closedTag);
                        }
                        else if (tag == "u")
                        {
                            // [u][/u]
                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Underline, !closedTag);
                        }
                        else if (tag == "url")
                        {
                            // bad impementation
                            // [url][/url] and [url=...][/url], but now only [url=...][/url]
                            string url = "";

                            tok = strTok.Next();
                            if (tok.Kind == TokenKind.Symbol && tok.Value == "=")
                            {
                                tok = strTok.Next();
                                do
                                {
                                    url += tok.Value;
                                    tok  = strTok.Next();
                                } while (tok.Kind != TokenKind.Symbol || tok.Value != "]");
                            }
                            else
                            {
                                //
                            }

                            lastChunk = SetChunkFontStyle(tok.Line, lastChunk, ExtFontStyle.Underline, !closedTag);
                            IColor color = (closedTag) ? fTextColor : fLinkColor;
                            lastChunk = SetChunkColor(tok.Line, lastChunk, color);
                            if (!closedTag)
                            {
                                lastChunk.URL = url;
                            }
                        }
                        else
                        {
                            // not tag
                            lastChunk = SetChunkText(tok.Line, lastChunk, temp + tok.Value);
                        }

                        if (tok.Kind != TokenKind.Symbol || tok.Value != "]")
                        {
                            // Possible syntax error?
                            strTok.Next();
                        }
                    }
                }
                else if (tok.Kind == TokenKind.EOL)
                {
                    lastChunk = SetChunkText(tok.Line, null, EMPTY_CHUNK);
                    lastChunk = null;
                }
                else
                {
                    lastChunk = SetChunkText(tok.Line, lastChunk, tok.Value);
                }

                tok = strTok.Next();
            }

            // eof
            lastChunk = SetChunkText(tok.Line, null, EMPTY_CHUNK);
        }